[0277d084] | 1 | |
---|
| 2 | import sys, os |
---|
| 3 | import wx |
---|
| 4 | import numpy |
---|
| 5 | import time |
---|
| 6 | import copy |
---|
| 7 | import math |
---|
| 8 | import string |
---|
| 9 | from sans.guiframe.utils import format_number,check_float |
---|
| 10 | from sans.guicomm.events import StatusEvent |
---|
| 11 | import pagestate |
---|
| 12 | from pagestate import PageState |
---|
| 13 | (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() |
---|
| 14 | (PreviousStateEvent, EVT_PREVIOUS_STATE) = wx.lib.newevent.NewEvent() |
---|
| 15 | (NextStateEvent, EVT_NEXT_STATE) = wx.lib.newevent.NewEvent() |
---|
| 16 | _BOX_WIDTH = 76 |
---|
| 17 | _QMIN_DEFAULT = 0.001 |
---|
| 18 | _QMAX_DEFAULT = 0.13 |
---|
| 19 | _NPTS_DEFAULT = 50 |
---|
| 20 | #Control panel width |
---|
| 21 | if sys.platform.count("darwin")==0: |
---|
| 22 | PANEL_WIDTH = 450 |
---|
| 23 | FONT_VARIANT = 0 |
---|
| 24 | ON_MAC = False |
---|
| 25 | else: |
---|
| 26 | PANEL_WIDTH = 500 |
---|
| 27 | FONT_VARIANT = 1 |
---|
| 28 | ON_MAC = True |
---|
| 29 | |
---|
| 30 | class BasicPage(wx.ScrolledWindow): |
---|
| 31 | """ |
---|
[74755ff] | 32 | This class provide general structure of fitpanel page |
---|
| 33 | |
---|
[0277d084] | 34 | """ |
---|
| 35 | ## Internal name for the AUI manager |
---|
| 36 | window_name = "Basic Page" |
---|
| 37 | ## Title to appear on top of the window |
---|
| 38 | window_caption = "Basic page " |
---|
| 39 | |
---|
| 40 | def __init__(self,parent, page_info= None, model_list_box=None): |
---|
| 41 | wx.ScrolledWindow.__init__(self, parent, |
---|
| 42 | style= wx.FULL_REPAINT_ON_RESIZE ) |
---|
| 43 | #Set window's font size |
---|
| 44 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
| 45 | |
---|
| 46 | ## parent of the page |
---|
| 47 | self.parent = parent |
---|
| 48 | self.model_list_box = model_list_box |
---|
| 49 | self.model = None |
---|
| 50 | self.manager = None |
---|
| 51 | self.data = None |
---|
| 52 | ## owner of the page (fitting plugin) |
---|
| 53 | self.event_owner = None |
---|
| 54 | |
---|
| 55 | if page_info is not None: |
---|
| 56 | ## manager is the fitting plugin |
---|
| 57 | self.manager= page_info.manager |
---|
| 58 | ## owner of the page (fitting plugin) |
---|
| 59 | self.event_owner= page_info.event_owner |
---|
| 60 | ## current model |
---|
| 61 | self.model = page_info.model |
---|
| 62 | ## data |
---|
| 63 | self.data = page_info.data |
---|
| 64 | ## dictionary containing list of models |
---|
| 65 | self.model_list_box = page_info.model_list_box |
---|
| 66 | ##window_name |
---|
| 67 | self.window_name = page_info.window_name |
---|
| 68 | ##window_caption |
---|
| 69 | self.window_caption = page_info.window_caption |
---|
| 70 | ## Data member to store the dispersion object created |
---|
| 71 | self._disp_obj_dict = {} |
---|
| 72 | ## selected parameters to apply dispersion |
---|
| 73 | self.disp_cb_dict ={} |
---|
| 74 | |
---|
| 75 | ## smearer object |
---|
| 76 | self.smearer = None |
---|
| 77 | |
---|
| 78 | ##list of model parameters. each item must have same length |
---|
| 79 | ## each item related to a given parameters |
---|
| 80 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 81 | self.parameters=[] |
---|
| 82 | ## list of parameters to fit , must be like self.parameters |
---|
| 83 | self.param_toFit=[] |
---|
| 84 | ## list of looking like parameters but with non fittable parameters info |
---|
| 85 | self.fixed_param=[] |
---|
| 86 | ## list of looking like parameters but with fittable parameters info |
---|
| 87 | self.fittable_param=[] |
---|
| 88 | ##list of dispersion parameters |
---|
| 89 | self.disp_list=[] |
---|
| 90 | self.disp_name="" |
---|
| 91 | ## list of orientation parameters |
---|
| 92 | self.orientation_params=[] |
---|
| 93 | self.orientation_params_disp=[] |
---|
| 94 | if self.model != None: |
---|
| 95 | self.disp_list= self.model.getDispParamList() |
---|
| 96 | |
---|
| 97 | ##enable model 2D draw |
---|
| 98 | self.enable2D= False |
---|
| 99 | ## check that the fit range is correct to plot the model again |
---|
| 100 | self.fitrange= True |
---|
| 101 | |
---|
| 102 | ## Q range |
---|
| 103 | self.qmin_x= _QMIN_DEFAULT |
---|
| 104 | self.qmax_x= _QMAX_DEFAULT |
---|
| 105 | self.num_points= _NPTS_DEFAULT |
---|
| 106 | |
---|
| 107 | ## Create memento to save the current state |
---|
| 108 | self.state= PageState(parent= self.parent,model=self.model, data=self.data) |
---|
| 109 | ## flag to determine if state has change |
---|
| 110 | self.state_change= False |
---|
| 111 | ## save customized array |
---|
| 112 | self.values=[] |
---|
| 113 | self.weights=[] |
---|
| 114 | ## retrieve saved state |
---|
| 115 | self.number_saved_state= 0 |
---|
| 116 | ## dictionary of saved state |
---|
| 117 | self.saved_states={} |
---|
| 118 | |
---|
| 119 | ## Create context menu for page |
---|
| 120 | self.popUpMenu = wx.Menu() |
---|
| 121 | #id = wx.NewId() |
---|
| 122 | #self._undo = wx.MenuItem(self.popUpMenu,id, "Undo","cancel the previous action") |
---|
| 123 | #self.popUpMenu.AppendItem(self._undo) |
---|
| 124 | #self._undo.Enable(False) |
---|
| 125 | #wx.EVT_MENU(self, id, self.onUndo) |
---|
| 126 | |
---|
| 127 | #id = wx.NewId() |
---|
| 128 | #self._redo = wx.MenuItem(self.popUpMenu,id,"Redo"," Restore the previous action") |
---|
| 129 | #self.popUpMenu.AppendItem(self._redo) |
---|
| 130 | #self._redo.Enable(False) |
---|
| 131 | #wx.EVT_MENU(self, id, self.onRedo) |
---|
| 132 | #self.popUpMenu.AppendSeparator() |
---|
| 133 | #if sys.platform.count("win32")>0: |
---|
| 134 | id = wx.NewId() |
---|
| 135 | self._keep = wx.MenuItem(self.popUpMenu,id,"BookMark"," Keep the panel status to recall it later") |
---|
| 136 | self.popUpMenu.AppendItem(self._keep) |
---|
| 137 | self._keep.Enable(True) |
---|
| 138 | wx.EVT_MENU(self, id, self.onSave) |
---|
| 139 | self.popUpMenu.AppendSeparator() |
---|
| 140 | |
---|
| 141 | ## Default locations |
---|
| 142 | self._default_save_location = os.getcwd() |
---|
| 143 | ## save initial state on context menu |
---|
| 144 | #self.onSave(event=None) |
---|
| 145 | self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) |
---|
| 146 | |
---|
| 147 | ## create the basic structure of the panel with empty sizer |
---|
| 148 | self.define_page_structure() |
---|
| 149 | ## drawing Initial dispersion parameters sizer |
---|
| 150 | self.set_dispers_sizer() |
---|
| 151 | self._fill_save_sizer() |
---|
| 152 | ## layout |
---|
| 153 | self.set_layout() |
---|
| 154 | |
---|
| 155 | class ModelTextCtrl(wx.TextCtrl): |
---|
| 156 | """ |
---|
[74755ff] | 157 | Text control for model and fit parameters. |
---|
| 158 | Binds the appropriate events for user interactions. |
---|
| 159 | Default callback methods can be overwritten on initialization |
---|
| 160 | |
---|
| 161 | :param kill_focus_callback: callback method for EVT_KILL_FOCUS event |
---|
| 162 | :param set_focus_callback: callback method for EVT_SET_FOCUS event |
---|
| 163 | :param mouse_up_callback: callback method for EVT_LEFT_UP event |
---|
| 164 | :param text_enter_callback: callback method for EVT_TEXT_ENTER event |
---|
| 165 | |
---|
[0277d084] | 166 | """ |
---|
| 167 | ## Set to True when the mouse is clicked while the whole string is selected |
---|
| 168 | full_selection = False |
---|
| 169 | ## Call back for EVT_SET_FOCUS events |
---|
| 170 | _on_set_focus_callback = None |
---|
| 171 | |
---|
| 172 | def __init__(self, parent, id=-1, value=wx.EmptyString, pos=wx.DefaultPosition, |
---|
| 173 | size=wx.DefaultSize, style=0, validator=wx.DefaultValidator, name=wx.TextCtrlNameStr, |
---|
| 174 | kill_focus_callback = None, set_focus_callback = None, |
---|
| 175 | mouse_up_callback = None, text_enter_callback = None): |
---|
| 176 | |
---|
| 177 | wx.TextCtrl.__init__(self, parent, id, value, pos, size, style, validator, name) |
---|
| 178 | |
---|
| 179 | # Bind appropriate events |
---|
| 180 | self._on_set_focus_callback = parent.onSetFocus \ |
---|
| 181 | if set_focus_callback is None else set_focus_callback |
---|
| 182 | self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) |
---|
| 183 | self.Bind(wx.EVT_KILL_FOCUS, parent._onparamEnter \ |
---|
| 184 | if kill_focus_callback is None else kill_focus_callback) |
---|
| 185 | self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \ |
---|
| 186 | if text_enter_callback is None else text_enter_callback) |
---|
| 187 | if not ON_MAC : |
---|
| 188 | self.Bind(wx.EVT_LEFT_UP, self._highlight_text \ |
---|
| 189 | if mouse_up_callback is None else mouse_up_callback) |
---|
| 190 | |
---|
| 191 | def _on_set_focus(self, event): |
---|
| 192 | """ |
---|
[74755ff] | 193 | Catch when the text control is set in focus to highlight the whole |
---|
| 194 | text if necessary |
---|
| 195 | |
---|
| 196 | :param event: mouse event |
---|
[0277d084] | 197 | """ |
---|
| 198 | |
---|
| 199 | event.Skip() |
---|
| 200 | self.full_selection = True |
---|
| 201 | return self._on_set_focus_callback(event) |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | def _highlight_text(self, event): |
---|
| 206 | """ |
---|
[74755ff] | 207 | Highlight text of a TextCtrl only of no text has be selected |
---|
| 208 | |
---|
| 209 | :param event: mouse event |
---|
| 210 | |
---|
[0277d084] | 211 | """ |
---|
| 212 | # Make sure the mouse event is available to other listeners |
---|
| 213 | event.Skip() |
---|
| 214 | control = event.GetEventObject() |
---|
| 215 | if self.full_selection: |
---|
| 216 | self.full_selection = False |
---|
| 217 | # Check that we have a TextCtrl |
---|
| 218 | if issubclass(control.__class__, wx.TextCtrl): |
---|
| 219 | # Check whether text has been selected, |
---|
| 220 | # if not, select the whole string |
---|
| 221 | (start, end) = control.GetSelection() |
---|
| 222 | if start==end: |
---|
| 223 | control.SetSelection(-1,-1) |
---|
| 224 | |
---|
| 225 | def onContextMenu(self, event): |
---|
| 226 | """ |
---|
[74755ff] | 227 | Retrieve the state selected state |
---|
| 228 | |
---|
[0277d084] | 229 | """ |
---|
| 230 | pos = event.GetPosition() |
---|
| 231 | pos = self.ScreenToClient(pos) |
---|
| 232 | self.PopupMenu(self.popUpMenu, pos) |
---|
| 233 | |
---|
| 234 | def onUndo(self, event): |
---|
| 235 | """ |
---|
[74755ff] | 236 | Cancel the previous action |
---|
| 237 | |
---|
[0277d084] | 238 | """ |
---|
| 239 | event = PreviousStateEvent(page = self) |
---|
| 240 | wx.PostEvent(self.parent, event) |
---|
[74755ff] | 241 | |
---|
[0277d084] | 242 | def onRedo(self, event): |
---|
| 243 | """ |
---|
[74755ff] | 244 | Restore the previous action canceled |
---|
| 245 | |
---|
[0277d084] | 246 | """ |
---|
| 247 | event = NextStateEvent(page= self) |
---|
| 248 | wx.PostEvent(self.parent, event) |
---|
[74755ff] | 249 | |
---|
[0277d084] | 250 | def define_page_structure(self): |
---|
| 251 | """ |
---|
[74755ff] | 252 | Create empty sizer for a panel |
---|
| 253 | |
---|
[0277d084] | 254 | """ |
---|
| 255 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 256 | self.sizer0 = wx.BoxSizer(wx.VERTICAL) |
---|
| 257 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
| 258 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
| 259 | self.sizer3 = wx.BoxSizer(wx.VERTICAL) |
---|
| 260 | self.sizer4 = wx.BoxSizer(wx.VERTICAL) |
---|
| 261 | self.sizer5 = wx.BoxSizer(wx.VERTICAL) |
---|
| 262 | self.sizer6 = wx.BoxSizer(wx.VERTICAL) |
---|
| 263 | |
---|
| 264 | self.sizer0.SetMinSize((PANEL_WIDTH,-1)) |
---|
| 265 | self.sizer1.SetMinSize((PANEL_WIDTH,-1)) |
---|
| 266 | self.sizer2.SetMinSize((PANEL_WIDTH,-1)) |
---|
| 267 | self.sizer3.SetMinSize((PANEL_WIDTH,-1)) |
---|
| 268 | self.sizer4.SetMinSize((PANEL_WIDTH,-1)) |
---|
| 269 | self.sizer5.SetMinSize((PANEL_WIDTH,-1)) |
---|
| 270 | #self.sizer6.SetMinSize((375,-1)) |
---|
| 271 | |
---|
| 272 | self.vbox.Add(self.sizer0) |
---|
| 273 | self.vbox.Add(self.sizer1) |
---|
| 274 | self.vbox.Add(self.sizer2) |
---|
| 275 | self.vbox.Add(self.sizer3) |
---|
| 276 | self.vbox.Add(self.sizer4) |
---|
| 277 | self.vbox.Add(self.sizer5) |
---|
| 278 | #self.vbox.Add(self.sizer6) |
---|
| 279 | |
---|
| 280 | |
---|
| 281 | def set_layout(self): |
---|
| 282 | """ |
---|
[74755ff] | 283 | layout |
---|
| 284 | |
---|
[0277d084] | 285 | """ |
---|
| 286 | self.vbox.Layout() |
---|
| 287 | self.vbox.Fit(self) |
---|
| 288 | self.SetSizer(self.vbox) |
---|
| 289 | self.set_scroll() |
---|
| 290 | self.Centre() |
---|
| 291 | |
---|
| 292 | def set_scroll(self): |
---|
[74755ff] | 293 | """ |
---|
| 294 | """ |
---|
[0277d084] | 295 | self.SetScrollbars(20,20,25,65) |
---|
| 296 | self.Layout() |
---|
| 297 | self.SetAutoLayout(True) |
---|
| 298 | |
---|
[74755ff] | 299 | def set_owner(self, owner): |
---|
[0277d084] | 300 | """ |
---|
[74755ff] | 301 | set owner of fitpage |
---|
| 302 | @param owner: the class responsible of plotting |
---|
[0277d084] | 303 | """ |
---|
| 304 | self.event_owner = owner |
---|
| 305 | self.state.event_owner = owner |
---|
| 306 | |
---|
| 307 | def set_manager(self, manager): |
---|
| 308 | """ |
---|
[74755ff] | 309 | set panel manager |
---|
| 310 | |
---|
| 311 | :param manager: instance of plugin fitting |
---|
[0277d084] | 312 | """ |
---|
| 313 | self.manager = manager |
---|
| 314 | self.state.manager = manager |
---|
| 315 | |
---|
| 316 | def populate_box(self, dict): |
---|
| 317 | """ |
---|
[74755ff] | 318 | Store list of model |
---|
| 319 | |
---|
| 320 | :param dict: dictionary containing list of models |
---|
| 321 | |
---|
[0277d084] | 322 | """ |
---|
| 323 | self.model_list_box = dict |
---|
| 324 | self.state.model_list_box = self.model_list_box |
---|
| 325 | |
---|
| 326 | def set_dispers_sizer(self): |
---|
| 327 | """ |
---|
[74755ff] | 328 | fill sizer containing dispersity info |
---|
| 329 | |
---|
[0277d084] | 330 | """ |
---|
| 331 | self.sizer4.Clear(True) |
---|
[74755ff] | 332 | name = "Polydispersity and Orientational Distribution" |
---|
[0277d084] | 333 | box_description= wx.StaticBox(self, -1,name) |
---|
| 334 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 335 | #---------------------------------------------------- |
---|
| 336 | self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), style=wx.RB_GROUP) |
---|
| 337 | self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) |
---|
| 338 | |
---|
| 339 | self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.disable_disp.GetId()) |
---|
| 340 | self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.enable_disp.GetId()) |
---|
| 341 | #MAC needs SetValue |
---|
| 342 | self.disable_disp.SetValue(True) |
---|
| 343 | sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 344 | sizer_dispersion.Add((20,20)) |
---|
| 345 | name=""#Polydispersity and \nOrientational Distribution " |
---|
| 346 | sizer_dispersion.Add(wx.StaticText(self,-1,name)) |
---|
| 347 | sizer_dispersion.Add(self.enable_disp ) |
---|
| 348 | sizer_dispersion.Add((20,20)) |
---|
| 349 | sizer_dispersion.Add(self.disable_disp ) |
---|
| 350 | sizer_dispersion.Add((10,10)) |
---|
| 351 | |
---|
| 352 | ## fill a sizer with the combobox to select dispersion type |
---|
| 353 | sizer_select_dispers = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 354 | self.model_disp = wx.StaticText(self, -1, 'Distribution Function ') |
---|
| 355 | |
---|
| 356 | import sans.models.dispersion_models |
---|
| 357 | self.polydisp= sans.models.dispersion_models.models |
---|
| 358 | self.disp_box = wx.ComboBox(self, -1) |
---|
| 359 | |
---|
| 360 | for key, value in self.polydisp.iteritems(): |
---|
| 361 | name = str(key) |
---|
| 362 | self.disp_box.Append(name,value) |
---|
| 363 | self.disp_box.SetStringSelection("gaussian") |
---|
| 364 | wx.EVT_COMBOBOX(self.disp_box,-1, self._on_select_Disp) |
---|
| 365 | |
---|
| 366 | sizer_select_dispers.Add((10,10)) |
---|
| 367 | sizer_select_dispers.Add(self.model_disp) |
---|
| 368 | sizer_select_dispers.Add(self.disp_box,0, |
---|
| 369 | wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
| 370 | |
---|
| 371 | self.model_disp.Hide() |
---|
| 372 | self.disp_box.Hide() |
---|
| 373 | |
---|
| 374 | boxsizer1.Add( sizer_dispersion,0, |
---|
| 375 | wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
| 376 | #boxsizer1.Add( (10,10) ) |
---|
| 377 | boxsizer1.Add( sizer_select_dispers ) |
---|
| 378 | self.sizer4_4 = wx.GridBagSizer(5,5) |
---|
| 379 | boxsizer1.Add( self.sizer4_4 ) |
---|
| 380 | #----------------------------------------------------- |
---|
| 381 | self.sizer4.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 382 | self.sizer4_4.Layout() |
---|
| 383 | self.sizer4.Layout() |
---|
| 384 | self.Layout() |
---|
| 385 | self.SetScrollbars(20,20,25,65) |
---|
| 386 | self.Refresh() |
---|
| 387 | ## saving the state of enable dispersity button |
---|
| 388 | self.state.enable_disp= self.enable_disp.GetValue() |
---|
| 389 | self.state.disable_disp= self.disable_disp.GetValue() |
---|
| 390 | |
---|
| 391 | |
---|
| 392 | def select_disp_angle(self, event): |
---|
| 393 | """ |
---|
[74755ff] | 394 | Event for when a user select a parameter to average over. |
---|
| 395 | |
---|
| 396 | :param event: radiobutton event |
---|
[0277d084] | 397 | """ |
---|
| 398 | self.values=[] |
---|
| 399 | self.weights=[] |
---|
| 400 | if event.GetEventObject()==self.noDisper_rbox: |
---|
| 401 | if self.noDisper_rbox.GetValue(): |
---|
| 402 | #No array dispersity apply yet |
---|
| 403 | self._reset_dispersity() |
---|
| 404 | ## Redraw the model ??? |
---|
| 405 | self._draw_model() |
---|
| 406 | # Go through the list of dispersion check boxes to identify which one has changed |
---|
| 407 | for p in self.disp_cb_dict: |
---|
| 408 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
| 409 | # Catch which one of the box was just checked or unchecked. |
---|
| 410 | if event.GetEventObject() == self.disp_cb_dict[p]: |
---|
| 411 | if self.disp_cb_dict[p].GetValue() == True: |
---|
| 412 | |
---|
| 413 | ##Temp. FIX for V1.0 regarding changing checkbox to radiobutton. |
---|
| 414 | ##This (self._reset_dispersity) should be removed when the array dispersion is fixed. |
---|
| 415 | self._reset_dispersity() |
---|
| 416 | |
---|
| 417 | # The user wants this parameter to be averaged. |
---|
| 418 | # Pop up the file selection dialog. |
---|
| 419 | path = self._selectDlg() |
---|
| 420 | |
---|
| 421 | # If nothing was selected, just return |
---|
| 422 | if path is None: |
---|
| 423 | self.disp_cb_dict[p].SetValue(False) |
---|
[4cf7443] | 424 | self.noDisper_rbox.SetValue(True) |
---|
[0277d084] | 425 | return |
---|
| 426 | try: |
---|
| 427 | self._default_save_location = os.path.dirname(path) |
---|
| 428 | except: |
---|
| 429 | pass |
---|
| 430 | try: |
---|
| 431 | self.values,self.weights = self.read_file(path) |
---|
| 432 | except: |
---|
| 433 | msg="Could not read input file" |
---|
| 434 | wx.PostEvent(self.parent, StatusEvent(status= msg)) |
---|
| 435 | return |
---|
| 436 | |
---|
| 437 | # If any of the two arrays is empty, notify the user that we won't |
---|
| 438 | # proceed |
---|
| 439 | if self.values is None or self.weights is None or \ |
---|
| 440 | self.values ==[] or self.weights ==[]: |
---|
| 441 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
| 442 | "The loaded %s distrubtion is corrupted or empty" % p)) |
---|
| 443 | return |
---|
| 444 | |
---|
| 445 | # Tell the user that we are about to apply the distribution |
---|
| 446 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
| 447 | "Applying loaded %s distribution: %s" % (p, path))) |
---|
| 448 | |
---|
| 449 | # Create the dispersion objects |
---|
| 450 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 451 | disp_model = ArrayDispersion() |
---|
| 452 | disp_model.set_weights(self.values, self.weights) |
---|
| 453 | |
---|
| 454 | # Store the object to make it persist outside the scope of this method |
---|
| 455 | #TODO: refactor model to clean this up? |
---|
| 456 | self._disp_obj_dict[p] = disp_model |
---|
| 457 | self.state._disp_obj_dict [p]= disp_model |
---|
| 458 | self.state.values=[] |
---|
| 459 | self.state.weights=[] |
---|
| 460 | self.state.values = copy.deepcopy(self.values) |
---|
| 461 | self.state.weights = copy.deepcopy(self.weights) |
---|
| 462 | # Set the new model as the dispersion object for the selected parameter |
---|
| 463 | self.model.set_dispersion(p, disp_model) |
---|
| 464 | # Store a reference to the weights in the model object so that |
---|
| 465 | # it's not lost when we use the model within another thread. |
---|
| 466 | #TODO: total hack - fix this |
---|
| 467 | self.state.model= self.model.clone() |
---|
| 468 | |
---|
| 469 | self.model._persistency_dict = {} |
---|
| 470 | self.model._persistency_dict[p] = [self.values, self.weights] |
---|
| 471 | self.state.model._persistency_dict[p] = [self.values, self.weights] |
---|
| 472 | else: |
---|
| 473 | self._reset_dispersity() |
---|
| 474 | |
---|
| 475 | ## Redraw the model |
---|
| 476 | self._draw_model() |
---|
| 477 | |
---|
| 478 | ## post state to fit panel |
---|
| 479 | event = PageInfoEvent(page = self) |
---|
| 480 | wx.PostEvent(self.parent, event) |
---|
| 481 | |
---|
| 482 | def onResetModel(self, event): |
---|
| 483 | """ |
---|
[74755ff] | 484 | Reset model state |
---|
| 485 | |
---|
[0277d084] | 486 | """ |
---|
| 487 | ## post help message for the selected model |
---|
| 488 | msg = self.popUpMenu.GetHelpString(event.GetId()) |
---|
| 489 | msg +=" reloaded" |
---|
| 490 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 491 | |
---|
| 492 | name= self.popUpMenu.GetLabel(event.GetId()) |
---|
| 493 | self._on_select_model_helper() |
---|
| 494 | |
---|
| 495 | if name in self.saved_states.keys(): |
---|
| 496 | previous_state = self.saved_states[name] |
---|
| 497 | ## reset state of checkbox,textcrtl and regular parameters value |
---|
| 498 | self.reset_page(previous_state) |
---|
| 499 | |
---|
| 500 | def onSave(self, event): |
---|
| 501 | """ |
---|
[74755ff] | 502 | save history of the data and model |
---|
| 503 | |
---|
[0277d084] | 504 | """ |
---|
| 505 | if self.model==None: |
---|
| 506 | return |
---|
| 507 | if hasattr(self,"enable_disp"): |
---|
| 508 | self.state.enable_disp = copy.deepcopy(self.enable_disp.GetValue()) |
---|
| 509 | if hasattr(self, "disp_box"): |
---|
| 510 | self.state.disp_box = copy.deepcopy(self.disp_box.GetSelection()) |
---|
| 511 | |
---|
| 512 | self.state.model.name= self.model.name |
---|
| 513 | |
---|
| 514 | new_state = self.state.clone() |
---|
| 515 | new_state.model.name = self.state.model.name |
---|
| 516 | |
---|
| 517 | new_state.enable2D = copy.deepcopy(self.enable2D) |
---|
| 518 | ##Add model state on context menu |
---|
| 519 | self.number_saved_state += 1 |
---|
| 520 | #name= self.model.name+"[%g]"%self.number_saved_state |
---|
| 521 | name= self.model.__class__.__name__+"[%g]"%self.number_saved_state |
---|
| 522 | self.saved_states[name]= new_state |
---|
| 523 | |
---|
| 524 | ## Add item in the context menu |
---|
| 525 | |
---|
| 526 | year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() |
---|
| 527 | my_time= str(hour)+" : "+str(minute)+" : "+str(second)+" " |
---|
| 528 | date= str( month)+"|"+str(day)+"|"+str(year) |
---|
| 529 | msg= "Model saved at %s on %s"%(my_time, date) |
---|
| 530 | ## post help message for the selected model |
---|
| 531 | msg +=" Saved! right click on this page to retrieve this model" |
---|
| 532 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 533 | |
---|
| 534 | id = wx.NewId() |
---|
| 535 | self.popUpMenu.Append(id,name,str(msg)) |
---|
| 536 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
| 537 | |
---|
| 538 | def onSetFocus(self, evt): |
---|
| 539 | """ |
---|
[74755ff] | 540 | highlight the current textcrtl and hide the error text control shown |
---|
| 541 | after fitting |
---|
| 542 | :Not implemented. |
---|
[0277d084] | 543 | """ |
---|
| 544 | return |
---|
| 545 | |
---|
| 546 | def read_file(self, path): |
---|
| 547 | """ |
---|
[74755ff] | 548 | Read two columns file |
---|
| 549 | |
---|
| 550 | :param path: the path to the file to read |
---|
[0277d084] | 551 | """ |
---|
| 552 | try: |
---|
| 553 | if path==None: |
---|
| 554 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
| 555 | " Selected Distribution was not loaded: %s"%path)) |
---|
| 556 | return None, None |
---|
| 557 | input_f = open(path, 'r') |
---|
| 558 | buff = input_f.read() |
---|
| 559 | lines = buff.split('\n') |
---|
| 560 | |
---|
| 561 | angles = [] |
---|
| 562 | weights=[] |
---|
| 563 | for line in lines: |
---|
| 564 | toks = line.split() |
---|
| 565 | try: |
---|
| 566 | angle = float(toks[0]) |
---|
| 567 | weight = float(toks[1]) |
---|
| 568 | except: |
---|
| 569 | # Skip non-data lines |
---|
| 570 | pass |
---|
| 571 | angles.append(angle) |
---|
| 572 | weights.append(weight) |
---|
| 573 | return numpy.array(angles), numpy.array(weights) |
---|
| 574 | except: |
---|
| 575 | raise |
---|
| 576 | |
---|
| 577 | |
---|
| 578 | def createMemento(self): |
---|
| 579 | """ |
---|
[74755ff] | 580 | return the current state of the page |
---|
[0277d084] | 581 | """ |
---|
| 582 | return self.state.clone() |
---|
| 583 | |
---|
| 584 | |
---|
| 585 | def save_current_state(self): |
---|
| 586 | """ |
---|
[74755ff] | 587 | Store current state |
---|
| 588 | |
---|
[0277d084] | 589 | """ |
---|
| 590 | ## save model option |
---|
| 591 | if self.model!= None: |
---|
| 592 | self.disp_list= self.model.getDispParamList() |
---|
| 593 | self.state.disp_list= copy.deepcopy(self.disp_list) |
---|
| 594 | self.state.model = self.model.clone() |
---|
| 595 | |
---|
| 596 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
| 597 | self.state.values= copy.deepcopy(self.values) |
---|
| 598 | self.state.weights = copy.deepcopy( self.weights) |
---|
| 599 | ## save data |
---|
| 600 | self.state.data= copy.deepcopy(self.data) |
---|
| 601 | try: |
---|
| 602 | n = self.disp_box.GetCurrentSelection() |
---|
| 603 | dispersity= self.disp_box.GetClientData(n) |
---|
| 604 | name= dispersity.__name__ |
---|
| 605 | self.disp_name = name |
---|
| 606 | if name == "GaussianDispersion" : |
---|
| 607 | if hasattr(self,"cb1"): |
---|
| 608 | self.state.cb1= self.cb1.GetValue() |
---|
| 609 | except: |
---|
| 610 | pass |
---|
| 611 | |
---|
| 612 | if hasattr(self,"enable_disp"): |
---|
| 613 | self.state.enable_disp= self.enable_disp.GetValue() |
---|
| 614 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
| 615 | |
---|
| 616 | self.state.smearer = copy.deepcopy(self.smearer) |
---|
| 617 | if hasattr(self,"enable_smearer"): |
---|
| 618 | self.state.enable_smearer = copy.deepcopy(self.enable_smearer.GetValue()) |
---|
| 619 | self.state.disable_smearer = copy.deepcopy(self.disable_smearer.GetValue()) |
---|
| 620 | |
---|
| 621 | if hasattr(self,"disp_box"): |
---|
| 622 | self.state.disp_box = self.disp_box.GetCurrentSelection() |
---|
| 623 | |
---|
| 624 | if len(self.disp_cb_dict)>0: |
---|
| 625 | for k , v in self.disp_cb_dict.iteritems(): |
---|
| 626 | |
---|
| 627 | if v ==None : |
---|
| 628 | self.state.disp_cb_dict[k]= v |
---|
| 629 | else: |
---|
| 630 | try: |
---|
| 631 | self.state.disp_cb_dict[k]=v.GetValue() |
---|
| 632 | except: |
---|
| 633 | self.state.disp_cb_dict[k]= None |
---|
| 634 | |
---|
| 635 | if len(self._disp_obj_dict)>0: |
---|
| 636 | for k , v in self._disp_obj_dict.iteritems(): |
---|
| 637 | |
---|
| 638 | self.state._disp_obj_dict[k]= v |
---|
| 639 | |
---|
| 640 | |
---|
| 641 | self.state.values = copy.deepcopy(self.values) |
---|
| 642 | self.state.weights = copy.deepcopy(self.weights) |
---|
| 643 | ## save plotting range |
---|
| 644 | self._save_plotting_range() |
---|
| 645 | |
---|
| 646 | self.state.orientation_params =[] |
---|
| 647 | self.state.orientation_params_disp =[] |
---|
| 648 | self.state.parameters =[] |
---|
| 649 | self.state.fittable_param =[] |
---|
| 650 | self.state.fixed_param =[] |
---|
| 651 | |
---|
| 652 | |
---|
| 653 | ## save checkbutton state and txtcrtl values |
---|
| 654 | self._copy_parameters_state(self.orientation_params, |
---|
| 655 | self.state.orientation_params) |
---|
| 656 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 657 | self.state.orientation_params_disp) |
---|
| 658 | |
---|
| 659 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
| 660 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 661 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[74755ff] | 662 | |
---|
| 663 | def reset_page_helper(self, state): |
---|
[0277d084] | 664 | """ |
---|
[74755ff] | 665 | Use page_state and change the state of existing page |
---|
[0277d084] | 666 | |
---|
[74755ff] | 667 | :precondition: the page is already drawn or created |
---|
[0277d084] | 668 | |
---|
[74755ff] | 669 | :postcondition: the state of the underlying data change as well as the |
---|
[0277d084] | 670 | state of the graphic interface |
---|
| 671 | """ |
---|
| 672 | if state ==None: |
---|
| 673 | #self._undo.Enable(False) |
---|
| 674 | return |
---|
| 675 | |
---|
| 676 | self.model= state.model |
---|
| 677 | self.data = state.data |
---|
| 678 | if self.data !=None: |
---|
| 679 | from DataLoader.qsmearing import smear_selection |
---|
| 680 | self.smearer= smear_selection( self.data ) |
---|
| 681 | self.enable2D= state.enable2D |
---|
| 682 | self.engine_type = state.engine_type |
---|
| 683 | |
---|
| 684 | self.disp_cb_dict = state.disp_cb_dict |
---|
| 685 | self.disp_list = state.disp_list |
---|
| 686 | |
---|
| 687 | ## set the state of the radio box |
---|
| 688 | self.shape_rbutton.SetValue(state.shape_rbutton ) |
---|
| 689 | self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) |
---|
| 690 | self.struct_rbutton.SetValue(state.struct_rbutton ) |
---|
| 691 | self.plugin_rbutton.SetValue(state.plugin_rbutton) |
---|
| 692 | ##draw sizer containing model parameters value for the current model |
---|
| 693 | self._set_model_sizer_selection( self.model ) |
---|
| 694 | self.set_model_param_sizer(self.model) |
---|
| 695 | |
---|
| 696 | ## reset value of combox box |
---|
| 697 | self.structurebox.SetSelection(state.structurecombobox ) |
---|
| 698 | self.formfactorbox.SetSelection(state.formfactorcombobox) |
---|
| 699 | |
---|
| 700 | ## enable the view 2d button if this is a modelpage type |
---|
| 701 | if hasattr(self,"model_view"): |
---|
| 702 | if self.enable2D: |
---|
| 703 | self.model_view.Disable() |
---|
| 704 | else: |
---|
| 705 | self.model_view.Enable() |
---|
| 706 | ## set the select all check box to the a given state |
---|
| 707 | if hasattr(self, "cb1"): |
---|
| 708 | self.cb1.SetValue(state.cb1) |
---|
| 709 | |
---|
| 710 | ## reset state of checkbox,textcrtl and regular parameters value |
---|
| 711 | |
---|
| 712 | self._reset_parameters_state(self.orientation_params_disp, |
---|
| 713 | state.orientation_params_disp) |
---|
| 714 | self._reset_parameters_state(self.orientation_params, |
---|
| 715 | state.orientation_params) |
---|
| 716 | self._reset_parameters_state(self.parameters,state.parameters) |
---|
| 717 | ## display dispersion info layer |
---|
| 718 | self.enable_disp.SetValue(state.enable_disp) |
---|
| 719 | self.disable_disp.SetValue(state.disable_disp) |
---|
| 720 | |
---|
| 721 | if hasattr(self, "disp_box"): |
---|
| 722 | |
---|
| 723 | self.disp_box.SetSelection(state.disp_box) |
---|
| 724 | n= self.disp_box.GetCurrentSelection() |
---|
| 725 | dispersity= self.disp_box.GetClientData(n) |
---|
| 726 | name= dispersity.__name__ |
---|
| 727 | |
---|
| 728 | self._set_dipers_Param(event=None) |
---|
| 729 | |
---|
| 730 | if name=="ArrayDispersion": |
---|
| 731 | |
---|
| 732 | for item in self.disp_cb_dict.keys(): |
---|
| 733 | |
---|
| 734 | if hasattr(self.disp_cb_dict[item],"SetValue") : |
---|
| 735 | self.disp_cb_dict[item].SetValue(state.disp_cb_dict[item]) |
---|
| 736 | # Create the dispersion objects |
---|
| 737 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 738 | disp_model = ArrayDispersion() |
---|
| 739 | if hasattr(state,"values")and self.disp_cb_dict[item].GetValue()==True: |
---|
| 740 | if len(state.values)>0: |
---|
| 741 | self.values=state.values |
---|
| 742 | self.weights=state.weights |
---|
| 743 | disp_model.set_weights(self.values, state.weights) |
---|
| 744 | else: |
---|
| 745 | self._reset_dispersity() |
---|
| 746 | |
---|
| 747 | self._disp_obj_dict[item] = disp_model |
---|
| 748 | # Set the new model as the dispersion object for the selected parameter |
---|
| 749 | self.model.set_dispersion(item, disp_model) |
---|
| 750 | |
---|
| 751 | self.model._persistency_dict[item] = [state.values, state.weights] |
---|
| 752 | |
---|
| 753 | else: |
---|
| 754 | keys = self.model.getParamList() |
---|
| 755 | for item in keys: |
---|
| 756 | if item in self.disp_list and not self.model.details.has_key(item): |
---|
| 757 | self.model.details[item]=["",None,None] |
---|
| 758 | for k,v in self.state.disp_cb_dict.iteritems(): |
---|
| 759 | self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
| 760 | self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
| 761 | |
---|
| 762 | ##plotting range restore |
---|
| 763 | self._reset_plotting_range(state) |
---|
| 764 | |
---|
| 765 | ## smearing info restore |
---|
| 766 | if hasattr(self,"enable_smearer"): |
---|
| 767 | ## set smearing value whether or not the data contain the smearing info |
---|
| 768 | self.enable_smearer.SetValue(state.enable_smearer) |
---|
| 769 | self.disable_smearer.SetValue(state.disable_smearer) |
---|
| 770 | self.onSmear(event=None) |
---|
| 771 | |
---|
| 772 | ## reset state of checkbox,textcrtl and dispersity parameters value |
---|
| 773 | self._reset_parameters_state(self.fittable_param,state.fittable_param) |
---|
| 774 | self._reset_parameters_state(self.fixed_param,state.fixed_param) |
---|
| 775 | |
---|
| 776 | ## draw the model with previous parameters value |
---|
| 777 | self._onparamEnter_helper() |
---|
| 778 | |
---|
| 779 | ## reset context menu items |
---|
| 780 | self._reset_context_menu() |
---|
| 781 | ## set the value of the current state to the state given as parameter |
---|
| 782 | self.state = state.clone() |
---|
| 783 | self._draw_model() |
---|
| 784 | |
---|
| 785 | def _selectDlg(self): |
---|
| 786 | """ |
---|
[74755ff] | 787 | open a dialog file to selected the customized dispersity |
---|
| 788 | |
---|
[0277d084] | 789 | """ |
---|
| 790 | import os |
---|
| 791 | dlg = wx.FileDialog(self, "Choose a weight file", |
---|
| 792 | self._default_save_location , "", "*.*", wx.OPEN) |
---|
| 793 | path = None |
---|
| 794 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 795 | path = dlg.GetPath() |
---|
| 796 | dlg.Destroy() |
---|
| 797 | return path |
---|
| 798 | |
---|
| 799 | def _reset_context_menu(self): |
---|
| 800 | """ |
---|
[74755ff] | 801 | reset the context menu |
---|
| 802 | |
---|
[0277d084] | 803 | """ |
---|
| 804 | for name, state in self.state.saved_states.iteritems(): |
---|
| 805 | self.number_saved_state += 1 |
---|
| 806 | ## Add item in the context menu |
---|
| 807 | id = wx.NewId() |
---|
| 808 | self.popUpMenu.Append(id,name, 'Save model and state %g'%self.number_saved_state) |
---|
| 809 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
| 810 | |
---|
| 811 | |
---|
| 812 | def _reset_plotting_range(self, state): |
---|
| 813 | """ |
---|
[74755ff] | 814 | Reset the plotting range to a given state |
---|
| 815 | |
---|
[0277d084] | 816 | """ |
---|
| 817 | self.qmin.SetValue(str(state.qmin)) |
---|
| 818 | self.qmax.SetValue(str(state.qmax)) |
---|
| 819 | if self.state.npts!=None: |
---|
| 820 | self.npts.SetValue(str(state.npts)) |
---|
| 821 | |
---|
| 822 | |
---|
| 823 | def _save_typeOfmodel(self): |
---|
| 824 | """ |
---|
[74755ff] | 825 | save radiobutton containing the type model that can be selected |
---|
| 826 | |
---|
[0277d084] | 827 | """ |
---|
| 828 | self.state.shape_rbutton = self.shape_rbutton.GetValue() |
---|
| 829 | self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() |
---|
| 830 | self.state.struct_rbutton = self.struct_rbutton.GetValue() |
---|
| 831 | self.state.plugin_rbutton = self.plugin_rbutton.GetValue() |
---|
| 832 | self.state.structurebox= self.structurebox.GetCurrentSelection() |
---|
| 833 | self.state.formfactorbox = self.formfactorbox.GetCurrentSelection() |
---|
| 834 | |
---|
| 835 | #self._undo.Enable(True) |
---|
| 836 | ## post state to fit panel |
---|
| 837 | event = PageInfoEvent(page = self) |
---|
| 838 | wx.PostEvent(self.parent, event) |
---|
| 839 | |
---|
| 840 | |
---|
| 841 | def _save_plotting_range(self ): |
---|
| 842 | """ |
---|
[74755ff] | 843 | save the state of plotting range |
---|
| 844 | |
---|
[0277d084] | 845 | """ |
---|
| 846 | self.state.qmin = self.qmin_x |
---|
| 847 | self.state.qmax = self.qmax_x |
---|
| 848 | if self.npts!=None: |
---|
| 849 | self.state.npts= self.num_points |
---|
| 850 | |
---|
| 851 | |
---|
| 852 | def _onparamEnter_helper(self): |
---|
| 853 | """ |
---|
[74755ff] | 854 | check if values entered by the user are changed and valid to replot |
---|
| 855 | model |
---|
| 856 | use : _check_value_enter |
---|
| 857 | |
---|
[0277d084] | 858 | """ |
---|
| 859 | # Flag to register when a parameter has changed. |
---|
| 860 | is_modified = False |
---|
| 861 | #self._undo.Enable(True) |
---|
| 862 | if self.model !=None: |
---|
| 863 | try: |
---|
| 864 | is_modified =self._check_value_enter( self.fittable_param ,is_modified) |
---|
| 865 | is_modified =self._check_value_enter( self.fixed_param ,is_modified) |
---|
| 866 | is_modified =self._check_value_enter( self.parameters ,is_modified) |
---|
| 867 | except: |
---|
| 868 | pass |
---|
| 869 | #if is_modified: |
---|
| 870 | # Here we should check whether the boundaries have been modified. |
---|
| 871 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
| 872 | # set the is_modified flag to True |
---|
| 873 | if self._validate_qrange(self.qmin, self.qmax): |
---|
| 874 | tempmin = float(self.qmin.GetValue()) |
---|
| 875 | if tempmin != self.qmin_x: |
---|
| 876 | self.qmin_x = tempmin |
---|
| 877 | is_modified = True |
---|
| 878 | tempmax = float(self.qmax.GetValue()) |
---|
| 879 | if tempmax != self.qmax_x: |
---|
| 880 | self.qmax_x = tempmax |
---|
| 881 | is_modified = True |
---|
| 882 | self.fitrange = True |
---|
| 883 | else: |
---|
| 884 | self.fitrange = False |
---|
| 885 | if self.npts != None: |
---|
| 886 | if check_float(self.npts): |
---|
| 887 | temp_npts = float(self.npts.GetValue()) |
---|
| 888 | if temp_npts != self.num_points: |
---|
| 889 | self.num_points = temp_npts |
---|
| 890 | is_modified = True |
---|
| 891 | else: |
---|
| 892 | msg= "Cannot Plot :Must enter a number!!! " |
---|
| 893 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 894 | |
---|
| 895 | |
---|
| 896 | ## if any value is modify draw model with new value |
---|
| 897 | if is_modified: |
---|
| 898 | self.state_change= True |
---|
| 899 | self._draw_model() |
---|
| 900 | self.Refresh() |
---|
| 901 | return is_modified |
---|
[885857e] | 902 | |
---|
[0277d084] | 903 | |
---|
| 904 | def _is_modified(self, is_modified): |
---|
| 905 | """ |
---|
[74755ff] | 906 | return to self._is_modified |
---|
| 907 | |
---|
[0277d084] | 908 | """ |
---|
| 909 | return is_modified |
---|
| 910 | |
---|
| 911 | def _reset_parameters_state(self, listtorestore,statelist): |
---|
| 912 | """ |
---|
[74755ff] | 913 | Reset the parameters at the given state |
---|
| 914 | |
---|
[0277d084] | 915 | """ |
---|
| 916 | if len(statelist)==0 or len(listtorestore)==0 : |
---|
| 917 | return |
---|
| 918 | if len(statelist)!= len(listtorestore) : |
---|
| 919 | return |
---|
| 920 | |
---|
| 921 | for j in range(len(listtorestore)): |
---|
| 922 | item_page = listtorestore[j] |
---|
| 923 | item_page_info = statelist[j] |
---|
| 924 | ##change the state of the check box for simple parameters |
---|
| 925 | if item_page[0]!=None: |
---|
| 926 | item_page[0].SetValue(item_page_info[0]) |
---|
| 927 | |
---|
| 928 | if item_page[2]!=None: |
---|
| 929 | item_page[2].SetValue(item_page_info[2]) |
---|
| 930 | |
---|
| 931 | if item_page[3]!=None: |
---|
| 932 | ## show or hide text +/- |
---|
| 933 | if item_page_info[2]: |
---|
| 934 | item_page[3].Show(True) |
---|
| 935 | else: |
---|
| 936 | item_page[3].Hide() |
---|
| 937 | if item_page[4]!=None: |
---|
| 938 | ## show of hide the text crtl for fitting error |
---|
| 939 | if item_page_info[4][0]: |
---|
| 940 | item_page[4].Show(True) |
---|
| 941 | item_page[4].SetValue(item_page_info[4][1]) |
---|
| 942 | else: |
---|
| 943 | item_page[3].Hide() |
---|
| 944 | if item_page[5]!=None: |
---|
| 945 | ## show of hide the text crtl for fitting error |
---|
| 946 | if item_page_info[5][0]: |
---|
| 947 | item_page[5].Show(True) |
---|
| 948 | item_page[5].SetValue(item_page_info[5][1]) |
---|
| 949 | else: |
---|
| 950 | item_page[5].Hide() |
---|
| 951 | |
---|
| 952 | if item_page[6]!=None: |
---|
| 953 | ## show of hide the text crtl for fitting error |
---|
| 954 | if item_page_info[6][0]: |
---|
| 955 | item_page[6].Show(True) |
---|
| 956 | item_page[6].SetValue(item_page_info[6][1]) |
---|
| 957 | else: |
---|
| 958 | item_page[6].Hide() |
---|
[74755ff] | 959 | |
---|
[0277d084] | 960 | def _copy_parameters_state(self, listtocopy, statelist): |
---|
| 961 | """ |
---|
[74755ff] | 962 | copy the state of button |
---|
| 963 | |
---|
| 964 | :param listtocopy: the list of widgets 's state to copy |
---|
| 965 | :param statelist: container for the state of widgets that must be copied |
---|
| 966 | |
---|
[0277d084] | 967 | """ |
---|
| 968 | if len(listtocopy)==0: |
---|
| 969 | return |
---|
| 970 | |
---|
| 971 | for item in listtocopy: |
---|
| 972 | |
---|
| 973 | checkbox_state = None |
---|
| 974 | if item[0]!= None: |
---|
| 975 | checkbox_state= item[0].GetValue() |
---|
| 976 | parameter_name = item[1] |
---|
| 977 | parameter_value = None |
---|
| 978 | if item[2]!=None: |
---|
| 979 | parameter_value = item[2].GetValue() |
---|
| 980 | static_text = None |
---|
| 981 | if item[3]!=None: |
---|
| 982 | static_text = item[3].IsShown() |
---|
| 983 | error_value = None |
---|
| 984 | error_state = None |
---|
| 985 | if item[4]!= None: |
---|
| 986 | error_value = item[4].GetValue() |
---|
| 987 | error_state = item[4].IsShown() |
---|
| 988 | |
---|
| 989 | min_value = None |
---|
| 990 | min_state = None |
---|
| 991 | if item[5]!= None: |
---|
| 992 | min_value = item[5].GetValue() |
---|
| 993 | min_state = item[5].IsShown() |
---|
| 994 | |
---|
| 995 | max_value = None |
---|
| 996 | max_state = None |
---|
| 997 | if item[6]!= None: |
---|
| 998 | max_value = item[6].GetValue() |
---|
| 999 | max_state = item[6].IsShown() |
---|
| 1000 | unit=None |
---|
| 1001 | if item[7]!=None: |
---|
| 1002 | unit = item[7].GetLabel() |
---|
| 1003 | |
---|
| 1004 | statelist.append([checkbox_state, parameter_name, parameter_value, |
---|
| 1005 | static_text ,[error_state,error_value], |
---|
| 1006 | [min_state,min_value],[max_state , max_value],unit]) |
---|
| 1007 | |
---|
| 1008 | def _set_model_sizer_selection(self, model): |
---|
| 1009 | """ |
---|
[74755ff] | 1010 | Display the sizer according to the type of the current model |
---|
| 1011 | |
---|
[0277d084] | 1012 | """ |
---|
| 1013 | if model ==None: |
---|
| 1014 | return |
---|
| 1015 | if hasattr(model ,"s_model"): |
---|
| 1016 | |
---|
| 1017 | class_name= model.s_model.__class__ |
---|
| 1018 | name= model.s_model.name |
---|
| 1019 | flag= name != "NoStructure" |
---|
| 1020 | if flag and (class_name in self.model_list_box["Structure Factors"]): |
---|
| 1021 | self.structurebox.Show() |
---|
| 1022 | self.text2.Show() |
---|
| 1023 | self.structurebox.Enable() |
---|
| 1024 | self.text2.Enable() |
---|
| 1025 | items = self.structurebox.GetItems() |
---|
| 1026 | self.sizer1.Layout() |
---|
| 1027 | self.SetScrollbars(20,20,25,65) |
---|
| 1028 | for i in range(len(items)): |
---|
| 1029 | if items[i]== str(name): |
---|
| 1030 | self.structurebox.SetSelection(i) |
---|
| 1031 | break |
---|
| 1032 | |
---|
| 1033 | if hasattr(model ,"p_model"): |
---|
| 1034 | class_name = model.p_model.__class__ |
---|
| 1035 | name = model.p_model.name |
---|
| 1036 | self.formfactorbox.Clear() |
---|
| 1037 | |
---|
| 1038 | for k, list in self.model_list_box.iteritems(): |
---|
| 1039 | if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: |
---|
| 1040 | self.shape_rbutton.SetValue(True) |
---|
| 1041 | ## fill the form factor list with new model |
---|
| 1042 | self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) |
---|
| 1043 | items = self.formfactorbox.GetItems() |
---|
| 1044 | ## set comboxbox to the selected item |
---|
| 1045 | for i in range(len(items)): |
---|
| 1046 | if items[i]== str(name): |
---|
| 1047 | self.formfactorbox.SetSelection(i) |
---|
| 1048 | break |
---|
| 1049 | return |
---|
| 1050 | elif k == "Shape-Independent": |
---|
| 1051 | self.shape_indep_rbutton.SetValue(True) |
---|
| 1052 | elif k == "Structure Factors": |
---|
| 1053 | self.struct_rbutton.SetValue(True) |
---|
| 1054 | else: |
---|
| 1055 | self.plugin_rbutton.SetValue(True) |
---|
| 1056 | |
---|
| 1057 | if class_name in list: |
---|
| 1058 | ## fill the form factor list with new model |
---|
| 1059 | self._populate_box(self.formfactorbox, list) |
---|
| 1060 | items = self.formfactorbox.GetItems() |
---|
| 1061 | ## set comboxbox to the selected item |
---|
| 1062 | for i in range(len(items)): |
---|
| 1063 | if items[i]== str(name): |
---|
| 1064 | self.formfactorbox.SetSelection(i) |
---|
| 1065 | break |
---|
| 1066 | break |
---|
| 1067 | else: |
---|
| 1068 | |
---|
| 1069 | ## Select the model from the menu |
---|
| 1070 | class_name = model.__class__ |
---|
| 1071 | name = model.name |
---|
| 1072 | self.formfactorbox.Clear() |
---|
| 1073 | items = self.formfactorbox.GetItems() |
---|
| 1074 | |
---|
| 1075 | for k, list in self.model_list_box.iteritems(): |
---|
| 1076 | if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: |
---|
| 1077 | if class_name in self.model_list_box["P(Q)*S(Q)"]: |
---|
| 1078 | self.structurebox.Show() |
---|
| 1079 | self.text2.Show() |
---|
| 1080 | self.structurebox.Enable() |
---|
| 1081 | self.structurebox.SetSelection(0) |
---|
| 1082 | self.text2.Enable() |
---|
| 1083 | else: |
---|
| 1084 | self.structurebox.Hide() |
---|
| 1085 | self.text2.Hide() |
---|
| 1086 | self.structurebox.Disable() |
---|
| 1087 | self.structurebox.SetSelection(0) |
---|
| 1088 | self.text2.Disable() |
---|
| 1089 | |
---|
| 1090 | self.shape_rbutton.SetValue(True) |
---|
| 1091 | ## fill the form factor list with new model |
---|
| 1092 | self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) |
---|
| 1093 | items = self.formfactorbox.GetItems() |
---|
| 1094 | ## set comboxbox to the selected item |
---|
| 1095 | for i in range(len(items)): |
---|
| 1096 | if items[i]== str(name): |
---|
| 1097 | self.formfactorbox.SetSelection(i) |
---|
| 1098 | break |
---|
| 1099 | return |
---|
| 1100 | elif k == "Shape-Independent": |
---|
| 1101 | self.shape_indep_rbutton.SetValue(True) |
---|
| 1102 | elif k == "Structure Factors": |
---|
| 1103 | self.struct_rbutton.SetValue(True) |
---|
| 1104 | else: |
---|
| 1105 | self.plugin_rbutton.SetValue(True) |
---|
| 1106 | if class_name in list: |
---|
| 1107 | self.structurebox.SetSelection(0) |
---|
| 1108 | self.structurebox.Disable() |
---|
| 1109 | self.text2.Disable() |
---|
| 1110 | ## fill the form factor list with new model |
---|
| 1111 | self._populate_box(self.formfactorbox, list) |
---|
| 1112 | items = self.formfactorbox.GetItems() |
---|
| 1113 | ## set comboxbox to the selected item |
---|
| 1114 | for i in range(len(items)): |
---|
| 1115 | if items[i]== str(name): |
---|
| 1116 | self.formfactorbox.SetSelection(i) |
---|
| 1117 | break |
---|
| 1118 | break |
---|
| 1119 | |
---|
| 1120 | def _draw_model(self): |
---|
| 1121 | """ |
---|
[74755ff] | 1122 | Method to draw or refresh a plotted model. |
---|
| 1123 | The method will use the data member from the model page |
---|
| 1124 | to build a call to the fitting perspective manager. |
---|
| 1125 | |
---|
| 1126 | :Note to coder: This way future changes will be done in only one place. |
---|
| 1127 | |
---|
[0277d084] | 1128 | """ |
---|
| 1129 | if self.model !=None: |
---|
| 1130 | temp_smear=None |
---|
| 1131 | if hasattr(self, "enable_smearer"): |
---|
| 1132 | if self.enable_smearer.GetValue(): |
---|
| 1133 | temp_smear= self.smearer |
---|
| 1134 | |
---|
| 1135 | self.manager.draw_model(self.model, data=self.data, |
---|
| 1136 | smearer= temp_smear, |
---|
| 1137 | qmin=float(self.qmin_x), |
---|
| 1138 | qmax=float(self.qmax_x), |
---|
| 1139 | qstep= float(self.num_points), |
---|
| 1140 | enable2D=self.enable2D) |
---|
| 1141 | |
---|
| 1142 | def _set_model_sizer(self,sizer, box_sizer, title="", object=None): |
---|
| 1143 | """ |
---|
[74755ff] | 1144 | Use lists to fill a sizer for model info |
---|
| 1145 | |
---|
[0277d084] | 1146 | """ |
---|
| 1147 | |
---|
| 1148 | sizer.Clear(True) |
---|
| 1149 | ##For MAC, this should defined here. |
---|
| 1150 | if box_sizer == None: |
---|
| 1151 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
| 1152 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 1153 | else: |
---|
| 1154 | boxsizer1 = box_sizer |
---|
| 1155 | |
---|
| 1156 | #-------------------------------------------------------- |
---|
| 1157 | self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', style=wx.RB_GROUP) |
---|
| 1158 | self.shape_indep_rbutton = wx.RadioButton(self, -1, "Shape-Independent") |
---|
| 1159 | self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") |
---|
| 1160 | self.plugin_rbutton = wx.RadioButton(self, -1, "Customized Models") |
---|
| 1161 | |
---|
| 1162 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 1163 | id= self.shape_rbutton.GetId() ) |
---|
| 1164 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 1165 | id= self.shape_indep_rbutton.GetId() ) |
---|
| 1166 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 1167 | id= self.struct_rbutton.GetId() ) |
---|
| 1168 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 1169 | id= self.plugin_rbutton.GetId() ) |
---|
| 1170 | #MAC needs SetValue |
---|
| 1171 | self.shape_rbutton.SetValue(True) |
---|
| 1172 | |
---|
| 1173 | sizer_radiobutton = wx.GridSizer(2, 2,5, 5) |
---|
| 1174 | sizer_radiobutton.Add(self.shape_rbutton) |
---|
| 1175 | sizer_radiobutton.Add(self.shape_indep_rbutton) |
---|
| 1176 | sizer_radiobutton.Add(self.plugin_rbutton) |
---|
| 1177 | sizer_radiobutton.Add(self.struct_rbutton) |
---|
| 1178 | |
---|
| 1179 | sizer_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1180 | |
---|
| 1181 | self.text1 = wx.StaticText( self,-1,"" ) |
---|
| 1182 | self.text2 = wx.StaticText( self,-1,"P(Q)*S(Q)" ) |
---|
| 1183 | |
---|
| 1184 | |
---|
| 1185 | self.formfactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
| 1186 | if self.model!=None: |
---|
| 1187 | self.formfactorbox.SetValue(self.model.name) |
---|
| 1188 | |
---|
| 1189 | |
---|
| 1190 | self.structurebox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
| 1191 | wx.EVT_COMBOBOX(self.formfactorbox,-1, self._on_select_model) |
---|
| 1192 | wx.EVT_COMBOBOX(self.structurebox,-1, self._on_select_model) |
---|
| 1193 | |
---|
| 1194 | |
---|
| 1195 | ## fill combox box |
---|
| 1196 | if len(self.model_list_box)>0: |
---|
| 1197 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
| 1198 | |
---|
| 1199 | if len(self.model_list_box)>0: |
---|
| 1200 | self._populate_box( self.structurebox, |
---|
| 1201 | self.model_list_box["Structure Factors"]) |
---|
| 1202 | self.structurebox.Insert("None", 0,None) |
---|
| 1203 | self.structurebox.SetSelection(0) |
---|
| 1204 | self.structurebox.Hide() |
---|
| 1205 | self.text2.Hide() |
---|
| 1206 | self.structurebox.Disable() |
---|
| 1207 | self.text2.Disable() |
---|
| 1208 | |
---|
| 1209 | if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: |
---|
| 1210 | self.structurebox.Show() |
---|
| 1211 | self.text2.Show() |
---|
| 1212 | self.structurebox.Enable() |
---|
| 1213 | self.text2.Enable() |
---|
| 1214 | |
---|
| 1215 | ## check model type to show sizer |
---|
| 1216 | if self.model !=None: |
---|
| 1217 | self._set_model_sizer_selection( self.model ) |
---|
| 1218 | |
---|
| 1219 | sizer_selection.Add(self.text1) |
---|
| 1220 | sizer_selection.Add((5,5)) |
---|
| 1221 | sizer_selection.Add(self.formfactorbox) |
---|
| 1222 | sizer_selection.Add((5,5)) |
---|
| 1223 | sizer_selection.Add(self.text2) |
---|
| 1224 | sizer_selection.Add((5,5)) |
---|
| 1225 | sizer_selection.Add(self.structurebox) |
---|
| 1226 | sizer_selection.Add((5,5)) |
---|
| 1227 | |
---|
| 1228 | boxsizer1.Add( sizer_radiobutton ) |
---|
| 1229 | boxsizer1.Add( (20,20)) |
---|
| 1230 | boxsizer1.Add( sizer_selection ) |
---|
| 1231 | if object !=None: |
---|
| 1232 | boxsizer1.Add( (-72,-72)) |
---|
| 1233 | boxsizer1.Add( object, 0, wx.ALIGN_RIGHT| wx.RIGHT, 35) |
---|
| 1234 | boxsizer1.Add( (60,60)) |
---|
| 1235 | #-------------------------------------------------------- |
---|
| 1236 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 1237 | sizer.Layout() |
---|
| 1238 | self.SetScrollbars(20,20,25,65) |
---|
| 1239 | |
---|
| 1240 | |
---|
| 1241 | def _show_combox(self, event): |
---|
| 1242 | """ |
---|
[74755ff] | 1243 | Show combox box associate with type of model selected |
---|
| 1244 | |
---|
[0277d084] | 1245 | """ |
---|
| 1246 | ## Don't want to populate combo box again if the event comes from check box |
---|
| 1247 | if self.shape_rbutton.GetValue()and\ |
---|
| 1248 | event.GetEventObject()==self.shape_rbutton: |
---|
| 1249 | ##fill the combobox with form factor list |
---|
| 1250 | self.structurebox.SetSelection(0) |
---|
| 1251 | self.structurebox.Disable() |
---|
| 1252 | self.formfactorbox.Clear() |
---|
| 1253 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
| 1254 | |
---|
| 1255 | if self.shape_indep_rbutton.GetValue()and\ |
---|
| 1256 | event.GetEventObject()==self.shape_indep_rbutton: |
---|
| 1257 | ##fill the combobox with shape independent factor list |
---|
| 1258 | self.structurebox.SetSelection(0) |
---|
| 1259 | self.structurebox.Disable() |
---|
| 1260 | self.formfactorbox.Clear() |
---|
| 1261 | self._populate_box( self.formfactorbox, |
---|
| 1262 | self.model_list_box["Shape-Independent"]) |
---|
| 1263 | |
---|
| 1264 | if self.struct_rbutton.GetValue() and\ |
---|
| 1265 | event.GetEventObject()==self.struct_rbutton: |
---|
| 1266 | ##fill the combobox with structure factor list |
---|
| 1267 | self.structurebox.SetSelection(0) |
---|
| 1268 | self.structurebox.Disable() |
---|
| 1269 | self.formfactorbox.Clear() |
---|
| 1270 | self._populate_box( self.formfactorbox, |
---|
| 1271 | self.model_list_box["Structure Factors"]) |
---|
| 1272 | |
---|
| 1273 | if self.plugin_rbutton.GetValue()and\ |
---|
| 1274 | event.GetEventObject()==self.plugin_rbutton: |
---|
| 1275 | |
---|
| 1276 | ##fill the combobox with form factor list |
---|
| 1277 | self.structurebox.Disable() |
---|
| 1278 | self.formfactorbox.Clear() |
---|
| 1279 | self._populate_box( self.formfactorbox, |
---|
| 1280 | self.model_list_box["Customized Models"]) |
---|
| 1281 | |
---|
| 1282 | self._on_select_model(event=None) |
---|
| 1283 | self._save_typeOfmodel() |
---|
| 1284 | self.sizer4_4.Layout() |
---|
| 1285 | self.sizer4.Layout() |
---|
| 1286 | self.Layout() |
---|
| 1287 | self.Refresh() |
---|
| 1288 | self.SetScrollbars(20,20,25,65) |
---|
| 1289 | |
---|
| 1290 | def _populate_box(self, combobox, list): |
---|
| 1291 | """ |
---|
[74755ff] | 1292 | fill combox box with dict item |
---|
| 1293 | |
---|
| 1294 | :param list: contains item to fill the combox |
---|
[0277d084] | 1295 | item must model class |
---|
| 1296 | """ |
---|
| 1297 | for models in list: |
---|
| 1298 | model= models() |
---|
| 1299 | name = model.__class__.__name__ |
---|
| 1300 | if models.__name__!="NoStructure": |
---|
| 1301 | if hasattr(model, "name"): |
---|
| 1302 | name = model.name |
---|
| 1303 | combobox.Append(name,models) |
---|
| 1304 | |
---|
| 1305 | return 0 |
---|
| 1306 | |
---|
| 1307 | def _onparamEnter(self,event): |
---|
| 1308 | """ |
---|
[74755ff] | 1309 | when enter value on panel redraw model according to changed |
---|
| 1310 | |
---|
[0277d084] | 1311 | """ |
---|
| 1312 | tcrtl= event.GetEventObject() |
---|
| 1313 | |
---|
| 1314 | #Clear msg if previously shown. |
---|
| 1315 | msg= "" |
---|
| 1316 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 1317 | |
---|
| 1318 | ## save current state |
---|
| 1319 | self.save_current_state() |
---|
| 1320 | if event !=None: |
---|
| 1321 | #self._undo.Enable(True) |
---|
| 1322 | event = PageInfoEvent(page = self) |
---|
| 1323 | wx.PostEvent(self.parent, event) |
---|
| 1324 | |
---|
| 1325 | if check_float(tcrtl): |
---|
| 1326 | |
---|
| 1327 | self._onparamEnter_helper() |
---|
| 1328 | #event.Skip() |
---|
| 1329 | else: |
---|
| 1330 | msg= "Cannot Plot :Must enter a number!!! " |
---|
| 1331 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 1332 | #event.Skip() |
---|
| 1333 | return |
---|
| 1334 | |
---|
| 1335 | def _onQrangeEnter(self, event): |
---|
| 1336 | """ |
---|
[74755ff] | 1337 | Check validity of value enter in the Q range field |
---|
| 1338 | |
---|
[0277d084] | 1339 | """ |
---|
| 1340 | |
---|
| 1341 | tcrtl= event.GetEventObject() |
---|
| 1342 | #Clear msg if previously shown. |
---|
| 1343 | msg= "" |
---|
| 1344 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 1345 | # Flag to register when a parameter has changed. |
---|
| 1346 | is_modified = False |
---|
| 1347 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
| 1348 | try: |
---|
| 1349 | value = float(tcrtl.GetValue()) |
---|
| 1350 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
| 1351 | |
---|
| 1352 | # If qmin and qmax have been modified, update qmin and qmax |
---|
| 1353 | if self._validate_qrange( self.qmin, self.qmax): |
---|
| 1354 | tempmin = float(self.qmin.GetValue()) |
---|
| 1355 | if tempmin != self.qmin_x: |
---|
| 1356 | self.qmin_x = tempmin |
---|
| 1357 | tempmax = float(self.qmax.GetValue()) |
---|
| 1358 | if tempmax != self.qmax_x: |
---|
| 1359 | self.qmax_x = tempmax |
---|
| 1360 | else: |
---|
| 1361 | tcrtl.SetBackgroundColour("pink") |
---|
| 1362 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
| 1363 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 1364 | return |
---|
| 1365 | |
---|
| 1366 | except: |
---|
| 1367 | tcrtl.SetBackgroundColour("pink") |
---|
| 1368 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
| 1369 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 1370 | return |
---|
| 1371 | #Check if # of points for theory model are valid(>0). |
---|
| 1372 | if self.npts != None: |
---|
| 1373 | if check_float(self.npts): |
---|
| 1374 | temp_npts = float(self.npts.GetValue()) |
---|
| 1375 | if temp_npts != self.num_points: |
---|
| 1376 | self.num_points = temp_npts |
---|
| 1377 | is_modified = True |
---|
| 1378 | else: |
---|
| 1379 | msg= "Cannot Plot :No npts in that Qrange!!! " |
---|
| 1380 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 1381 | |
---|
| 1382 | else: |
---|
| 1383 | tcrtl.SetBackgroundColour("pink") |
---|
| 1384 | msg= "Model Error:wrong value entered!!!" |
---|
| 1385 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
| 1386 | |
---|
| 1387 | #self._undo.Enable(True) |
---|
| 1388 | self.save_current_state() |
---|
| 1389 | event = PageInfoEvent(page = self) |
---|
| 1390 | wx.PostEvent(self.parent, event) |
---|
| 1391 | self.state_change= False |
---|
| 1392 | #Draw the model for a different range |
---|
| 1393 | self._draw_model() |
---|
| 1394 | |
---|
| 1395 | def _on_select_model_helper(self): |
---|
| 1396 | """ |
---|
[74755ff] | 1397 | call back for model selection |
---|
| 1398 | |
---|
[0277d084] | 1399 | """ |
---|
| 1400 | ## reset dictionary containing reference to dispersion |
---|
| 1401 | self._disp_obj_dict = {} |
---|
| 1402 | self.disp_cb_dict ={} |
---|
| 1403 | |
---|
| 1404 | f_id = self.formfactorbox.GetCurrentSelection() |
---|
| 1405 | #For MAC |
---|
| 1406 | form_factor = None |
---|
| 1407 | if f_id >= 0: |
---|
| 1408 | form_factor = self.formfactorbox.GetClientData( f_id ) |
---|
| 1409 | |
---|
| 1410 | if not form_factor in self.model_list_box["multiplication"]: |
---|
| 1411 | self.structurebox.Hide() |
---|
| 1412 | self.text2.Hide() |
---|
| 1413 | self.structurebox.Disable() |
---|
| 1414 | self.structurebox.SetSelection(0) |
---|
| 1415 | self.text2.Disable() |
---|
| 1416 | else: |
---|
| 1417 | self.structurebox.Show() |
---|
| 1418 | self.text2.Show() |
---|
| 1419 | self.structurebox.Enable() |
---|
| 1420 | self.text2.Enable() |
---|
| 1421 | |
---|
| 1422 | s_id = self.structurebox.GetCurrentSelection() |
---|
| 1423 | struct_factor = self.structurebox.GetClientData( s_id ) |
---|
| 1424 | |
---|
| 1425 | if struct_factor !=None: |
---|
| 1426 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
| 1427 | self.model= MultiplicationModel(form_factor(),struct_factor()) |
---|
| 1428 | |
---|
| 1429 | else: |
---|
| 1430 | if form_factor != None: |
---|
| 1431 | self.model= form_factor() |
---|
| 1432 | else: |
---|
| 1433 | self.model = None |
---|
| 1434 | return self.model |
---|
| 1435 | |
---|
| 1436 | ## post state to fit panel |
---|
| 1437 | self.state.parameters =[] |
---|
| 1438 | self.state.model =self.model |
---|
| 1439 | self.disp_list =self.model.getDispParamList() |
---|
| 1440 | self.state.disp_list = self.disp_list |
---|
| 1441 | self.Layout() |
---|
| 1442 | |
---|
| 1443 | def _validate_qrange(self, qmin_ctrl, qmax_ctrl): |
---|
| 1444 | """ |
---|
[74755ff] | 1445 | Verify that the Q range controls have valid values |
---|
| 1446 | and that Qmin < Qmax. |
---|
| 1447 | |
---|
| 1448 | :param qmin_ctrl: text control for Qmin |
---|
| 1449 | :param qmax_ctrl: text control for Qmax |
---|
| 1450 | |
---|
| 1451 | :return: True is the Q range is value, False otherwise |
---|
| 1452 | |
---|
[0277d084] | 1453 | """ |
---|
| 1454 | qmin_validity = check_float(qmin_ctrl) |
---|
| 1455 | qmax_validity = check_float(qmax_ctrl) |
---|
| 1456 | if not (qmin_validity and qmax_validity): |
---|
| 1457 | return False |
---|
| 1458 | else: |
---|
| 1459 | qmin = float(qmin_ctrl.GetValue()) |
---|
| 1460 | qmax = float(qmax_ctrl.GetValue()) |
---|
| 1461 | if qmin < qmax: |
---|
| 1462 | #Make sure to set both colours white. |
---|
| 1463 | qmin_ctrl.SetBackgroundColour(wx.WHITE) |
---|
| 1464 | qmin_ctrl.Refresh() |
---|
| 1465 | qmax_ctrl.SetBackgroundColour(wx.WHITE) |
---|
| 1466 | qmax_ctrl.Refresh() |
---|
| 1467 | else: |
---|
| 1468 | qmin_ctrl.SetBackgroundColour("pink") |
---|
| 1469 | qmin_ctrl.Refresh() |
---|
| 1470 | qmax_ctrl.SetBackgroundColour("pink") |
---|
| 1471 | qmax_ctrl.Refresh() |
---|
| 1472 | msg= "Invalid Q range: Q min must be smaller than Q max" |
---|
| 1473 | wx.PostEvent(self.parent, StatusEvent(status = msg)) |
---|
| 1474 | return False |
---|
| 1475 | return True |
---|
| 1476 | |
---|
| 1477 | def _check_value_enter(self, list, modified): |
---|
| 1478 | """ |
---|
[74755ff] | 1479 | :param list: model parameter and panel info |
---|
| 1480 | each item of the list should be as follow: :: |
---|
| 1481 | |
---|
| 1482 | item = [cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 1483 | |
---|
[0277d084] | 1484 | """ |
---|
| 1485 | is_modified = modified |
---|
| 1486 | if len(list)==0: |
---|
| 1487 | return is_modified |
---|
| 1488 | for item in list: |
---|
| 1489 | #skip angle parameters for 1D |
---|
[885857e] | 1490 | if not self.enable2D: |
---|
[0277d084] | 1491 | if item in self.orientation_params: |
---|
| 1492 | continue |
---|
| 1493 | #try: |
---|
| 1494 | name = str(item[1]) |
---|
| 1495 | |
---|
| 1496 | try: |
---|
| 1497 | value= float(item[2].GetValue()) |
---|
| 1498 | # If the value of the parameter has changed, |
---|
| 1499 | # +update the model and set the is_modified flag |
---|
| 1500 | if value != self.model.getParam(name) and numpy.isfinite(value): |
---|
| 1501 | self.model.setParam(name,value) |
---|
| 1502 | is_modified = True |
---|
| 1503 | except: |
---|
[885857e] | 1504 | msg = "Wrong parameter value entered " |
---|
[0277d084] | 1505 | wx.PostEvent(self.parent, StatusEvent(status = msg)) |
---|
| 1506 | |
---|
| 1507 | return is_modified |
---|
[74755ff] | 1508 | |
---|
[0277d084] | 1509 | def _set_dipers_Param(self, event): |
---|
| 1510 | """ |
---|
[74755ff] | 1511 | respond to self.enable_disp and self.disable_disp radio box. |
---|
| 1512 | The dispersity object is reset inside the model into Gaussian. |
---|
| 1513 | When the user select yes , this method display a combo box for more selection |
---|
| 1514 | when the user selects No,the combo box disappears. |
---|
| 1515 | Redraw the model with the default dispersity (Gaussian) |
---|
| 1516 | |
---|
[0277d084] | 1517 | """ |
---|
| 1518 | |
---|
| 1519 | self._reset_dispersity() |
---|
| 1520 | |
---|
| 1521 | if self.model ==None: |
---|
| 1522 | self.model_disp.Hide() |
---|
| 1523 | self.disp_box.Hide() |
---|
| 1524 | self.sizer4_4.Clear(True) |
---|
| 1525 | return |
---|
| 1526 | |
---|
| 1527 | if self.enable_disp.GetValue(): |
---|
| 1528 | self.model_disp.Show(True) |
---|
| 1529 | self.disp_box.Show(True) |
---|
| 1530 | ## layout for model containing no dispersity parameters |
---|
| 1531 | |
---|
| 1532 | self.disp_list= self.model.getDispParamList() |
---|
| 1533 | |
---|
| 1534 | if len(self.disp_list)==0 and len(self.disp_cb_dict)==0: |
---|
| 1535 | self._layout_sizer_noDipers() |
---|
| 1536 | else: |
---|
| 1537 | ## set gaussian sizer |
---|
| 1538 | self._on_select_Disp(event=None) |
---|
| 1539 | else: |
---|
| 1540 | self.model_disp.Hide() |
---|
| 1541 | self.disp_box.Hide() |
---|
| 1542 | self.disp_box.SetSelection(0) |
---|
| 1543 | self.sizer4_4.Clear(True) |
---|
| 1544 | |
---|
| 1545 | ## post state to fit panel |
---|
| 1546 | self.save_current_state() |
---|
| 1547 | if event !=None: |
---|
| 1548 | #self._undo.Enable(True) |
---|
| 1549 | event = PageInfoEvent(page = self) |
---|
| 1550 | wx.PostEvent(self.parent, event) |
---|
| 1551 | #draw the model with the current dispersity |
---|
| 1552 | self._draw_model() |
---|
| 1553 | self.sizer4_4.Layout() |
---|
| 1554 | self.sizer5.Layout() |
---|
| 1555 | self.Layout() |
---|
| 1556 | self.Refresh() |
---|
| 1557 | |
---|
| 1558 | |
---|
| 1559 | def _layout_sizer_noDipers(self): |
---|
| 1560 | """ |
---|
[74755ff] | 1561 | Draw a sizer with no dispersity info |
---|
| 1562 | |
---|
[0277d084] | 1563 | """ |
---|
| 1564 | ix=0 |
---|
| 1565 | iy=1 |
---|
| 1566 | self.fittable_param=[] |
---|
| 1567 | self.fixed_param=[] |
---|
| 1568 | self.orientation_params_disp=[] |
---|
| 1569 | |
---|
| 1570 | self.model_disp.Hide() |
---|
| 1571 | self.disp_box.Hide() |
---|
| 1572 | self.sizer4_4.Clear(True) |
---|
| 1573 | model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model') |
---|
| 1574 | self.sizer4_4.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1575 | self.sizer4_4.Layout() |
---|
| 1576 | self.sizer4.Layout() |
---|
| 1577 | self.SetScrollbars(20,20,25,65) |
---|
| 1578 | |
---|
| 1579 | |
---|
| 1580 | def _reset_dispersity(self): |
---|
| 1581 | """ |
---|
[74755ff] | 1582 | put gaussian dispersity into current model |
---|
| 1583 | |
---|
[0277d084] | 1584 | """ |
---|
| 1585 | if len(self.param_toFit)>0: |
---|
| 1586 | for item in self.fittable_param: |
---|
| 1587 | if item in self.param_toFit: |
---|
| 1588 | self.param_toFit.remove(item) |
---|
| 1589 | |
---|
| 1590 | for item in self.orientation_params_disp: |
---|
| 1591 | if item in self.param_toFit: |
---|
| 1592 | self.param_toFit.remove(item) |
---|
| 1593 | |
---|
| 1594 | self.fittable_param=[] |
---|
| 1595 | self.fixed_param=[] |
---|
| 1596 | self.orientation_params_disp=[] |
---|
| 1597 | self.values=[] |
---|
| 1598 | self.weights=[] |
---|
| 1599 | |
---|
| 1600 | from sans.models.dispersion_models import GaussianDispersion, ArrayDispersion |
---|
| 1601 | if len(self.disp_cb_dict)==0: |
---|
| 1602 | self.save_current_state() |
---|
| 1603 | self.sizer4_4.Clear(True) |
---|
| 1604 | self.Layout() |
---|
| 1605 | |
---|
| 1606 | return |
---|
| 1607 | if (len(self.disp_cb_dict)>0) : |
---|
| 1608 | for p in self.disp_cb_dict: |
---|
| 1609 | # The parameter was un-selected. Go back to Gaussian model (with 0 pts) |
---|
| 1610 | disp_model = GaussianDispersion() |
---|
| 1611 | |
---|
| 1612 | self._disp_obj_dict[p] = disp_model |
---|
| 1613 | # Set the new model as the dispersion object for the selected parameter |
---|
| 1614 | try: |
---|
| 1615 | self.model.set_dispersion(p, disp_model) |
---|
| 1616 | except: |
---|
| 1617 | |
---|
| 1618 | pass |
---|
| 1619 | |
---|
| 1620 | ## save state into |
---|
| 1621 | self.save_current_state() |
---|
| 1622 | self.Layout() |
---|
| 1623 | self.Refresh() |
---|
| 1624 | |
---|
| 1625 | |
---|
| 1626 | def _on_select_Disp(self,event): |
---|
| 1627 | """ |
---|
[74755ff] | 1628 | allow selecting different dispersion |
---|
| 1629 | self.disp_list should change type later .now only gaussian |
---|
| 1630 | |
---|
[0277d084] | 1631 | """ |
---|
| 1632 | n = self.disp_box.GetCurrentSelection() |
---|
| 1633 | name = self.disp_box.GetValue() |
---|
| 1634 | dispersity= self.disp_box.GetClientData(n) |
---|
| 1635 | self.disp_name = name |
---|
| 1636 | |
---|
| 1637 | if name.lower() == "array": |
---|
| 1638 | self._set_sizer_arraydispersion() |
---|
| 1639 | else: |
---|
| 1640 | self._set_sizer_dispersion(dispersity= dispersity) |
---|
| 1641 | |
---|
| 1642 | self.state.disp_box= n |
---|
| 1643 | ## Redraw the model |
---|
| 1644 | self._draw_model() |
---|
| 1645 | #self._undo.Enable(True) |
---|
| 1646 | event = PageInfoEvent(page = self) |
---|
| 1647 | wx.PostEvent(self.parent, event) |
---|
| 1648 | |
---|
| 1649 | self.sizer4_4.Layout() |
---|
| 1650 | self.sizer4.Layout() |
---|
| 1651 | self.SetScrollbars(20,20,25,65) |
---|
| 1652 | |
---|
| 1653 | def _set_sizer_arraydispersion(self): |
---|
| 1654 | """ |
---|
[74755ff] | 1655 | draw sizer with array dispersity parameters |
---|
| 1656 | |
---|
[0277d084] | 1657 | """ |
---|
| 1658 | |
---|
| 1659 | if len(self.param_toFit)>0: |
---|
| 1660 | for item in self.fittable_param: |
---|
| 1661 | if item in self.param_toFit: |
---|
| 1662 | self.param_toFit.remove(item) |
---|
| 1663 | for item in self.orientation_params_disp: |
---|
| 1664 | if item in self.param_toFit: |
---|
| 1665 | self.param_toFit.remove(item) |
---|
| 1666 | for item in self.model.details.keys(): |
---|
| 1667 | if item in self.model.fixed: |
---|
| 1668 | del self.model.details [item] |
---|
| 1669 | |
---|
| 1670 | self.fittable_param=[] |
---|
| 1671 | self.fixed_param=[] |
---|
| 1672 | self.orientation_params_disp=[] |
---|
| 1673 | self.sizer4_4.Clear(True) |
---|
| 1674 | self._reset_dispersity() |
---|
| 1675 | ix=0 |
---|
| 1676 | iy=1 |
---|
| 1677 | disp1 = wx.StaticText(self, -1, 'Array Dispersion') |
---|
| 1678 | self.sizer4_4.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1679 | |
---|
| 1680 | # Look for model parameters to which we can apply an ArrayDispersion model |
---|
| 1681 | # Add a check box for each parameter. |
---|
| 1682 | self.disp_cb_dict = {} |
---|
| 1683 | ix+=1 |
---|
| 1684 | self.noDisper_rbox = wx.RadioButton(self, -1,"None", (10, 10),style= wx.RB_GROUP) |
---|
| 1685 | self.Bind(wx.EVT_RADIOBUTTON,self.select_disp_angle , id=self.noDisper_rbox.GetId()) |
---|
| 1686 | #MAC needs SetValue |
---|
| 1687 | self.noDisper_rbox.SetValue(True) |
---|
| 1688 | self.sizer4_4.Add(self.noDisper_rbox, (iy, ix), |
---|
| 1689 | (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1690 | |
---|
| 1691 | for p in self.model.dispersion.keys(): |
---|
| 1692 | if not p in self.model.orientation_params: |
---|
| 1693 | ix+=1 |
---|
| 1694 | self.disp_cb_dict[p] = wx.RadioButton(self, -1, p, (10, 10)) |
---|
| 1695 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
| 1696 | self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, id=self.disp_cb_dict[p].GetId()) |
---|
| 1697 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1698 | |
---|
| 1699 | for p in self.model.dispersion.keys(): |
---|
| 1700 | if p in self.model.orientation_params: |
---|
| 1701 | ix+=1 |
---|
| 1702 | self.disp_cb_dict[p] = wx.RadioButton(self, -1, p, (10, 10)) |
---|
| 1703 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
| 1704 | if not (self.enable2D or self.data.__class__.__name__ =="Data2D"): |
---|
| 1705 | self.disp_cb_dict[p].Hide() |
---|
| 1706 | else: |
---|
| 1707 | self.disp_cb_dict[p].Show(True) |
---|
| 1708 | self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, id=self.disp_cb_dict[p].GetId()) |
---|
| 1709 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1710 | |
---|
| 1711 | |
---|
| 1712 | ix =0 |
---|
| 1713 | iy +=1 |
---|
| 1714 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1715 | self.Layout() |
---|
| 1716 | |
---|
| 1717 | self.state.orientation_params =[] |
---|
| 1718 | self.state.orientation_params_disp =[] |
---|
| 1719 | self.state.parameters =[] |
---|
| 1720 | self.state.fittable_param =[] |
---|
| 1721 | self.state.fixed_param =[] |
---|
| 1722 | |
---|
| 1723 | ## save checkbutton state and txtcrtl values |
---|
| 1724 | self._copy_parameters_state(self.orientation_params, |
---|
| 1725 | self.state.orientation_params) |
---|
| 1726 | |
---|
| 1727 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 1728 | self.state.orientation_params_disp) |
---|
| 1729 | |
---|
| 1730 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
| 1731 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 1732 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[74755ff] | 1733 | |
---|
[0277d084] | 1734 | ## post state to fit panel |
---|
| 1735 | event = PageInfoEvent(page = self) |
---|
| 1736 | wx.PostEvent(self.parent, event) |
---|
| 1737 | |
---|
| 1738 | def _set_range_sizer(self, title, box_sizer=None, object1=None,object=None): |
---|
| 1739 | """ |
---|
[74755ff] | 1740 | Fill the Q range sizer |
---|
| 1741 | |
---|
[0277d084] | 1742 | """ |
---|
| 1743 | self.sizer5.Clear(True) |
---|
| 1744 | #-------------------------------------------------------------- |
---|
| 1745 | if box_sizer == None: |
---|
| 1746 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
| 1747 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 1748 | else: |
---|
| 1749 | #for MAC |
---|
| 1750 | boxsizer1 = box_sizer |
---|
| 1751 | |
---|
| 1752 | self.qmin = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER, |
---|
| 1753 | kill_focus_callback = self._onQrangeEnter, |
---|
| 1754 | text_enter_callback = self._onQrangeEnter) |
---|
| 1755 | self.qmin.SetValue(str(self.qmin_x)) |
---|
| 1756 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
| 1757 | |
---|
| 1758 | self.qmax = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER, |
---|
| 1759 | kill_focus_callback = self._onQrangeEnter, |
---|
| 1760 | text_enter_callback = self._onQrangeEnter) |
---|
| 1761 | self.qmax.SetValue(str(self.qmax_x)) |
---|
| 1762 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
| 1763 | |
---|
| 1764 | id = wx.NewId() |
---|
| 1765 | self.reset_qrange =wx.Button(self,id,'Reset',size=(70,23)) |
---|
| 1766 | |
---|
| 1767 | self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked,id=id) |
---|
| 1768 | self.reset_qrange.SetToolTipString("Reset Q range to the default values") |
---|
| 1769 | |
---|
| 1770 | sizer_horizontal=wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1771 | sizer= wx.GridSizer(3, 3,2, 5) |
---|
| 1772 | |
---|
| 1773 | sizer.Add(wx.StaticText(self, -1, ' Q range')) |
---|
| 1774 | sizer.Add(wx.StaticText(self, -1, ' Min')) |
---|
| 1775 | sizer.Add(wx.StaticText(self, -1, ' Max')) |
---|
| 1776 | sizer.Add(self.reset_qrange) |
---|
| 1777 | |
---|
| 1778 | sizer.Add(self.qmin) |
---|
| 1779 | sizer.Add(self.qmax) |
---|
| 1780 | sizer_horizontal.Add(sizer) |
---|
| 1781 | if object!=None: |
---|
| 1782 | sizer_horizontal.Add(object) |
---|
| 1783 | |
---|
| 1784 | if object1!=None: |
---|
| 1785 | boxsizer1.Add(object1) |
---|
| 1786 | boxsizer1.Add((10,10)) |
---|
| 1787 | boxsizer1.Add(sizer_horizontal) |
---|
| 1788 | ## save state |
---|
| 1789 | self.save_current_state() |
---|
| 1790 | #---------------------------------------------------------------- |
---|
| 1791 | self.sizer5.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 1792 | self.sizer5.Layout() |
---|
| 1793 | |
---|
| 1794 | def _fill_save_sizer(self): |
---|
| 1795 | """ |
---|
[74755ff] | 1796 | Draw the layout for saving option |
---|
| 1797 | |
---|
[0277d084] | 1798 | """ |
---|
| 1799 | # Skipping save state functionality for release 0.9.0 |
---|
| 1800 | return |
---|
| 1801 | |
---|
| 1802 | self.sizer6.Clear(True) |
---|
| 1803 | box_description= wx.StaticBox(self, -1,"Save Model") |
---|
| 1804 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 1805 | sizer_save = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1806 | |
---|
| 1807 | self.btSave_title = wx.StaticText(self, -1, 'Save the current Model') |
---|
| 1808 | self.btSave = wx.Button(self,wx.NewId(),'Save') |
---|
| 1809 | self.btSave.Bind(wx.EVT_BUTTON, self.onSave,id= self.btSave.GetId()) |
---|
| 1810 | self.btSave.SetToolTipString("Save the current Model") |
---|
| 1811 | |
---|
| 1812 | sizer_save.Add(self.btSave_title) |
---|
| 1813 | sizer_save.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,45) |
---|
| 1814 | |
---|
| 1815 | sizer_save.Add(self.btSave) |
---|
| 1816 | |
---|
| 1817 | boxsizer1.Add(sizer_save) |
---|
| 1818 | self.sizer6.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 1819 | self.sizer6.Layout() |
---|
| 1820 | self.SetScrollbars(20,20,25,65) |
---|
| 1821 | |
---|
| 1822 | def _lay_out(self): |
---|
| 1823 | """ |
---|
[74755ff] | 1824 | returns self.Layout |
---|
| 1825 | |
---|
| 1826 | :Note: Mac seems to like this better when self.Layout |
---|
| 1827 | is called after fitting. |
---|
| 1828 | |
---|
[0277d084] | 1829 | """ |
---|
| 1830 | self._sleep4sec() |
---|
| 1831 | self.Layout() |
---|
| 1832 | #self._sleep4sec() |
---|
| 1833 | return |
---|
| 1834 | |
---|
| 1835 | def _sleep4sec(self): |
---|
| 1836 | """ |
---|
[74755ff] | 1837 | sleep for 1 sec only applied on Mac |
---|
| 1838 | |
---|
| 1839 | :Note: This 1sec helps for Mac not to crash on |
---|
| 1840 | self.layout after self._draw_model |
---|
| 1841 | |
---|
[0277d084] | 1842 | """ |
---|
| 1843 | if ON_MAC == True: |
---|
| 1844 | time.sleep(1) |
---|
| 1845 | |
---|
| 1846 | def on_reset_clicked(self,event): |
---|
| 1847 | """ |
---|
[74755ff] | 1848 | On 'Reset' button for Q range clicked |
---|
| 1849 | |
---|
[0277d084] | 1850 | """ |
---|
| 1851 | ##For 3 different cases: Data2D, Data1D, and theory |
---|
| 1852 | if self.data.__class__.__name__ == "Data2D": |
---|
| 1853 | data_min= 0 |
---|
| 1854 | x= max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
| 1855 | y= max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
| 1856 | self.qmin_x = data_min |
---|
| 1857 | self.qmax_x = math.sqrt(x*x + y*y) |
---|
| 1858 | elif self.data.__class__.__name__ == "Data1D": |
---|
| 1859 | self.qmin_x = min(self.data.x) |
---|
| 1860 | self.qmax_x = max(self.data.x) |
---|
| 1861 | else: |
---|
| 1862 | self.qmin_x = _QMIN_DEFAULT |
---|
| 1863 | self.qmax_x = _QMAX_DEFAULT |
---|
| 1864 | self.num_points = _NPTS_DEFAULT |
---|
| 1865 | self.state.npts = self.num_points |
---|
| 1866 | |
---|
| 1867 | self.state.qmin = self.qmin_x |
---|
| 1868 | self.state.qmax = self.qmax_x |
---|
| 1869 | |
---|
| 1870 | #reset the q range values |
---|
| 1871 | self._reset_plotting_range(self.state) |
---|
| 1872 | #Re draw plot |
---|
| 1873 | self._draw_model() |
---|