Changeset 730 for moxy/trunk/src/moxy/vc_pv.py
- Timestamp:
- Dec 20, 2011 4:14:28 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
moxy/trunk/src/moxy/vc_pv.py
r729 r730 29 29 30 30 __svnid__ = "$Id$" 31 COLOR_MOVING = wx.Colour(179, 250, 142) # pale green 32 COLOR_NOT_MOVING = wx.Colour(200, 191, 140) # not exactly background color 33 COLOR_PALE_PURPLE = wx.Colour(200, 200, 255) # my name for this 34 COLOR_LIGHTGREEN = wx.Colour(200, 255, 200) # my name for this 35 COLOR_LIGHTRED = wx.Colour(255, 200, 200) # my name for this 31 36 32 37 … … 35 40 36 41 class DemoView(wx.Frame): 42 ''' 43 Show an EPICS PV connection. 44 Allow it to connect and disconnect. 45 (This is like CA Probe.) 46 ''' 47 48 _cb_counter = 0 37 49 38 50 def __init__(self, pvname = ''): 39 51 self.pvname = pvname 52 self.value = '' 53 self.state = 'not connected' 54 self.remarks = '' 55 self.pv = None 56 40 57 wx.Frame.__init__(self, id=wx.ID_ANY, name=u'Frame1', 41 58 parent=None, title=u'PV Connection',) 42 #self.SetClientSize(wx.Size(7 32, 439))59 #self.SetClientSize(wx.Size(750, 440)) 43 60 self.SetToolTipString(u'PV Connection') 44 61 45 62 self._init_widgets() 46 self._init_sizers()47 63 48 64 def _init_widgets(self): 49 65 self.panel = wx.Panel(id=wx.ID_ANY, name='panel1', parent=self) 50 51 #self.sbTop = wx.StaticBox(id=wx.ID_ANY,52 # label=u'PV name and value', name='sbTop', parent=self.panel, size=wx.Size(300, 100),)53 #self.sbTop.SetToolTipString(u'PV name and value')54 55 #self.sbBottom = wx.StaticBox(id=wx.ID_ANY,56 # label='connection info', name='sbBottom', parent=self.panel, size=wx.Size(300, 100),)57 #self.sbBottom.SetToolTipString(u'EPICS connection info')58 59 self.genButton1 = wx.lib.buttons.GenButton(id=wx.ID_ANY,60 label=u'Connect', name='connectButton', parent=self.panel,)61 self.genButton1.SetToolTipString(u'Connect with EPICS PV')62 self.genButton1.Bind(wx.EVT_BUTTON, self.doConnectButton)63 64 self.genButton2 = wx.lib.buttons.GenButton(id=wx.ID_ANY,65 label=u'Disconnect', name='disconnectButton', parent=self.panel,)66 self.genButton2.SetToolTipString(u'Disconnect from EPICS PV')67 self.genButton2.Bind(wx.EVT_BUTTON, self.doDisconnectButton)68 69 # wx.StaticBoxSizer( wx.StaticBox( parent_window, id, "label" ), wx.HORIZONTAL )70 71 def _init_sizers(self):72 66 self.panelSizer = wx.BoxSizer(orient=wx.VERTICAL) 67 self.panelSizer.AddSizer(self._init_upper_part(self.panel), 1, border=0, flag=wx.EXPAND) 68 self.panelSizer.AddSizer(self._init_lower_part(self.panel), 1, border=0, flag=wx.EXPAND) 69 self.panelSizer.AddSizer(self._init_buttons(self.panel), 0, border=0, flag=wx.EXPAND) 73 70 self.panel.SetSizer(self.panelSizer) 74 #self.panelSizer.AddWindow(self.sbTop, proportion=1, border=0, flag=wx.EXPAND) 75 #self.panelSizer.AddWindow(self.sbBottom, proportion=1, border=0, flag=wx.EXPAND) 76 self.buttonSizer = wx.BoxSizer(orient=wx.HORIZONTAL) 77 self.panelSizer.AddSizer(self.buttonSizer, 0, border=0, flag=wx.EXPAND) 78 self.buttonSizer.AddWindow(self.genButton1, proportion=1, border=0, flag=wx.EXPAND) 79 self.buttonSizer.AddWindow(self.genButton2, proportion=1, border=0, flag=wx.EXPAND) 80 81 #self.sbTopSizer = wx.StaticBoxSizer(self.sbTop, wx.VERTICAL) 82 #self.sbBottomSizer = wx.StaticBoxSizer(self.sbBottom, wx.VERTICAL ) 83 84 def _example_(self, parent): 85 ''' 86 StaticBoxSizer example 87 88 create the control items, 89 defines self.motorList dictionary, 90 returns FlexGridSizer object 71 72 def _init_upper_part(self, parent): 73 ''' 74 edit the PV name string if not connected 91 75 ''' 92 76 sbox = wx.StaticBox(parent, id=wx.ID_ANY, 93 label=' watch EPICS motors', style=0)77 label='PV name and value', style=0) 94 78 sbs = wx.StaticBoxSizer(sbox, wx.VERTICAL) 95 fgs = wx.FlexGridSizer(rows=4, cols=3, hgap=4, vgap=4) 96 97 # column labels 98 for item in self.AXIS_LABELS: 99 fgs.Add( 100 wx.StaticText(parent, wx.ID_ANY, item), 101 0, flag=wx.EXPAND) 102 # one motor axis per row 103 self.motorList = {} 104 for axis in self.AXIS_NAMES: 105 fgs.Add( 106 wx.StaticText(parent, wx.ID_ANY, axis, style=wx.ALIGN_RIGHT), 107 0, flag=wx.EXPAND) 108 D = {} 109 for field in self.AXIS_FIELDS: 110 text = '[%s].%s' % (axis, field) 111 widget = wx.TextCtrl(parent, wx.ID_ANY, text, style=wx.TE_READONLY|wx.ALIGN_RIGHT) 112 widget.SetBackgroundColour(self.NOT_MOVING_COLOR) 113 widget.SetToolTipString("motor,%s,%s" % (axis, field)) 114 widget.SetFont(self.basicFont) 115 fgs.Add(widget, 0, flag=wx.EXPAND) 116 D[field] = widget 117 self.motorList[axis] = D 118 79 fgs = wx.FlexGridSizer(rows=2, cols=2, hgap=4, vgap=4) 119 80 fgs.AddGrowableCol(1) 120 fgs.AddGrowableCol(2)121 122 81 sbs.Add(fgs, 0, wx.EXPAND|wx.ALIGN_CENTRE|wx.ALL, 5) 123 82 83 self.w_pvname = wx.TextCtrl(parent=parent, id=wx.ID_ANY) 84 self.w_pvname.SetEditable(True) 85 self.w_value = wx.TextCtrl(parent=parent, id=wx.ID_ANY) 86 self.w_value.SetEditable(False) 87 88 self.SetPV(self.pvname) 89 self.SetValue(self.value) 90 91 fgs.Add(wx.StaticText(parent, wx.ID_ANY, 'one'), 0, flag=wx.EXPAND) 92 fgs.Add(self.w_pvname, 0, flag=wx.EXPAND) 93 fgs.Add(wx.StaticText(parent, wx.ID_ANY, 'three'), 0, flag=wx.EXPAND) 94 fgs.Add(self.w_value, 0, flag=wx.EXPAND) 95 124 96 return sbs 97 98 def _init_lower_part(self, parent): 99 ''' 100 show connection state and something else useful 101 ''' 102 sbox = wx.StaticBox(parent, id=wx.ID_ANY, 103 label='connection status', style=0) 104 sbs = wx.StaticBoxSizer(sbox, wx.VERTICAL) 105 fgs = wx.FlexGridSizer(rows=2, cols=1, hgap=4, vgap=4) 106 fgs.AddGrowableCol(0) 107 sbs.Add(fgs, 0, wx.EXPAND|wx.ALIGN_CENTRE|wx.ALL, 5) 108 109 self.w_state = wx.TextCtrl(parent=parent, id=wx.ID_ANY) 110 self.w_state.SetEditable(False) 111 self.w_remarks = wx.TextCtrl(parent=parent, id=wx.ID_ANY) 112 self.w_remarks.SetEditable(False) 113 114 self.SetState(self.state) 115 self.SetRemarks(self.remarks) 116 117 fgs.Add(self.w_state, 0, flag=wx.EXPAND) 118 fgs.Add(self.w_remarks, 0, flag=wx.EXPAND) 119 120 return sbs 121 122 def _init_buttons(self, parent): 123 ''' 124 build the buttons row and place it in a sizer, return the sizer 125 ''' 126 self.connectButton = self._my_button(parent, 127 label=u'Connect', name='connectButton', 128 tip=u'Connect with EPICS PV', 129 binding=self.doConnectButton) 130 self.disconnectButton = self._my_button(parent, 131 label=u'Disconnect', name='disconnectButton', 132 tip=u'Disconnect from EPICS PV', 133 binding=self.doDisconnectButton) 134 135 sizer = wx.BoxSizer(orient=wx.HORIZONTAL) 136 self.panelSizer.AddSizer(sizer, 0, border=0, flag=wx.EXPAND) 137 sizer.AddWindow(self.connectButton, proportion=1, border=0, flag=wx.EXPAND) 138 sizer.AddWindow(self.disconnectButton, proportion=1, border=0, flag=wx.EXPAND) 139 return sizer 140 141 def _my_button(self, parent, label, name, tip, binding): 142 ''' 143 Create a button and bind it to a method. 144 Return the button object 145 ''' 146 button = wx.lib.buttons.GenButton(id=wx.ID_ANY, 147 label=label, name=name, parent=parent,) 148 button.SetToolTipString(tip) 149 button.Bind(wx.EVT_BUTTON, binding) 150 return button 125 151 126 152 def doConnectButton(self, event): 127 153 event.Skip() 128 154 print "Connect button pressed" 155 self.w_pvname.SetEditable(False) 156 pvname = self.w_pvname.GetValue() 157 if len(pvname.strip()) > 0: 158 self.pvname = pvname 159 self.pv = PvConnection(pvname) 160 kw = {'vc_pv': True} 161 # TODO: we want a PV connection callback, as well 162 self.pv.connect(self.callback, **kw) 129 163 130 164 def doDisconnectButton(self, event): 131 165 event.Skip() 132 166 print "Disconnect button pressed" 133 167 self.w_pvname.SetEditable(True) 168 self.pv = None # throw away the PV connection 169 170 def SetPV(self, value): 171 self.pvname = str(value) 172 self.w_pvname.SetValue( self.pvname ) 173 174 def SetRemarks(self, value): 175 self.remarks = str(value) 176 self.w_remarks.SetValue( self.remarks ) 177 178 def SetState(self, value): 179 self.state = str(value) 180 self.w_state.SetValue( self.state ) 181 182 def SetValue(self, value): 183 self.value = str(value) 184 self.w_value.SetValue( self.value ) 185 186 def callback(self, **kw): 187 "generic monitor callback" 188 print kw 189 self.SetRemarks(kw['cb_info']) 190 self.SetValue(kw['value']) 191 self._cb_counter += 1 192 color = self.ColorSelector(self._cb_counter) 193 print self._cb_counter, color 194 self.w_value.SetBackgroundColour(color) 195 196 def ColorSelector(self, index): 197 clut = [ COLOR_NOT_MOVING, COLOR_MOVING, COLOR_PALE_PURPLE, COLOR_LIGHTGREEN, COLOR_LIGHTRED, ] 198 return clut[index % len(clut)] 199 134 200 135 201 # - - - - - - - - - - - - - - - - - - methods … … 142 208 app = wx.PySimpleApp() 143 209 frame = DemoView('Godzilla') 210 frame.SetPV('pj:test') 211 frame.SetValue( 'loves Tokyo' ) 212 frame.SetState( 'just started' ) 144 213 frame.Show() 145 214
Note: See TracChangeset
for help on using the changeset viewer.