source: moxy/trunk/src/test/test5.py @ 710

Last change on this file since 710 was 710, checked in by jemian, 14 years ago

a little progress with test7.py

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.8 KB
Line 
1#!/usr/bin/env python
2
3########### SVN repository information ###################
4# $Date: 2011-12-07 01:11:43 -0600 (Wed, 07 Dec 2011) $
5# $Author: jemian $
6# $Revision: 707 $
7# $URL: https://subversion.xor.aps.anl.gov/bcdaext/moxy/trunk/src/moxy/moxy.py $
8# $Id: moxy.py 707 2011-12-07 07:11:43Z jemian $
9########### SVN repository information ###################
10
11'''
12========================================
13want the axes_list to be tabbed
14========================================
15
16Built using the Traits library from the
17Enthought Python Distribution.
18
19Copyright (c) 2011, UChicago Argonne, LLC
20'''
21
22
23import os
24os.environ['UBUNTU_MENUPROXY'] = "1"    # work around a menubar bug in Ubuntu 11.04
25
26
27from traits.api import *        #@UnusedWildImport
28from traitsui.api import *      #@UnusedWildImport
29from traitsui.menu import *     #@UnusedWildImport
30
31__svnid__ = "$Id: moxy.py 707 2011-12-07 07:11:43Z jemian $"
32
33
34class TestClass(HasTraits):
35    name = Str
36    details = Str
37    number = Float(0.0)
38
39
40class MainGuiHandler ( Handler ):
41    """ Handler class to perform restructuring action when conditions are met.
42    """
43
44    def object_axes_list_changed ( self, info ):
45        print "object_axes_list_changed"
46        print info.object.display_group
47        #
48        # Build a Group in info.object.display_group that looks like this table
49        #
50        divider = "#"*10
51        for axis in info.object.axes_list:
52            divider += "   " + "#"*10
53        print divider
54        print "%10s" % "axis",
55        for axis in info.object.axes_list:
56            print %10s" % axis.name.strip(),
57        print
58        print divider
59        print "%10s" % "number",
60        for axis in info.object.axes_list:
61            print %10g" % axis.number,
62        print
63        print divider
64
65    def show_about(self, uinfo):
66        '''About this application ...'''
67        print """show this app's AboutBox() dialog ..."""
68
69
70class Moxy(HasTraits):
71    '''
72    move motor sets, typically (x,y) pairs, from
73    a table of user-defined positions
74    '''
75    axes_list = ListInstance(TestClass,
76                    help='Simple test class (replace with AxesSets).'
77                )
78   
79    axes_dict = DictStrList(value_trait = TestClass)
80    axes_dict = {}
81    for item in range(1, 5):
82        name = "example%d" % item
83        desc = 'this is example %d' % item
84        number = float(item)
85        axes_dict[name] = TestClass(name=name, details=desc, number=number)
86
87    axes_list = [axes_dict[item] for item in sorted(axes_dict)]
88   
89    display_group = Group(
90        UItem('axes_list', style='custom'),
91        show_border = True,
92        scrollable = True,
93    ),
94
95    status_label = Str('status:')
96    status_msg = Str
97   
98    WatchAction = Action(name = "Watch",
99                         desc = "start monitoring PVs",
100                         action = "do_watch")
101    IgnoreAction = Action(name = "Ignore",
102                          desc = "stop monitoring PVs",
103                          action = "undo_watch")
104    AboutAction = Action(name = 'About', desc='the big advert',
105                         action = 'show_about')
106    QuitAction = Action(name = 'Quit',
107                         action = '_on_close')
108
109    menubar = StandardMenuBar
110    menubar = MenuBar(
111        # File: New, Open, Close, -, Save, SaveAs, -, Import, Export, Preferences, -, Quit
112        Menu(Separator(), QuitAction, name='File'),   
113        # Edit: ?
114        Menu(UndoAction, RedoAction, name='Edit'),
115        # Page: Create, Delete, Change, -, EpicsConfig
116        Menu(name='Page'),
117        # Tab: Create, Delete, Change, -, Create Row
118        Menu(name='Tab'),
119        # Help: About, -, Help
120        Menu(HelpAction, Separator(), AboutAction, name='Help'),
121    )
122   
123    def reconstructDisplayGroup(self):
124        pass
125
126    def connect(self):
127        '''Connect all the axes sets with EPICS'''
128        for a_set in self.axes_list:
129            a_set.connect()
130
131    def disconnect(self):
132        '''Disconnect all the axes sets from EPICS'''
133        for a_set in self.axes_list:
134            a_set.disconnect()
135
136    view = View(
137                Tabbed('axes_list'),
138                display_group,
139                title="Moxy (development) GUI",
140                width=500,
141                height=300,
142                statusbar = [
143                   StatusItem(name = 'status_label', width = 80),
144                   StatusItem(name = 'status_msg', width = 0.5),
145                ],
146                handler = MainGuiHandler(),
147                resizable=True,
148                menubar = menubar,
149            )
150
151    def __init__(self, **kwtraits):
152        '''make this class callable from other applications'''
153        super(Moxy, self).__init__(**kwtraits)
154        self.SetStatus('Moxy has started')
155
156    def SetStatus(self, msg):
157        '''put text in the status box'''
158        self.status_msg = msg
159
160
161if __name__ == '__main__':
162    Moxy().configure_traits()
163    pass
Note: See TracBrowser for help on using the repository browser.