- Timestamp:
- Dec 24, 2011 12:07:31 AM (14 years ago)
- Location:
- moxy/trunk/src/moxy
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified moxy/trunk/src/moxy/m_pv.py ¶
r738 r741 21 21 import epics 22 22 from threading import Thread 23 from time import sleep 23 24 24 25 … … 100 101 def waitmove(pv, position, seconds): 101 102 '''move this motor pv and wait for a fixed time''' 102 from time import sleep103 103 print "moving", pv, " to ", position 104 104 epics.caput(pv, position) … … 119 119 # now try a couple moves 120 120 waitmove(pv, position=5, seconds=5) 121 sleep(2.5) 121 122 waitmove(pv, position=1.1, seconds=5) -
TabularUnified moxy/trunk/src/moxy/vc_axis.py ¶
r740 r741 35 35 COLOR_BACKGROUND = wx.Colour(237, 233, 227) # boa-constructor uses this 36 36 37 COLOR_NOT_MOVING = COLOR_BACKGROUND # slight revision 38 37 39 38 40 # - - - - - - - - - - - - - - - - - - classes … … 65 67 ''' 66 68 def __init__(self, parent, axis): #@ReservedAssignment 67 wx.Frame.__init__(self, parent, wx.ID_ANY, 'DemoView' )69 wx.Frame.__init__(self, parent, wx.ID_ANY, 'DemoView', size=(200,300)) 68 70 self.SetToolTipString(u'Single Axis DemoFrame') 69 71 self.panel = SingleAxisPanel(parent=self, axis=axis) … … 74 76 Show a single motion axis in a panel. 75 77 The EPICS CA connections must be made here to get the callbacks. 76 ''' 77 78 def __init__(self, parent, axis): #@ReservedAssignment 78 79 The buttons (STOP, Configure, Connect, Disconnect) are optional 80 and can be suppressed by adding ``show_buttons = False`` 81 ''' 82 83 def __init__(self, parent, axis, show_buttons = True): 79 84 self.axis = axis 80 # self.axis.connect(ext_handler=None) 85 self.connected = False 86 self.show_buttons = show_buttons 87 81 88 wx.Panel.__init__(self, id=wx.ID_ANY, parent=parent) 82 89 self.SetToolTipString( self.axis.val.pvname ) 83 self._init_widgets(self) 84 self.axis.connect(ext_handler=None) # TODO: need a callback handler 90 91 self.SetSizer(self._init_widgets(self)) 92 93 self.SetStatus( 'initialized' ) 94 self.connect() 85 95 86 96 def _init_widgets(self, panel): 87 self.panelSizer = wx.BoxSizer(orient=wx.VERTICAL) 88 panel.SetSizer(self.panelSizer) 89 90 self.panelSizer.AddSizer(self._init_upper(panel), 0, flag=wx.EXPAND) 91 self.panelSizer.AddSizer(self._init_lower(panel), 0, flag=wx.EXPAND) 92 self.panelSizer.AddSizer(self._init_buttons(panel), 0, flag=wx.EXPAND) 97 '''create and layout all the widgets, return the sizer''' 98 sizer = wx.BoxSizer(orient=wx.VERTICAL) 99 100 sizer.AddSizer(self._init_upper(panel), 0, flag=wx.EXPAND) 101 sizer.AddSizer(self._init_lower(panel), 0, flag=wx.EXPAND) 102 if self.show_buttons: 103 sizer.AddSizer(self._init_buttons1(panel), 0, flag=wx.EXPAND) 104 sizer.AddSizer(self._init_buttons2(panel), 0, flag=wx.EXPAND) 105 return sizer 93 106 94 107 def _init_upper(self, parent): 95 108 ''' 96 describe this axis 109 describe this axis, return a sizer 97 110 ''' 98 111 self.w_name = wx.TextCtrl(parent=parent, id=wx.ID_ANY) 99 112 self.w_name.SetEditable(True) 100 113 self.w_name.SetValue(self.axis.name) 101 102 # TODO: get from desc PV when connected114 self.w_name.SetToolTipString(u'local name for this axis') 115 103 116 self.w_desc = wx.lib.stattext.GenStaticText(parent, wx.ID_ANY, 'description') 104 #self.w_desc.SetBackgroundColour( COLOR_BACKGROUND ) 105 106 # TODO: get from egu PV when connected 117 self.w_desc.SetToolTipString(u'EPICS description for this axis') 118 107 119 self.w_egu = wx.lib.stattext.GenStaticText(parent, wx.ID_ANY, 'units') 108 #self.w_egu.SetBackgroundColour( COLOR_BACKGROUND)120 self.w_egu.SetToolTipString(u'engineering units') 109 121 110 122 sbox = wx.StaticBox(parent, id=wx.ID_ANY, … … 115 127 sbs.Add(fgs, 0, wx.EXPAND|wx.ALIGN_CENTRE|wx.ALL, 5) 116 128 117 fgs.Add(self.w_name, flag=wx.EXPAND )118 fgs.Add(self.w_desc, flag=wx.EXPAND )119 fgs.Add(self.w_egu, flag=wx.EXPAND )129 fgs.Add(self.w_name, flag=wx.EXPAND|wx.GROW) 130 fgs.Add(self.w_desc, flag=wx.EXPAND|wx.GROW) 131 fgs.Add(self.w_egu, flag=wx.EXPAND|wx.GROW) 120 132 121 133 return sbs … … 123 135 def _init_lower(self, parent): 124 136 ''' 125 show readback and target values and connection state 137 show readback and target values and connection state, return the sizer 126 138 ''' 127 139 self.w_readback = wx.lib.stattext.GenStaticText(parent, wx.ID_ANY, 'readback') 140 self.w_readback.SetToolTipString(u'readback value') 141 128 142 self.w_target = wx.TextCtrl(parent=parent, id=wx.ID_ANY) 129 143 self.w_target.SetEditable(False) 144 self.w_target.SetToolTipString(u'target value') 145 130 146 self.w_status = wx.lib.stattext.GenStaticText(parent, wx.ID_ANY, 'status') 131 132 # TODO: unfinished 133 # self.SetState(self.state) 134 # self.SetRemarks(self.remarks) 147 self.w_status.SetToolTipString(u'EPICS connection status') 135 148 136 149 sbox = wx.StaticBox(parent, id=wx.ID_ANY, … … 141 154 sbs.Add(fgs, 0, wx.EXPAND|wx.ALIGN_CENTRE|wx.ALL, 5) 142 155 143 fgs.Add(self.w_readback, 0, flag=wx.EXPAND)144 fgs.Add(self.w_target, 0, flag=wx.EXPAND)145 fgs.Add(self.w_status, 0, flag=wx.EXPAND)156 fgs.Add(self.w_readback, flag=wx.EXPAND|wx.ALL) 157 fgs.Add(self.w_target, flag=wx.EXPAND|wx.ALL) 158 fgs.Add(self.w_status, flag=wx.EXPAND|wx.ALL) 146 159 147 160 return sbs 148 161 149 def _init_buttons (self, parent):162 def _init_buttons1(self, parent): 150 163 ''' 151 164 build the buttons row and place it in a sizer, return the sizer … … 158 171 self.stopButton.SetForegroundColour('yellow') 159 172 173 sizer = wx.BoxSizer(orient=wx.HORIZONTAL) 174 sizer.AddWindow(self.stopButton, proportion=1, flag=wx.EXPAND) 175 return sizer 176 177 def _init_buttons2(self, parent): 178 ''' 179 build the second buttons row and place it in a sizer, return the sizer 180 ''' 160 181 self.configureButton = self._my_button(parent, 161 182 label=u'Configure', name='configureButton', … … 163 184 binding=self.doConfigureButton) 164 185 186 self.connectButton = self._my_button(parent, 187 label=u'Connect', name='connectButton', 188 tip=u'Connect this axis with EPICS', 189 binding=self.doConnnectButton) 190 self.disconnectButton = self._my_button(parent, 191 label=u'Disconnect', name='disconnectButton', 192 tip=u'Disconnect this axis from EPICS', 193 binding=self.doDisconnnectButton) 194 165 195 sizer = wx.BoxSizer(orient=wx.HORIZONTAL) 166 sizer.AddWindow(self.stopButton, proportion=1, flag=wx.EXPAND) 167 sizer.AddWindow(self.configureButton, proportion=0, flag=wx.EXPAND) 196 sizer.AddWindow(self.configureButton, proportion=1, flag=wx.EXPAND) 197 sizer.AddWindow(self.connectButton, proportion=1, flag=wx.EXPAND) 198 sizer.AddWindow(self.disconnectButton, proportion=1, flag=wx.EXPAND) 168 199 return sizer 169 200 … … 180 211 181 212 def doStopButton(self, event): 182 print "STOP pressed" # TODO: unfinished213 '''stop this axis from moving''' 183 214 self.axis.stopMotion() 184 215 185 216 def doConfigureButton(self, event): 186 print "Configure pressed" # TODO: unfinished 187 188 def SetWidgetValue(self, widget, value): 189 wx.CallAfter(widget.SetValue, value) 217 '''run dialog to configure the EPICS PVs of this axis''' 218 print "Configure pressed - feature not enabled yet" # TODO: unfinished 219 220 def doConnnectButton(self, event): 221 '''user clicked button to connect''' 222 self.connect() 223 224 def doDisconnnectButton(self, event): 225 '''user clicked button to disconnect''' 226 self.disconnect() 227 228 def connect(self): 229 '''connect the PVs of this axis with EPICS''' 230 if not self.connected: 231 self.axis.connect(ext_handler=self.callback) 232 self.SetStatus( 'connected' ) 233 self.w_name.SetEditable(False) 234 self.w_target.SetEditable(True) 235 self.connected = True 236 237 def disconnect(self): 238 '''connect the PVs of this axis from EPICS''' 239 if self.connected: 240 self.axis.disconnect() 241 self.SetStatus( 'disconnected' ) 242 self.w_name.SetEditable(True) 243 self.w_target.SetEditable(False) 244 self.connected = False 190 245 191 246 def SetVAL(self, value): 192 print "set VAL" # TODO: unfinished193 # self.SetWidgetValue(self.WIDGET, value)247 '''put the value into the widget text''' 248 wx.CallAfter(self.w_target.SetValue, str(value) ) 194 249 195 250 def SetRBV(self, value): 196 print "set RBV" # TODO: unfinished197 # self.SetWidgetValue(self.WIDGET, value)251 '''put the value into the widget text''' 252 wx.CallAfter(self.w_readback.SetLabel, str(value) ) 198 253 199 254 def SetEGU(self, value): 200 print "set EGU" # TODO: unfinished201 # self.SetWidgetValue(self.WIDGET, value)255 '''put the value into the widget text''' 256 wx.CallAfter(self.w_egu.SetLabel, value) 202 257 203 258 def SetDESC(self, value): 204 print "set DESC" # TODO: unfinished205 # self.SetWidgetValue(self.WIDGET, value)259 '''put the value into the widget text''' 260 wx.CallAfter(self.w_desc.SetLabel, value) 206 261 207 262 def SetDMOV(self, value): 208 print "set DMOV" # TODO: unfinished 209 # change the color 210 #wx.CallAfter(self.WIDGET.SetBackgroundColour, value) 211 212 # TODO: unfinished 263 '''set the widget background color based on moving state''' 264 moving = not value 265 color = {False: COLOR_NOT_MOVING, True: COLOR_MOVING}[moving] 266 wx.CallAfter(self.w_target.SetBackgroundColour, color ) 267 wx.CallAfter(self.w_readback.SetBackgroundColour, color ) 268 269 def SetSTOP(self, value): 270 '''a no-op''' 271 pass 272 273 def SetStatus(self, value): 274 '''describe what's what''' 275 wx.CallAfter(self.w_status.SetLabel, value) 276 277 def callback(self, **kw): 278 "PyEPICS CA monitor callback" 279 #print kw 280 if 'conn' in kw.keys(): 281 print "connection event", kw 282 if kw['conn']: 283 self.SetStatus( 'connected event received' ) 284 else: 285 self.SetStatus( 'disconnect received, IOC is unavailable?' ) 286 else: 287 #print "PV update event" 288 if 'field' in kw: 289 #print kw['field'] 290 {'VAL': self.SetVAL, 291 'RBV': self.SetRBV, 292 'EGU': self.SetEGU, 293 'DESC': self.SetDESC, 294 'DMOV': self.SetDMOV, 295 'STOP': self.SetSTOP, 296 }[ kw['field'] ]( kw['value'] ) 213 297 214 298 -
TabularUnified moxy/trunk/src/moxy/vc_pv.py ¶
r738 r741 71 71 upper = self._init_upper(self.panel) 72 72 lower = self._init_lower(self.panel) 73 buttons = self._init_buttons (self.panel)73 buttons = self._init_buttons1(self.panel) 74 74 75 75 sizer.AddSizer(upper, 1, flag=wx.EXPAND) … … 128 128 return sbs 129 129 130 def _init_buttons (self, parent):130 def _init_buttons1(self, parent): 131 131 ''' 132 132 build the buttons row and place it in a sizer, return the sizer
Note: See TracChangeset
for help on using the changeset viewer.