source: moxy/trunk/src/moxy/wxlib/set.py @ 839

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

refactor

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