[c128284] | 1 | """ |
---|
[d7a39e5] | 2 | This module provide GUI for the neutron scattering length density calculator |
---|
| 3 | |
---|
[c128284] | 4 | """ |
---|
[4a2b054] | 5 | import copy |
---|
| 6 | import time |
---|
| 7 | import sys |
---|
| 8 | import os |
---|
[c128284] | 9 | import wx |
---|
[9abec44] | 10 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
[272d91e] | 11 | from sans.invariant import invariant |
---|
[4a2b054] | 12 | from sans.guiframe.utils import format_number |
---|
| 13 | from sans.guiframe.utils import check_float |
---|
[f1e06a8e] | 14 | from sans.guiframe.events import StatusEvent |
---|
[cb69775] | 15 | from sans.guiframe.events import AppendBookmarkEvent |
---|
[f1e06a8e] | 16 | from .invariant_details import InvariantDetailsPanel |
---|
| 17 | from .invariant_details import InvariantContainer |
---|
| 18 | from .invariant_widgets import OutputTextCtrl |
---|
| 19 | from .invariant_widgets import InvTextCtrl |
---|
| 20 | from .invariant_state import InvariantState as IState |
---|
[6a0cbcf4] | 21 | from sans.guiframe.panel_base import PanelBase |
---|
[c128284] | 22 | # The minimum q-value to be used when extrapolating |
---|
| 23 | Q_MINIMUM = 1e-5 |
---|
| 24 | # The maximum q-value to be used when extrapolating |
---|
| 25 | Q_MAXIMUM = 10 |
---|
[90b9a17] | 26 | # the ratio of maximum q value/(qmax of data) to plot the theory data |
---|
| 27 | Q_MAXIMUM_PLOT = 3 |
---|
[c128284] | 28 | # the number of points to consider during fit |
---|
| 29 | NPTS = 10 |
---|
| 30 | #Default value for background |
---|
| 31 | BACKGROUND = 0.0 |
---|
| 32 | #default value for the scale |
---|
| 33 | SCALE = 1.0 |
---|
[9ce7641c] | 34 | #default value of the contrast |
---|
| 35 | CONTRAST = 1.0 |
---|
[d0cc0bbc] | 36 | #default value of the power used for power law |
---|
| 37 | POWER = 4.0 |
---|
[c128284] | 38 | #Invariant panel size |
---|
| 39 | _BOX_WIDTH = 76 |
---|
| 40 | |
---|
[4e1c362] | 41 | |
---|
[4a2b054] | 42 | if sys.platform.count("win32") > 0: |
---|
[c128284] | 43 | _STATICBOX_WIDTH = 450 |
---|
[355b684] | 44 | PANEL_WIDTH = 500 |
---|
[c128284] | 45 | PANEL_HEIGHT = 700 |
---|
| 46 | FONT_VARIANT = 0 |
---|
| 47 | else: |
---|
| 48 | _STATICBOX_WIDTH = 480 |
---|
| 49 | PANEL_WIDTH = 530 |
---|
| 50 | PANEL_HEIGHT = 700 |
---|
| 51 | FONT_VARIANT = 1 |
---|
[d0cc0bbc] | 52 | |
---|
| 53 | |
---|
[6a0cbcf4] | 54 | class InvariantPanel(ScrolledPanel, PanelBase): |
---|
[c128284] | 55 | """ |
---|
[d7a39e5] | 56 | Provides the Invariant GUI. |
---|
[c128284] | 57 | """ |
---|
| 58 | ## Internal nickname for the window, used by the AUI manager |
---|
| 59 | window_name = "Invariant" |
---|
| 60 | ## Name to appear on the window title bar |
---|
| 61 | window_caption = "Invariant" |
---|
| 62 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
| 63 | CENTER_PANE = True |
---|
[4a2b054] | 64 | def __init__(self, parent, data=None, manager=None, *args, **kwds): |
---|
| 65 | kwds["size"] = (PANEL_WIDTH, PANEL_HEIGHT) |
---|
| 66 | kwds["style"] = wx.FULL_REPAINT_ON_RESIZE |
---|
[355b684] | 67 | ScrolledPanel.__init__(self, parent=parent, *args, **kwds) |
---|
[27f3831] | 68 | PanelBase.__init__(self, parent) |
---|
[3de66c1] | 69 | self.SetupScrolling() |
---|
[c128284] | 70 | #Font size |
---|
| 71 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
| 72 | #Object that receive status event |
---|
| 73 | self.parent = parent |
---|
[272d91e] | 74 | #plug-in using this panel |
---|
| 75 | self._manager = manager |
---|
| 76 | #Data uses for computation |
---|
| 77 | self._data = data |
---|
[6d55d81] | 78 | self._scale = SCALE |
---|
| 79 | self._background = BACKGROUND |
---|
[4e1c362] | 80 | self._bmark = None |
---|
| 81 | self.bookmark_num = 0 |
---|
| 82 | |
---|
[cb69775] | 83 | #self._set_bookmark_menu() |
---|
[4e1c362] | 84 | #Init state |
---|
| 85 | self.set_state() |
---|
| 86 | # default flags for state |
---|
| 87 | self.new_state = False |
---|
[d318616] | 88 | self.is_state_data = False |
---|
[f24925ab] | 89 | self.is_power_out = False |
---|
[cef847c] | 90 | |
---|
[9ce7641c] | 91 | #container of invariant value |
---|
| 92 | self.inv_container = None |
---|
[c128284] | 93 | #Draw the panel |
---|
| 94 | self._do_layout() |
---|
[d0cc0bbc] | 95 | self.reset_panel() |
---|
[4e1c362] | 96 | self._reset_state_list() |
---|
| 97 | |
---|
[a0a4486] | 98 | if self.parent is not None: |
---|
| 99 | msg = "" |
---|
[e3f721e4] | 100 | wx.PostEvent(self.parent,StatusEvent(status=msg, info="info")) |
---|
[4e1c362] | 101 | |
---|
| 102 | ## Default file location for save |
---|
| 103 | self._default_save_location = os.getcwd() |
---|
[cb69775] | 104 | self._set_bookmark_flag(False) |
---|
[cef847c] | 105 | |
---|
[35f2f49] | 106 | def get_data(self): |
---|
| 107 | """ |
---|
| 108 | """ |
---|
| 109 | return self._manager.get_data() |
---|
| 110 | |
---|
| 111 | def get_state(self): |
---|
| 112 | """ |
---|
| 113 | """ |
---|
| 114 | return self.state |
---|
| 115 | |
---|
[210ff4f] | 116 | def set_data(self, data): |
---|
[343fdb6] | 117 | """ |
---|
[210ff4f] | 118 | Set the data |
---|
[c128284] | 119 | """ |
---|
[272d91e] | 120 | self._data = data |
---|
| 121 | #edit the panel |
---|
[210ff4f] | 122 | if self._data is not None: |
---|
[9b18735] | 123 | self.get_state_by_num(0) |
---|
[272d91e] | 124 | data_name = self._data.name |
---|
[210ff4f] | 125 | data_qmin = min (self._data.x) |
---|
| 126 | data_qmax = max (self._data.x) |
---|
| 127 | self.data_name_tcl.SetValue(str(data_name)) |
---|
[effce1d] | 128 | self.data_min_tcl.SetValue(str(data_qmin)) |
---|
| 129 | self.data_max_tcl.SetValue(str(data_qmax)) |
---|
[d0cc0bbc] | 130 | self.reset_panel() |
---|
| 131 | self.compute_invariant(event=None) |
---|
[b35d3d1] | 132 | self.state.file = self._data.name |
---|
[9b18735] | 133 | #Reset the list of states |
---|
| 134 | self.state.data = copy.deepcopy(data) |
---|
[7065641] | 135 | self._set_preview_flag(False) |
---|
[9b18735] | 136 | self._reset_state_list() |
---|
[f1e06a8e] | 137 | |
---|
[210ff4f] | 138 | return True |
---|
[4a2b054] | 139 | |
---|
[d0cc0bbc] | 140 | def set_message(self): |
---|
| 141 | """ |
---|
[d7a39e5] | 142 | Display warning message if available |
---|
[d0cc0bbc] | 143 | """ |
---|
| 144 | if self.inv_container is not None: |
---|
| 145 | if self.inv_container.existing_warning: |
---|
| 146 | msg = "Warning! Computations on invariant require your " |
---|
| 147 | msg += "attention.\n Please click on Details button." |
---|
| 148 | self.hint_msg_txt.SetForegroundColour("red") |
---|
[1c271f2] | 149 | |
---|
[4a2b054] | 150 | wx.PostEvent(self.parent, |
---|
| 151 | StatusEvent(status=msg,info="warning")) |
---|
[d0cc0bbc] | 152 | else: |
---|
| 153 | msg = "For more information, click on Details button." |
---|
| 154 | self.hint_msg_txt.SetForegroundColour("black") |
---|
[4a2b054] | 155 | wx.PostEvent(self.parent, |
---|
| 156 | StatusEvent(status=msg,info="info")) |
---|
[d0cc0bbc] | 157 | self.hint_msg_txt.SetLabel(msg) |
---|
[cb274d9e] | 158 | |
---|
[d0cc0bbc] | 159 | |
---|
[c128284] | 160 | def set_manager(self, manager): |
---|
| 161 | """ |
---|
[d7a39e5] | 162 | set value for the manager |
---|
[c128284] | 163 | """ |
---|
[272d91e] | 164 | self._manager = manager |
---|
[4e1c362] | 165 | |
---|
| 166 | def set_state(self,state=None,data=None): |
---|
| 167 | """ |
---|
[9b18735] | 168 | set state when loading it from a .inv/.svs file |
---|
[4e1c362] | 169 | """ |
---|
[645f9b6] | 170 | if state == None and data == None: |
---|
[4e1c362] | 171 | self.state = IState() |
---|
[645f9b6] | 172 | elif state == None or data == None: return |
---|
[4e1c362] | 173 | else: |
---|
[f24925ab] | 174 | self.new_state = True |
---|
[210ff4f] | 175 | if not self.set_data(data): |
---|
[4e1c362] | 176 | return |
---|
[b35d3d1] | 177 | self.state = state |
---|
| 178 | self.state.file = data.name |
---|
[645f9b6] | 179 | |
---|
[4e1c362] | 180 | num = self.state.saved_state['state_num'] |
---|
[cb463b4] | 181 | if num > 0 : |
---|
[27f3831] | 182 | self._set_undo_flag(True) |
---|
[4a2b054] | 183 | if num < len(state.state_list) - 1: |
---|
[27f3831] | 184 | self._set_redo_flag(True) |
---|
[4e1c362] | 185 | |
---|
| 186 | # get bookmarks |
---|
| 187 | self.bookmark_num = len(self.state.bookmark_list) |
---|
[cef847c] | 188 | |
---|
[4a2b054] | 189 | total_bookmark_num = self.bookmark_num + 1 |
---|
[4e1c362] | 190 | for ind in range(1,total_bookmark_num): |
---|
| 191 | #bookmark_num = ind |
---|
| 192 | value = self.state.bookmark_list[ind] |
---|
| 193 | name = "%d] bookmarked at %s on %s"% (ind,value[0], value[1]) |
---|
| 194 | # append it to menu |
---|
| 195 | id = wx.NewId() |
---|
| 196 | self.popUpMenu.Append(id,name,str('')) |
---|
[cef847c] | 197 | wx.EVT_MENU(self, id, self._back_to_bookmark) |
---|
[cb463b4] | 198 | |
---|
| 199 | self.get_state_by_num(state_num=str(num)) |
---|
| 200 | |
---|
[1a3a03b] | 201 | self._get_input_list() |
---|
[4a2b054] | 202 | #make sure that the data is reset (especially |
---|
| 203 | # when loaded from a inv file) |
---|
[cb274d9e] | 204 | self.state.data = self._data |
---|
[645f9b6] | 205 | |
---|
[4e1c362] | 206 | self.new_state = False |
---|
[f24925ab] | 207 | self.is_state_data = False |
---|
[0399c78] | 208 | |
---|
[cb69775] | 209 | def clear_panel(self): |
---|
[9b18735] | 210 | """ |
---|
| 211 | Clear panel to defaults, used by set_state of manager |
---|
| 212 | """ |
---|
[cb69775] | 213 | |
---|
| 214 | self._data = None |
---|
| 215 | # default data testctrl |
---|
| 216 | self.hint_msg_txt.SetLabel('') |
---|
| 217 | data_name = '' |
---|
| 218 | data_qmin = '' |
---|
| 219 | data_qmax = '' |
---|
| 220 | self.data_name_tcl.SetValue(str(data_name)) |
---|
| 221 | self.data_min_tcl.SetValue(str(data_qmin)) |
---|
| 222 | self.data_max_tcl.SetValue(str(data_qmax)) |
---|
| 223 | #reset output textctrl |
---|
| 224 | self._reset_output() |
---|
| 225 | #reset panel |
---|
| 226 | self.reset_panel() |
---|
| 227 | #reset state w/o data |
---|
| 228 | self.set_state() |
---|
| 229 | # default flags for state |
---|
| 230 | self.new_state = False |
---|
| 231 | self.is_state_data = False |
---|
| 232 | self.is_power_out = False |
---|
[4e1c362] | 233 | |
---|
[9ce7641c] | 234 | def get_background(self): |
---|
[c128284] | 235 | """ |
---|
[d7a39e5] | 236 | return the background textcrtl value as a float |
---|
[c128284] | 237 | """ |
---|
[9ce7641c] | 238 | background = self.background_tcl.GetValue().lstrip().rstrip() |
---|
[c128284] | 239 | if background == "": |
---|
[9ce7641c] | 240 | raise ValueError, "Need a background" |
---|
| 241 | if check_float(self.background_tcl): |
---|
| 242 | return float(background) |
---|
| 243 | else: |
---|
[4a2b054] | 244 | msg = "Receive invalid value for background : %s" % (background) |
---|
| 245 | raise ValueError, msg |
---|
[9ce7641c] | 246 | |
---|
| 247 | def get_scale(self): |
---|
| 248 | """ |
---|
[d7a39e5] | 249 | return the scale textcrtl value as a float |
---|
[9ce7641c] | 250 | """ |
---|
| 251 | scale = self.scale_tcl.GetValue().lstrip().rstrip() |
---|
[c128284] | 252 | if scale == "": |
---|
[9ce7641c] | 253 | raise ValueError, "Need a background" |
---|
| 254 | if check_float(self.scale_tcl): |
---|
[4a2b054] | 255 | if float(scale) <= 0.0: |
---|
[6d55d81] | 256 | self.scale_tcl.SetBackgroundColour("pink") |
---|
| 257 | self.scale_tcl.Refresh() |
---|
[4a2b054] | 258 | msg = "Receive invalid value for scale: %s" % (scale) |
---|
| 259 | raise ValueError, msg |
---|
[9ce7641c] | 260 | return float(scale) |
---|
| 261 | else: |
---|
[4a2b054] | 262 | raise ValueError, "Receive invalid value for scale : %s" % (scale) |
---|
[9ce7641c] | 263 | |
---|
| 264 | def get_contrast(self): |
---|
| 265 | """ |
---|
[d7a39e5] | 266 | return the contrast textcrtl value as a float |
---|
[9ce7641c] | 267 | """ |
---|
| 268 | par_str = self.contrast_tcl.GetValue().strip() |
---|
| 269 | contrast = None |
---|
[4a2b054] | 270 | if par_str !=" " and check_float(self.contrast_tcl): |
---|
[9ce7641c] | 271 | contrast = float(par_str) |
---|
| 272 | return contrast |
---|
| 273 | |
---|
| 274 | def get_extrapolation_type(self, low_q, high_q): |
---|
| 275 | """ |
---|
| 276 | """ |
---|
| 277 | extrapolation = None |
---|
| 278 | if low_q and not high_q: |
---|
| 279 | extrapolation = "low" |
---|
| 280 | elif not low_q and high_q: |
---|
| 281 | extrapolation = "high" |
---|
| 282 | elif low_q and high_q: |
---|
| 283 | extrapolation = "both" |
---|
| 284 | return extrapolation |
---|
[272d91e] | 285 | |
---|
[9ce7641c] | 286 | def get_porod_const(self): |
---|
| 287 | """ |
---|
[d7a39e5] | 288 | return the porod constant textcrtl value as a float |
---|
[9ce7641c] | 289 | """ |
---|
| 290 | par_str = self.porod_constant_tcl.GetValue().strip() |
---|
| 291 | porod_const = None |
---|
[4a2b054] | 292 | if par_str != "" and check_float(self.porod_constant_tcl): |
---|
[9ce7641c] | 293 | porod_const = float(par_str) |
---|
| 294 | return porod_const |
---|
| 295 | |
---|
| 296 | def get_volume(self, inv, contrast, extrapolation): |
---|
| 297 | """ |
---|
| 298 | """ |
---|
| 299 | if contrast is not None: |
---|
[c128284] | 300 | try: |
---|
[9ce7641c] | 301 | v, dv = inv.get_volume_fraction_with_error(contrast=contrast, |
---|
[4a2b054] | 302 | extrapolation=extrapolation) |
---|
[9ce7641c] | 303 | self.volume_tcl.SetValue(format_number(v)) |
---|
| 304 | self.volume_err_tcl.SetValue(format_number(dv)) |
---|
[c128284] | 305 | except: |
---|
[0a8759f] | 306 | self.volume_tcl.SetValue(format_number(None)) |
---|
| 307 | self.volume_err_tcl.SetValue(format_number(None)) |
---|
[4a2b054] | 308 | msg = "Error occurred computing volume " |
---|
| 309 | msg += " fraction: %s" % sys.exc_value |
---|
[e3f721e4] | 310 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
| 311 | info="error", |
---|
| 312 | type="stop")) |
---|
[9ce7641c] | 313 | |
---|
| 314 | def get_surface(self, inv, contrast, porod_const, extrapolation): |
---|
| 315 | """ |
---|
| 316 | """ |
---|
| 317 | if contrast is not None and porod_const is not None: |
---|
[c128284] | 318 | try: |
---|
[9ce7641c] | 319 | s, ds = inv.get_surface_with_error(contrast=contrast, |
---|
| 320 | porod_const=porod_const, |
---|
| 321 | extrapolation=extrapolation) |
---|
| 322 | self.surface_tcl.SetValue(format_number(s)) |
---|
| 323 | self.surface_err_tcl.SetValue(format_number(ds)) |
---|
[c128284] | 324 | except: |
---|
[0a8759f] | 325 | self.surface_tcl.SetValue(format_number(None)) |
---|
| 326 | self.surface_err_tcl.SetValue(format_number(None)) |
---|
[4a2b054] | 327 | msg = "Error occurred computing " |
---|
| 328 | msg += "specific surface: %s" % sys.exc_value |
---|
[e3f721e4] | 329 | wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", |
---|
| 330 | type="stop")) |
---|
[53b6b74] | 331 | |
---|
[9ce7641c] | 332 | def get_total_qstar(self, inv, extrapolation): |
---|
| 333 | """ |
---|
| 334 | """ |
---|
| 335 | try: |
---|
| 336 | qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation) |
---|
[0a8759f] | 337 | |
---|
[9ce7641c] | 338 | self.invariant_total_tcl.SetValue(format_number(qstar_total)) |
---|
[518d35d] | 339 | self.invariant_total_err_tcl.SetValue(format_number(qstar_total_err)) |
---|
[9ce7641c] | 340 | self.inv_container.qstar_total = qstar_total |
---|
| 341 | self.inv_container.qstar_total_err = qstar_total_err |
---|
[518d35d] | 342 | |
---|
[9ce7641c] | 343 | except: |
---|
[0a8759f] | 344 | self.inv_container.qstar_total = "Error" |
---|
| 345 | self.inv_container.qstar_total_err = "Error" |
---|
| 346 | self.invariant_total_tcl.SetValue(format_number(None)) |
---|
| 347 | self.invariant_total_err_tcl.SetValue(format_number(None)) |
---|
[4a2b054] | 348 | msg = "Error occurred computing invariant using" |
---|
| 349 | msg += " extrapolation: %s" % sys.exc_value |
---|
[9ce7641c] | 350 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
| 351 | |
---|
| 352 | def get_low_qstar(self, inv, npts_low, low_q=False): |
---|
| 353 | """ |
---|
| 354 | """ |
---|
| 355 | if low_q: |
---|
| 356 | try: |
---|
| 357 | qstar_low, qstar_low_err = inv.get_qstar_low() |
---|
| 358 | self.inv_container.qstar_low = qstar_low |
---|
| 359 | self.inv_container.qstar_low_err = qstar_low_err |
---|
| 360 | extrapolated_data = inv.get_extra_data_low(npts_in=npts_low) |
---|
| 361 | power_low = inv.get_extrapolation_power(range='low') |
---|
[518d35d] | 362 | if self.power_law_low.GetValue(): |
---|
[d0cc0bbc] | 363 | self.power_low_tcl.SetValue(format_number(power_low)) |
---|
[9ce7641c] | 364 | self._manager.plot_theory(data=extrapolated_data, |
---|
| 365 | name="Low-Q extrapolation") |
---|
| 366 | except: |
---|
[a07e72f] | 367 | raise |
---|
[0a8759f] | 368 | self.inv_container.qstar_low = "ERROR" |
---|
| 369 | self.inv_container.qstar_low_err = "ERROR" |
---|
| 370 | self._manager.plot_theory(name="Low-Q extrapolation") |
---|
[4a2b054] | 371 | msg = "Error occurred computing low-Q " |
---|
| 372 | msg += "invariant: %s" % sys.exc_value |
---|
| 373 | wx.PostEvent(self.parent, |
---|
| 374 | StatusEvent(status=msg, type="stop")) |
---|
[c128284] | 375 | else: |
---|
[4e1c362] | 376 | try: |
---|
| 377 | self._manager.plot_theory(name="Low-Q extrapolation") |
---|
| 378 | except: pass |
---|
[9ce7641c] | 379 | |
---|
| 380 | def get_high_qstar(self, inv, high_q=False): |
---|
| 381 | """ |
---|
| 382 | """ |
---|
| 383 | if high_q: |
---|
| 384 | try: |
---|
[90b9a17] | 385 | qmax_plot = Q_MAXIMUM_PLOT * max(self._data.x) |
---|
| 386 | if qmax_plot > Q_MAXIMUM: qmax_plot = Q_MAXIMUM |
---|
[9ce7641c] | 387 | qstar_high, qstar_high_err = inv.get_qstar_high() |
---|
| 388 | self.inv_container.qstar_high = qstar_high |
---|
| 389 | self.inv_container.qstar_high_err = qstar_high_err |
---|
[518d35d] | 390 | power_high = inv.get_extrapolation_power(range='high') |
---|
[d0cc0bbc] | 391 | self.power_high_tcl.SetValue(format_number(power_high)) |
---|
[4a2b054] | 392 | high_out_data = inv.get_extra_data_high(q_end=qmax_plot, |
---|
| 393 | npts=500) |
---|
[9ce7641c] | 394 | self._manager.plot_theory(data=high_out_data, |
---|
| 395 | name="High-Q extrapolation") |
---|
| 396 | except: |
---|
[7065641] | 397 | #raise |
---|
[0a8759f] | 398 | self.inv_container.qstar_high = "ERROR" |
---|
| 399 | self.inv_container.qstar_high_err = "ERROR" |
---|
| 400 | self._manager.plot_theory(name="High-Q extrapolation") |
---|
[4a2b054] | 401 | msg = "Error occurred computing high-Q " |
---|
| 402 | msg += "invariant: %s" % sys.exc_value |
---|
| 403 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
| 404 | type="stop")) |
---|
[9ce7641c] | 405 | else: |
---|
[4e1c362] | 406 | try: |
---|
| 407 | self._manager.plot_theory(name="High-Q extrapolation") |
---|
| 408 | except: pass |
---|
| 409 | |
---|
[9ce7641c] | 410 | def get_qstar(self, inv): |
---|
| 411 | """ |
---|
| 412 | """ |
---|
| 413 | qstar, qstar_err = inv.get_qstar_with_error() |
---|
| 414 | self.inv_container.qstar = qstar |
---|
| 415 | self.inv_container.qstar_err = qstar_err |
---|
| 416 | |
---|
| 417 | def set_extrapolation_low(self, inv, low_q=False): |
---|
| 418 | """ |
---|
[d7a39e5] | 419 | return float value necessary to compute invariant a low q |
---|
[9ce7641c] | 420 | """ |
---|
| 421 | #get funtion |
---|
| 422 | if self.guinier.GetValue(): |
---|
| 423 | function_low = "guinier" |
---|
| 424 | # get the function |
---|
[518d35d] | 425 | power_low = None #2.0/3.0 |
---|
[9ce7641c] | 426 | if self.power_law_low.GetValue(): |
---|
| 427 | function_low = "power_law" |
---|
[518d35d] | 428 | if self.fit_enable_low.GetValue(): |
---|
[9ce7641c] | 429 | #set value of power_low to none to allow fitting |
---|
| 430 | power_low = None |
---|
| 431 | else: |
---|
| 432 | power_low = self.power_low_tcl.GetValue().lstrip().rstrip() |
---|
| 433 | if check_float(self.power_low_tcl): |
---|
| 434 | power_low = float(power_low) |
---|
| 435 | else: |
---|
| 436 | if low_q : |
---|
| 437 | #Raise error only when qstar at low q is requested |
---|
[4a2b054] | 438 | msg = "Expect float for power at low q, " |
---|
| 439 | msg += " got %s" % (power_low) |
---|
[9ce7641c] | 440 | raise ValueError, msg |
---|
[518d35d] | 441 | |
---|
[9ce7641c] | 442 | #Get the number of points to extrapolated |
---|
| 443 | npts_low = self.npts_low_tcl.GetValue().lstrip().rstrip() |
---|
| 444 | if check_float(self.npts_low_tcl): |
---|
| 445 | npts_low = float(npts_low) |
---|
| 446 | else: |
---|
| 447 | if low_q: |
---|
[4a2b054] | 448 | msg = "Expect float for number of points at low q," |
---|
| 449 | msg += " got %s" % (npts_low) |
---|
[9ce7641c] | 450 | raise ValueError, msg |
---|
| 451 | #Set the invariant calculator |
---|
| 452 | inv.set_extrapolation(range="low", npts=npts_low, |
---|
| 453 | function=function_low, power=power_low) |
---|
| 454 | return inv, npts_low |
---|
[4e1c362] | 455 | |
---|
| 456 | |
---|
[9ce7641c] | 457 | def set_extrapolation_high(self, inv, high_q=False): |
---|
| 458 | """ |
---|
[d7a39e5] | 459 | return float value necessary to compute invariant a high q |
---|
[9ce7641c] | 460 | """ |
---|
| 461 | power_high = None |
---|
[277fad8] | 462 | #if self.power_law_high.GetValue(): |
---|
| 463 | function_high = "power_law" |
---|
| 464 | if self.fit_enable_high.GetValue(): |
---|
| 465 | #set value of power_high to none to allow fitting |
---|
| 466 | power_high = None |
---|
| 467 | else: |
---|
| 468 | power_high = self.power_high_tcl.GetValue().lstrip().rstrip() |
---|
| 469 | if check_float(self.power_high_tcl): |
---|
| 470 | power_high = float(power_high) |
---|
[9ce7641c] | 471 | else: |
---|
[277fad8] | 472 | if high_q : |
---|
| 473 | #Raise error only when qstar at high q is requested |
---|
[4a2b054] | 474 | msg = "Expect float for power at high q," |
---|
| 475 | msg += " got %s" % (power_high) |
---|
[277fad8] | 476 | raise ValueError, msg |
---|
[9ce7641c] | 477 | |
---|
| 478 | npts_high = self.npts_high_tcl.GetValue().lstrip().rstrip() |
---|
| 479 | if check_float(self.npts_high_tcl): |
---|
| 480 | npts_high = float(npts_high) |
---|
| 481 | else: |
---|
| 482 | if high_q: |
---|
[4a2b054] | 483 | msg = "Expect float for number of points at high q," |
---|
| 484 | msg += " got %s" % (npts_high) |
---|
[9ce7641c] | 485 | raise ValueError, msg |
---|
| 486 | inv.set_extrapolation(range="high", npts=npts_high, |
---|
| 487 | function=function_high, power=power_high) |
---|
| 488 | return inv, npts_high |
---|
| 489 | |
---|
| 490 | def display_details(self, event): |
---|
| 491 | """ |
---|
[d7a39e5] | 492 | open another panel for more details on invariant calculation |
---|
[9ce7641c] | 493 | """ |
---|
[d3fac18] | 494 | panel = InvariantDetailsPanel(parent=self, |
---|
| 495 | qstar_container=self.inv_container) |
---|
| 496 | panel.ShowModal() |
---|
| 497 | panel.Destroy() |
---|
[d0cc0bbc] | 498 | self.button_calculate.SetFocus() |
---|
[9ce7641c] | 499 | |
---|
[d0cc0bbc] | 500 | def compute_invariant(self, event=None): |
---|
[9ce7641c] | 501 | """ |
---|
[d7a39e5] | 502 | compute invariant |
---|
[9ce7641c] | 503 | """ |
---|
[4e1c362] | 504 | if self._data == None: |
---|
[4a2b054] | 505 | msg = "\n\nData must be loaded first in order" |
---|
| 506 | msg += " to perform a compution..." |
---|
[4e1c362] | 507 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
| 508 | # set a state for this computation for saving |
---|
| 509 | elif event != None: |
---|
| 510 | self._set_compute_state(state='compute') |
---|
[27f3831] | 511 | self._set_bookmark_flag(True) |
---|
[4e1c362] | 512 | msg= "\n\nStarting a new invariant computation..." |
---|
| 513 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
[cef847c] | 514 | |
---|
[4e1c362] | 515 | |
---|
[cb69775] | 516 | if self._data is None: |
---|
[9ce7641c] | 517 | return |
---|
[cb69775] | 518 | self.button_details.Enable() |
---|
[9ce7641c] | 519 | #clear outputs textctrl |
---|
| 520 | self._reset_output() |
---|
| 521 | try: |
---|
| 522 | background = self.get_background() |
---|
| 523 | scale = self.get_scale() |
---|
| 524 | except: |
---|
[4a2b054] | 525 | msg = "Invariant Error: %s" % (sys.exc_value) |
---|
| 526 | wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) |
---|
[9ce7641c] | 527 | return |
---|
| 528 | |
---|
| 529 | low_q = self.enable_low_cbox.GetValue() |
---|
[f1e06a8e] | 530 | high_q = self.enable_high_cbox.GetValue() |
---|
| 531 | temp_data = copy.deepcopy(self._data) |
---|
| 532 | |
---|
[9ce7641c] | 533 | #set invariant calculator |
---|
[f1e06a8e] | 534 | inv = invariant.InvariantCalculator(data=temp_data, |
---|
[9ce7641c] | 535 | background=background, |
---|
| 536 | scale=scale) |
---|
[437e639] | 537 | try: |
---|
| 538 | inv, npts_low = self.set_extrapolation_low(inv=inv, low_q=low_q) |
---|
| 539 | inv, npts_high = self.set_extrapolation_high(inv=inv, high_q=high_q) |
---|
| 540 | except: |
---|
[4a2b054] | 541 | msg = "Error occurred computing invariant: %s" % sys.exc_value |
---|
[e3f721e4] | 542 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
| 543 | info="warning",type="stop")) |
---|
[437e639] | 544 | return |
---|
[9ce7641c] | 545 | #check the type of extrapolation |
---|
| 546 | extrapolation = self.get_extrapolation_type(low_q=low_q, high_q=high_q) |
---|
[a0a4486] | 547 | |
---|
[9ce7641c] | 548 | #Compute invariant |
---|
[6d55d81] | 549 | bkg_changed = False |
---|
| 550 | scale_changed = False |
---|
[9ce7641c] | 551 | try: |
---|
| 552 | self.get_qstar(inv=inv) |
---|
[6d55d81] | 553 | #if scale_changed or bkg_changed: |
---|
[353f467] | 554 | #self._manager.plot_data(data=inv.get_data()) |
---|
[6d55d81] | 555 | |
---|
[9ce7641c] | 556 | except: |
---|
[4a2b054] | 557 | msg= "Error occurred computing invariant: %s" % sys.exc_value |
---|
[e3f721e4] | 558 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
[4a2b054] | 559 | info="warning", |
---|
| 560 | type="stop")) |
---|
[c128284] | 561 | return |
---|
[0a8759f] | 562 | |
---|
[9ce7641c] | 563 | #Compute qstar extrapolated to low q range |
---|
| 564 | self.get_low_qstar(inv=inv, npts_low=npts_low, low_q=low_q) |
---|
| 565 | #Compute qstar extrapolated to high q range |
---|
| 566 | self.get_high_qstar(inv=inv, high_q=high_q) |
---|
| 567 | #Compute qstar extrapolated to total q range and set value to txtcrtl |
---|
| 568 | self.get_total_qstar(inv=inv, extrapolation=extrapolation) |
---|
| 569 | # Parse additional parameters |
---|
| 570 | porod_const = self.get_porod_const() |
---|
| 571 | contrast = self.get_contrast() |
---|
[4e1c362] | 572 | |
---|
[f43827cc] | 573 | try: |
---|
| 574 | #Compute volume and set value to txtcrtl |
---|
[4a2b054] | 575 | self.get_volume(inv=inv, contrast=contrast, |
---|
| 576 | extrapolation=extrapolation) |
---|
[f43827cc] | 577 | #compute surface and set value to txtcrtl |
---|
| 578 | except: |
---|
[4a2b054] | 579 | msg = "Error occurred computing invariant: %s" % sys.exc_value |
---|
[e3f721e4] | 580 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
[4a2b054] | 581 | info="warning", |
---|
| 582 | type="stop")) |
---|
[f43827cc] | 583 | try: |
---|
[4a2b054] | 584 | self.get_surface(inv=inv, contrast=contrast, |
---|
| 585 | porod_const=porod_const, |
---|
[9ce7641c] | 586 | extrapolation=extrapolation) |
---|
[4e1c362] | 587 | |
---|
[f43827cc] | 588 | except: |
---|
[4a2b054] | 589 | msg = "Error occurred computing invariant: %s" % sys.exc_value |
---|
[e3f721e4] | 590 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
[4a2b054] | 591 | info="warning", |
---|
| 592 | type="stop")) |
---|
[d0cc0bbc] | 593 | |
---|
| 594 | #compute percentage of each invariant |
---|
| 595 | self.inv_container.compute_percentage() |
---|
[4e1c362] | 596 | |
---|
[d0cc0bbc] | 597 | #display a message |
---|
| 598 | self.set_message() |
---|
[645f9b6] | 599 | |
---|
[4e1c362] | 600 | # reset power_out to default to get ready for another '_on_text' |
---|
| 601 | if self.is_power_out == True: |
---|
| 602 | self.state.container = copy.deepcopy(self.inv_container) |
---|
| 603 | self.state.timestamp= self._get_time_stamp() |
---|
| 604 | msg = self.state.__str__() |
---|
[97ec26b] | 605 | #self.state.set_report_string() |
---|
[4e1c362] | 606 | self.is_power_out = False |
---|
| 607 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
[cef847c] | 608 | |
---|
[9ce7641c] | 609 | #enable the button_ok for more details |
---|
[cb69775] | 610 | self._set_preview_flag(True) |
---|
[645f9b6] | 611 | |
---|
[4e1c362] | 612 | if event != None: |
---|
[cb69775] | 613 | self._set_preview_flag(True) |
---|
| 614 | self._set_save_flag(True) |
---|
[4a2b054] | 615 | wx.PostEvent(self.parent, |
---|
| 616 | StatusEvent(status='\nFinished invariant computation...')) |
---|
[27f3831] | 617 | |
---|
| 618 | def on_undo(self,event=None): |
---|
[4e1c362] | 619 | """ |
---|
| 620 | Go back to the previous state |
---|
| 621 | |
---|
| 622 | : param event: undo button event |
---|
| 623 | """ |
---|
[4a2b054] | 624 | if event != None: |
---|
| 625 | event.Skip() |
---|
| 626 | if self.state.state_num < 0: |
---|
| 627 | return |
---|
[4e1c362] | 628 | self.is_power_out = True |
---|
| 629 | # get the previous state_num |
---|
| 630 | pre_state_num = int(self.state.saved_state['state_num']) - 1 |
---|
| 631 | self.get_state_by_num(state_num=str(pre_state_num)) |
---|
| 632 | |
---|
[4a2b054] | 633 | if float(pre_state_num) <= 0: |
---|
[27f3831] | 634 | self._set_undo_flag(False) |
---|
[cb274d9e] | 635 | else: |
---|
[27f3831] | 636 | self._set_undo_flag(True) |
---|
| 637 | self._set_redo_flag(True) |
---|
[4e1c362] | 638 | self.is_power_out = False |
---|
| 639 | self._info_state_num() |
---|
| 640 | |
---|
| 641 | |
---|
[27f3831] | 642 | def on_redo(self,event=None): |
---|
[4e1c362] | 643 | """ |
---|
| 644 | Go forward to the previous state |
---|
| 645 | |
---|
| 646 | : param event: redo button event |
---|
| 647 | """ |
---|
[4a2b054] | 648 | if event != None: |
---|
| 649 | event.Skip() |
---|
[4e1c362] | 650 | self.is_power_out = True |
---|
[cb274d9e] | 651 | # get the next state_num |
---|
[4e1c362] | 652 | next_state_num = int(self.state.saved_state['state_num']) + 1 |
---|
| 653 | |
---|
| 654 | self.get_state_by_num(state_num=str(next_state_num)) |
---|
| 655 | |
---|
| 656 | if float(next_state_num)+2 > len(self.state.state_list): |
---|
[27f3831] | 657 | self._set_redo_flag(False) |
---|
[178bfea] | 658 | else: |
---|
[cb69775] | 659 | self._set_redo_flag(True) |
---|
| 660 | |
---|
[27f3831] | 661 | self._set_undo_flag(True) |
---|
[4e1c362] | 662 | self.is_power_out = False |
---|
| 663 | self._info_state_num() |
---|
| 664 | |
---|
[27f3831] | 665 | def on_preview(self, event=None): |
---|
[cb463b4] | 666 | """ |
---|
| 667 | Invoke report dialog panel |
---|
| 668 | |
---|
| 669 | : param event: report button event |
---|
| 670 | """ |
---|
[f1e06a8e] | 671 | from .report_dialog import ReportDialog |
---|
[cb463b4] | 672 | |
---|
[a94c4e1] | 673 | self.state.set_report_string() |
---|
[cb274d9e] | 674 | report_html_str = self.state.report_str |
---|
| 675 | report_text_str = self.state.__str__() |
---|
| 676 | report_img = self.state.image |
---|
| 677 | report_list = [report_html_str,report_text_str,report_img] |
---|
| 678 | dialog = ReportDialog(report_list, None, -1, "") |
---|
[cb463b4] | 679 | dialog.ShowModal() |
---|
| 680 | |
---|
[4e1c362] | 681 | def get_state_by_num(self,state_num=None): |
---|
| 682 | """ |
---|
| 683 | Get the state given by number |
---|
| 684 | |
---|
| 685 | : param state_num: the given state number |
---|
[cb274d9e] | 686 | """ |
---|
[4e1c362] | 687 | if state_num == None: |
---|
| 688 | return |
---|
| 689 | |
---|
| 690 | backup_state_list = copy.deepcopy(self.state.state_list) |
---|
[cef847c] | 691 | |
---|
[4e1c362] | 692 | # get the previous state |
---|
| 693 | try: |
---|
| 694 | current_state = copy.deepcopy(self.state.state_list[str(state_num)]) |
---|
[4a2b054] | 695 | # get the previously computed state number |
---|
| 696 | #(computation before the state changes happened) |
---|
[4e1c362] | 697 | current_compute_num = str(current_state['compute_num']) |
---|
| 698 | except : |
---|
[3641881] | 699 | raise |
---|
| 700 | #raise ValueError, "No such state exists in history" |
---|
[cef847c] | 701 | |
---|
[4e1c362] | 702 | # get the state at pre_compute_num |
---|
| 703 | comp_state = copy.deepcopy(self.state.state_list[current_compute_num]) |
---|
| 704 | |
---|
| 705 | # set the parameters |
---|
| 706 | for key in comp_state: |
---|
| 707 | value = comp_state[key] |
---|
| 708 | try: |
---|
| 709 | exec "self.%s.SetValue(str(%s))" % (key, value) |
---|
| 710 | except TypeError: |
---|
| 711 | exec "self.%s.SetValue(%s)" % (key, value) |
---|
| 712 | except: |
---|
| 713 | pass |
---|
[f1e06a8e] | 714 | |
---|
[4e1c362] | 715 | self.compute_invariant(event=None) |
---|
[f1e06a8e] | 716 | |
---|
[4e1c362] | 717 | # set the input params at the state at pre_state_num |
---|
| 718 | for key in current_state: |
---|
| 719 | # set the inputs and boxes |
---|
| 720 | value = current_state[key] |
---|
| 721 | try: |
---|
| 722 | exec 'self.%s.SetValue(str(%s))' % (key, value) |
---|
| 723 | except TypeError: |
---|
| 724 | exec 'self.%s.SetValue(%s)' % (key, value) |
---|
| 725 | except: |
---|
| 726 | pass |
---|
| 727 | |
---|
| 728 | self._enable_high_q_section(event=None) |
---|
| 729 | self._enable_low_q_section(event=None) |
---|
| 730 | self.state.state_list = backup_state_list |
---|
| 731 | self.state.saved_state = current_state |
---|
| 732 | self.state.state_num = state_num |
---|
[cb274d9e] | 733 | |
---|
[4e1c362] | 734 | |
---|
| 735 | def get_bookmark_by_num(self, num=None): |
---|
| 736 | """ |
---|
| 737 | Get the bookmark state given by number |
---|
| 738 | |
---|
| 739 | : param num: the given bookmark number |
---|
| 740 | |
---|
| 741 | """ |
---|
| 742 | current_state = {} |
---|
| 743 | comp_state = {} |
---|
| 744 | backup_state_list = copy.deepcopy(self.state.state_list) |
---|
| 745 | |
---|
| 746 | # get the previous state |
---|
| 747 | try: |
---|
| 748 | time,date,current_state,comp_state = self.state.bookmark_list[int(num)] |
---|
| 749 | except : |
---|
| 750 | raise ValueError, "No such bookmark exists" |
---|
| 751 | |
---|
| 752 | # set the parameters |
---|
| 753 | for key in comp_state: |
---|
| 754 | value = comp_state[key] |
---|
| 755 | try: |
---|
| 756 | exec "self.%s.SetValue(str(%s))" % (key, value) |
---|
| 757 | except TypeError: |
---|
| 758 | exec "self.%s.SetValue(%s)" % (key, value) |
---|
| 759 | except: |
---|
| 760 | pass |
---|
| 761 | |
---|
| 762 | self.compute_invariant(event=None) |
---|
| 763 | # set the input params at the state of pre_state_num |
---|
| 764 | for key in current_state: |
---|
| 765 | value = current_state[key] |
---|
| 766 | try: |
---|
| 767 | exec 'self.%s.SetValue(str(%s))' % (key, value) |
---|
| 768 | except TypeError: |
---|
| 769 | exec 'self.%s.SetValue(%s)' % (key, value) |
---|
| 770 | except: |
---|
| 771 | pass |
---|
| 772 | self.state.saved_state = copy.deepcopy(current_state) |
---|
[cef847c] | 773 | |
---|
[4e1c362] | 774 | self._enable_high_q_section(event=None) |
---|
| 775 | self._enable_low_q_section(event=None) |
---|
| 776 | self.state.state_list = backup_state_list |
---|
| 777 | #self.state.saved_state = current_state |
---|
| 778 | #self.state.state_num = state_num |
---|
| 779 | |
---|
[f338d3b] | 780 | def reset_panel(self): |
---|
| 781 | """ |
---|
[d7a39e5] | 782 | set the panel at its initial state. |
---|
[f338d3b] | 783 | """ |
---|
[d0cc0bbc] | 784 | self.background_tcl.SetValue(str(BACKGROUND)) |
---|
| 785 | self.scale_tcl.SetValue(str(SCALE)) |
---|
[4e74e13] | 786 | self.contrast_tcl.SetValue(str(CONTRAST)) |
---|
| 787 | self.porod_constant_tcl.SetValue('') |
---|
[d0cc0bbc] | 788 | self.npts_low_tcl.SetValue(str(NPTS)) |
---|
| 789 | self.enable_low_cbox.SetValue(False) |
---|
| 790 | self.fix_enable_low.SetValue(True) |
---|
| 791 | self.power_low_tcl.SetValue(str(POWER)) |
---|
| 792 | self.guinier.SetValue(True) |
---|
| 793 | self.power_low_tcl.Disable() |
---|
| 794 | self.enable_high_cbox.SetValue(False) |
---|
| 795 | self.fix_enable_high.SetValue(True) |
---|
| 796 | self.power_high_tcl.SetValue(str(POWER)) |
---|
| 797 | self.npts_high_tcl.SetValue(str(NPTS)) |
---|
| 798 | self.button_details.Disable() |
---|
| 799 | #Change the state of txtcrtl to enable/disable |
---|
| 800 | self._enable_low_q_section() |
---|
| 801 | #Change the state of txtcrtl to enable/disable |
---|
| 802 | self._enable_high_q_section() |
---|
| 803 | self._reset_output() |
---|
[27f3831] | 804 | self._set_undo_flag(False) |
---|
| 805 | self._set_redo_flag(False) |
---|
| 806 | self._set_bookmark_flag(False) |
---|
| 807 | self._set_preview_flag(False) |
---|
| 808 | self._set_save_flag(False) |
---|
[d0cc0bbc] | 809 | self.button_calculate.SetFocus() |
---|
[4e1c362] | 810 | #self.SetupScrolling() |
---|
| 811 | |
---|
| 812 | def _set_state(self, event): |
---|
| 813 | """ |
---|
| 814 | Set the state list |
---|
| 815 | |
---|
| 816 | :param event: rb/cb event |
---|
| 817 | """ |
---|
| 818 | if event == None: |
---|
| 819 | return |
---|
| 820 | obj = event.GetEventObject() |
---|
| 821 | name = str(obj.GetName()) |
---|
| 822 | value = str(obj.GetValue()) |
---|
[4a2b054] | 823 | rb_list = [['power_law_low','guinier'], |
---|
| 824 | ['fit_enable_low','fix_enable_low'], |
---|
| 825 | ['fit_enable_high','fix_enable_high']] |
---|
[4e1c362] | 826 | |
---|
| 827 | try: |
---|
| 828 | if value == None or value.lstrip().rstrip() =='': |
---|
| 829 | value = 'None' |
---|
| 830 | exec 'self.state.%s = %s' % (name, value) |
---|
| 831 | exec "self.state.saved_state['%s'] = %s" % (name, value) |
---|
| 832 | |
---|
[4a2b054] | 833 | # set the count part of radio button clicked |
---|
| 834 | #False for the saved_state |
---|
[4e1c362] | 835 | for title,content in rb_list: |
---|
| 836 | if name == title: |
---|
| 837 | name = content |
---|
| 838 | value = False |
---|
| 839 | elif name == content: |
---|
| 840 | name = title |
---|
| 841 | value = False |
---|
| 842 | exec "self.state.saved_state['%s'] = %s" % (name, value) |
---|
| 843 | |
---|
| 844 | # Instead of changing the future, create a new future. |
---|
[4a2b054] | 845 | max_state_num = len(self.state.state_list) - 1 |
---|
[4e1c362] | 846 | self.state.saved_state['state_num'] = max_state_num |
---|
| 847 | |
---|
[4a2b054] | 848 | self.state.saved_state['state_num'] += 1 |
---|
[4e1c362] | 849 | self.state.state_num = self.state.saved_state['state_num'] |
---|
| 850 | self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) |
---|
| 851 | except: |
---|
| 852 | pass |
---|
[7065641] | 853 | |
---|
[27f3831] | 854 | self._set_undo_flag(True) |
---|
| 855 | self._set_redo_flag(False) |
---|
[7065641] | 856 | event.Skip() |
---|
| 857 | |
---|
[4e1c362] | 858 | def _set_compute_state(self,state=None): |
---|
| 859 | """ |
---|
| 860 | Notify the compute_invariant state to self.state |
---|
| 861 | |
---|
[4a2b054] | 862 | : param state: set 'compute' when the computation is |
---|
| 863 | activated by the 'compute' button, else None |
---|
[4e1c362] | 864 | |
---|
| 865 | """ |
---|
| 866 | # reset the default |
---|
| 867 | if state != 'compute': |
---|
| 868 | self.new_state = False |
---|
| 869 | self.is_power_out = False |
---|
| 870 | else: |
---|
| 871 | self.is_power_out = True |
---|
| 872 | # Instead of changing the future, create a new future. |
---|
| 873 | max_state_num = len(self.state.state_list)-1 |
---|
| 874 | self.state.saved_state['state_num'] = max_state_num |
---|
| 875 | # A new computation is also A state |
---|
[4a2b054] | 876 | #copy.deepcopy(self.state.saved_state) |
---|
| 877 | temp_saved_states = self.state.clone_state() |
---|
| 878 | temp_saved_states['state_num'] += 1 |
---|
[4e1c362] | 879 | self.state.state_num = temp_saved_states['state_num'] |
---|
| 880 | |
---|
| 881 | |
---|
| 882 | # set the state number of the computation |
---|
| 883 | if state == 'compute': |
---|
| 884 | temp_saved_states['compute_num'] = self.state.state_num |
---|
| 885 | self.state.saved_state= copy.deepcopy(temp_saved_states) |
---|
[4a2b054] | 886 | #copy.deepcopy(self.state.saved_state) |
---|
| 887 | self.state.state_list[str(self.state.state_num)] = self.state.clone_state() |
---|
[4e1c362] | 888 | |
---|
[4a2b054] | 889 | # A computation is a new state, so delete the states with any higher |
---|
| 890 | # state numbers |
---|
[4e1c362] | 891 | for i in range(self.state.state_num+1,len(self.state.state_list)): |
---|
| 892 | try: |
---|
| 893 | del (self.state.state_list[str(i)]) |
---|
| 894 | except: |
---|
| 895 | pass |
---|
| 896 | # Enable the undo button if it was not |
---|
[27f3831] | 897 | self._set_undo_flag(True) |
---|
| 898 | self._set_redo_flag(False) |
---|
[cef847c] | 899 | |
---|
[4a2b054] | 900 | def _reset_state_list(self, data=None): |
---|
[4e1c362] | 901 | """ |
---|
[4a2b054] | 902 | Reset the state_list just before data was loading: |
---|
| 903 | Used in 'set_current_data()' |
---|
[4e1c362] | 904 | """ |
---|
| 905 | #if data == None: return |
---|
[4a2b054] | 906 | #temp_state = self.state.clone_state() |
---|
| 907 | #copy.deepcopy(self.state.saved_state) |
---|
[4e1c362] | 908 | # Clear the list |
---|
| 909 | self.state.state_list.clear() |
---|
| 910 | self.state.bookmark_list.clear() |
---|
| 911 | # Set defaults |
---|
| 912 | self.state.saved_state['state_num'] = 0 |
---|
| 913 | self.state.saved_state['compute_num'] = 0 |
---|
| 914 | if self._data != None: |
---|
| 915 | self.state.saved_state['file'] = str(self._data.name) |
---|
| 916 | else: |
---|
| 917 | self.state.saved_state['file'] = 'None' |
---|
| 918 | self.state.file = self.state.saved_state['file'] |
---|
| 919 | |
---|
| 920 | self.state.state_num = self.state.saved_state['state_num'] |
---|
[cb463b4] | 921 | self.state.timestamp = "('00:00:00', '00/00/0000')" |
---|
| 922 | |
---|
[4e1c362] | 923 | # Put only the current state in the list |
---|
[4a2b054] | 924 | #copy.deepcopy(self.state.saved_state) |
---|
| 925 | self.state.state_list[str(self.state.state_num)] = self.state.clone_state() |
---|
[cb69775] | 926 | self._set_undo_flag(False) |
---|
[4e1c362] | 927 | |
---|
| 928 | def _on_text(self, event): |
---|
| 929 | """ |
---|
| 930 | Catch text change event to add the state to the state_list |
---|
| 931 | |
---|
| 932 | :param event: txtctr event ; assumes not None |
---|
| 933 | |
---|
| 934 | """ |
---|
| 935 | if self._data == None: |
---|
| 936 | return |
---|
| 937 | # check if this event is from do/undo button |
---|
| 938 | if self.state.saved_state['is_time_machine'] or self.new_state: |
---|
| 939 | event.Skip() |
---|
| 940 | return |
---|
| 941 | |
---|
| 942 | # get the object |
---|
| 943 | obj = event.GetEventObject() |
---|
| 944 | name = str(obj.GetName()) |
---|
| 945 | value = str(obj.GetValue()) |
---|
| 946 | state_num = self.state.saved_state['state_num'] |
---|
| 947 | |
---|
| 948 | # text event is a new state, so delete the states with higher state_num |
---|
| 949 | # i.e., change the future |
---|
| 950 | for i in range(int(state_num)+1,len(self.state.state_list)): |
---|
| 951 | try: |
---|
| 952 | del (self.state.state_list[str(i)]) |
---|
| 953 | except: |
---|
| 954 | pass |
---|
| 955 | |
---|
| 956 | # Instead of changing the future, create a new future. |
---|
| 957 | #max_state_num = len(self.state.state_list)-1 |
---|
| 958 | #self.state.saved_state['state_num'] = max_state_num |
---|
| 959 | |
---|
| 960 | # try to add new state of the text changes in the state_list |
---|
| 961 | try: |
---|
| 962 | if value.strip() == None: value = '' |
---|
| 963 | exec "self.state.%s = '%s'" % (name, value) |
---|
| 964 | exec "self.state.saved_state['%s'] = '%s'" % (name, value) |
---|
| 965 | exec "self.state.input_list['%s'] = '%s'" % (name, value) |
---|
| 966 | if not self.is_power_out: |
---|
| 967 | if name != 'power_low_tcl' and name !='power_high_tcl': |
---|
| 968 | self.state.saved_state['state_num'] += 1 |
---|
| 969 | self.state.state_num = self.state.saved_state['state_num'] |
---|
[4a2b054] | 970 | #copy.deepcopy(self.state.saved_state) |
---|
| 971 | self.state.state_list[str(self.state.state_num)] = self.state.clone_state() |
---|
[4e1c362] | 972 | except: |
---|
| 973 | pass |
---|
| 974 | |
---|
| 975 | event.Skip() |
---|
[27f3831] | 976 | self._set_undo_flag(True) |
---|
| 977 | self._set_redo_flag(False) |
---|
| 978 | self._set_bookmark_flag(True) |
---|
| 979 | self._set_preview_flag(False) |
---|
[cb463b4] | 980 | |
---|
[4e1c362] | 981 | def _on_out_text(self, event): |
---|
| 982 | """ |
---|
| 983 | Catch ouput text change to add the state |
---|
| 984 | |
---|
| 985 | :param event: txtctr event ; assumes not None |
---|
| 986 | |
---|
| 987 | """ |
---|
| 988 | # get the object |
---|
| 989 | obj = event.GetEventObject() |
---|
| 990 | name = str(obj.GetName()) |
---|
| 991 | value = str(obj.GetValue()) |
---|
| 992 | try: |
---|
| 993 | exec "self.state.saved_state['%s'] = '%s'" % (name, value) |
---|
| 994 | self.state.state_list[str(self.state.state_num)] = self.state.clone_state() |
---|
| 995 | except: |
---|
| 996 | pass |
---|
| 997 | if event != None: event.Skip()\ |
---|
[1a3a03b] | 998 | |
---|
| 999 | def _get_input_list(self): |
---|
| 1000 | """ |
---|
| 1001 | get input_list; called by set_state |
---|
| 1002 | """ |
---|
| 1003 | # get state num of the last compute state |
---|
| 1004 | compute_num = self.state.saved_state['compute_num'] |
---|
| 1005 | # find values and put into the input list |
---|
| 1006 | for key1,value1 in self.state.state_list[str(compute_num)].iteritems(): |
---|
| 1007 | for key,value in self.state.input_list.iteritems(): |
---|
| 1008 | if key == key1: |
---|
| 1009 | self.state.input_list[key]=value1 |
---|
| 1010 | break |
---|
[4e1c362] | 1011 | |
---|
| 1012 | def _set_bookmark_menu(self): |
---|
| 1013 | """ |
---|
| 1014 | Setup 'bookmark' context menu |
---|
| 1015 | """ |
---|
| 1016 | ## Create context menu for page |
---|
| 1017 | self.popUpMenu = wx.Menu() |
---|
| 1018 | id = wx.NewId() |
---|
[4a2b054] | 1019 | self._bmark = wx.MenuItem(self.popUpMenu,id,"BookMark", |
---|
| 1020 | " Bookmark the panel to recall it later") |
---|
[4e1c362] | 1021 | self.popUpMenu.AppendItem(self._bmark) |
---|
| 1022 | self._bmark.Enable(True) |
---|
[27f3831] | 1023 | wx.EVT_MENU(self, id, self.on_bookmark) |
---|
[4e1c362] | 1024 | self.popUpMenu.AppendSeparator() |
---|
| 1025 | self.Bind(wx.EVT_CONTEXT_MENU, self._on_context_menu) |
---|
| 1026 | |
---|
[27f3831] | 1027 | def on_bookmark(self,event): |
---|
[4e1c362] | 1028 | """ |
---|
[4a2b054] | 1029 | Save the panel state in memory and add the list on |
---|
| 1030 | the popup menu on bookmark context menu event |
---|
[4e1c362] | 1031 | """ |
---|
| 1032 | if self._data == None: return |
---|
| 1033 | if event == None: return |
---|
| 1034 | self.bookmark_num += 1 |
---|
| 1035 | # date and time of the event |
---|
| 1036 | #year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() |
---|
| 1037 | #my_time= str(hour)+" : "+str(minute)+" : "+str(second)+" " |
---|
| 1038 | #date= str( month)+"/"+str(day)+"/"+str(year) |
---|
| 1039 | my_time, date = self._get_time_stamp() |
---|
| 1040 | state_num = self.state.state_num |
---|
| 1041 | compute_num = self.state.saved_state['compute_num'] |
---|
| 1042 | # name and message of the bookmark list |
---|
| 1043 | msg= "State saved at %s on %s"%(my_time, date) |
---|
| 1044 | ## post help message for the selected model |
---|
[cb274d9e] | 1045 | msg +=" Right click on the panel to retrieve this state" |
---|
[4e1c362] | 1046 | #wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[cb69775] | 1047 | name = "%d] bookmarked at %s on %s"%(self.bookmark_num, my_time, date) |
---|
[4e1c362] | 1048 | |
---|
| 1049 | # append it to menu |
---|
[cb69775] | 1050 | #id = wx.NewId() |
---|
| 1051 | #self.popUpMenu.Append(id,name,str(msg)) |
---|
| 1052 | #wx.EVT_MENU(self, id, self._back_to_bookmark) |
---|
[4e1c362] | 1053 | state = self.state.clone_state() |
---|
| 1054 | comp_state = copy.deepcopy(self.state.state_list[str(compute_num)]) |
---|
[4a2b054] | 1055 | self.state.bookmark_list[self.bookmark_num] = [my_time, date, |
---|
| 1056 | state,comp_state] |
---|
[4e1c362] | 1057 | self.state.toXML(self, doc=None, entry_node=None) |
---|
[cb274d9e] | 1058 | |
---|
| 1059 | wx.PostEvent(self.parent,StatusEvent(status=msg,info="info")) |
---|
[cb69775] | 1060 | wx.PostEvent(self.parent, |
---|
| 1061 | AppendBookmarkEvent(title=name, |
---|
| 1062 | hint=str(msg), |
---|
| 1063 | handler=self._back_to_bookmark)) |
---|
[4e1c362] | 1064 | |
---|
| 1065 | def _back_to_bookmark(self,event): |
---|
| 1066 | """ |
---|
[4a2b054] | 1067 | Bring the panel back to the state of bookmarked requested by |
---|
| 1068 | context menu event |
---|
[4e1c362] | 1069 | and set it as a new state |
---|
| 1070 | """ |
---|
[cb69775] | 1071 | self._manager.on_perspective(event) |
---|
| 1072 | menu = event.GetEventObject() |
---|
[4e1c362] | 1073 | ## post help message for the selected model |
---|
[cb69775] | 1074 | msg = menu.GetHelpString(event.GetId()) |
---|
[4e1c362] | 1075 | msg +=" reloaded" |
---|
| 1076 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 1077 | |
---|
[cb69775] | 1078 | name= menu.GetLabel(event.GetId()) |
---|
| 1079 | |
---|
[4e1c362] | 1080 | num,time = name.split(']') |
---|
| 1081 | current_state_num = self.state.state_num |
---|
| 1082 | self.get_bookmark_by_num(num) |
---|
| 1083 | state_num = int(current_state_num)+1 |
---|
| 1084 | |
---|
| 1085 | self.state.saved_state['state_num'] = state_num |
---|
[4a2b054] | 1086 | #copy.deepcopy(self.state.saved_state) |
---|
| 1087 | self.state.state_list[str(state_num)] = self.state.clone_state() |
---|
[4e1c362] | 1088 | self.state.state_num = state_num |
---|
[cb69775] | 1089 | |
---|
[27f3831] | 1090 | self._set_undo_flag(True) |
---|
[4e1c362] | 1091 | self._info_bookmark_num(event) |
---|
| 1092 | |
---|
| 1093 | def _info_bookmark_num(self,event=None): |
---|
| 1094 | """ |
---|
| 1095 | print the bookmark number in info |
---|
| 1096 | |
---|
| 1097 | : event: popUpMenu event |
---|
| 1098 | """ |
---|
| 1099 | if event == None: return |
---|
| 1100 | # get the object |
---|
[cb69775] | 1101 | menu = event.GetEventObject() |
---|
| 1102 | item = menu.FindItemById(event.GetId()) |
---|
[4e1c362] | 1103 | text = item.GetText() |
---|
| 1104 | num = text.split(']')[0] |
---|
| 1105 | msg = "bookmark num = %s "% num |
---|
| 1106 | |
---|
| 1107 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 1108 | |
---|
| 1109 | def _info_state_num(self): |
---|
| 1110 | """ |
---|
| 1111 | print the current state number in info |
---|
| 1112 | """ |
---|
| 1113 | msg = "state num = " |
---|
| 1114 | msg += self.state.state_num |
---|
| 1115 | |
---|
| 1116 | wx.PostEvent(self.parent, StatusEvent(status = msg)) |
---|
| 1117 | |
---|
| 1118 | def _get_time_stamp(self): |
---|
| 1119 | """ |
---|
| 1120 | return time and date stings |
---|
| 1121 | """ |
---|
| 1122 | # date and time |
---|
| 1123 | year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() |
---|
| 1124 | my_time= str(hour)+":"+str(minute)+":"+str(second) |
---|
| 1125 | date= str( month)+"/"+str(day)+"/"+str(year) |
---|
| 1126 | return my_time, date |
---|
[cb69775] | 1127 | |
---|
[4e1c362] | 1128 | |
---|
[27f3831] | 1129 | def on_save(self, evt=None): |
---|
[4e1c362] | 1130 | """ |
---|
| 1131 | Save invariant state into a file |
---|
| 1132 | """ |
---|
| 1133 | # Ask the user the location of the file to write to. |
---|
| 1134 | path = None |
---|
[4a2b054] | 1135 | dlg = wx.FileDialog(self, "Choose a file", |
---|
| 1136 | self._default_save_location, "", "*.inv", wx.SAVE) |
---|
[4e1c362] | 1137 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 1138 | path = dlg.GetPath() |
---|
| 1139 | self._default_save_location = os.path.dirname(path) |
---|
| 1140 | else: |
---|
| 1141 | return None |
---|
| 1142 | |
---|
| 1143 | dlg.Destroy() |
---|
| 1144 | |
---|
| 1145 | self._manager.save_file(filepath=path, state=self.state) |
---|
| 1146 | |
---|
| 1147 | def _show_message(self, mssg='',msg='Warning'): |
---|
| 1148 | """ |
---|
| 1149 | Show warning message when resetting data |
---|
| 1150 | """ |
---|
[f24925ab] | 1151 | # no message for now |
---|
| 1152 | return True |
---|
[0399c78] | 1153 | count_bf = self.data_cbbox.GetCount() |
---|
| 1154 | if count_bf > 1: |
---|
[4a2b054] | 1155 | msg += "Loading a new data set will reset all the work" |
---|
| 1156 | msg += " done in this panel. \n\r" |
---|
| 1157 | mssg += "Please make sure to save it first... \n\r" |
---|
| 1158 | answer = wx.MessageBox(mssg, msg, |
---|
| 1159 | wx.CANCEL|wx.OK|wx.ICON_EXCLAMATION) |
---|
[0399c78] | 1160 | |
---|
| 1161 | if answer == wx.OK: |
---|
| 1162 | return True |
---|
| 1163 | else: |
---|
| 1164 | return False |
---|
| 1165 | else: True |
---|
[9ce7641c] | 1166 | |
---|
[c128284] | 1167 | def _reset_output(self): |
---|
| 1168 | """ |
---|
[d7a39e5] | 1169 | clear outputs textcrtl |
---|
[c128284] | 1170 | """ |
---|
[9ce7641c] | 1171 | self.invariant_total_tcl.Clear() |
---|
| 1172 | self.invariant_total_err_tcl.Clear() |
---|
| 1173 | self.volume_tcl.Clear() |
---|
| 1174 | self.volume_err_tcl.Clear() |
---|
| 1175 | self.surface_tcl.Clear() |
---|
| 1176 | self.surface_err_tcl.Clear() |
---|
[a0a4486] | 1177 | #prepare a new container to put result of invariant |
---|
| 1178 | self.inv_container = InvariantContainer() |
---|
[4e1c362] | 1179 | |
---|
| 1180 | |
---|
| 1181 | def _on_context_menu(self,event): |
---|
| 1182 | |
---|
| 1183 | pos = event.GetPosition() |
---|
| 1184 | pos = self.ScreenToClient(pos) |
---|
[b7f29fc] | 1185 | |
---|
[4e1c362] | 1186 | self.PopupMenu(self.popUpMenu, pos) |
---|
| 1187 | |
---|
[9ce7641c] | 1188 | def _define_structure(self): |
---|
[c128284] | 1189 | """ |
---|
[d7a39e5] | 1190 | Define main sizers needed for this panel |
---|
[c128284] | 1191 | """ |
---|
[4a2b054] | 1192 | ## Box sizers must be defined first before |
---|
| 1193 | #defining buttons/textctrls (MAC). |
---|
[9ce7641c] | 1194 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
| 1195 | #Sizer related to outputs |
---|
| 1196 | outputs_box = wx.StaticBox(self, -1, "Outputs") |
---|
| 1197 | self.outputs_sizer = wx.StaticBoxSizer(outputs_box, wx.VERTICAL) |
---|
| 1198 | self.outputs_sizer.SetMinSize((PANEL_WIDTH,-1)) |
---|
| 1199 | #Sizer related to data |
---|
| 1200 | data_name_box = wx.StaticBox(self, -1, "I(q) Data Source") |
---|
| 1201 | self.data_name_boxsizer = wx.StaticBoxSizer(data_name_box, wx.VERTICAL) |
---|
| 1202 | self.data_name_boxsizer.SetMinSize((PANEL_WIDTH,-1)) |
---|
| 1203 | self.hint_msg_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
[210ff4f] | 1204 | self.data_name_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
[3641881] | 1205 | |
---|
[9ce7641c] | 1206 | self.data_range_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
[d0cc0bbc] | 1207 | #Sizer related to background and scale |
---|
| 1208 | self.bkg_scale_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1209 | #Sizer related to contrast and porod constant |
---|
| 1210 | self.contrast_porod_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1211 | #Sizer related to inputs |
---|
| 1212 | inputs_box = wx.StaticBox(self, -1, "Customized Inputs") |
---|
| 1213 | self.inputs_sizer = wx.StaticBoxSizer(inputs_box, wx.VERTICAL) |
---|
| 1214 | #Sizer related to extrapolation |
---|
[d5f0dcb9] | 1215 | extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") |
---|
[9ce7641c] | 1216 | self.extrapolation_sizer = wx.StaticBoxSizer(extrapolation_box, |
---|
| 1217 | wx.VERTICAL) |
---|
| 1218 | self.extrapolation_sizer.SetMinSize((PANEL_WIDTH,-1)) |
---|
| 1219 | self.extrapolation_range_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1220 | self.extrapolation_low_high_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1221 | #Sizer related to extrapolation at low q range |
---|
[d5f0dcb9] | 1222 | low_q_box = wx.StaticBox(self, -1, "Low Q") |
---|
[9ce7641c] | 1223 | self.low_extrapolation_sizer = wx.StaticBoxSizer(low_q_box, wx.VERTICAL) |
---|
| 1224 | self.low_q_sizer = wx.GridBagSizer(5,5) |
---|
| 1225 | #Sizer related to extrapolation at low q range |
---|
| 1226 | high_q_box = wx.StaticBox(self, -1, "High Q") |
---|
[4a2b054] | 1227 | self.high_extrapolation_sizer = wx.StaticBoxSizer(high_q_box, |
---|
| 1228 | wx.VERTICAL) |
---|
[9ce7641c] | 1229 | self.high_q_sizer = wx.GridBagSizer(5,5) |
---|
| 1230 | #sizer to define outputs |
---|
| 1231 | self.volume_surface_sizer = wx.GridBagSizer(5,5) |
---|
| 1232 | #Sizer related to invariant output |
---|
[277fad8] | 1233 | self.invariant_sizer = wx.GridBagSizer(5, 5) |
---|
[9ce7641c] | 1234 | #Sizer related to button |
---|
| 1235 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
[4e1c362] | 1236 | #Sizer related to save button |
---|
| 1237 | self.save_button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1238 | |
---|
[9ce7641c] | 1239 | def _layout_data_name(self): |
---|
| 1240 | """ |
---|
[d7a39e5] | 1241 | Draw widgets related to data's name |
---|
[9ce7641c] | 1242 | """ |
---|
| 1243 | #Sizer hint |
---|
[cb69775] | 1244 | hint_msg = "" |
---|
| 1245 | |
---|
[277fad8] | 1246 | self.hint_msg_txt = wx.StaticText(self, -1, hint_msg) |
---|
| 1247 | self.hint_msg_txt.SetForegroundColour("red") |
---|
[4a2b054] | 1248 | msg = "Highlight = mouse the mouse's cursor on the data until" |
---|
| 1249 | msg += " the plot's color changes to yellow" |
---|
[6848131] | 1250 | self.hint_msg_txt.SetToolTipString(msg) |
---|
[277fad8] | 1251 | self.hint_msg_sizer.Add(self.hint_msg_txt) |
---|
[210ff4f] | 1252 | #Data name [string] |
---|
| 1253 | data_name_txt = wx.StaticText(self, -1, 'Data : ') |
---|
| 1254 | |
---|
[4a2b054] | 1255 | self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), |
---|
| 1256 | style=0) |
---|
[210ff4f] | 1257 | self.data_name_tcl.SetToolTipString("Data's name.") |
---|
| 1258 | self.data_name_sizer.AddMany([(data_name_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 1259 | (self.data_name_tcl, 0, wx.EXPAND)]) |
---|
[9ce7641c] | 1260 | #Data range [string] |
---|
| 1261 | data_range_txt = wx.StaticText(self, -1, 'Total Q Range (1/A): ') |
---|
| 1262 | data_min_txt = wx.StaticText(self, -1, 'Min : ') |
---|
[4a2b054] | 1263 | self.data_min_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
| 1264 | style=0, name='data_min_tcl') |
---|
[9ce7641c] | 1265 | self.data_min_tcl.SetToolTipString("The minimum value of q range.") |
---|
| 1266 | data_max_txt = wx.StaticText(self, -1, 'Max : ') |
---|
[4a2b054] | 1267 | self.data_max_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
| 1268 | style=0, name='data_max_tcl') |
---|
[9ce7641c] | 1269 | self.data_max_tcl.SetToolTipString("The maximum value of q range.") |
---|
| 1270 | self.data_range_sizer.AddMany([(data_range_txt, 0, wx.RIGHT, 10), |
---|
| 1271 | (data_min_txt, 0, wx.RIGHT, 10), |
---|
| 1272 | (self.data_min_tcl, 0, wx.RIGHT, 10), |
---|
| 1273 | (data_max_txt, 0, wx.RIGHT, 10), |
---|
| 1274 | (self.data_max_tcl, 0, wx.RIGHT, 10)]) |
---|
[4e1c362] | 1275 | self.data_name_boxsizer.AddMany([(self.hint_msg_sizer, 0 , wx.ALL, 5), |
---|
[210ff4f] | 1276 | (self.data_name_sizer, 0 , wx.ALL, 10), |
---|
[343fdb6] | 1277 | (self.data_range_sizer, 0 , wx.ALL, 10)]) |
---|
[9ce7641c] | 1278 | |
---|
[d0cc0bbc] | 1279 | def _layout_bkg_scale(self): |
---|
[9ce7641c] | 1280 | """ |
---|
[d7a39e5] | 1281 | Draw widgets related to background and scale |
---|
[9ce7641c] | 1282 | """ |
---|
| 1283 | background_txt = wx.StaticText(self, -1, 'Background : ') |
---|
[4a2b054] | 1284 | self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
| 1285 | style=0, name='background_tcl') |
---|
[4e1c362] | 1286 | wx.EVT_TEXT(self, self.background_tcl.GetId(), self._on_text) |
---|
| 1287 | background_hint_txt = "Background" |
---|
[518d35d] | 1288 | self.background_tcl.SetToolTipString(background_hint_txt) |
---|
| 1289 | background_unit_txt = wx.StaticText(self, -1, '[1/cm]') |
---|
[9ce7641c] | 1290 | scale_txt = wx.StaticText(self, -1, 'Scale : ') |
---|
[4a2b054] | 1291 | self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, |
---|
| 1292 | name='scale_tcl') |
---|
[4e1c362] | 1293 | wx.EVT_TEXT(self, self.scale_tcl.GetId(), self._on_text) |
---|
[518d35d] | 1294 | scale_hint_txt = "Scale" |
---|
| 1295 | self.scale_tcl.SetToolTipString(scale_hint_txt) |
---|
[d0cc0bbc] | 1296 | self.bkg_scale_sizer.AddMany([(background_txt, 0, wx.LEFT, 10), |
---|
| 1297 | (self.background_tcl, 0, wx.LEFT, 5), |
---|
| 1298 | (background_unit_txt, 0, wx.LEFT, 10), |
---|
| 1299 | (scale_txt, 0, wx.LEFT, 70), |
---|
| 1300 | (self.scale_tcl, 0, wx.LEFT, 40)]) |
---|
| 1301 | |
---|
| 1302 | def _layout_contrast_porod(self): |
---|
[9ce7641c] | 1303 | """ |
---|
[d7a39e5] | 1304 | Draw widgets related to porod constant and contrast |
---|
[9ce7641c] | 1305 | """ |
---|
| 1306 | contrast_txt = wx.StaticText(self, -1, 'Contrast : ') |
---|
[4a2b054] | 1307 | self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
| 1308 | style=0,name='contrast_tcl') |
---|
[4e1c362] | 1309 | wx.EVT_TEXT(self, self.contrast_tcl.GetId(), self._on_text) |
---|
[518d35d] | 1310 | contrast_hint_txt = "Contrast" |
---|
| 1311 | self.contrast_tcl.SetToolTipString(contrast_hint_txt) |
---|
| 1312 | contrast_unit_txt = wx.StaticText(self, -1, '[1/A^(2)]') |
---|
[9ce7641c] | 1313 | porod_const_txt = wx.StaticText(self, -1, 'Porod Constant:') |
---|
[518d35d] | 1314 | self.porod_constant_tcl = InvTextCtrl(self, -1, |
---|
[4a2b054] | 1315 | size=(_BOX_WIDTH, 20), style=0, |
---|
| 1316 | name='porod_constant_tcl') |
---|
[4e1c362] | 1317 | wx.EVT_TEXT(self, self.porod_constant_tcl.GetId(), self._on_text) |
---|
[518d35d] | 1318 | porod_const_hint_txt = "Porod Constant" |
---|
| 1319 | self.porod_constant_tcl.SetToolTipString(porod_const_hint_txt) |
---|
[9ce7641c] | 1320 | optional_txt = wx.StaticText(self, -1, '(Optional)') |
---|
[d0cc0bbc] | 1321 | self.contrast_porod_sizer.AddMany([(contrast_txt, 0, wx.LEFT, 10), |
---|
| 1322 | (self.contrast_tcl, 0, wx.LEFT, 20), |
---|
| 1323 | (contrast_unit_txt, 0, wx.LEFT, 10), |
---|
| 1324 | (porod_const_txt, 0, wx.LEFT, 50), |
---|
[9ce7641c] | 1325 | (self.porod_constant_tcl, 0, wx.LEFT, 0), |
---|
| 1326 | (optional_txt, 0, wx.LEFT, 10)]) |
---|
| 1327 | |
---|
[518d35d] | 1328 | def _enable_fit_power_law_low(self, event=None): |
---|
| 1329 | """ |
---|
[d7a39e5] | 1330 | Enable and disable the power value editing |
---|
[518d35d] | 1331 | """ |
---|
[4e1c362] | 1332 | if event != None: |
---|
[27f3831] | 1333 | self._set_bookmark_flag(True) |
---|
| 1334 | self._set_preview_flag(False) |
---|
[cb69775] | 1335 | |
---|
[518d35d] | 1336 | if self.fix_enable_low.IsEnabled(): |
---|
[4e1c362] | 1337 | |
---|
[518d35d] | 1338 | if self.fix_enable_low.GetValue(): |
---|
[4e1c362] | 1339 | self.fit_enable_low.SetValue(False) |
---|
[518d35d] | 1340 | self.power_low_tcl.Enable() |
---|
| 1341 | else: |
---|
[4e1c362] | 1342 | self.fit_enable_low.SetValue(True) |
---|
[518d35d] | 1343 | self.power_low_tcl.Disable() |
---|
[4e1c362] | 1344 | self._set_state(event=event) |
---|
| 1345 | |
---|
[518d35d] | 1346 | def _enable_low_q_section(self, event=None): |
---|
| 1347 | """ |
---|
[d7a39e5] | 1348 | Disable or enable some button if the user enable low q extrapolation |
---|
[518d35d] | 1349 | """ |
---|
[cb463b4] | 1350 | if event != None: |
---|
[27f3831] | 1351 | self._set_bookmark_flag(True) |
---|
| 1352 | self._set_preview_flag(False) |
---|
[cb463b4] | 1353 | |
---|
[518d35d] | 1354 | if self.enable_low_cbox.GetValue(): |
---|
| 1355 | self.npts_low_tcl.Enable() |
---|
| 1356 | self.fix_enable_low.Enable() |
---|
| 1357 | self.fit_enable_low.Enable() |
---|
| 1358 | self.guinier.Enable() |
---|
| 1359 | self.power_law_low.Enable() |
---|
| 1360 | |
---|
| 1361 | else: |
---|
| 1362 | self.npts_low_tcl.Disable() |
---|
| 1363 | self.fix_enable_low.Disable() |
---|
| 1364 | self.fit_enable_low.Disable() |
---|
| 1365 | self.guinier.Disable() |
---|
| 1366 | self.power_law_low.Disable() |
---|
[4e1c362] | 1367 | |
---|
[518d35d] | 1368 | self._enable_power_law_low() |
---|
| 1369 | self._enable_fit_power_law_low() |
---|
[4e1c362] | 1370 | self._set_state(event=event) |
---|
[d0cc0bbc] | 1371 | self.button_calculate.SetFocus() |
---|
[4e1c362] | 1372 | |
---|
[518d35d] | 1373 | def _enable_power_law_low(self, event=None): |
---|
| 1374 | """ |
---|
[d7a39e5] | 1375 | Enable editing power law section at low q range |
---|
[518d35d] | 1376 | """ |
---|
[cb463b4] | 1377 | if event != None: |
---|
[27f3831] | 1378 | self._set_bookmark_flag(True) |
---|
| 1379 | self._set_preview_flag(False) |
---|
[518d35d] | 1380 | if self.guinier.GetValue(): |
---|
[4e1c362] | 1381 | self.power_law_low.SetValue(False) |
---|
[518d35d] | 1382 | self.fix_enable_low.Disable() |
---|
| 1383 | self.fit_enable_low.Disable() |
---|
| 1384 | self.power_low_tcl.Disable() |
---|
| 1385 | else: |
---|
[4e1c362] | 1386 | self.power_law_low.SetValue(True) |
---|
[518d35d] | 1387 | self.fix_enable_low.Enable() |
---|
| 1388 | self.fit_enable_low.Enable() |
---|
| 1389 | self.power_low_tcl.Enable() |
---|
| 1390 | self._enable_fit_power_law_low() |
---|
[4e1c362] | 1391 | self._set_state(event=event) |
---|
[518d35d] | 1392 | |
---|
[9ce7641c] | 1393 | def _layout_extrapolation_low(self): |
---|
| 1394 | """ |
---|
[d7a39e5] | 1395 | Draw widgets related to extrapolation at low q range |
---|
[9ce7641c] | 1396 | """ |
---|
[4a2b054] | 1397 | self.enable_low_cbox = wx.CheckBox(self, -1, |
---|
| 1398 | "Enable Extrapolate Low Q", |
---|
| 1399 | name='enable_low_cbox') |
---|
[518d35d] | 1400 | wx.EVT_CHECKBOX(self, self.enable_low_cbox.GetId(), |
---|
| 1401 | self._enable_low_q_section) |
---|
| 1402 | self.fix_enable_low = wx.RadioButton(self, -1, 'Fix', |
---|
[4a2b054] | 1403 | (10, 10), style=wx.RB_GROUP, |
---|
| 1404 | name='fix_enable_low') |
---|
[518d35d] | 1405 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, |
---|
| 1406 | id=self.fix_enable_low.GetId()) |
---|
[4a2b054] | 1407 | self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10), |
---|
| 1408 | name='fit_enable_low') |
---|
[518d35d] | 1409 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, |
---|
| 1410 | id=self.fit_enable_low.GetId()) |
---|
[c128284] | 1411 | self.guinier = wx.RadioButton(self, -1, 'Guinier', |
---|
[4a2b054] | 1412 | (10, 10), style=wx.RB_GROUP, |
---|
| 1413 | name='guinier') |
---|
[518d35d] | 1414 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, |
---|
[4e1c362] | 1415 | id=self.guinier.GetId()) |
---|
[4a2b054] | 1416 | self.power_law_low = wx.RadioButton(self, -1, 'Power Law', |
---|
| 1417 | (10, 10), name='power_law_low') |
---|
[518d35d] | 1418 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, |
---|
| 1419 | id=self.power_law_low.GetId()) |
---|
| 1420 | |
---|
[c128284] | 1421 | npts_low_txt = wx.StaticText(self, -1, 'Npts') |
---|
[4a2b054] | 1422 | self.npts_low_tcl = InvTextCtrl(self, -1, |
---|
| 1423 | size=(_BOX_WIDTH*2/3, -1), |
---|
| 1424 | name='npts_low_tcl') |
---|
[4e1c362] | 1425 | wx.EVT_TEXT(self, self.npts_low_tcl.GetId(), self._on_text) |
---|
[2661d8b] | 1426 | msg_hint = "Number of Q points to consider" |
---|
| 1427 | msg_hint +="while extrapolating the low-Q region" |
---|
[9ce7641c] | 1428 | self.npts_low_tcl.SetToolTipString(msg_hint) |
---|
| 1429 | power_txt = wx.StaticText(self, -1, 'Power') |
---|
[4a2b054] | 1430 | self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1), |
---|
| 1431 | name='power_low_tcl') |
---|
[4e1c362] | 1432 | wx.EVT_TEXT(self, self.power_low_tcl.GetId(), self._on_text) |
---|
[d0cc0bbc] | 1433 | |
---|
[9ce7641c] | 1434 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
| 1435 | self.power_low_tcl.SetToolTipString(power_hint_txt) |
---|
[c128284] | 1436 | iy = 0 |
---|
| 1437 | ix = 0 |
---|
[4a2b054] | 1438 | self.low_q_sizer.Add(self.enable_low_cbox,(iy, ix), (1, 5), |
---|
[518d35d] | 1439 | wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1440 | iy += 1 |
---|
| 1441 | ix = 0 |
---|
[4a2b054] | 1442 | self.low_q_sizer.Add(npts_low_txt,(iy, ix), (1, 1), |
---|
[518d35d] | 1443 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1444 | ix += 1 |
---|
| 1445 | self.low_q_sizer.Add(self.npts_low_tcl, (iy, ix), (1,1), |
---|
| 1446 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1447 | iy += 1 |
---|
| 1448 | ix = 0 |
---|
[9ce7641c] | 1449 | self.low_q_sizer.Add(self.guinier,(iy, ix),(1,2), |
---|
[c128284] | 1450 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1451 | iy += 1 |
---|
| 1452 | ix = 0 |
---|
[4a2b054] | 1453 | self.low_q_sizer.Add(self.power_law_low,(iy, ix), (1, 2), |
---|
[2661d8b] | 1454 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[518d35d] | 1455 | |
---|
[2661d8b] | 1456 | # Parameter controls for power law |
---|
| 1457 | ix = 1 |
---|
| 1458 | iy += 1 |
---|
[4a2b054] | 1459 | self.low_q_sizer.Add(self.fix_enable_low,(iy, ix), (1, 1), |
---|
[518d35d] | 1460 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1461 | ix += 1 |
---|
| 1462 | self.low_q_sizer.Add(self.fit_enable_low,(iy, ix),(1,1), |
---|
| 1463 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[9ce7641c] | 1464 | ix = 1 |
---|
| 1465 | iy += 1 |
---|
[4a2b054] | 1466 | self.low_q_sizer.Add(power_txt,(iy, ix), (1, 1), |
---|
[518d35d] | 1467 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[c128284] | 1468 | ix += 1 |
---|
[4a2b054] | 1469 | self.low_q_sizer.Add(self.power_low_tcl, (iy, ix), (1, 1), |
---|
[c128284] | 1470 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[9ce7641c] | 1471 | self.low_extrapolation_sizer.AddMany([(self.low_q_sizer, 0, |
---|
[d0cc0bbc] | 1472 | wx.BOTTOM|wx.RIGHT, 15)]) |
---|
| 1473 | |
---|
[518d35d] | 1474 | def _enable_fit_power_law_high(self, event=None): |
---|
| 1475 | """ |
---|
[d7a39e5] | 1476 | Enable and disable the power value editing |
---|
[518d35d] | 1477 | """ |
---|
[cb463b4] | 1478 | if event != None: |
---|
[27f3831] | 1479 | self._set_bookmark_flag(True) |
---|
[cb69775] | 1480 | |
---|
[27f3831] | 1481 | self._set_preview_flag(False) |
---|
[518d35d] | 1482 | if self.fix_enable_high.IsEnabled(): |
---|
| 1483 | if self.fix_enable_high.GetValue(): |
---|
[4e1c362] | 1484 | self.fit_enable_high.SetValue(False) |
---|
[518d35d] | 1485 | self.power_high_tcl.Enable() |
---|
| 1486 | else: |
---|
[4e1c362] | 1487 | self.fit_enable_high.SetValue(True) |
---|
[518d35d] | 1488 | self.power_high_tcl.Disable() |
---|
[4e1c362] | 1489 | self._set_state(event=event) |
---|
[9ce7641c] | 1490 | |
---|
[518d35d] | 1491 | def _enable_high_q_section(self, event=None): |
---|
| 1492 | """ |
---|
[d7a39e5] | 1493 | Disable or enable some button if the user enable high q extrapolation |
---|
[518d35d] | 1494 | """ |
---|
[cb463b4] | 1495 | if event != None: |
---|
[27f3831] | 1496 | self._set_bookmark_flag(True) |
---|
| 1497 | self._set_preview_flag(False) |
---|
[518d35d] | 1498 | if self.enable_high_cbox.GetValue(): |
---|
| 1499 | self.npts_high_tcl.Enable() |
---|
| 1500 | self.power_law_high.Enable() |
---|
| 1501 | self.power_high_tcl.Enable() |
---|
| 1502 | self.fix_enable_high.Enable() |
---|
| 1503 | self.fit_enable_high.Enable() |
---|
| 1504 | else: |
---|
| 1505 | self.npts_high_tcl.Disable() |
---|
| 1506 | self.power_law_high.Disable() |
---|
| 1507 | self.power_high_tcl.Disable() |
---|
| 1508 | self.fix_enable_high.Disable() |
---|
| 1509 | self.fit_enable_high.Disable() |
---|
| 1510 | self._enable_fit_power_law_high() |
---|
[4e1c362] | 1511 | self._set_state(event=event) |
---|
[d0cc0bbc] | 1512 | self.button_calculate.SetFocus() |
---|
[b7f29fc] | 1513 | |
---|
[9ce7641c] | 1514 | def _layout_extrapolation_high(self): |
---|
| 1515 | """ |
---|
[d7a39e5] | 1516 | Draw widgets related to extrapolation at high q range |
---|
[9ce7641c] | 1517 | """ |
---|
[4a2b054] | 1518 | self.enable_high_cbox = wx.CheckBox(self, -1, |
---|
| 1519 | "Enable Extrapolate high-Q", |
---|
| 1520 | name='enable_high_cbox') |
---|
[518d35d] | 1521 | wx.EVT_CHECKBOX(self, self.enable_high_cbox.GetId(), |
---|
| 1522 | self._enable_high_q_section) |
---|
| 1523 | self.fix_enable_high = wx.RadioButton(self, -1, 'Fix', |
---|
[4a2b054] | 1524 | (10, 10), style=wx.RB_GROUP, |
---|
| 1525 | name='fix_enable_high') |
---|
[518d35d] | 1526 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, |
---|
| 1527 | id=self.fix_enable_high.GetId()) |
---|
[4a2b054] | 1528 | self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10), |
---|
| 1529 | name='fit_enable_high') |
---|
[518d35d] | 1530 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, |
---|
| 1531 | id=self.fit_enable_high.GetId()) |
---|
| 1532 | |
---|
[277fad8] | 1533 | self.power_law_high = wx.StaticText(self, -1, 'Power Law') |
---|
[d0cc0bbc] | 1534 | msg_hint ="Check to extrapolate data at high-Q" |
---|
| 1535 | self.power_law_high.SetToolTipString(msg_hint) |
---|
[c128284] | 1536 | npts_high_txt = wx.StaticText(self, -1, 'Npts') |
---|
[4a2b054] | 1537 | self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1), |
---|
| 1538 | name='npts_high_tcl') |
---|
[4e1c362] | 1539 | wx.EVT_TEXT(self, self.npts_high_tcl.GetId(), self._on_text) |
---|
[2661d8b] | 1540 | msg_hint = "Number of Q points to consider" |
---|
| 1541 | msg_hint += "while extrapolating the high-Q region" |
---|
[9ce7641c] | 1542 | self.npts_high_tcl.SetToolTipString(msg_hint) |
---|
| 1543 | power_txt = wx.StaticText(self, -1, 'Power') |
---|
[4a2b054] | 1544 | self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1), |
---|
| 1545 | name='power_high_tcl') |
---|
[4e1c362] | 1546 | wx.EVT_TEXT(self, self.power_high_tcl.GetId(), self._on_text) |
---|
[9ce7641c] | 1547 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
| 1548 | self.power_high_tcl.SetToolTipString(power_hint_txt) |
---|
[518d35d] | 1549 | iy = 0 |
---|
| 1550 | ix = 0 |
---|
[4a2b054] | 1551 | self.high_q_sizer.Add(self.enable_high_cbox, (iy, ix), (1, 5), |
---|
[518d35d] | 1552 | wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1553 | iy += 1 |
---|
| 1554 | ix = 0 |
---|
[4a2b054] | 1555 | self.high_q_sizer.Add(npts_high_txt, (iy, ix), (1, 1), |
---|
[518d35d] | 1556 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1557 | ix += 1 |
---|
[4a2b054] | 1558 | self.high_q_sizer.Add(self.npts_high_tcl, (iy, ix), (1, 1), |
---|
[518d35d] | 1559 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1560 | iy += 2 |
---|
[c128284] | 1561 | ix = 0 |
---|
[4a2b054] | 1562 | self.high_q_sizer.Add(self.power_law_high, (iy, ix),(1, 2), |
---|
[2661d8b] | 1563 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[518d35d] | 1564 | |
---|
| 1565 | # Parameter controls for power law |
---|
[2661d8b] | 1566 | ix = 1 |
---|
| 1567 | iy += 1 |
---|
[4a2b054] | 1568 | self.high_q_sizer.Add(self.fix_enable_high,(iy, ix), (1, 1), |
---|
[518d35d] | 1569 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1570 | ix += 1 |
---|
[4a2b054] | 1571 | self.high_q_sizer.Add(self.fit_enable_high,(iy, ix), (1, 1), |
---|
[518d35d] | 1572 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[9ce7641c] | 1573 | ix = 1 |
---|
| 1574 | iy += 1 |
---|
[4a2b054] | 1575 | self.high_q_sizer.Add(power_txt,(iy, ix), (1, 1), |
---|
[c128284] | 1576 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1577 | ix += 1 |
---|
[4a2b054] | 1578 | self.high_q_sizer.Add(self.power_high_tcl, (iy, ix), (1, 1), |
---|
[c128284] | 1579 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[d0cc0bbc] | 1580 | self.high_extrapolation_sizer.AddMany([(self.high_q_sizer, 0, |
---|
| 1581 | wx.BOTTOM|wx.RIGHT, 10)]) |
---|
[c128284] | 1582 | |
---|
[9ce7641c] | 1583 | def _layout_extrapolation(self): |
---|
| 1584 | """ |
---|
[d7a39e5] | 1585 | Draw widgets related to extrapolation |
---|
[9ce7641c] | 1586 | """ |
---|
[518d35d] | 1587 | extra_hint = "Extrapolation Maximum Q Range [1/A]: " |
---|
[9ce7641c] | 1588 | extra_hint_txt = wx.StaticText(self, -1, extra_hint) |
---|
| 1589 | #Extrapolation range [string] |
---|
[4e1c362] | 1590 | extrapolation_min_txt = wx.StaticText(self, -1, 'Min :') |
---|
[518d35d] | 1591 | self.extrapolation_min_tcl = OutputTextCtrl(self, -1, |
---|
[4a2b054] | 1592 | size=(_BOX_WIDTH, 20), style=0, |
---|
| 1593 | name='extrapolation_min_tcl') |
---|
[9ce7641c] | 1594 | self.extrapolation_min_tcl.SetValue(str(Q_MINIMUM)) |
---|
[4a2b054] | 1595 | hint_msg = "The minimum extrapolated q value." |
---|
| 1596 | self.extrapolation_min_tcl.SetToolTipString(hint_msg) |
---|
[4e1c362] | 1597 | extrapolation_max_txt = wx.StaticText(self, -1, 'Max :') |
---|
[518d35d] | 1598 | self.extrapolation_max_tcl = OutputTextCtrl(self, -1, |
---|
[4a2b054] | 1599 | size=(_BOX_WIDTH, 20), |
---|
| 1600 | style=0, |
---|
| 1601 | name='extrapolation_max_tcl') |
---|
[9ce7641c] | 1602 | self.extrapolation_max_tcl.SetValue(str(Q_MAXIMUM)) |
---|
[4a2b054] | 1603 | hint_msg = "The maximum extrapolated q value." |
---|
| 1604 | self.extrapolation_max_tcl.SetToolTipString(hint_msg) |
---|
| 1605 | self.extrapolation_range_sizer.AddMany([(extra_hint_txt, 0, |
---|
| 1606 | wx.LEFT, 10), |
---|
| 1607 | (extrapolation_min_txt, 0, |
---|
| 1608 | wx.LEFT, 10), |
---|
[9ce7641c] | 1609 | (self.extrapolation_min_tcl, |
---|
| 1610 | 0, wx.LEFT, 10), |
---|
[4a2b054] | 1611 | (extrapolation_max_txt, 0, |
---|
| 1612 | wx.LEFT, 10), |
---|
[9ce7641c] | 1613 | (self.extrapolation_max_tcl, |
---|
| 1614 | 0, wx.LEFT, 10), |
---|
| 1615 | ]) |
---|
| 1616 | self._layout_extrapolation_low() |
---|
| 1617 | self._layout_extrapolation_high() |
---|
| 1618 | self.extrapolation_low_high_sizer.AddMany([(self.low_extrapolation_sizer, |
---|
[4e1c362] | 1619 | 0, wx.ALL, 5), |
---|
[9ce7641c] | 1620 | (self.high_extrapolation_sizer, |
---|
[4e1c362] | 1621 | 0, wx.ALL, 5)]) |
---|
[9ce7641c] | 1622 | self.extrapolation_sizer.AddMany([(self.extrapolation_range_sizer, 0, |
---|
[4e1c362] | 1623 | wx.RIGHT, 5), |
---|
[9ce7641c] | 1624 | (self.extrapolation_low_high_sizer, 0, |
---|
[4e1c362] | 1625 | wx.ALL, 5)]) |
---|
[9ce7641c] | 1626 | |
---|
| 1627 | def _layout_volume_surface_sizer(self): |
---|
| 1628 | """ |
---|
[d7a39e5] | 1629 | Draw widgets related to volume and surface |
---|
[9ce7641c] | 1630 | """ |
---|
| 1631 | unit_volume = '' |
---|
| 1632 | unit_surface = '' |
---|
| 1633 | uncertainty = "+/-" |
---|
[dce0756] | 1634 | volume_txt = wx.StaticText(self, -1, 'Volume Fraction ') |
---|
[4a2b054] | 1635 | self.volume_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), |
---|
| 1636 | name='volume_tcl') |
---|
[4e1c362] | 1637 | wx.EVT_TEXT(self, self.volume_tcl.GetId(), self._on_out_text) |
---|
[9ce7641c] | 1638 | self.volume_tcl.SetToolTipString("Volume fraction.") |
---|
[4a2b054] | 1639 | self.volume_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), |
---|
| 1640 | name='volume_err_tcl') |
---|
[4e1c362] | 1641 | wx.EVT_TEXT(self, self.volume_err_tcl.GetId(), self._on_out_text) |
---|
[4a2b054] | 1642 | hint_msg = "Uncertainty on the volume fraction." |
---|
| 1643 | self.volume_err_tcl.SetToolTipString(hint_msg) |
---|
[c128284] | 1644 | volume_units_txt = wx.StaticText(self, -1, unit_volume) |
---|
| 1645 | |
---|
[277fad8] | 1646 | surface_txt = wx.StaticText(self, -1, 'Specific Surface') |
---|
[4a2b054] | 1647 | self.surface_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), |
---|
| 1648 | name='surface_tcl') |
---|
[4e1c362] | 1649 | wx.EVT_TEXT(self, self.surface_tcl.GetId(), self._on_out_text) |
---|
[9ce7641c] | 1650 | self.surface_tcl.SetToolTipString("Specific surface value.") |
---|
[4a2b054] | 1651 | self.surface_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), |
---|
| 1652 | name='surface_err_tcl') |
---|
[4e1c362] | 1653 | wx.EVT_TEXT(self, self.surface_err_tcl.GetId(), self._on_out_text) |
---|
[4a2b054] | 1654 | hint_msg = "Uncertainty on the specific surface." |
---|
| 1655 | self.surface_err_tcl.SetToolTipString(hint_msg) |
---|
[c128284] | 1656 | surface_units_txt = wx.StaticText(self, -1, unit_surface) |
---|
| 1657 | iy = 0 |
---|
| 1658 | ix = 0 |
---|
[4a2b054] | 1659 | self.volume_surface_sizer.Add(volume_txt, (iy, ix), (1, 1), |
---|
[c128284] | 1660 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[9ce7641c] | 1661 | ix += 1 |
---|
[4a2b054] | 1662 | self.volume_surface_sizer.Add(self.volume_tcl, (iy, ix), (1, 1), |
---|
[9ce7641c] | 1663 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 1664 | ix += 1 |
---|
| 1665 | self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty), |
---|
| 1666 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 1667 | ix += 1 |
---|
[4a2b054] | 1668 | self.volume_surface_sizer.Add(self.volume_err_tcl, (iy, ix), (1, 1), |
---|
[9ce7641c] | 1669 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 1670 | ix += 1 |
---|
[4a2b054] | 1671 | self.volume_surface_sizer.Add(volume_units_txt, (iy, ix), (1, 1), |
---|
[9ce7641c] | 1672 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[c128284] | 1673 | iy += 1 |
---|
| 1674 | ix = 0 |
---|
[4a2b054] | 1675 | self.volume_surface_sizer.Add(surface_txt, (iy, ix), (1, 1), |
---|
[9ce7641c] | 1676 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[c128284] | 1677 | ix += 1 |
---|
[4a2b054] | 1678 | self.volume_surface_sizer.Add(self.surface_tcl, (iy, ix), (1, 1), |
---|
[9ce7641c] | 1679 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[c128284] | 1680 | ix += 1 |
---|
[9ce7641c] | 1681 | self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty), |
---|
[c128284] | 1682 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1683 | ix += 1 |
---|
[4a2b054] | 1684 | self.volume_surface_sizer.Add(self.surface_err_tcl, (iy, ix), (1, 1), |
---|
[c128284] | 1685 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1686 | ix += 1 |
---|
[4a2b054] | 1687 | self.volume_surface_sizer.Add(surface_units_txt, (iy, ix), (1, 1), |
---|
[9ce7641c] | 1688 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 1689 | |
---|
| 1690 | def _layout_invariant_sizer(self): |
---|
| 1691 | """ |
---|
[d7a39e5] | 1692 | Draw widgets related to invariant |
---|
[9ce7641c] | 1693 | """ |
---|
| 1694 | uncertainty = "+/-" |
---|
[277fad8] | 1695 | unit_invariant = '[1/(cm * A)]' |
---|
[eed601e] | 1696 | invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total [Q*]') |
---|
[4a2b054] | 1697 | self.invariant_total_tcl = OutputTextCtrl(self, -1, |
---|
| 1698 | size=(_BOX_WIDTH,-1), |
---|
| 1699 | name='invariant_total_tcl') |
---|
[eed601e] | 1700 | msg_hint = "Total invariant [Q*], including extrapolated regions." |
---|
[9ce7641c] | 1701 | self.invariant_total_tcl.SetToolTipString(msg_hint) |
---|
[4a2b054] | 1702 | self.invariant_total_err_tcl = OutputTextCtrl(self, -1, |
---|
| 1703 | size=(_BOX_WIDTH,-1), |
---|
| 1704 | name='invariant_total_err_tcl') |
---|
| 1705 | hint_msg = "Uncertainty on invariant." |
---|
| 1706 | self.invariant_total_err_tcl.SetToolTipString(hint_msg) |
---|
[9ce7641c] | 1707 | invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
| 1708 | |
---|
| 1709 | #Invariant total |
---|
| 1710 | iy = 0 |
---|
[c128284] | 1711 | ix = 0 |
---|
[4a2b054] | 1712 | self.invariant_sizer.Add(invariant_total_txt, (iy, ix), (1, 1), |
---|
[c128284] | 1713 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[9ce7641c] | 1714 | ix += 1 |
---|
[4a2b054] | 1715 | self.invariant_sizer.Add(self.invariant_total_tcl, (iy, ix), (1, 1), |
---|
[dce0756] | 1716 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[c128284] | 1717 | ix += 1 |
---|
[9ce7641c] | 1718 | self.invariant_sizer.Add( wx.StaticText(self, -1, uncertainty), |
---|
[277fad8] | 1719 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[c128284] | 1720 | ix += 1 |
---|
[4a2b054] | 1721 | self.invariant_sizer.Add(self.invariant_total_err_tcl, (iy, ix), (1, 1), |
---|
[277fad8] | 1722 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[c128284] | 1723 | ix += 1 |
---|
[4a2b054] | 1724 | self.invariant_sizer.Add(invariant_total_units_txt,(iy, ix), (1, 1), |
---|
[277fad8] | 1725 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[9ce7641c] | 1726 | |
---|
[d0cc0bbc] | 1727 | def _layout_inputs_sizer(self): |
---|
| 1728 | """ |
---|
[d7a39e5] | 1729 | Draw widgets related to inputs |
---|
[d0cc0bbc] | 1730 | """ |
---|
| 1731 | self._layout_bkg_scale() |
---|
| 1732 | self._layout_contrast_porod() |
---|
| 1733 | self.inputs_sizer.AddMany([(self.bkg_scale_sizer, 0, wx.ALL, 5), |
---|
| 1734 | (self.contrast_porod_sizer, 0, wx.ALL, 5)]) |
---|
| 1735 | |
---|
[9ce7641c] | 1736 | def _layout_outputs_sizer(self): |
---|
| 1737 | """ |
---|
[d7a39e5] | 1738 | Draw widgets related to outputs |
---|
[9ce7641c] | 1739 | """ |
---|
| 1740 | self._layout_volume_surface_sizer() |
---|
| 1741 | self._layout_invariant_sizer() |
---|
| 1742 | static_line = wx.StaticLine(self, -1) |
---|
| 1743 | self.outputs_sizer.AddMany([(self.volume_surface_sizer, 0, wx.ALL, 10), |
---|
| 1744 | (static_line, 0, wx.EXPAND, 0), |
---|
| 1745 | (self.invariant_sizer, 0, wx.ALL, 10)]) |
---|
| 1746 | def _layout_button(self): |
---|
| 1747 | """ |
---|
[d7a39e5] | 1748 | Do the layout for the button widgets |
---|
[9ce7641c] | 1749 | """ |
---|
| 1750 | #compute button |
---|
[c128284] | 1751 | id = wx.NewId() |
---|
[4a2b054] | 1752 | self.button_calculate = wx.Button(self, id, "Compute", |
---|
| 1753 | name='compute_invariant') |
---|
[d0cc0bbc] | 1754 | self.button_calculate.SetToolTipString("Compute invariant") |
---|
[9ce7641c] | 1755 | self.Bind(wx.EVT_BUTTON, self.compute_invariant, id=id) |
---|
| 1756 | #detail button |
---|
| 1757 | id = wx.NewId() |
---|
[d0cc0bbc] | 1758 | self.button_details = wx.Button(self, id, "Details?") |
---|
[4a2b054] | 1759 | hint_msg = "Details about the results of the computation" |
---|
| 1760 | self.button_details.SetToolTipString(hint_msg) |
---|
[9ce7641c] | 1761 | self.Bind(wx.EVT_BUTTON, self.display_details, id=id) |
---|
| 1762 | details = "Details on Invariant Total Calculations" |
---|
| 1763 | details_txt = wx.StaticText(self, -1, details) |
---|
[4e1c362] | 1764 | self.button_sizer.AddMany([((50,10), 0 , wx.LEFT,0), |
---|
[d0cc0bbc] | 1765 | (details_txt, 0 , |
---|
| 1766 | wx.RIGHT|wx.BOTTOM|wx.TOP, 10), |
---|
| 1767 | (self.button_details, 0 , wx.ALL, 10), |
---|
[4a2b054] | 1768 | (self.button_calculate, 0 , |
---|
[cb69775] | 1769 | wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) |
---|
[9ce7641c] | 1770 | def _do_layout(self): |
---|
| 1771 | """ |
---|
[d7a39e5] | 1772 | Draw window content |
---|
[9ce7641c] | 1773 | """ |
---|
| 1774 | self._define_structure() |
---|
| 1775 | self._layout_data_name() |
---|
| 1776 | self._layout_extrapolation() |
---|
[d0cc0bbc] | 1777 | self._layout_inputs_sizer() |
---|
[9ce7641c] | 1778 | self._layout_outputs_sizer() |
---|
| 1779 | self._layout_button() |
---|
[355b684] | 1780 | self.main_sizer.AddMany([(self.data_name_boxsizer,0, wx.ALL, 10), |
---|
[9ce7641c] | 1781 | (self.outputs_sizer, 0, |
---|
| 1782 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
[355b684] | 1783 | (self.button_sizer,0, |
---|
[d0cc0bbc] | 1784 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
| 1785 | (self.inputs_sizer, 0, |
---|
| 1786 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
| 1787 | (self.extrapolation_sizer, 0, |
---|
[9ce7641c] | 1788 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10)]) |
---|
| 1789 | self.SetSizer(self.main_sizer) |
---|
[355b684] | 1790 | self.SetAutoLayout(True) |
---|
[0399c78] | 1791 | |
---|
| 1792 | |
---|
[c128284] | 1793 | class InvariantDialog(wx.Dialog): |
---|
[d7a39e5] | 1794 | """ |
---|
| 1795 | """ |
---|
[c128284] | 1796 | def __init__(self, parent=None, id=1,graph=None, |
---|
[272d91e] | 1797 | data=None, title="Invariant",base=None): |
---|
| 1798 | wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH, |
---|
[c128284] | 1799 | PANEL_HEIGHT)) |
---|
[272d91e] | 1800 | self.panel = InvariantPanel(self) |
---|
[c128284] | 1801 | self.Centre() |
---|
| 1802 | self.Show(True) |
---|
| 1803 | |
---|
| 1804 | class InvariantWindow(wx.Frame): |
---|
[d7a39e5] | 1805 | """ |
---|
| 1806 | """ |
---|
[4a2b054] | 1807 | def __init__(self, parent=None, id=1, graph=None, |
---|
| 1808 | data=None, title="Invariant", base=None): |
---|
[c128284] | 1809 | |
---|
[9ce7641c] | 1810 | wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH +100, |
---|
| 1811 | PANEL_HEIGHT+100)) |
---|
[4e1c362] | 1812 | from DataLoader.loader import Loader |
---|
| 1813 | self.loader = Loader() |
---|
| 1814 | import invariant |
---|
[4a2b054] | 1815 | path = "C:/ECLPS/workspace/trunk/DataLoader/test/ascii_test_3.txt" |
---|
| 1816 | data= self.loader.load(path) |
---|
[272d91e] | 1817 | self.panel = InvariantPanel(self) |
---|
[4e1c362] | 1818 | |
---|
| 1819 | data.name = data.filename |
---|
[210ff4f] | 1820 | self.panel.set_data(data) |
---|
[c128284] | 1821 | self.Centre() |
---|
| 1822 | self.Show(True) |
---|
| 1823 | |
---|
| 1824 | class MyApp(wx.App): |
---|
| 1825 | def OnInit(self): |
---|
| 1826 | wx.InitAllImageHandlers() |
---|
| 1827 | frame = InvariantWindow() |
---|
| 1828 | frame.Show(True) |
---|
| 1829 | self.SetTopWindow(frame) |
---|
| 1830 | |
---|
| 1831 | return True |
---|
[272d91e] | 1832 | |
---|
[c128284] | 1833 | # end of class MyApp |
---|
| 1834 | |
---|
| 1835 | if __name__ == "__main__": |
---|
| 1836 | app = MyApp(0) |
---|
| 1837 | app.MainLoop() |
---|