- Timestamp:
- Nov 30, 2011 6:04:49 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified moxy/trunk/src/test/gui.py ¶
r686 r687 23 23 24 24 import epics 25 import threading 25 26 26 27 from enthought.traits.api import HasTraits, String, List, Bool, Generic, \ 27 Float, Dict 28 Float, Dict, Color 28 29 from enthought.traits.ui.api import Item, UItem, UReadonly, View, StatusItem, \ 29 30 Action, Handler, VGrid, Label … … 36 37 37 38 38 class ActionHandler(Handler ):39 class ActionHandler(Handler, threading.Thread): 39 40 '''implements controls for PvMail GUI application''' 41 42 def __init__(self): 43 threading.Thread.__init__(self) 40 44 41 45 def _findGui(self, uinfo): … … 54 58 gui.SetStatus('pressed <Run>, starting CA monitors') 55 59 56 kw = {'gui': gui} 57 for name in ('prj:m1', 'prj:m2'): 58 for field in ('VAL', 'RBV'): 59 pvname = name+"."+field 60 if pvname not in channel: 61 channel[pvname] = ch = epics.PV(pvname) 62 callback_index[pvname] = ch.add_callback(self.ca_callback, **kw) 60 kw = {'gui': gui} # needed for processing in the callback 61 for axis in ('x', 'y'): 62 for field in ('VAL', 'RBV', 'DMOV'): 63 ref = gui.axes[axis][field] 64 pvname = ref['pvname'] 65 ref['channel'] = ch = epics.PV(pvname) 66 ref['cb_index'] = ch.add_callback(self.ca_callback, **kw) 67 gui.axes[pvname] = {'axis': axis, 'field': field} 68 if field == 'DMOV': 69 for editor in uinfo.ui._editors: 70 if editor.name == axis + "_VAL": 71 ref['VAL_editor'] = editor 72 if editor.name == axis + "_RBV": 73 ref['RBV_editor'] = editor 63 74 64 75 def do_stop(self, uinfo): … … 73 84 gui.SetStatus('pressed <Stop>') 74 85 75 for pvname in channel.keys(): 76 channel[pvname].remove_callback( callback_index[pvname] ) 77 del callback_index[pvname] 78 del channel[pvname] 86 for axis in ('x', 'y'): 87 for field in ('VAL', 'RBV', 'DMOV'): 88 ref = gui.axes[axis][field] 89 if ref['cb_index']: 90 ref['channel'].remove_callback( ref['cb_index'] ) 91 ref['cb_index'] = None 92 ref['channel'] = None 93 if field == 'DMOV': 94 ref['VAL_editor'] = None 95 ref['RBV_editor'] = None 79 96 80 97 def ca_callback(self, **kw): … … 83 100 ''' 84 101 pvname = kw['pvname'] 102 value = kw['value'] 85 103 gui = kw['gui'] 86 value = kw['value'] 87 88 if pvname == "prj:m1.VAL": 89 gui.x_VAL = value 90 elif pvname == "prj:m1.RBV": 91 gui.x_RBV = value 92 elif pvname == "prj:m2.VAL": 93 gui.y_VAL = value 94 elif pvname == "prj:m2.RBV": 95 gui.y_RBV = value 104 axis = gui.axes[pvname]['axis'] 105 field = gui.axes[pvname]['field'] 106 107 # can this be more efficient? 108 if axis == 'x': 109 if field == 'VAL': 110 gui.x_VAL = value 111 elif field == "RBV": 112 gui.x_RBV = value 113 elif field == "DMOV": 114 # set the background color based on moving status 115 self.setDmovColor(gui, axis, field, value) 116 elif axis == 'y': 117 if field == 'VAL': 118 gui.y_VAL = value 119 elif field == "RBV": 120 gui.y_RBV = value 121 elif field == "DMOV": 122 self.setDmovColor(gui, axis, field, value) 123 124 def setDmovColor(self, gui, axis, field, value): 125 ''' 126 set the background color of the VAL and RBV widgets based on DMOV 127 ''' 128 dmov_spec = gui.axes[axis][field] 129 for ed_field in ('VAL', 'RBV'): 130 editor = dmov_spec[ed_field + "_editor"] 131 #color_old = editor.control.GetBackgroundColour() 132 if value == 0: # moving 133 color_new = gui.pale_green 134 else: 135 if ed_field == 'VAL': 136 color_new = gui.val_default_color 137 elif ed_field == 'RBV': 138 color_new = gui.rbv_default_color 139 # This command crashes things! 140 #editor.control.SetBackgroundColour(color_new) 141 # TODO: how to set the color? 96 142 97 143 … … 106 152 y_VAL = Float 107 153 154 color_fmt = "#" + "%02x"*3 155 pale_green = Color((179, 250, 142)) 156 rbv_default_color = Color((220, 218, 213)) 157 val_default_color = Color((255, 255, 255)) 158 some_default_color = Color((200, 191, 140)) 159 boa_default_color = Color((237, 233, 227)) 160 161 trait_color = Color 162 163 axes = { 164 'x': { 165 'name': 'x', 166 'VAL': { 167 'pvname' : 'prj:m1.VAL', 168 'channel' : None, 169 'cb_index': None, 170 }, 171 'RBV': { 172 'pvname' : 'prj:m1.RBV', 173 'channel' : None, 174 'cb_index': None, 175 }, 176 'DMOV': { 177 'pvname' : 'prj:m1.DMOV', 178 'channel' : None, 179 'cb_index': None, 180 'VAL_editor': None, 181 'RBV_editor': None, 182 }, 183 }, 184 'y': { 185 'name': 'y', 186 'VAL': { 187 'pvname' : 'prj:m2.VAL', 188 'channel' : None, 189 'cb_index': None, 190 }, 191 'RBV': { 192 'pvname' : 'prj:m2.RBV', 193 'channel' : None, 194 'cb_index': None, 195 }, 196 'DMOV': { 197 'pvname' : 'prj:m2.DMOV', 198 'channel' : None, 199 'cb_index': None, 200 'VAL_editor': None, 201 'RBV_editor': None, 202 }, 203 }, 204 } 205 108 206 actionRun = Action(name = "Run", 109 207 desc = "start monitoring PVs", … … 117 215 monitors = [] # list of active CA monitors 118 216 217 vgrid = VGrid( 218 Label('field'), Label('X axis'), Label('Y axis'), 219 Label('readback (RBV)'), UReadonly('x_RBV'), UReadonly('y_RBV'), 220 Label('target (VAL)'), UItem('x_VAL'), UItem('y_VAL'), 221 columns = 3, 222 show_border=True, 223 ) 224 119 225 view = View( 120 VGrid( 121 Label('field'), 122 Label('X axis'), 123 Label('Y axis'), 124 Label('readback (RBV)'), 125 UReadonly('x_RBV'), 126 UReadonly('y_RBV'), 127 Label('target (VAL)'), 128 UItem('x_VAL'), 129 UItem('y_VAL'), 130 columns = 3, 131 show_border=True, 132 ), 226 vgrid, 133 227 title="moxy prototype GUI", 134 228 width=500,
Note: See TracChangeset
for help on using the changeset viewer.