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