Changeset 856


Ignore:
Timestamp:
May 31, 2012 12:37:51 PM (10 years ago)
Author:
jemian
Message:

try to connect to PV on start, try to add PV name to GUI title bar on connection setup (not working yet)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • qtprobe-demo/traits_probe.py

    r820 r856  
    99########### SVN repository information ###################
    1010
     11'''
     12EPICS PvProbe built using Enthought Traits
     13
     14*pvProbe* is one of the simplest EPICS user GUI tools.
     15It is used to watch the value of an EPICS Process Variable.
     16
     17This version is based on the Enthought Traits user interface toolkit.
     18
     19USAGE::
     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
     33SEE ALSO:
     34
     35For more information about Python version of pvProbe, see
     36this presentation from the 2012 EPICS Collaboration Meeting:
     37https://subversion.xor.aps.anl.gov/bcdaext/qtprobe-demo/docs/build/html/index.html
     38
     39This code is the work entitled *traits_probe.py*.
     40'''
     41
     42__description__ = "EPICS Traits-based version of pvProbe"
     43
     44
    1145import argparse
    1246import epics
    1347import sys                  #@UnusedImport
    1448
     49
    1550choose_Qt4 = True
    16 #choose_Qt4 = False
     51choose_Qt4 = False
    1752from traits.etsconfig.api import ETSConfig
    1853if choose_Qt4:
     
    2358from traits.api import *    #@UnusedWildImport
    2459from traitsui.api import *  #@UnusedWildImport
    25 
    2660from traitsui.key_bindings \
    2761    import KeyBinding, KeyBindings
     
    3872
    3973
    40 # TraitsUI Handler class for bound methods
     74#
    4175class CodeHandler ( Handler ):
     76    '''TraitsUI Handler class for bound methods
     77    '''
    4278   
    4379    def connect ( self, info ):
     80        '''handle a request to connect with an EPICS PV
     81        '''
     82        info.object.do_connect()
    4483        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)
    5386
    5487
    5588class Probe( HasTraits ):
     89    '''EPICS PvProbe built using Enthought Traits
     90    '''
    5691    name = Str
    5792    value = Str
     
    5994
    6095    def do_callback(self, value=None, **kwds):
    61         "simple monitor callback"
     96        """simple monitor callback"""
    6297        self.value = str(value)
    6398
     
    67102        resizable=True,
    68103        width = 250,
    69         title='Traits-based EPICS Probe',
     104        title='pvProbe',
    70105        key_bindings = key_bindings,
    71106        handler   = CodeHandler()
    72107    )
     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
    73129
    74130if __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")
    80137    results = parser.parse_args()
    81138
Note: See TracChangeset for help on using the changeset viewer.