1 | #Boa:FramePanel:Row |
---|
2 | |
---|
3 | #************************************************************************* |
---|
4 | # Copyright (c) 2009-2010 The University of Chicago, as Operator of Argonne |
---|
5 | # National Laboratory. |
---|
6 | # Copyright (c) 2009-2010 The Regents of the University of California, as |
---|
7 | # Operator of Los Alamos National Laboratory. |
---|
8 | # This file is distributed subject to a Software License Agreement found |
---|
9 | # in the file LICENSE that is included with this distribution. |
---|
10 | #************************************************************************* |
---|
11 | |
---|
12 | ''' |
---|
13 | Define the GUI elements and interface for one row of the table |
---|
14 | |
---|
15 | @version: |
---|
16 | ########### SVN repository information ################### |
---|
17 | # $Date: 2011-09-09 17:12:01 +0000 (Fri, 09 Sep 2011) $ |
---|
18 | # $Author: jemian $ |
---|
19 | # $Revision: 631 $ |
---|
20 | # $URL: wxmtxy/trunk/src/moxy/row.py $ |
---|
21 | # $Id: row.py 631 2011-09-09 17:12:01Z jemian $ |
---|
22 | ########### SVN repository information ################### |
---|
23 | ''' |
---|
24 | |
---|
25 | import wx |
---|
26 | import inspect |
---|
27 | import os |
---|
28 | |
---|
29 | [wxID_ROW, wxID_ROWDELETE, wxID_ROWGO, wxID_ROWLABEL, wxID_ROWSET, wxID_ROWX, |
---|
30 | wxID_ROWY, |
---|
31 | ] = [wx.NewId() for _init_ctrls in range(7)] |
---|
32 | |
---|
33 | class Row(wx.Panel): |
---|
34 | '''One row of settings in a wxmtxy table''' |
---|
35 | |
---|
36 | def _init_coll_sizer_Items(self, parent): |
---|
37 | # generated method, don't edit |
---|
38 | |
---|
39 | parent.AddWindow(self.delete, 0, border=0, flag=0) |
---|
40 | parent.AddWindow(self.label, 0, border=0, flag=0) |
---|
41 | parent.AddWindow(self.set, 0, border=0, flag=0) |
---|
42 | parent.AddWindow(self.x, 0, border=0, flag=0) |
---|
43 | parent.AddWindow(self.y, 0, border=0, flag=0) |
---|
44 | parent.AddWindow(self.go, 0, border=0, flag=0) |
---|
45 | |
---|
46 | def _init_sizers(self): |
---|
47 | # generated method, don't edit |
---|
48 | self.sizer = wx.BoxSizer(orient=wx.HORIZONTAL) |
---|
49 | |
---|
50 | self._init_coll_sizer_Items(self.sizer) |
---|
51 | |
---|
52 | self.SetSizer(self.sizer) |
---|
53 | |
---|
54 | def _init_ctrls(self, prnt): |
---|
55 | # generated method, don't edit |
---|
56 | wx.Panel.__init__(self, id=wxID_ROW, name='Row', parent=prnt, |
---|
57 | pos=wx.Point(51, 84), size=wx.Size(312, 25), |
---|
58 | style=wx.TAB_TRAVERSAL) |
---|
59 | self.SetClientSize(wx.Size(312, 25)) |
---|
60 | self.SetMinSize(wx.Size(312, 25)) |
---|
61 | |
---|
62 | self.delete = wx.BitmapButton( |
---|
63 | id=wxID_ROWDELETE, name='delete', |
---|
64 | parent=self, pos=wx.Point(0, 0), size=wx.Size(24, 24), |
---|
65 | style=wx.BU_AUTODRAW) |
---|
66 | self.delete.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=wxID_ROWDELETE) |
---|
67 | self.delete.SetToolTipString(u'Delete this row') |
---|
68 | |
---|
69 | self.label = wx.TextCtrl(id=wxID_ROWLABEL, name='label', parent=self, |
---|
70 | pos=wx.Point(24, 0), size=wx.Size(80, 25), style=0, value='') |
---|
71 | self.label.SetMinSize(wx.Size(80, 25)) |
---|
72 | self.label.SetToolTipString(u'Description of this row') |
---|
73 | |
---|
74 | self.set = wx.BitmapButton( |
---|
75 | id=wxID_ROWSET, name='set', parent=self, |
---|
76 | pos=wx.Point(104, 0), size=wx.Size(24, 24), style=wx.BU_AUTODRAW) |
---|
77 | self.set.Bind(wx.EVT_BUTTON, self.OnSetButton, id=wxID_ROWSET) |
---|
78 | self.set.SetToolTipString(u'Copy current X,Y readback values to this row') |
---|
79 | |
---|
80 | self.x = wx.TextCtrl(id=wxID_ROWX, name='x', parent=self, |
---|
81 | pos=wx.Point(128, 0), size=wx.Size(80, 25), style=0, value='') |
---|
82 | self.x.SetMinSize(wx.Size(80, 25)) |
---|
83 | self.x.SetToolTipString(u'X axis target position') |
---|
84 | |
---|
85 | self.y = wx.TextCtrl(id=wxID_ROWY, name='y', parent=self, |
---|
86 | pos=wx.Point(208, 0), size=wx.Size(80, 25), style=0, value='') |
---|
87 | self.y.SetMinSize(wx.Size(80, 25)) |
---|
88 | self.y.SetToolTipString(u'Y axis target position') |
---|
89 | |
---|
90 | self.go = wx.BitmapButton( |
---|
91 | id=wxID_ROWGO, name='go', parent=self, |
---|
92 | pos=wx.Point(288, 0), size=wx.Size(24, 24), style=wx.BU_AUTODRAW) |
---|
93 | self.go.Bind(wx.EVT_BUTTON, self.OnGoButton, id=wxID_ROWGO) |
---|
94 | self.go.SetToolTipString(u'Command EPICS to move motors to this X,Y position') |
---|
95 | |
---|
96 | self._init_sizers() |
---|
97 | |
---|
98 | def __init__(self, tab, tabCallback): |
---|
99 | '''initialize the row |
---|
100 | @param tab: parent object (Tab object that owns this Row object) |
---|
101 | @param tabCallback: callback function that takes two arguments |
---|
102 | ''' |
---|
103 | # first, find the directory where this code is installed |
---|
104 | # so the bitmaps can be found |
---|
105 | # Note that this breaks edit ability of BoaConstructor |
---|
106 | root_dir = os.path.split(inspect.getsourcefile(Row))[0] |
---|
107 | self.bmp = {} |
---|
108 | for item in ['delete', 'set', 'go']: |
---|
109 | file = os.path.join(root_dir, 'graphics', item + '.bmp') |
---|
110 | self.bmp[item] = wx.Bitmap(file, wx.BITMAP_TYPE_BMP) |
---|
111 | self._init_ctrls(tab) |
---|
112 | self.delete.SetBitmapLabel(self.bmp['delete']) |
---|
113 | self.set.SetBitmapLabel(self.bmp['set']) |
---|
114 | self.go.SetBitmapLabel(self.bmp['go']) |
---|
115 | self.tab = tab |
---|
116 | self.tabCallback = tabCallback |
---|
117 | # sizes keep getting botched in Boa, fix them here |
---|
118 | self._fix_sizer(self.label, wx.GROW, 2) |
---|
119 | self._fix_sizer(self.x, wx.GROW, 1) |
---|
120 | self._fix_sizer(self.y, wx.GROW, 1) |
---|
121 | |
---|
122 | # ################################ |
---|
123 | # ## added methods ### |
---|
124 | # ################################ |
---|
125 | |
---|
126 | def _fix_sizer(self, widget, flag, proportion): |
---|
127 | '''sizes keep getting botched in Boa, fix them here |
---|
128 | @param widget: GUI object to be adjusted |
---|
129 | @param flag: usually wx.GROW |
---|
130 | @param proportion: [int]''' |
---|
131 | item = self.sizer.GetItem(widget) |
---|
132 | item.SetFlag(flag) |
---|
133 | item.SetProportion(proportion) |
---|
134 | |
---|
135 | def GetLabel(self): |
---|
136 | '''@return row label''' |
---|
137 | return self.label.GetValue() |
---|
138 | |
---|
139 | def SetLabel(self, text): |
---|
140 | '''Define the label |
---|
141 | @param text: [string] user description of this row''' |
---|
142 | self.label.SetValue(text) |
---|
143 | |
---|
144 | def GetXY(self): |
---|
145 | '''@return X, Y values as a tuple''' |
---|
146 | x = self.x.GetValue() |
---|
147 | y = self.y.GetValue() |
---|
148 | return x, y |
---|
149 | |
---|
150 | def SetXY(self, x, y): |
---|
151 | '''Define the values |
---|
152 | @param x: [float] X axis position to remember |
---|
153 | @param y: [float] Y axis position to remember''' |
---|
154 | self.x.SetValue(x) |
---|
155 | self.y.SetValue(y) |
---|
156 | |
---|
157 | def DeleteRow(self, parent): |
---|
158 | '''Tell parent to delete this row (may be tricky) |
---|
159 | @param parent: object of Tab that owns this Row''' |
---|
160 | self.tabCallback(self, 'delete') |
---|
161 | |
---|
162 | def SetPositions(self, parent): |
---|
163 | '''Tell parent to set positions on this row |
---|
164 | @param parent: object of Tab that owns this Row''' |
---|
165 | self.tabCallback(self, 'set') |
---|
166 | |
---|
167 | def Go(self, parent): |
---|
168 | '''Tell parent to move motors to this X,Y |
---|
169 | @param parent: object of Tab that owns this Row''' |
---|
170 | self.tabCallback(self, 'go') |
---|
171 | |
---|
172 | # ################################ |
---|
173 | # ## event handling routines ### |
---|
174 | # ################################ |
---|
175 | |
---|
176 | def OnDeleteButton(self, event): |
---|
177 | '''Delete button pressed |
---|
178 | @param event: wxPython event object''' |
---|
179 | self.DeleteRow(self.tab) |
---|
180 | |
---|
181 | def OnSetButton(self, event): |
---|
182 | '''Set button pressed |
---|
183 | @param event: wxPython event object''' |
---|
184 | self.SetPositions(self.tab) |
---|
185 | |
---|
186 | def OnGoButton(self, event): |
---|
187 | '''Go button pressed |
---|
188 | @param event: wxPython event object''' |
---|
189 | self.Go(self.tab) |
---|