source: qtprobe/traits_probe.py @ 814

Last change on this file since 814 was 814, checked in by jemian, 11 years ago

now it's an eclipse/pydev project!!!

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Rev Url
File size: 2.0 KB
Line 
1#!/usr/bin/env python
2
3########### SVN repository information ###################
4# $Date: 2012-04-22 23:49:05 +0000 (Sun, 22 Apr 2012) $
5# $Author: jemian $
6# $Revision: 814 $
7# $URL$
8# $Id: traits_probe.py 814 2012-04-22 23:49:05Z jemian $
9########### SVN repository information ###################
10
11import argparse
12import epics
13import sys                  #@UnusedImport
14
15choose_Qt4 = True
16#choose_Qt4 = False
17from traits.etsconfig.api import ETSConfig
18if choose_Qt4:
19    ETSConfig.toolkit = 'qt4'
20else:
21    ETSConfig.toolkit = 'wx'
22
23from traits.api import *    #@UnusedWildImport
24from traitsui.api import *  #@UnusedWildImport
25
26from traitsui.key_bindings \
27    import KeyBinding, KeyBindings
28
29
30key_bindings = KeyBindings(
31    KeyBinding( binding1    = 'Enter',
32                description = 'Connect to new PV',
33                method_name = 'connect' ),
34)
35
36
37# TraitsUI Handler class for bound methods
38class CodeHandler ( Handler ):
39   
40    def connect ( self, info ):
41        if len(info.object.name) > 0:
42            try:
43                if info.object._chid is not None:
44                    info.object._chid.cancel_callback()
45                    info.object._chid.disconnect()
46            except:
47                pass
48            info.object._chid = epics.PV(str(info.object.name), 
49                                         callback=info.object.do_callback)
50
51
52class Probe( HasTraits ):
53    name = Str
54    value = Str
55    _chid = Instance( epics.PV, value = None )
56
57    def do_callback(self, value=None, **kwds):
58        "simple monitor callback"
59        self.value = str(value)
60
61    traits_view = View(
62        Item('name'),
63        Readonly('value'),
64        resizable=True,
65        width = 250,
66        title='Traits-based EPICS Probe',
67        key_bindings = key_bindings,
68        handler   = CodeHandler()
69    )
70
71if __name__ == '__main__':
72    #pv = ''
73    #if len(sys.argv) == 2:
74    #    pv = sys.argv[1]
75    parser = argparse.ArgumentParser(description="traits_probe")
76    parser.add_argument('pv', action='store', nargs='?', help="EPICS PV name", default="EpicsDemo1")
77    results = parser.parse_args()
78
79    probe = Probe(name=results.pv)
80    probe.configure_traits()
Note: See TracBrowser for help on using the repository browser.