1 | import wx |
---|
2 | import sys |
---|
3 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
4 | from sas.sasgui.guiframe.events import PlotQrangeEvent |
---|
5 | from sas.sasgui.guiframe.events import StatusEvent |
---|
6 | from sas.sasgui.guiframe.panel_base import PanelBase |
---|
7 | from sas.sasgui.guiframe.utils import check_float |
---|
8 | from sas.sasgui.guiframe.dataFitting import Data1D |
---|
9 | from sas.sasgui.perspectives.invariant.invariant_widgets import OutputTextCtrl |
---|
10 | from sas.sasgui.perspectives.invariant.invariant_widgets import InvTextCtrl |
---|
11 | from sas.sasgui.perspectives.fitting.basepage import ModelTextCtrl |
---|
12 | from sas.sasgui.perspectives.corfunc.corfunc_state import CorfuncState |
---|
13 | import sas.sasgui.perspectives.corfunc.corfunc |
---|
14 | from sas.sascalc.corfunc.corfunc_calculator import CorfuncCalculator |
---|
15 | |
---|
16 | if sys.platform.count("win32") > 0: |
---|
17 | _STATICBOX_WIDTH = 350 |
---|
18 | PANEL_WIDTH = 400 |
---|
19 | PANEL_HEIGHT = 700 |
---|
20 | FONT_VARIANT = 0 |
---|
21 | else: |
---|
22 | _STATICBOX_WIDTH = 390 |
---|
23 | PANEL_WIDTH = 430 |
---|
24 | PANEL_HEIGHT = 700 |
---|
25 | FONT_VARIANT = 1 |
---|
26 | |
---|
27 | class CorfuncPanel(ScrolledPanel,PanelBase): |
---|
28 | window_name = "Correlation Function" |
---|
29 | window_caption = "Correlation Function" |
---|
30 | CENTER_PANE = True |
---|
31 | |
---|
32 | def __init__(self, parent, data=None, manager=None, *args, **kwds): |
---|
33 | kwds["size"] = (PANEL_WIDTH, PANEL_HEIGHT) |
---|
34 | kwds["style"] = wx.FULL_REPAINT_ON_RESIZE |
---|
35 | ScrolledPanel.__init__(self, parent=parent, *args, **kwds) |
---|
36 | PanelBase.__init__(self, parent) |
---|
37 | self.SetupScrolling() |
---|
38 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
39 | self._manager = manager |
---|
40 | # The data with no correction for background values |
---|
41 | self._data = data # The data to be analysed (corrected fr background) |
---|
42 | self._extrapolated_data = None # The extrapolated data set |
---|
43 | self._calculator = CorfuncCalculator() |
---|
44 | self._data_name_box = None # Text box to show name of file |
---|
45 | self._background_input = None |
---|
46 | self._qmin_input = None |
---|
47 | self._qmax1_input = None |
---|
48 | self._qmax2_input = None |
---|
49 | self._transform_btn = None |
---|
50 | self._compute_btn = None |
---|
51 | self.qmin = 0 |
---|
52 | self.qmax = (0, 0) |
---|
53 | self.background = 0 |
---|
54 | # Dictionary for saving IDs of text boxes used to display output data |
---|
55 | self._output_ids = None |
---|
56 | self.state = None |
---|
57 | self._do_layout() |
---|
58 | self._disable_inputs() |
---|
59 | self.set_state() |
---|
60 | self._qmin_input.Bind(wx.EVT_TEXT, self._on_enter_input) |
---|
61 | self._qmax1_input.Bind(wx.EVT_TEXT, self._on_enter_input) |
---|
62 | self._qmax2_input.Bind(wx.EVT_TEXT, self._on_enter_input) |
---|
63 | self._qmin_input.Bind(wx.EVT_MOUSE_EVENTS, self._on_click_qrange) |
---|
64 | self._qmax1_input.Bind(wx.EVT_MOUSE_EVENTS, self._on_click_qrange) |
---|
65 | self._qmax2_input.Bind(wx.EVT_MOUSE_EVENTS, self._on_click_qrange) |
---|
66 | self._background_input.Bind(wx.EVT_TEXT, self._on_enter_input) |
---|
67 | |
---|
68 | def set_state(self, state=None, data=None): |
---|
69 | """ |
---|
70 | Set the state of the panel. If no state is provided, the panel will |
---|
71 | be set to the default state. |
---|
72 | |
---|
73 | :param state: A CorfuncState object |
---|
74 | :param data: A Data1D object |
---|
75 | """ |
---|
76 | if state is None: |
---|
77 | self.state = CorfuncState() |
---|
78 | else: |
---|
79 | self.state = state |
---|
80 | if data is not None: |
---|
81 | self.state.data = data |
---|
82 | self.set_data(data, set_qrange=False) |
---|
83 | if self.state.qmin is not None: |
---|
84 | self.set_qmin(self.state.qmin) |
---|
85 | if self.state.qmax is not None and self.state.qmax != (None, None): |
---|
86 | self.set_qmax(tuple(self.state.qmax)) |
---|
87 | if self.state.background is not None: |
---|
88 | self.set_background(self.state.background) |
---|
89 | |
---|
90 | def get_state(self): |
---|
91 | """ |
---|
92 | Return the state of the panel |
---|
93 | """ |
---|
94 | state = CorfuncState() |
---|
95 | state.set_saved_state('qmin_tcl', self.qmin) |
---|
96 | state.set_saved_state('qmax1_tcl', self.qmax[0]) |
---|
97 | state.set_saved_state('qmax2_tcl', self.qmax[1]) |
---|
98 | state.set_saved_state('background_tcl', self.background) |
---|
99 | if self._data is not None: |
---|
100 | state.file = self._data.title |
---|
101 | state.data = self._data |
---|
102 | self.state = state |
---|
103 | |
---|
104 | return self.state |
---|
105 | |
---|
106 | def onSetFocus(self, evt): |
---|
107 | if evt is not None: |
---|
108 | evt.Skip() |
---|
109 | self._validate_inputs() |
---|
110 | |
---|
111 | def set_data(self, data=None, set_qrange=True): |
---|
112 | """ |
---|
113 | Update the GUI to reflect new data that has been loaded in |
---|
114 | |
---|
115 | :param data: The data that has been loaded |
---|
116 | """ |
---|
117 | if data is None: |
---|
118 | return |
---|
119 | self._enable_inputs() |
---|
120 | self._transform_btn.Disable() |
---|
121 | self._data_name_box.SetValue(str(data.title)) |
---|
122 | self._data = data |
---|
123 | self._calculator.set_data(data) |
---|
124 | if self._manager is not None: |
---|
125 | from sas.sasgui.perspectives.corfunc.corfunc import IQ_DATA_LABEL |
---|
126 | self._manager.show_data(self._data, IQ_DATA_LABEL, reset=True) |
---|
127 | if set_qrange: |
---|
128 | lower = data.x[-1]*0.05 |
---|
129 | upper1 = data.x[-1] - lower*5 |
---|
130 | upper2 = data.x[-1] |
---|
131 | self.set_qmin(lower) |
---|
132 | self.set_qmax((upper1, upper2)) |
---|
133 | self.set_background(self._calculator.compute_background(self.qmax)) |
---|
134 | |
---|
135 | def get_data(self): |
---|
136 | return self._data |
---|
137 | |
---|
138 | def compute_extrapolation(self, event=None): |
---|
139 | """ |
---|
140 | Compute and plot the extrapolated data. |
---|
141 | Called when Extrapolate button is pressed. |
---|
142 | """ |
---|
143 | if self._data is None: |
---|
144 | msg = "Data must be loaded in order to perform an extrapolation." |
---|
145 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
146 | return |
---|
147 | if not self._validate_inputs: |
---|
148 | msg = "Invalid Q range entered." |
---|
149 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
150 | return |
---|
151 | self._calculator.set_data(self._data) |
---|
152 | self._calculator.lowerq = self.qmin |
---|
153 | self._calculator.upperq = self.qmax |
---|
154 | self._extrapolated_data = self._calculator.compute_extrapolation() |
---|
155 | # TODO: Find way to set xlim and ylim so full range of data can be |
---|
156 | # plotted |
---|
157 | maxq = self._data.x.max() |
---|
158 | mask = self._extrapolated_data.x <= maxq |
---|
159 | numpts = len(self._extrapolated_data.x[mask]) + 250 |
---|
160 | plot_x = self._extrapolated_data.x[0:numpts] |
---|
161 | plot_y = self._extrapolated_data.y[0:numpts] |
---|
162 | to_plot = Data1D(plot_x, plot_y) |
---|
163 | from sas.sasgui.perspectives.corfunc.corfunc import\ |
---|
164 | IQ_EXTRAPOLATED_DATA_LABEL |
---|
165 | self._manager.show_data(to_plot, IQ_EXTRAPOLATED_DATA_LABEL) |
---|
166 | self._transform_btn.Enable() |
---|
167 | |
---|
168 | def compute_transform(self, event=None): |
---|
169 | """ |
---|
170 | Compute and plot the transformed data. |
---|
171 | Called when Transform button is pressed. |
---|
172 | """ |
---|
173 | transformed_data = self._calculator.compute_transform( |
---|
174 | self._extrapolated_data, self.background) |
---|
175 | from sas.sasgui.perspectives.corfunc.corfunc import TRANSFORM_LABEL |
---|
176 | import numpy as np |
---|
177 | plot_x = transformed_data.x[np.where(transformed_data.x <= 200)] |
---|
178 | plot_y = transformed_data.y[np.where(transformed_data.x <= 200)] |
---|
179 | self._manager.show_data(Data1D(plot_x, plot_y), TRANSFORM_LABEL) |
---|
180 | |
---|
181 | |
---|
182 | def save_project(self, doc=None): |
---|
183 | """ |
---|
184 | Return an XML node containing the state of the panel |
---|
185 | |
---|
186 | :param doc: Am xml node to attach the project state to (optional) |
---|
187 | """ |
---|
188 | data = self._data |
---|
189 | state = self.get_state() |
---|
190 | if data is not None: |
---|
191 | new_doc, sasentry = self._manager.state_reader._to_xml_doc(data) |
---|
192 | new_doc = state.toXML(doc=new_doc, entry_node=sasentry) |
---|
193 | if new_doc is not None: |
---|
194 | if doc is not None and hasattr(doc, "firstChild"): |
---|
195 | child = new_doc.getElementsByTagName("SASentry") |
---|
196 | for item in child: |
---|
197 | doc.firstChild.appendChild(item) |
---|
198 | else: |
---|
199 | doc = new_doc |
---|
200 | return doc |
---|
201 | |
---|
202 | def set_qmin(self, qmin): |
---|
203 | self.qmin = qmin |
---|
204 | self._qmin_input.SetValue(str(qmin)) |
---|
205 | |
---|
206 | def set_qmax(self, qmax): |
---|
207 | self.qmax = qmax |
---|
208 | self._qmax1_input.SetValue(str(qmax[0])) |
---|
209 | self._qmax2_input.SetValue(str(qmax[1])) |
---|
210 | |
---|
211 | def set_background(self, bg): |
---|
212 | self.background = bg |
---|
213 | self._background_input.SetValue(str(bg)) |
---|
214 | self._calculator.background = bg |
---|
215 | |
---|
216 | def _compute_background(self, event=None): |
---|
217 | self.set_background(self._calculator.compute_background(self.qmax)) |
---|
218 | |
---|
219 | def _on_enter_input(self, event=None): |
---|
220 | """ |
---|
221 | Read values from input boxes and save to memory. |
---|
222 | """ |
---|
223 | if event is not None: event.Skip() |
---|
224 | if not self._validate_inputs(): |
---|
225 | return |
---|
226 | self.qmin = float(self._qmin_input.GetValue()) |
---|
227 | new_qmax1 = float(self._qmax1_input.GetValue()) |
---|
228 | new_qmax2 = float(self._qmax2_input.GetValue()) |
---|
229 | self.qmax = (new_qmax1, new_qmax2) |
---|
230 | self.background = float(self._background_input.GetValue()) |
---|
231 | self._calculator.background = self.background |
---|
232 | from sas.sasgui.perspectives.corfunc.corfunc import GROUP_ID_IQ_DATA,\ |
---|
233 | IQ_DATA_LABEL |
---|
234 | if event is not None: |
---|
235 | active_ctrl = event.GetEventObject() |
---|
236 | if active_ctrl == self._background_input: |
---|
237 | from sas.sasgui.perspectives.corfunc.corfunc\ |
---|
238 | import IQ_DATA_LABEL |
---|
239 | self._manager.show_data(self._data, IQ_DATA_LABEL, reset=False) |
---|
240 | wx.PostEvent(self._manager.parent, PlotQrangeEvent( |
---|
241 | ctrl=[self._qmin_input, self._qmax1_input, self._qmax2_input], |
---|
242 | active=active_ctrl, id=IQ_DATA_LABEL, |
---|
243 | group_id=GROUP_ID_IQ_DATA, leftdown=False)) |
---|
244 | |
---|
245 | def _on_click_qrange(self, event=None): |
---|
246 | if event is None: |
---|
247 | return |
---|
248 | event.Skip() |
---|
249 | if not self._validate_inputs(): return |
---|
250 | is_click = event.LeftDown() |
---|
251 | if is_click: |
---|
252 | from sas.sasgui.perspectives.corfunc.corfunc import GROUP_ID_IQ_DATA,\ |
---|
253 | IQ_DATA_LABEL |
---|
254 | wx.PostEvent(self._manager.parent, PlotQrangeEvent( |
---|
255 | ctrl=[self._qmin_input, self._qmax1_input, self._qmax2_input], |
---|
256 | active=event.GetEventObject(), id=IQ_DATA_LABEL, |
---|
257 | group_id=GROUP_ID_IQ_DATA, leftdown=is_click)) |
---|
258 | |
---|
259 | def _validate_inputs(self): |
---|
260 | """ |
---|
261 | Check that the values for qmin and qmax in the input boxes are valid |
---|
262 | """ |
---|
263 | if self._data is None: |
---|
264 | return False |
---|
265 | qmin_valid = check_float(self._qmin_input) |
---|
266 | qmax1_valid = check_float(self._qmax1_input) |
---|
267 | qmax2_valid = check_float(self._qmax2_input) |
---|
268 | qmax_valid = qmax1_valid and qmax2_valid |
---|
269 | background_valid = check_float(self._background_input) |
---|
270 | msg = "" |
---|
271 | if (qmin_valid and qmax_valid and background_valid): |
---|
272 | qmin = float(self._qmin_input.GetValue()) |
---|
273 | qmax1 = float(self._qmax1_input.GetValue()) |
---|
274 | qmax2 = float(self._qmax2_input.GetValue()) |
---|
275 | background = float(self._background_input.GetValue()) |
---|
276 | if not qmin > self._data.x.min(): |
---|
277 | msg = "qmin must be greater than the lowest q value" |
---|
278 | qmin_valid = False |
---|
279 | elif qmax2 < qmax1: |
---|
280 | msg = "qmax1 must be less than qmax2" |
---|
281 | qmax_valid = False |
---|
282 | elif qmin > qmax1: |
---|
283 | msg = "qmin must be less than qmax" |
---|
284 | qmin_valid = False |
---|
285 | elif background < 0 or background > self._data.y.max(): |
---|
286 | msg = "background must be positive and less than highest I" |
---|
287 | background_valid = False |
---|
288 | if not qmin_valid: |
---|
289 | self._qmin_input.SetBackgroundColour('pink') |
---|
290 | if not qmax_valid: |
---|
291 | self._qmax1_input.SetBackgroundColour('pink') |
---|
292 | self._qmax2_input.SetBackgroundColour('pink') |
---|
293 | if not background_valid: |
---|
294 | self._background_input.SetBackgroundColour('pink') |
---|
295 | if msg != "": |
---|
296 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
297 | if (qmin_valid and qmax_valid and background_valid): |
---|
298 | self._qmin_input.SetBackgroundColour(wx.WHITE) |
---|
299 | self._qmax1_input.SetBackgroundColour(wx.WHITE) |
---|
300 | self._qmax2_input.SetBackgroundColour(wx.WHITE) |
---|
301 | self._background_input.SetBackgroundColour(wx.WHITE) |
---|
302 | self._qmin_input.Refresh() |
---|
303 | self._qmax1_input.Refresh() |
---|
304 | self._qmax2_input.Refresh() |
---|
305 | self._background_input.Refresh() |
---|
306 | return (qmin_valid and qmax_valid and background_valid) |
---|
307 | |
---|
308 | def _do_layout(self): |
---|
309 | """ |
---|
310 | Draw the window content |
---|
311 | """ |
---|
312 | vbox = wx.GridBagSizer(0,0) |
---|
313 | |
---|
314 | # I(q) data box |
---|
315 | databox = wx.StaticBox(self, -1, "I(Q) Data Source") |
---|
316 | databox_sizer = wx.StaticBoxSizer(databox, wx.VERTICAL) |
---|
317 | |
---|
318 | file_sizer = wx.GridBagSizer(5, 5) |
---|
319 | |
---|
320 | file_name_label = wx.StaticText(self, -1, "Name:") |
---|
321 | file_sizer.Add(file_name_label, (0, 0), (1, 1), |
---|
322 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
323 | |
---|
324 | self._data_name_box = OutputTextCtrl(self, -1, |
---|
325 | size=(300,20)) |
---|
326 | file_sizer.Add(self._data_name_box, (0, 1), (1, 1), |
---|
327 | wx.CENTER | wx.ADJUST_MINSIZE, 15) |
---|
328 | |
---|
329 | file_sizer.AddSpacer((1, 25), pos=(0,2)) |
---|
330 | databox_sizer.Add(file_sizer, wx.TOP, 15) |
---|
331 | |
---|
332 | vbox.Add(databox_sizer, (0, 0), (1, 1), |
---|
333 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE | wx.TOP, 15) |
---|
334 | |
---|
335 | |
---|
336 | # Parameters |
---|
337 | qbox = wx.StaticBox(self, -1, "Parameters") |
---|
338 | qbox_sizer = wx.StaticBoxSizer(qbox, wx.VERTICAL) |
---|
339 | qbox_sizer.SetMinSize((_STATICBOX_WIDTH, 75)) |
---|
340 | |
---|
341 | q_sizer = wx.GridBagSizer(5, 5) |
---|
342 | |
---|
343 | # Explanation |
---|
344 | explanation_txt = ("Corfunc will use all values in the lower range for" |
---|
345 | " Guinier back extrapolation, and all values in the upper range " |
---|
346 | "for Porod forward extrapolation.") |
---|
347 | explanation_label = wx.StaticText(self, -1, explanation_txt, |
---|
348 | size=(_STATICBOX_WIDTH, 60)) |
---|
349 | |
---|
350 | q_sizer.Add(explanation_label, (0,0), (1,4), wx.LEFT | wx.EXPAND, 5) |
---|
351 | |
---|
352 | qrange_label = wx.StaticText(self, -1, "Q Range:", size=(50,20)) |
---|
353 | q_sizer.Add(qrange_label, (1,0), (1,1), wx.LEFT | wx.EXPAND, 5) |
---|
354 | |
---|
355 | # Lower Q Range |
---|
356 | qmin_label = wx.StaticText(self, -1, "Lower:", size=(50,20)) |
---|
357 | qmin_dash_label = wx.StaticText(self, -1, "-", size=(10,20), |
---|
358 | style=wx.ALIGN_CENTER_HORIZONTAL) |
---|
359 | |
---|
360 | qmin_lower = OutputTextCtrl(self, -1, size=(50, 20), value="0.0") |
---|
361 | self._qmin_input = ModelTextCtrl(self, -1, size=(50, 20), |
---|
362 | style=wx.TE_PROCESS_ENTER, name='qmin_input', |
---|
363 | text_enter_callback=self._on_enter_input) |
---|
364 | self._qmin_input.SetToolTipString(("Values with q < qmin will be used " |
---|
365 | "for Guinier back extrapolation")) |
---|
366 | |
---|
367 | q_sizer.Add(qmin_label, (2, 0), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
368 | q_sizer.Add(qmin_lower, (2, 1), (1, 1), wx.LEFT, 5) |
---|
369 | q_sizer.Add(qmin_dash_label, (2, 2), (1, 1), wx.CENTER | wx.EXPAND, 5) |
---|
370 | q_sizer.Add(self._qmin_input, (2, 3), (1, 1), wx.LEFT, 5) |
---|
371 | |
---|
372 | # Upper Q range |
---|
373 | qmax_tooltip = ("Values with qmax1 < q < qmax2 will be used for Porod" |
---|
374 | " forward extrapolation") |
---|
375 | |
---|
376 | qmax_label = wx.StaticText(self, -1, "Upper:", size=(50,20)) |
---|
377 | qmax_dash_label = wx.StaticText(self, -1, "-", size=(10,20), |
---|
378 | style=wx.ALIGN_CENTER_HORIZONTAL) |
---|
379 | |
---|
380 | self._qmax1_input = ModelTextCtrl(self, -1, size=(50, 20), |
---|
381 | style=wx.TE_PROCESS_ENTER, name="qmax1_input", |
---|
382 | text_enter_callback=self._on_enter_input) |
---|
383 | self._qmax1_input.SetToolTipString(qmax_tooltip) |
---|
384 | self._qmax2_input = ModelTextCtrl(self, -1, size=(50, 20), |
---|
385 | style=wx.TE_PROCESS_ENTER, name="qmax2_input", |
---|
386 | text_enter_callback=self._on_enter_input) |
---|
387 | self._qmax2_input.SetToolTipString(qmax_tooltip) |
---|
388 | |
---|
389 | q_sizer.Add(qmax_label, (3, 0), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
390 | q_sizer.Add(self._qmax1_input, (3, 1), (1, 1), wx.LEFT, 5) |
---|
391 | q_sizer.Add(qmax_dash_label, (3, 2), (1, 1), wx.CENTER | wx.EXPAND, 5) |
---|
392 | q_sizer.Add(self._qmax2_input, (3,3), (1, 1), wx.LEFT, 5) |
---|
393 | |
---|
394 | background_label = wx.StaticText(self, -1, "Background:", size=(80,20)) |
---|
395 | q_sizer.Add(background_label, (4,0), (1,1), wx.LEFT | wx.EXPAND, 5) |
---|
396 | |
---|
397 | self._background_input = ModelTextCtrl(self, -1, size=(50,20), |
---|
398 | style=wx.TE_PROCESS_ENTER, name='background_input', |
---|
399 | text_enter_callback=self._on_enter_input) |
---|
400 | self._background_input.SetToolTipString(("A background value to " |
---|
401 | "subtract from all intensity values")) |
---|
402 | q_sizer.Add(self._background_input, (4,1), (1,1), |
---|
403 | wx.RIGHT, 5) |
---|
404 | |
---|
405 | background_button = wx.Button(self, wx.NewId(), "Calculate", |
---|
406 | size=(75, 20)) |
---|
407 | background_button.Bind(wx.EVT_BUTTON, self._compute_background) |
---|
408 | q_sizer.Add(background_button, (4, 2), (1, 1), wx.RIGHT, 5) |
---|
409 | |
---|
410 | qbox_sizer.Add(q_sizer, wx.TOP, 0) |
---|
411 | |
---|
412 | vbox.Add(qbox_sizer, (1, 0), (1, 1), |
---|
413 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
414 | |
---|
415 | # Output data |
---|
416 | outputbox = wx.StaticBox(self, -1, "Output Measuments") |
---|
417 | outputbox_sizer = wx.StaticBoxSizer(outputbox, wx.VERTICAL) |
---|
418 | |
---|
419 | output_sizer = wx.GridBagSizer(5, 5) |
---|
420 | |
---|
421 | label_strings = [ |
---|
422 | "Long Period (A): ", |
---|
423 | "Average Hard Block Thickness (A): ", |
---|
424 | "Average Interface Thickness (A): ", |
---|
425 | "Average Core Thickness: ", |
---|
426 | "PolyDispersity: ", |
---|
427 | "Filling Fraction: " |
---|
428 | ] |
---|
429 | self._output_ids = dict() |
---|
430 | for i in range(len(label_strings)): |
---|
431 | # Create a label and a text box for each poperty |
---|
432 | label = wx.StaticText(self, -1, label_strings[i]) |
---|
433 | output_box = OutputTextCtrl(self, wx.NewId(), size=(50, 20), |
---|
434 | value="-", style=wx.ALIGN_CENTER_HORIZONTAL) |
---|
435 | # Save the ID of each of the text boxes for accessing after the |
---|
436 | # output data has been calculated |
---|
437 | self._output_ids[label_strings[i]] = output_box.GetId() |
---|
438 | output_sizer.Add(label, (i, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) |
---|
439 | output_sizer.Add(output_box, (i, 2), (1, 1), |
---|
440 | wx.RIGHT | wx.EXPAND, 15) |
---|
441 | |
---|
442 | outputbox_sizer.Add(output_sizer, wx.TOP, 0) |
---|
443 | |
---|
444 | vbox.Add(outputbox_sizer, (2, 0), (1, 1), |
---|
445 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
446 | |
---|
447 | # Controls |
---|
448 | controlbox = wx.StaticBox(self, -1, "Controls") |
---|
449 | controlbox_sizer = wx.StaticBoxSizer(controlbox, wx.VERTICAL) |
---|
450 | |
---|
451 | controls_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
452 | |
---|
453 | extrapolate_btn = wx.Button(self, wx.NewId(), "Extrapolate") |
---|
454 | self._transform_btn = wx.Button(self, wx.NewId(), "Transform") |
---|
455 | self._compute_btn = wx.Button(self, wx.NewId(), "Compute Measuments") |
---|
456 | |
---|
457 | self._transform_btn.Disable() |
---|
458 | self._compute_btn.Disable() |
---|
459 | |
---|
460 | extrapolate_btn.Bind(wx.EVT_BUTTON, self.compute_extrapolation) |
---|
461 | self._transform_btn.Bind(wx.EVT_BUTTON, self.compute_transform) |
---|
462 | |
---|
463 | controls_sizer.Add(extrapolate_btn, wx.CENTER | wx.EXPAND) |
---|
464 | controls_sizer.Add(self._transform_btn, wx.CENTER | wx.EXPAND) |
---|
465 | controls_sizer.Add(self._compute_btn, wx.CENTER | wx.EXPAND) |
---|
466 | |
---|
467 | controlbox_sizer.Add(controls_sizer, wx.TOP | wx.EXPAND, 0) |
---|
468 | vbox.Add(controlbox_sizer, (3, 0), (1, 1), |
---|
469 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
470 | |
---|
471 | self.SetSizer(vbox) |
---|
472 | |
---|
473 | def _disable_inputs(self): |
---|
474 | """ |
---|
475 | Disable all input fields |
---|
476 | """ |
---|
477 | self._qmin_input.Disable() |
---|
478 | self._qmax1_input.Disable() |
---|
479 | self._qmax2_input.Disable() |
---|
480 | self._background_input.Disable() |
---|
481 | |
---|
482 | def _enable_inputs(self): |
---|
483 | """ |
---|
484 | Enable all input fields |
---|
485 | """ |
---|
486 | self._qmin_input.Enable() |
---|
487 | self._qmax1_input.Enable() |
---|
488 | self._qmax2_input.Enable() |
---|
489 | self._background_input.Enable() |
---|