Changeset 741 for moxy


Ignore:
Timestamp:
Dec 24, 2011 12:07:31 AM (14 years ago)
Author:
jemian
Message:

SingleAxis? GUI works, needs a Configure dialog

Location:
moxy/trunk/src/moxy
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified moxy/trunk/src/moxy/m_pv.py

    r738 r741  
    2121import epics
    2222from threading import Thread
     23from time import sleep
    2324
    2425
     
    100101def waitmove(pv, position, seconds):
    101102    '''move this motor pv and wait for a fixed time'''
    102     from time import sleep
    103103    print "moving", pv, " to ", position
    104104    epics.caput(pv, position)
     
    119119    # now try a couple moves
    120120    waitmove(pv, position=5,   seconds=5)
     121    sleep(2.5)
    121122    waitmove(pv, position=1.1, seconds=5)
  • TabularUnified moxy/trunk/src/moxy/vc_axis.py

    r740 r741  
    3535COLOR_BACKGROUND = wx.Colour(237, 233, 227)     # boa-constructor uses this
    3636
     37COLOR_NOT_MOVING = COLOR_BACKGROUND     # slight revision
     38
    3739
    3840# - - - - - - - - - - - - - - - - - - classes
     
    6567    '''
    6668    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))
    6870        self.SetToolTipString(u'Single Axis DemoFrame')
    6971        self.panel = SingleAxisPanel(parent=self, axis=axis)
     
    7476    Show a single motion axis in a panel.
    7577    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):
    7984        self.axis = axis
    80         # self.axis.connect(ext_handler=None)
     85        self.connected = False
     86        self.show_buttons = show_buttons
     87
    8188        wx.Panel.__init__(self, id=wx.ID_ANY, parent=parent)
    8289        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()
    8595
    8696    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
    93106
    94107    def _init_upper(self, parent):
    95108        '''
    96         describe this axis
     109        describe this axis, return a sizer
    97110        '''
    98111        self.w_name = wx.TextCtrl(parent=parent, id=wx.ID_ANY)
    99112        self.w_name.SetEditable(True)
    100113        self.w_name.SetValue(self.axis.name)
    101        
    102         # TODO: get from desc PV when connected
     114        self.w_name.SetToolTipString(u'local name for this axis')
     115       
    103116        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       
    107119        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')
    109121
    110122        sbox = wx.StaticBox(parent, id=wx.ID_ANY,
     
    115127        sbs.Add(fgs, 0, wx.EXPAND|wx.ALIGN_CENTRE|wx.ALL, 5)
    116128
    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)
    120132
    121133        return sbs
     
    123135    def _init_lower(self, parent):
    124136        '''
    125         show readback and target values and connection state
     137        show readback and target values and connection state, return the sizer
    126138        '''
    127139        self.w_readback = wx.lib.stattext.GenStaticText(parent, wx.ID_ANY, 'readback')
     140        self.w_readback.SetToolTipString(u'readback value')
     141       
    128142        self.w_target = wx.TextCtrl(parent=parent, id=wx.ID_ANY)
    129143        self.w_target.SetEditable(False)
     144        self.w_target.SetToolTipString(u'target value')
     145       
    130146        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')
    135148       
    136149        sbox = wx.StaticBox(parent, id=wx.ID_ANY,
     
    141154        sbs.Add(fgs, 0, wx.EXPAND|wx.ALIGN_CENTRE|wx.ALL, 5)
    142155       
    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)
    146159
    147160        return sbs
    148161   
    149     def _init_buttons(self, parent):
     162    def _init_buttons1(self, parent):
    150163        '''
    151164        build the buttons row and place it in a sizer, return the sizer
     
    158171        self.stopButton.SetForegroundColour('yellow')
    159172
     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        '''
    160181        self.configureButton = self._my_button(parent,
    161182              label=u'Configure', name='configureButton',
     
    163184              binding=self.doConfigureButton)
    164185
     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
    165195        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)
    168199        return sizer
    169200       
     
    180211
    181212    def doStopButton(self, event):
    182         print "STOP pressed"    # TODO: unfinished
     213        '''stop this axis from moving'''
    183214        self.axis.stopMotion()
    184215
    185216    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
    190245
    191246    def SetVAL(self, value):
    192         print "set VAL"    # TODO: unfinished
    193         # self.SetWidgetValue(self.WIDGET, value)
     247        '''put the value into the widget text'''
     248        wx.CallAfter(self.w_target.SetValue, str(value) )
    194249
    195250    def SetRBV(self, value):
    196         print "set RBV"    # TODO: unfinished
    197         # self.SetWidgetValue(self.WIDGET, value)
     251        '''put the value into the widget text'''
     252        wx.CallAfter(self.w_readback.SetLabel, str(value) )
    198253
    199254    def SetEGU(self, value):
    200         print "set EGU"    # TODO: unfinished
    201         # self.SetWidgetValue(self.WIDGET, value)
     255        '''put the value into the widget text'''
     256        wx.CallAfter(self.w_egu.SetLabel, value)
    202257
    203258    def SetDESC(self, value):
    204         print "set DESC"    # TODO: unfinished
    205         # self.SetWidgetValue(self.WIDGET, value)
     259        '''put the value into the widget text'''
     260        wx.CallAfter(self.w_desc.SetLabel, value)
    206261
    207262    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'] )
    213297
    214298
  • TabularUnified moxy/trunk/src/moxy/vc_pv.py

    r738 r741  
    7171        upper = self._init_upper(self.panel)
    7272        lower = self._init_lower(self.panel)
    73         buttons = self._init_buttons(self.panel)
     73        buttons = self._init_buttons1(self.panel)
    7474       
    7575        sizer.AddSizer(upper, 1, flag=wx.EXPAND)
     
    128128        return sbs
    129129   
    130     def _init_buttons(self, parent):
     130    def _init_buttons1(self, parent):
    131131        '''
    132132        build the buttons row and place it in a sizer, return the sizer
Note: See TracChangeset for help on using the changeset viewer.