source: qtprobe-demo/traits_probe.py @ 820

Last change on this file since 820 was 820, checked in by jemian, 10 years ago

final tweaks for presentation

  • 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.1 KB
Line 
1#!/usr/bin/env python
2
3########### SVN repository information ###################
4# $Date: 2012-04-24 16:33:35 +0000 (Tue, 24 Apr 2012) $
5# $Author: jemian $
6# $Revision: 820 $
7# $URL$
8# $Id: traits_probe.py 820 2012-04-24 16:33:35Z 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    KeyBinding( binding1    = 'Return',
35                description = 'Connect to new PV',
36                method_name = 'connect' ),
37)
38
39
40# TraitsUI Handler class for bound methods
41class CodeHandler ( Handler ):
42   
43    def connect ( self, info ):
44        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)
53
54
55class Probe( HasTraits ):
56    name = Str
57    value = Str
58    _chid = Instance( epics.PV, value = None )
59
60    def do_callback(self, value=None, **kwds):
61        "simple monitor callback"
62        self.value = str(value)
63
64    traits_view = View(
65        Item('name'),
66        Readonly('value'),
67        resizable=True,
68        width = 250,
69        title='Traits-based EPICS Probe',
70        key_bindings = key_bindings,
71        handler   = CodeHandler()
72    )
73
74if __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")
80    results = parser.parse_args()
81
82    probe = Probe(name=results.pv)
83    probe.configure_traits()
Note: See TracBrowser for help on using the repository browser.