source: moxy/trunk/src/moxy/vc_set.py @ 833

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

uniform use of _demo_() method

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision Url
File size: 3.8 KB
Line 
1#!/usr/bin/env python
2
3########### SVN repository information ###################
4# $Date: 2012-04-26 15:30:26 +0000 (Thu, 26 Apr 2012) $
5# $Author: jemian $
6# $Revision: 833 $
7# $URL$
8# $Id: vc_set.py 833 2012-04-26 15:30:26Z jemian $
9########### SVN repository information ###################
10
11'''
12demo view for EPICS PV connection class: m_set.AxesSet()
13
14Copyright (c) 2009 - 2011, UChicago Argonne, LLC.
15See LICENSE file for details.
16'''
17
18
19# - - - - - - - - - - - - - - - - - - Imports
20
21
22import wx                   #@UnusedImport
23import wx.lib.buttons       #@UnusedImport
24import wx.lib.stattext      #@UnusedImport
25import m_pv                 #@UnusedImport
26import m_axis
27import m_set
28import vc_axis
29
30
31# - - - - - - - - - - - - - - - - - - Global
32
33
34__svnid__ = "$Id: vc_set.py 833 2012-04-26 15:30:26Z jemian $"
35
36
37# - - - - - - - - - - - - - - - - - - classes
38
39
40class MultiAxisPanel(wx.Panel):
41    '''
42    Show a set of motion axes in a panel.
43    The EPICS CA connections must be made here to get the callbacks.
44   
45    Some buttons (Configure, Connect, Disconnect) are optional
46    and can be suppressed by adding  ``show_buttons = False``
47    '''
48    def __init__(self, parent, axis_set):
49        self.parent = parent
50        self.aset = axis_set
51
52        wx.Panel.__init__(self, id=wx.ID_ANY, parent=parent)
53        #self.SetToolTipString( "self" )
54       
55        self.panel = self._Make_Axes_Panel(self)
56       
57        sizer = wx.BoxSizer( orient=wx.VERTICAL )
58        sizer.AddSizer( self.panel, 1, flag=wx.EXPAND )
59        self.SetSizer( sizer )
60        self.Fit()
61   
62    def _Make_Axes_Panel(self, parent):
63        panel = wx.Panel( parent )
64       
65        self.members = []
66        for axis in self.aset.axes:
67            obj = vc_axis.SingleAxisPanel(panel, axis, show_buttons=True)
68            self.members.append( obj )
69       
70        sizer = wx.BoxSizer( orient=wx.HORIZONTAL )
71        panel.SetSizer( sizer )
72        for obj in self.members:
73            sizer.AddSizer(obj, 1, flag=wx.EXPAND)
74
75        panel.Fit()
76        return panel
77   
78    def connect(self):
79        for obj in self.members:
80            obj.connect()
81   
82    def disconnect(self):
83        for obj in self.members:
84            obj.disconnect()
85
86
87class DemoFrame(wx.Frame):
88    '''
89    Put the standard panel in a frame
90    '''
91    def __init__(self, parent, axis_set):
92        self.axis_set = axis_set
93        # frame cannot be maximized
94        style = wx.MINIMIZE_BOX | \
95                wx.SYSTEM_MENU | \
96                wx.CAPTION | \
97                wx.CLOSE_BOX | \
98                wx.CLIP_CHILDREN | \
99                wx.RESIZE_BORDER
100        wx.Frame.__init__(self, parent, wx.ID_ANY, 'DemoView', style=style)
101        self.SetSize( (150*len(axis_set.axes),350) )
102        self.SetToolTipString(u'Multiple Axis Set DemoFrame')
103        self.panel = MultiAxisPanel(parent=self, axis_set = axis_set)
104        self.Bind(wx.EVT_CLOSE, self.OnClose)
105        self.panel.connect()
106
107    def OnClose(self, event):
108        dlg = wx.MessageDialog(self, 
109            "Do you really want to close this application?",
110            "Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
111        result = wx.ID_OK               # development
112        #result = dlg.ShowModal()        # TODO: production
113        dlg.Destroy()
114        if result == wx.ID_OK:
115            self.axis_set.disconnect()
116            self.Destroy()
117
118
119# - - - - - - - - - - - - - - - - - - methods
120
121
122def _demo_():
123    '''demonstrate use of this module'''
124    config = [
125        {'name': "*X*", 'val': "prj:m1", 'isMotorRecord': True},
126        {'name': "*Y*", 'val': "prj:m2", 'isMotorRecord': True},
127        {'name': "*Z*", 'val': "prj:m3", 'isMotorRecord': True},
128    ]
129    axes = []
130    for item in config:
131        axes.append( m_axis.SingleAxis(**item) )
132    aset = m_set.AxesSet( name = 'test XYZ axis set', axes = axes )
133    aset.connect()
134    #aset.report()
135
136    app = wx.App()
137    DemoFrame( None, aset ).Show()
138    app.MainLoop()
139
140
141# - - - - - - - - - - - - - - - - - - main
142
143
144if __name__ == '__main__':
145    _demo_()
Note: See TracBrowser for help on using the repository browser.