Module SimulatedProcessParameter
[hide private]
[frames] | no frames]

Source Code for Module SimulatedProcessParameter

  1  # -*- coding: iso-8859-1 -*- 
  2   
  3  import Tkinter 
  4  import math 
  5   
  6  #: Global variable which stores a reference to an existing top-level window 
  7  _SingleInstance = None 
  8   
9 -def Open(process):
10 """Open as top-level window.""" 11 global _SingleInstance 12 if _SingleInstance is None: 13 _SingleInstance = Tkinter.Toplevel() 14 _SingleInstance.title("Simulated Process Parameters") 15 _SingleInstance.bind("<Destroy>", _set_None) 16 _Window(_SingleInstance,process) 17 else: 18 _SingleInstance.deiconify()
19
20 -def Close():
21 """Close top-level window.""" 22 global _SingleInstance 23 if _SingleInstance is not None: 24 _SingleInstance.destroy()
25
26 -def _set_None(e=None):
27 """If used as top-level window, this is called at "destroy" 28 and sets our global variable to None.""" 29 global _SingleInstance 30 _SingleInstance = None
31 32
33 -def AddAsSubwidget(root,process):
34 """Add the view as subwidget into root.""" 35 _Window(root,process)
36
37 -class _Window(object):
38 """Gives access to process parameters.""" 39
40 - def __init__(self,root,process):
41 self.process = process 42 self.root = root 43 44 row = 0 45 self.log_length = Tkinter.DoubleVar(0) 46 self.text_length = Tkinter.StringVar() 47 Tkinter.Label(self.root,text="length of pendulum").grid(row=row) 48 Tkinter.Scale(self.root,showvalue=0,orient=Tkinter.HORIZONTAL,from_=-1,to=1,resolution=0.1,variable=self.log_length).grid(row=row,column=1) 49 Tkinter.Label(self.root,text="xxx",textvariable=self.text_length).grid(row=row,column=2) 50 self.log_length.trace_variable('w',lambda name,index,mode: self.Length_Changed()) 51 52 row = 1 53 self.log_mass = Tkinter.DoubleVar(0) 54 self.text_mass = Tkinter.StringVar() 55 Tkinter.Label(self.root,text="mass of pendulum").grid(row=row) 56 Tkinter.Scale(self.root,showvalue=0,orient=Tkinter.HORIZONTAL,from_=0,to=2,resolution=0.1,variable=self.log_mass).grid(row=row,column=1) 57 Tkinter.Label(self.root,text="xxx",textvariable=self.text_mass).grid(row=row,column=2) 58 self.log_mass.trace_variable('w',lambda name,index,mode: self.Mass_Changed()) 59 60 row = 2 61 self.log_gain = Tkinter.DoubleVar(0) 62 self.text_gain = Tkinter.StringVar() 63 Tkinter.Label(self.root,text="gain for incoming acceleration value").grid(row=row) 64 Tkinter.Scale(self.root,showvalue=0,orient=Tkinter.HORIZONTAL,from_=-1,to=1,resolution=0.1,variable=self.log_gain).grid(row=row,column=1) 65 Tkinter.Label(self.root,text="xxx",textvariable=self.text_gain).grid(row=row,column=2) 66 self.log_gain.trace_variable('w',lambda name,index,mode: self.Gain_Changed()) 67 68 row = 3 69 self.log_disturbance = Tkinter.DoubleVar(0) 70 self.text_disturbance = Tkinter.StringVar() 71 Tkinter.Label(self.root,text="disturbance").grid(row=row) 72 Tkinter.Scale(self.root,showvalue=0,orient=Tkinter.HORIZONTAL,from_=-3,to=1,resolution=0.1,variable=self.log_disturbance).grid(row=row,column=1) 73 Tkinter.Label(self.root,text="xxx",textvariable=self.text_disturbance).grid(row=row,column=2) 74 self.log_disturbance.trace_variable('w',lambda name,index,mode: self.Disturbance_Changed()) 75 76 77 self.log_length.set(math.log10(process.l)) # length of pendulum [m] 78 self.log_mass.set(math.log10(process.m)) # mass of pendulum [kg] 79 80 #self.M_P = 0.1 # friction XXXX [kgm²/s²=Nm] 81 #self.a_W = 0.1 # friction of car expressed as acceleration [m/s²] 82 83 self.log_gain.set(math.log10(process.W)) # gain for incoming acceleration value 84 self.log_disturbance.set(math.log10(process.Z)) # disturbance 85 86 row = 4 87 Tkinter.Button(self.root,text="down",command=self.Down_Pressed).grid(row=row)
88 89
90 - def Length_Changed(self):
91 v = math.pow(10.0,self.log_length.get()) 92 #print v 93 self.process.l = v 94 self.text_length.set("%4.2f m" % v)
95
96 - def Mass_Changed(self):
97 v = math.pow(10.0,self.log_mass.get()) 98 #print v 99 self.process.m = v 100 self.text_mass.set("%4.2f kg" % v)
101
102 - def Gain_Changed(self):
103 v = math.pow(10.0,self.log_gain.get()) 104 #print v 105 self.process.W = v 106 self.text_gain.set("%4.2f" % v)
107
108 - def Disturbance_Changed(self):
109 v = math.pow(10.0,self.log_disturbance.get()) 110 #print v 111 self.process.Z = v 112 self.text_disturbance.set("%4.2f" % v)
113
114 - def Down_Pressed(self):
115 self.process.setStateValues({ 116 "X" :0., 117 "dX_dT" :0., 118 "Phi" :270., 119 "dPhi_dT": 0. 120 })
121