Changeset 856
- Timestamp:
- May 31, 2012 12:37:51 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
qtprobe-demo/traits_probe.py
r820 r856 9 9 ########### SVN repository information ################### 10 10 11 ''' 12 EPICS PvProbe built using Enthought Traits 13 14 *pvProbe* is one of the simplest EPICS user GUI tools. 15 It is used to watch the value of an EPICS Process Variable. 16 17 This version is based on the Enthought Traits user interface toolkit. 18 19 USAGE:: 20 21 [jemian@gov]$ ./pvProbe.py -h 22 usage: pvProbe.py [-h] [pv] 23 24 pvProbe: EPICS Traits-based version of Probe 25 26 positional arguments: 27 pv EPICS PV name 28 29 optional arguments: 30 -h, --help show this help message and exit 31 32 33 SEE ALSO: 34 35 For more information about Python version of pvProbe, see 36 this presentation from the 2012 EPICS Collaboration Meeting: 37 https://subversion.xor.aps.anl.gov/bcdaext/qtprobe-demo/docs/build/html/index.html 38 39 This code is the work entitled *traits_probe.py*. 40 ''' 41 42 __description__ = "EPICS Traits-based version of pvProbe" 43 44 11 45 import argparse 12 46 import epics 13 47 import sys #@UnusedImport 14 48 49 15 50 choose_Qt4 = True 16 #choose_Qt4 = False51 choose_Qt4 = False 17 52 from traits.etsconfig.api import ETSConfig 18 53 if choose_Qt4: … … 23 58 from traits.api import * #@UnusedWildImport 24 59 from traitsui.api import * #@UnusedWildImport 25 26 60 from traitsui.key_bindings \ 27 61 import KeyBinding, KeyBindings … … 38 72 39 73 40 # TraitsUI Handler class for bound methods74 # 41 75 class CodeHandler ( Handler ): 76 '''TraitsUI Handler class for bound methods 77 ''' 42 78 43 79 def connect ( self, info ): 80 '''handle a request to connect with an EPICS PV 81 ''' 82 info.object.do_connect() 44 83 if len(info.object.name) > 0: 45 try: 46 if info.object._chid is not None: 47 info.object._chid.cancel_callback() 48 info.object._chid.disconnect() 49 except: 50 pass 51 info.object._chid = epics.PV(str(info.object.name), 52 callback=info.object.do_callback) 84 # FIXME: This is not working 85 info.object.title = "pvProbe: " + str(info.object.name) 53 86 54 87 55 88 class Probe( HasTraits ): 89 '''EPICS PvProbe built using Enthought Traits 90 ''' 56 91 name = Str 57 92 value = Str … … 59 94 60 95 def do_callback(self, value=None, **kwds): 61 " simple monitor callback"96 """simple monitor callback""" 62 97 self.value = str(value) 63 98 … … 67 102 resizable=True, 68 103 width = 250, 69 title=' Traits-based EPICSProbe',104 title='pvProbe', 70 105 key_bindings = key_bindings, 71 106 handler = CodeHandler() 72 107 ) 108 109 def do_connect(self): 110 '''connect this GUI with an EPICS Process Variable 111 and set up a Channel Access monitor to update ``value`` 112 whenever the PV changes. 113 ''' 114 if len(self.name) > 0: 115 try: 116 if self._chid is not None: 117 self._chid.cancel_callback() 118 self._chid.disconnect() 119 except: 120 pass 121 self._chid = epics.PV(str(self.name), 122 callback=self.do_callback) 123 124 def __init__(self, name=""): 125 HasTraits.__init__(self) 126 self.name = name 127 self.do_connect() 128 73 129 74 130 if __name__ == '__main__': 75 #pv = '' 76 #if len(sys.argv) == 2: 77 # pv = sys.argv[1] 78 parser = argparse.ArgumentParser(description="traits_probe") 79 parser.add_argument('pv', action='store', nargs='?', help="EPICS PV name", default="EpicsDemo1") 131 parser = argparse.ArgumentParser(description=__description__) 132 parser.add_argument('pv', 133 action='store', 134 nargs='?', 135 help="EPICS PV name", 136 default="EpicsDemo1") 80 137 results = parser.parse_args() 81 138
Note: See TracChangeset
for help on using the changeset viewer.