1+ import TKinterModernThemes as TKMT
2+ from matplotlib .axes ._axes import Axes
3+ from matplotlib .figure import Figure
4+ import time
5+ import numpy as np
6+ import random
7+
8+
9+ DO_COUNT = 5
10+
11+
12+ sample_autoseq = [
13+ {"Time" : 0 , "DO" : "DO_1" , "State" : "On" },
14+ {"Time" : 0.5 , "DO" : "DO_2" , "State" : "On" },
15+ {"Time" : 2 , "DO" : "DO_1" , "State" : "Off" }
16+ ]
17+
18+ class TKGraph :
19+ def __init__ (self , canvas , fig : Figure , ax : Axes , backgroundcolor : str , accentcolor : str , labels ):
20+ self .canvas = canvas
21+ self .fig = fig
22+ self .ax = ax
23+ self .backgroundcolor = backgroundcolor
24+ self .accentcolor = accentcolor
25+ self .labels = labels
26+
27+ self .xs = []
28+ self .points_1 = []
29+ self .points_2 = []
30+ self .last_x = 0
31+ self .last_y_1 = 50
32+ self .last_y_2 = 30
33+
34+ self .scatter1 = ax .scatter ([], [], c = self .accentcolor )
35+ self .scatter2 = ax .scatter ([], [], c = 'blue' )
36+ ax .axhline (y = 70 , color = 'r' , linestyle = '--' , label = 'redline' )
37+ self .ax .set_xlabel ("Time" )
38+ self .ax .set_ylim (0 , 100 )
39+ self .fig .legend (self .labels )
40+
41+
42+ def update (self ):
43+ self .xs .append (self .last_x )
44+ self .points_1 .append (self .last_y_1 )
45+ self .points_2 .append (self .last_y_2 )
46+ self .last_x += 1
47+ self .last_y_1 += (random .random () * 5 ) - 2.4
48+ self .last_y_2 += (random .random () * 5 ) - 2.4
49+
50+ self .xs = self .xs [- 20 :]
51+ self .points_1 = self .points_1 [- 20 :]
52+ self .points_2 = self .points_2 [- 20 :]
53+
54+ self .scatter1 .set_offsets (np .c_ [self .xs , self .points_1 ])
55+ self .scatter2 .set_offsets (np .c_ [self .xs , self .points_2 ])
56+ self .ax .set_xlim (self .last_x - 20 , self .last_x )
57+
58+ self .canvas .draw ()
59+
60+
61+ class App (TKMT .ThemedTKinterFrame ):
62+ def __init__ (self ):
63+ super ().__init__ ("Igniter DAQ" )
64+ self .root .tk .call ("source" , 'cust_ui.tcl' )
65+ #self.root.attributes("-fullscreen", True)
66+
67+ self .control_frame = self .addLabelFrame ("Control" )
68+ self .control_frame .Button ("START" , None , style = TKMT .ThemeStyles .ButtonStyles .AccentButton )
69+ self .control_frame .Button ("ABORT" , None , style = 'Red_' + TKMT .ThemeStyles .ButtonStyles .AccentButton , col = 1 )
70+ self .control_frame .Treeview (['Time' , 'DO' , 'State' ], [50 , 50 , 50 ], 10 , sample_autoseq , '' , colspan = 2 )
71+
72+ self .do_frame = self .control_frame .addFrame ("do frame" , colspan = 2 , padx = (0 ,0 ), pady = (0 ,0 ))
73+ for do_num in range (DO_COUNT ):
74+ self .do_frame .ToggleButton (f"DO_{ do_num } " , None , col = do_num )
75+
76+ self .serial_frame = self .control_frame .addLabelFrame ("Serial Command Interface" , colspan = 2 , padx = (5 ,5 ), pady = (5 ,5 ))
77+ self .serial_frame .Entry (None , widgetkwargs = {'width' : 50 })
78+ self .serial_frame .AccentButton ("Send" , None , col = 1 )
79+
80+ self .nextCol ()
81+ self .data_frame = self .addLabelFrame ("Data" )
82+ self .graph_1 = TKGraph (* self .data_frame .matplotlibFrame ("Graph 1" , figsize = (4 ,2.5 ), toolbar = False , padx = 0 , pady = 0 ), ['PT0' , 'PT1' ])
83+ self .graph_2 = TKGraph (* self .data_frame .matplotlibFrame ("Graph 2" , figsize = (4 ,2.5 ), toolbar = False , padx = 0 , pady = 0 ), ['PT2' , 'PT3' ])
84+ self .graph_3 = TKGraph (* self .data_frame .matplotlibFrame ("Graph 3" , figsize = (4 ,2.5 ), toolbar = False , padx = 0 , pady = 0 ), ['TC_LOX' , 'TC_IPA' ])
85+
86+ self .root .after (500 , self .periodic )
87+ #self.root.after(2000, self.fullscreen)
88+
89+ self .debugPrint ()
90+ self .run (onlyFrames = False )
91+
92+ def periodic (self ):
93+ s = time .time ()
94+ self .graph_1 .update ()
95+ self .graph_2 .update ()
96+ self .graph_3 .update ()
97+ print ('e' , time .time () - s )
98+ self .root .after (100 , self .periodic ) #Call every 0.1 seconds to keep UI updated
99+
100+ def fullscreen (self ):
101+ self .root .attributes ("-fullscreen" , True )
102+
103+
104+
105+ if __name__ == '__main__' :
106+ app = App ()
0 commit comments