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