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