-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwxmtusaxs_row.py
executable file
·353 lines (309 loc) · 13.4 KB
/
wxmtusaxs_row.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#Boa:FramePanel:Row
#*************************************************************************
# Copyright (c) 2009-2010 The University of Chicago, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2009-2010 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# This file is distributed subject to a Software License Agreement found
# in the file LICENSE that is included with this distribution.
#*************************************************************************
'''
Define the GUI elements and interface for one row of the table
@version:
########### SVN repository information ###################
# $Date: 2014-05-24 16:40:34 -0500 (Sat, 24 May 2014) $
# $Author: jemian $
# $Revision: 1017 $
# $URL: https://subversion.xray.aps.anl.gov/small_angle/USAXS/wxmtusaxs/trunk/wxmtusaxs_row.py $
# $Id: wxmtusaxs_row.py 1017 2014-05-24 21:40:34Z jemian $
########### SVN repository information ###################
'''
import wx
import inspect
import os
from wxmtusaxs_properties import USAXSproperties
import re
import pickle
[wxID_ROW, wxID_ROWDELETE, wxID_ROWGO, wxID_ROWLABEL, wxID_ROWSET, wxID_ROWX,
wxID_ROWY, wxID_ROWTHICKNESS, wxID_ROWADVANCED,
] = [wx.NewId() for _init_ctrls in range(9)]
class Row(wx.Panel):
'''One row of settings in a wxmtusaxs table'''
_custom_classes = {'wx.Dialog': ['USAXSproperties']}
def _init_coll_sizer_Items(self, parent):
# generated method, don't edit
parent.AddWindow(self.delete, 0, border=0, flag=0)
parent.AddWindow(self.label, 0, border=0, flag=0)
parent.AddWindow(self.set, 0, border=0, flag=0)
parent.AddWindow(self.x, 0, border=0, flag=0)
parent.AddWindow(self.y, 0, border=0, flag=0)
parent.AddWindow(self.go, 0, border=0, flag=0)
parent.AddWindow(self.thickness, 0, border=0, flag=0)
parent.AddWindow(self.advanced, 0, border=0, flag=0)
def _init_sizers(self):
# generated method, don't edit
self.sizer = wx.BoxSizer(orient=wx.HORIZONTAL)
self._init_coll_sizer_Items(self.sizer)
self.SetSizer(self.sizer)
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Panel.__init__(self, id=wxID_ROW, name='Row', parent=prnt,
pos=wx.Point(51, 84), size=wx.Size(312, 25),
style=wx.TAB_TRAVERSAL)
self.SetClientSize(wx.Size(312, 25))
self.SetMinSize(wx.Size(312, 25))
self.delete = wx.BitmapButton(
id=wxID_ROWDELETE, name='delete',
parent=self, pos=wx.Point(0, 0), size=wx.Size(24, 24),
style=wx.BU_AUTODRAW)
self.delete.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=wxID_ROWDELETE)
self.delete.SetToolTipString(u'delete this sample')
self.label = wx.TextCtrl(id=wxID_ROWLABEL, name='label', parent=self,
pos=wx.Point(24, 0), size=wx.Size(80, 25), style=0, value='')
self.label.SetMinSize(wx.Size(80, 25))
self.label.SetToolTipString(u'description of this sample')
self.set = wx.BitmapButton(
id=wxID_ROWSET, name='set', parent=self,
pos=wx.Point(104, 0), size=wx.Size(24, 24), style=wx.BU_AUTODRAW)
self.set.Bind(wx.EVT_BUTTON, self.OnSetButton, id=wxID_ROWSET)
self.set.SetToolTipString(u'save current x,y values in this row')
self.x = wx.TextCtrl(id=wxID_ROWX, name='x', parent=self,
pos=wx.Point(128, 0), size=wx.Size(80, 25), style=0, value='')
self.x.SetMinSize(wx.Size(80, 25))
self.x.SetToolTipString(u'x position of sample')
self.y = wx.TextCtrl(id=wxID_ROWY, name='y', parent=self,
pos=wx.Point(208, 0), size=wx.Size(80, 25), style=0, value='')
self.y.SetMinSize(wx.Size(80, 25))
self.y.SetToolTipString(u'y position of sample')
self.go = wx.BitmapButton(
id=wxID_ROWGO, name='go', parent=self,
pos=wx.Point(288, 0), size=wx.Size(24, 24), style=wx.BU_AUTODRAW)
self.go.Bind(wx.EVT_BUTTON, self.OnGoButton, id=wxID_ROWGO)
self.go.SetToolTipString(u'drive to this sample')
self.thickness = wx.TextCtrl(id=wxID_ROWTHICKNESS, name='thickness', parent=self,
pos=wx.Point(220, 0), size=wx.Size(80, 25), style=0, value='')
self.thickness.SetMinSize(wx.Size(80, 25))
self.thickness.SetToolTipString(u'sample thickness')
self.advanced = wx.Button(
id=wxID_ROWADVANCED, name='more', label='more', parent=self,
pos=wx.Point(300, 0), size=wx.Size(50, 24), style=wx.BU_AUTODRAW)
self.advanced.Bind(wx.EVT_BUTTON, self.OnAdvancedButton, id=wxID_ROWADVANCED)
self.advanced.SetToolTipString(u'Set Additional Parameters')
self._init_sizers()
def __init__(self, tab, tabCallback):
'''initialize the row
@param tab: parent object (Tab object that owns this Row object)
@param tabCallback: callback function that takes two arguments
'''
# first, find the directory where this code is installed
# so the bitmaps can be found
# Note that this breaks edit ability of BoaConstructor
root_dir = os.path.split(inspect.getsourcefile(Row))[0]
self.bmp = {}
for item in ['delete', 'set', 'go']:
file = os.path.join(root_dir, 'graphics', item + '.bmp')
self.bmp[item] = wx.Bitmap(file, wx.BITMAP_TYPE_BMP)
self._init_ctrls(tab)
self.delete.SetBitmapLabel(self.bmp['delete'])
self.set.SetBitmapLabel(self.bmp['set'])
self.go.SetBitmapLabel(self.bmp['go'])
self.tab = tab
self.tabCallback = tabCallback
# sizes keep getting botched in Boa, fix them here
self._fix_sizer(self.label, wx.GROW, 2)
self._fix_sizer(self.x, wx.GROW, 1)
self._fix_sizer(self.y, wx.GROW, 1)
self._fix_sizer(self.thickness, wx.GROW, 1)
self.doUSAXS = True
#josh add
self.doFUSAXS = True
#
self.CHG_NPTS = False
self.NPTS = "0"
self.CHG_CTIME = False
self.CTIME = "0"
self.CHG_QMAX = False
self.QMAX = "0"
self.doPinhole = True
self.CHG_EXPTIME = False
self.EXPTIME = "0"
self.CHG_NOEXP = False
self.NOEXP = "0"
self.doWAXS = True
self.CHG_WEXPTIME = False
self.WEXPTIME = "0"
self.CHG_WNOEXP = False
self.WNOEXP = "0"
# ################################
# ## added methods ###
# ################################
def _fix_sizer(self, widget, flag, proportion):
'''sizes keep getting botched in Boa, fix them here
@param widget: GUI object to be adjusted
@param flag: usually wx.GROW
@param proportion: [int]'''
item = self.sizer.GetItem(widget)
item.SetFlag(flag)
item.SetProportion(proportion)
def GetLabel(self):
'''@return row label'''
return self.label.GetValue()
def SetLabel(self, text):
'''Define the label
@param text: [string] user description of this row'''
self.label.SetValue(text)
def GetXY(self):
'''@return X, Y values as a tuple'''
x = self.x.GetValue()
y = self.y.GetValue()
return x, y
def SetXY(self, x, y):
'''Define the values
@param x: [float] X axis position to remember
@param y: [float] Y axis position to remember'''
self.x.SetValue(x)
self.y.SetValue(y)
def GetThickness(self):
'''@return row thickness'''
return self.thickness.GetValue()
def SetThickness(self, thickness):
'''Define the thickness
@param text: [string] thickness of this sample'''
self.thickness.SetValue(thickness)
def GetUSAXSMode(self):
'''@return row parameters'''
#new method, pickle the parameters object.
# advantages: simpler, standard, works around bug
# disadvantage: not very human readable
# you can say that again!
#as-yet-unimplemented
#return pickle.dumps(self.properties)
# old method, custom object serialization
modestring = ""
if self.doUSAXS:
modestring += "U:"
if self.CHG_NPTS:
modestring += ("[NPTS:" + self.NPTS + "]")
if self.CHG_CTIME:
modestring += ("[CTIME:" + self.CTIME + "]")
if self.CHG_QMAX:
modestring += ("[QMAX:" + self.QMAX + "]")
if self.doPinhole:
modestring += "P:"
if self.CHG_EXPTIME:
modestring += ("[EXPTIME:" + self.EXPTIME + "]")
if self.CHG_NOEXP:
modestring += ("[NOEXP:" + self.NOEXP + "]")
if self.doWAXS:
modestring += "W:"
if self.CHG_WEXPTIME:
modestring += ("[WEXPTIME:" + self.WEXPTIME + "]")
if self.CHG_WNOEXP:
modestring += ("[WNOEXP:" + self.WNOEXP + "]")
return modestring
def SetUSAXSMode(self, mode):
'''Define the parameters
@param text: [string] mode string for this sample'''
tempmode = mode.partition("U:")
mode = tempmode[0] + tempmode [2]
if tempmode[1] != "":
self.doUSAXS = True
else:
self.doUSAXS = False
tempmode = mode.partition("P:")
mode = tempmode[0] + tempmode[2]
if tempmode[1] != "":
self.doPinhole = True
else:
self.doPinhole = False
tempmode = mode.partition("W:")
mode = tempmode[0] + tempmode[2]
if tempmode[1] != "":
self.doWAXS = True
else:
self.doWAXS = False
mode = re.sub("]", "",mode)
parameters = mode.split("[")
for param in parameters:
test = param.partition("NPTS:")
if test[1] != "":
self.CHG_NPTS = True
self.NPTS = test[2]
test = param.partition("CTIME:")
if test[1] != "":
self.CHG_CTIME = True
self.CTIME = test[2]
test = param.partition("QMAX:")
if test[1] != "":
self.CHG_QMAX = True
self.QMAX = test[2]
test = param.partition("EXPTIME:")
if test[1] != "":
self.CHG_EXPTIME = True
self.EXPTIME = test[2]
test = param.partition("NOEXP:")
if test[1] != "":
self.CHG_NOEXP = True
self.NOEXP = test[2]
test = param.partition("WEXPTIME:")
if test[1] != "":
self.CHG_WEXPTIME = True
self.WEXPTIME = test[2]
test = param.partition("WNOEXP:")
if test[1] != "":
self.CHG_WNOEXP = True
self.WNOEXP = test[2]
#def setFUSAXSmode(self,mode):
def DeleteRow(self, parent):
'''Tell parent to delete this row (may be tricky)
@param parent: object of Tab that owns this Row'''
self.tabCallback(self, 'delete')
def SetPositions(self, parent):
'''Tell parent to set positions on this row
@param parent: object of Tab that owns this Row'''
self.tabCallback(self, 'set')
def Go(self, parent):
'''Tell parent to move motors to this X,Y
@param parent: object of Tab that owns this Row'''
self.tabCallback(self, 'go')
# ################################
# ## event handling routines ###
# ################################
def OnDeleteButton(self, event):
'''Delete button pressed
@param event: wxPython event object'''
self.DeleteRow(self.tab)
def OnSetButton(self, event):
'''Set button pressed
@param event: wxPython event object'''
self.SetPositions(self.tab)
def OnGoButton(self, event):
'''Go button pressed
@param event: wxPython event object'''
self.Go(self.tab)
def OnAdvancedButton(self, event):
'''More button pressed
@param event: wxPython event object'''
self.properties = USAXSproperties(self, -1, self.GetLabel())
self.properties.ShowModal()
#save properties locally
self.doUSAXS = self.properties.doUSAXS.GetValue()
self.CHG_NPTS = self.properties.CHG_NPTS.GetValue()
self.NPTS = self.properties.NPTS.GetValue()
self.CHG_CTIME = self.properties.CHG_CTIME.GetValue()
self.CTIME = self.properties.CTIME.GetValue()
self.CHG_QMAX = self.properties.CHG_QMAX.GetValue()
self.QMAX = self.properties.QMAX.GetValue()
self.doPinhole = self.properties.doPinhole.GetValue()
self.CHG_EXPTIME = self.properties.CHG_EXPTIME.GetValue()
self.EXPTIME = self.properties.EXPTIME.GetValue()
self.CHG_NOEXP = self.properties.CHG_NOEXP.GetValue()
self.NOEXP = self.properties.NOEXP.GetValue()
self.doWAXS = self.properties.doWAXS.GetValue()
self.CHG_WEXPTIME = self.properties.CHG_WEXPTIME.GetValue()
self.WEXPTIME = self.properties.WEXPTIME.GetValue()
self.CHG_WNOEXP = self.properties.CHG_WNOEXP.GetValue()
self.WNOEXP = self.properties.WNOEXP.GetValue()
if self.properties.SETALL.GetValue():
self.tabCallback(self, 'setall')
self.properties.Destroy()