1
2
3 import Tkinter
4
5
6 _SingleInstance = None
7
18
24
26 """If used as top-level window, this is called at "destroy"
27 and sets our global variable to None."""
28 global _SingleInstance
29 _SingleInstance = None
30
31
35
36
37 import math
38
40 """Shows current process state."""
41
42 _update_time = 50
43 _width = 3
44 _scale_x = 50
45 _scale_length = 50
46 _canvas_width = 530
47 _canvas_height = 400
48
50 self.system = system
51 self.root = root
52 self.canvas = Tkinter.Canvas(self.root,width=self._canvas_width,height=self._canvas_height)
53 l = self.system.process.l*self._scale_length
54 x = 0
55 y = 0
56 x_end = l*math.cos(math.pi/2.0)
57 y_end = l*math.sin(math.pi/2.0)
58 h = self._canvas_height
59 w = self._canvas_width
60 r = self._width
61 self.yzeroaxis = self.canvas.create_line((0,h/2,w,h/2),width=1)
62 self.xzeroaxis = self.canvas.create_line((w/2,0,w/2,h),width=1,fill="red")
63 self.pole = self.canvas.create_line((x,y,x_end,y_end),width=r*2.0,capstyle="round")
64 self.origin = self.canvas.create_oval((x-r,y-r,x+r,y+r),fill="white")
65 self.canvas.pack()
66
67 self.output = Tkinter.Text(self.root,width=80,height=1)
68 self.output.pack()
69 self.update()
70
72 """regularly called update of visualization."""
73
74 h = self._canvas_height
75 w = self._canvas_width
76 r = self._width
77
78
79 v = self.system.process.getStateValues()
80 x = v['X']*self._scale_x+w/2
81 phi = math.radians(v['Phi'])
82 l = self.system.process.l*self._scale_length
83
84
85
86 if x >= w:
87 self.canvas.coords(self.xzeroaxis,1,0,1,h)
88 elif x < 0:
89 self.canvas.coords(self.xzeroaxis,w-1,0,w-1,h)
90 else:
91 self.canvas.coords(self.xzeroaxis,w/2,0,w/2,h)
92
93
94 x = x % w
95 y = h/2
96 x_end = x+l*math.cos(phi)
97 y_end = y-l*math.sin(phi)
98 self.canvas.coords(self.pole,x,y,x_end,y_end)
99 self.canvas.coords(self.origin,x-r,y-r,x+r,y+r)
100
101
102 text = "Phi:%5.1f | dPhi_dT:%6.1f | X:%6.1f | dX_dT:%6.3f\n" % (v['Phi'],v['dPhi_dT'],v['X'],v['dX_dT'])
103 self.output.insert("1.0",text)
104 self.output.delete("2.0","3.0")
105
106
107 self.root.after(self._update_time,self.update)
108