[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 | """ |
---|
[f20767b] | 936 | #statelist=[] |
---|
[cfc0913] | 937 | if len(listtocopy)==0: |
---|
| 938 | return |
---|
[1c1436d] | 939 | |
---|
[cfc0913] | 940 | for item in listtocopy: |
---|
[f20767b] | 941 | |
---|
[cfc0913] | 942 | checkbox_state = None |
---|
| 943 | if item[0]!= None: |
---|
| 944 | checkbox_state= item[0].GetValue() |
---|
| 945 | parameter_name = item[1] |
---|
| 946 | parameter_value = None |
---|
| 947 | if item[2]!=None: |
---|
| 948 | parameter_value = item[2].GetValue() |
---|
| 949 | static_text = None |
---|
| 950 | if item[3]!=None: |
---|
| 951 | static_text = item[3].IsShown() |
---|
| 952 | error_value = None |
---|
| 953 | error_state = None |
---|
| 954 | if item[4]!= None: |
---|
| 955 | error_value = item[4].GetValue() |
---|
| 956 | error_state = item[4].IsShown() |
---|
| 957 | |
---|
| 958 | min_value = None |
---|
| 959 | min_state = None |
---|
| 960 | if item[5]!= None: |
---|
| 961 | min_value = item[5].GetValue() |
---|
| 962 | min_state = item[5].IsShown() |
---|
| 963 | |
---|
| 964 | max_value = None |
---|
| 965 | max_state = None |
---|
| 966 | if item[6]!= None: |
---|
| 967 | max_value = item[6].GetValue() |
---|
| 968 | max_state = item[6].IsShown() |
---|
[240b9966] | 969 | unit=None |
---|
| 970 | if item[7]!=None: |
---|
| 971 | unit = item[7].GetLabel() |
---|
[cfc0913] | 972 | |
---|
| 973 | statelist.append([checkbox_state, parameter_name, parameter_value, |
---|
| 974 | static_text ,[error_state,error_value], |
---|
[240b9966] | 975 | [min_state,min_value],[max_state , max_value],unit]) |
---|
[cfc0913] | 976 | |
---|
| 977 | |
---|
| 978 | |
---|
[c77d859] | 979 | def _set_model_sizer_selection(self, model): |
---|
| 980 | """ |
---|
| 981 | Display the sizer according to the type of the current model |
---|
| 982 | """ |
---|
[70c57ebf] | 983 | if model ==None: |
---|
| 984 | return |
---|
[c77d859] | 985 | if hasattr(model ,"model2"): |
---|
| 986 | |
---|
| 987 | class_name= model.model2.__class__ |
---|
| 988 | name= model.model2.name |
---|
| 989 | flag= name != "NoStructure" |
---|
| 990 | if flag and (class_name in self.model_list_box["Structure Factors"]): |
---|
[6dc9ad8] | 991 | self.structurebox.Show() |
---|
| 992 | self.text2.Show() |
---|
[3b605bb] | 993 | self.structurebox.Enable() |
---|
[c097f02] | 994 | self.text2.Enable() |
---|
[c77d859] | 995 | items = self.structurebox.GetItems() |
---|
| 996 | self.sizer1.Layout() |
---|
| 997 | self.SetScrollbars(20,20,200,100) |
---|
| 998 | for i in range(len(items)): |
---|
| 999 | if items[i]== str(name): |
---|
| 1000 | self.structurebox.SetSelection(i) |
---|
| 1001 | break |
---|
| 1002 | |
---|
| 1003 | if hasattr(model ,"model1"): |
---|
| 1004 | class_name = model.model1.__class__ |
---|
| 1005 | name = model.model1.name |
---|
| 1006 | self.formfactorbox.Clear() |
---|
| 1007 | |
---|
| 1008 | for k, list in self.model_list_box.iteritems(): |
---|
[376916c] | 1009 | if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: |
---|
[c77d859] | 1010 | self.shape_rbutton.SetValue(True) |
---|
[376916c] | 1011 | ## fill the form factor list with new model |
---|
| 1012 | self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) |
---|
| 1013 | items = self.formfactorbox.GetItems() |
---|
| 1014 | ## set comboxbox to the selected item |
---|
| 1015 | for i in range(len(items)): |
---|
| 1016 | if items[i]== str(name): |
---|
| 1017 | self.formfactorbox.SetSelection(i) |
---|
| 1018 | break |
---|
| 1019 | return |
---|
| 1020 | elif k == "Shape-Independent": |
---|
[c77d859] | 1021 | self.shape_indep_rbutton.SetValue(True) |
---|
| 1022 | elif k == "Structure Factors": |
---|
| 1023 | self.struct_rbutton.SetValue(True) |
---|
| 1024 | else: |
---|
| 1025 | self.plugin_rbutton.SetValue(True) |
---|
[376916c] | 1026 | |
---|
[c77d859] | 1027 | if class_name in list: |
---|
| 1028 | ## fill the form factor list with new model |
---|
| 1029 | self._populate_box(self.formfactorbox, list) |
---|
| 1030 | items = self.formfactorbox.GetItems() |
---|
| 1031 | ## set comboxbox to the selected item |
---|
| 1032 | for i in range(len(items)): |
---|
| 1033 | if items[i]== str(name): |
---|
| 1034 | self.formfactorbox.SetSelection(i) |
---|
| 1035 | break |
---|
| 1036 | break |
---|
| 1037 | else: |
---|
[cdbe88e] | 1038 | |
---|
| 1039 | ## Select the model from the menu |
---|
[c77d859] | 1040 | class_name = model.__class__ |
---|
| 1041 | name = model.name |
---|
| 1042 | self.formfactorbox.Clear() |
---|
| 1043 | items = self.formfactorbox.GetItems() |
---|
[376916c] | 1044 | |
---|
[cdbe88e] | 1045 | for k, list in self.model_list_box.iteritems(): |
---|
[376916c] | 1046 | if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: |
---|
[3b605bb] | 1047 | if class_name in self.model_list_box["P(Q)*S(Q)"]: |
---|
[6dc9ad8] | 1048 | self.structurebox.Show() |
---|
| 1049 | self.text2.Show() |
---|
[3b605bb] | 1050 | self.structurebox.Enable() |
---|
[cdbe88e] | 1051 | self.structurebox.SetSelection(0) |
---|
[c097f02] | 1052 | self.text2.Enable() |
---|
[3b605bb] | 1053 | else: |
---|
[6dc9ad8] | 1054 | self.structurebox.Hide() |
---|
| 1055 | self.text2.Hide() |
---|
[3b605bb] | 1056 | self.structurebox.Disable() |
---|
| 1057 | self.structurebox.SetSelection(0) |
---|
[c097f02] | 1058 | self.text2.Disable() |
---|
[3b605bb] | 1059 | |
---|
[c77d859] | 1060 | self.shape_rbutton.SetValue(True) |
---|
[376916c] | 1061 | ## fill the form factor list with new model |
---|
| 1062 | self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) |
---|
| 1063 | items = self.formfactorbox.GetItems() |
---|
| 1064 | ## set comboxbox to the selected item |
---|
| 1065 | for i in range(len(items)): |
---|
| 1066 | if items[i]== str(name): |
---|
| 1067 | self.formfactorbox.SetSelection(i) |
---|
| 1068 | break |
---|
| 1069 | return |
---|
| 1070 | elif k == "Shape-Independent": |
---|
[c77d859] | 1071 | self.shape_indep_rbutton.SetValue(True) |
---|
| 1072 | elif k == "Structure Factors": |
---|
[cdbe88e] | 1073 | self.struct_rbutton.SetValue(True) |
---|
[c77d859] | 1074 | else: |
---|
| 1075 | self.plugin_rbutton.SetValue(True) |
---|
| 1076 | if class_name in list: |
---|
[3b605bb] | 1077 | self.structurebox.SetSelection(0) |
---|
| 1078 | self.structurebox.Disable() |
---|
[c097f02] | 1079 | self.text2.Disable() |
---|
[376916c] | 1080 | ## fill the form factor list with new model |
---|
[c77d859] | 1081 | self._populate_box(self.formfactorbox, list) |
---|
| 1082 | items = self.formfactorbox.GetItems() |
---|
| 1083 | ## set comboxbox to the selected item |
---|
| 1084 | for i in range(len(items)): |
---|
| 1085 | if items[i]== str(name): |
---|
| 1086 | self.formfactorbox.SetSelection(i) |
---|
| 1087 | break |
---|
| 1088 | break |
---|
[240b9966] | 1089 | ## save state and post |
---|
| 1090 | |
---|
[c77d859] | 1091 | |
---|
| 1092 | |
---|
| 1093 | def _draw_model(self): |
---|
| 1094 | """ |
---|
| 1095 | Method to draw or refresh a plotted model. |
---|
| 1096 | The method will use the data member from the model page |
---|
| 1097 | to build a call to the fitting perspective manager. |
---|
| 1098 | |
---|
| 1099 | [Note to coder: This way future changes will be done in only one place.] |
---|
| 1100 | """ |
---|
| 1101 | if self.model !=None: |
---|
[fca9cbd9] | 1102 | temp_smear=None |
---|
| 1103 | if hasattr(self, "enable_smearer"): |
---|
| 1104 | if self.enable_smearer.GetValue(): |
---|
| 1105 | temp_smear= self.smearer |
---|
[0aeabc6] | 1106 | |
---|
[c77d859] | 1107 | self.manager.draw_model(self.model, data=self.data, |
---|
[c16557c] | 1108 | smearer= temp_smear, |
---|
[4e6b5939] | 1109 | qmin=float(self.qmin_x), qmax=float(self.qmax_x), |
---|
| 1110 | qstep= float(self.num_points), |
---|
[c77d859] | 1111 | enable2D=self.enable2D) |
---|
| 1112 | |
---|
[71f0373] | 1113 | |
---|
[c77d859] | 1114 | def _set_model_sizer(self, sizer, title="", object=None): |
---|
| 1115 | """ |
---|
| 1116 | Use lists to fill a sizer for model info |
---|
| 1117 | """ |
---|
| 1118 | |
---|
| 1119 | sizer.Clear(True) |
---|
| 1120 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
| 1121 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 1122 | #-------------------------------------------------------- |
---|
[376916c] | 1123 | self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', style=wx.RB_GROUP) |
---|
| 1124 | self.shape_indep_rbutton = wx.RadioButton(self, -1, "Shape-Independent") |
---|
| 1125 | self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") |
---|
| 1126 | self.plugin_rbutton = wx.RadioButton(self, -1, "Customized Models") |
---|
[c77d859] | 1127 | |
---|
| 1128 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 1129 | id= self.shape_rbutton.GetId() ) |
---|
| 1130 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 1131 | id= self.shape_indep_rbutton.GetId() ) |
---|
| 1132 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 1133 | id= self.struct_rbutton.GetId() ) |
---|
| 1134 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 1135 | id= self.plugin_rbutton.GetId() ) |
---|
[3b605bb] | 1136 | |
---|
[cfc0913] | 1137 | |
---|
[3b605bb] | 1138 | sizer_radiobutton = wx.GridSizer(2, 2,5, 5) |
---|
[c77d859] | 1139 | sizer_radiobutton.Add(self.shape_rbutton) |
---|
| 1140 | sizer_radiobutton.Add(self.shape_indep_rbutton) |
---|
| 1141 | sizer_radiobutton.Add(self.plugin_rbutton) |
---|
| 1142 | sizer_radiobutton.Add(self.struct_rbutton) |
---|
| 1143 | |
---|
| 1144 | sizer_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1145 | |
---|
[fa58441] | 1146 | self.text1 = wx.StaticText( self,-1,"" ) |
---|
| 1147 | self.text2 = wx.StaticText( self,-1,"P(Q)*S(Q)" ) |
---|
[c77d859] | 1148 | |
---|
| 1149 | |
---|
[8bd4dc0] | 1150 | self.formfactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
[c77d859] | 1151 | if self.model!=None: |
---|
| 1152 | self.formfactorbox.SetValue(self.model.name) |
---|
[c097f02] | 1153 | |
---|
[59a7f2d] | 1154 | |
---|
[8bd4dc0] | 1155 | self.structurebox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
[c77d859] | 1156 | wx.EVT_COMBOBOX(self.formfactorbox,-1, self._on_select_model) |
---|
| 1157 | wx.EVT_COMBOBOX(self.structurebox,-1, self._on_select_model) |
---|
[3b605bb] | 1158 | |
---|
[71f0373] | 1159 | |
---|
[c77d859] | 1160 | ## fill combox box |
---|
| 1161 | if len(self.model_list_box)>0: |
---|
[376916c] | 1162 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
[c77d859] | 1163 | |
---|
| 1164 | if len(self.model_list_box)>0: |
---|
| 1165 | self._populate_box( self.structurebox, |
---|
| 1166 | self.model_list_box["Structure Factors"]) |
---|
[3b605bb] | 1167 | self.structurebox.Insert("None", 0,None) |
---|
| 1168 | self.structurebox.SetSelection(0) |
---|
[6dc9ad8] | 1169 | self.structurebox.Hide() |
---|
| 1170 | self.text2.Hide() |
---|
[3b605bb] | 1171 | self.structurebox.Disable() |
---|
[c097f02] | 1172 | self.text2.Disable() |
---|
| 1173 | |
---|
[3b605bb] | 1174 | if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: |
---|
[6dc9ad8] | 1175 | self.structurebox.Show() |
---|
| 1176 | self.text2.Show() |
---|
[3b605bb] | 1177 | self.structurebox.Enable() |
---|
[c097f02] | 1178 | self.text2.Enable() |
---|
[c77d859] | 1179 | |
---|
[59a7f2d] | 1180 | ## check model type to show sizer |
---|
[c77d859] | 1181 | if self.model !=None: |
---|
| 1182 | self._set_model_sizer_selection( self.model ) |
---|
| 1183 | |
---|
| 1184 | sizer_selection.Add(self.text1) |
---|
| 1185 | sizer_selection.Add((5,5)) |
---|
| 1186 | sizer_selection.Add(self.formfactorbox) |
---|
| 1187 | sizer_selection.Add((5,5)) |
---|
| 1188 | sizer_selection.Add(self.text2) |
---|
| 1189 | sizer_selection.Add((5,5)) |
---|
| 1190 | sizer_selection.Add(self.structurebox) |
---|
| 1191 | sizer_selection.Add((5,5)) |
---|
| 1192 | |
---|
| 1193 | boxsizer1.Add( sizer_radiobutton ) |
---|
| 1194 | boxsizer1.Add( (20,20)) |
---|
| 1195 | boxsizer1.Add( sizer_selection ) |
---|
| 1196 | if object !=None: |
---|
[f6b65b8] | 1197 | boxsizer1.Add( (-72,-72)) |
---|
| 1198 | boxsizer1.Add( object, 0, wx.ALIGN_RIGHT| wx.RIGHT, 10) |
---|
| 1199 | boxsizer1.Add( (60,60)) |
---|
[c77d859] | 1200 | #-------------------------------------------------------- |
---|
| 1201 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 1202 | sizer.Layout() |
---|
| 1203 | self.SetScrollbars(20,20,200,100) |
---|
| 1204 | |
---|
| 1205 | |
---|
| 1206 | def _show_combox(self, event): |
---|
| 1207 | """ |
---|
| 1208 | Show combox box associate with type of model selected |
---|
| 1209 | """ |
---|
[376916c] | 1210 | ## Don't want to populate combo box again if the event comes from check box |
---|
| 1211 | if self.shape_rbutton.GetValue()and\ |
---|
| 1212 | event.GetEventObject()==self.shape_rbutton: |
---|
| 1213 | ##fill the combobox with form factor list |
---|
[3b605bb] | 1214 | self.structurebox.SetSelection(0) |
---|
| 1215 | self.structurebox.Disable() |
---|
[c77d859] | 1216 | self.formfactorbox.Clear() |
---|
[376916c] | 1217 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
[c77d859] | 1218 | |
---|
[376916c] | 1219 | if self.shape_indep_rbutton.GetValue()and\ |
---|
| 1220 | event.GetEventObject()==self.shape_indep_rbutton: |
---|
| 1221 | ##fill the combobox with shape independent factor list |
---|
[3b605bb] | 1222 | self.structurebox.SetSelection(0) |
---|
| 1223 | self.structurebox.Disable() |
---|
[c77d859] | 1224 | self.formfactorbox.Clear() |
---|
| 1225 | self._populate_box( self.formfactorbox, |
---|
[376916c] | 1226 | self.model_list_box["Shape-Independent"]) |
---|
[c77d859] | 1227 | |
---|
[376916c] | 1228 | if self.struct_rbutton.GetValue() and\ |
---|
| 1229 | event.GetEventObject()==self.struct_rbutton: |
---|
| 1230 | ##fill the combobox with structure factor list |
---|
[3b605bb] | 1231 | self.structurebox.SetSelection(0) |
---|
| 1232 | self.structurebox.Disable() |
---|
[c77d859] | 1233 | self.formfactorbox.Clear() |
---|
| 1234 | self._populate_box( self.formfactorbox, |
---|
| 1235 | self.model_list_box["Structure Factors"]) |
---|
| 1236 | |
---|
[376916c] | 1237 | if self.plugin_rbutton.GetValue()and\ |
---|
| 1238 | event.GetEventObject()==self.plugin_rbutton: |
---|
| 1239 | |
---|
| 1240 | ##fill the combobox with form factor list |
---|
[3b605bb] | 1241 | self.structurebox.Disable() |
---|
[c77d859] | 1242 | self.formfactorbox.Clear() |
---|
| 1243 | self._populate_box( self.formfactorbox, |
---|
[376916c] | 1244 | self.model_list_box["Customized Models"]) |
---|
[3595309d] | 1245 | |
---|
[77e23a2] | 1246 | self._on_select_model(event=None) |
---|
[3595309d] | 1247 | self._save_typeOfmodel() |
---|
[3b605bb] | 1248 | self.sizer4_4.Layout() |
---|
[9853ad0] | 1249 | self.sizer4.Layout() |
---|
[3b605bb] | 1250 | self.Layout() |
---|
| 1251 | self.Refresh() |
---|
| 1252 | self.SetScrollbars(20,20,200,100) |
---|
[c77d859] | 1253 | |
---|
| 1254 | def _populate_box(self, combobox, list): |
---|
| 1255 | """ |
---|
| 1256 | fill combox box with dict item |
---|
| 1257 | @param list: contains item to fill the combox |
---|
| 1258 | item must model class |
---|
| 1259 | """ |
---|
| 1260 | for models in list: |
---|
| 1261 | model= models() |
---|
| 1262 | name = model.__class__.__name__ |
---|
[0a518e4c] | 1263 | if models.__name__!="NoStructure": |
---|
| 1264 | if hasattr(model, "name"): |
---|
| 1265 | name = model.name |
---|
| 1266 | combobox.Append(name,models) |
---|
[71f0373] | 1267 | |
---|
[c77d859] | 1268 | return 0 |
---|
| 1269 | |
---|
| 1270 | |
---|
[59a7f2d] | 1271 | def _on_select_model_helper(self): |
---|
[c77d859] | 1272 | """ |
---|
| 1273 | call back for model selection |
---|
| 1274 | """ |
---|
[376916c] | 1275 | ## reset dictionary containing reference to dispersion |
---|
| 1276 | self._disp_obj_dict = {} |
---|
| 1277 | self.disp_cb_dict ={} |
---|
[c77d859] | 1278 | f_id = self.formfactorbox.GetCurrentSelection() |
---|
| 1279 | form_factor = self.formfactorbox.GetClientData( f_id ) |
---|
[376916c] | 1280 | if not form_factor in self.model_list_box["multiplication"]: |
---|
[6dc9ad8] | 1281 | self.structurebox.Hide() |
---|
| 1282 | self.text2.Hide() |
---|
[3b605bb] | 1283 | self.structurebox.Disable() |
---|
| 1284 | self.structurebox.SetSelection(0) |
---|
[c097f02] | 1285 | self.text2.Disable() |
---|
[87fbc60] | 1286 | else: |
---|
[6dc9ad8] | 1287 | self.structurebox.Show() |
---|
| 1288 | self.text2.Show() |
---|
[87fbc60] | 1289 | self.structurebox.Enable() |
---|
[c097f02] | 1290 | self.text2.Enable() |
---|
[a074145] | 1291 | |
---|
[3b605bb] | 1292 | s_id = self.structurebox.GetCurrentSelection() |
---|
| 1293 | struct_factor = self.structurebox.GetClientData( s_id ) |
---|
[a074145] | 1294 | |
---|
[3b605bb] | 1295 | if struct_factor !=None: |
---|
[9853ad0] | 1296 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
| 1297 | self.model= MultiplicationModel(form_factor(),struct_factor()) |
---|
[0aeabc6] | 1298 | |
---|
[c77d859] | 1299 | else: |
---|
[fbf4bf8] | 1300 | if form_factor != None: |
---|
| 1301 | self.model= form_factor() |
---|
| 1302 | else: |
---|
| 1303 | self.model = None |
---|
| 1304 | return self.model |
---|
[a074145] | 1305 | |
---|
[cfc0913] | 1306 | ## post state to fit panel |
---|
[f20767b] | 1307 | self.state.parameters =[] |
---|
[fc6ea43] | 1308 | self.state.model =self.model |
---|
[f20767b] | 1309 | |
---|
[71f0373] | 1310 | self.disp_list =self.model.getDispParamList() |
---|
[f20767b] | 1311 | self.state.disp_list = self.disp_list |
---|
[3b605bb] | 1312 | self.sizer4_4.Layout() |
---|
| 1313 | self.sizer4.Layout() |
---|
| 1314 | self.Layout() |
---|
| 1315 | self.SetScrollbars(20,20,200,100) |
---|
| 1316 | self.Refresh() |
---|
| 1317 | |
---|
[c77d859] | 1318 | |
---|
| 1319 | |
---|
| 1320 | def _onparamEnter(self,event): |
---|
| 1321 | """ |
---|
| 1322 | when enter value on panel redraw model according to changed |
---|
| 1323 | """ |
---|
[69bee6d] | 1324 | tcrtl= event.GetEventObject() |
---|
[330573d] | 1325 | ## save current state |
---|
| 1326 | self.save_current_state() |
---|
[3595309d] | 1327 | if event !=None: |
---|
| 1328 | self._undo.Enable(True) |
---|
| 1329 | event = PageInfoEvent(page = self) |
---|
| 1330 | wx.PostEvent(self.parent, event) |
---|
[330573d] | 1331 | |
---|
[69bee6d] | 1332 | if check_float(tcrtl): |
---|
[330573d] | 1333 | |
---|
[69bee6d] | 1334 | self._onparamEnter_helper() |
---|
| 1335 | else: |
---|
| 1336 | msg= "Cannot Plot :Must enter a number!!! " |
---|
| 1337 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1338 | return |
---|
[c77d859] | 1339 | |
---|
| 1340 | |
---|
| 1341 | def _check_value_enter(self, list, modified): |
---|
| 1342 | """ |
---|
| 1343 | @param list: model parameter and panel info |
---|
| 1344 | each item of the list should be as follow: |
---|
| 1345 | item=[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 1346 | """ |
---|
| 1347 | is_modified = modified |
---|
| 1348 | if len(list)==0: |
---|
| 1349 | return is_modified |
---|
| 1350 | for item in list: |
---|
| 1351 | try: |
---|
[77e23a2] | 1352 | name = str(item[1]) |
---|
[0a518e4c] | 1353 | if hasattr(self,"text2_3"): |
---|
| 1354 | self.text2_3.Hide() |
---|
[77e23a2] | 1355 | ## check model parameters range |
---|
| 1356 | ## check minimun value |
---|
| 1357 | param_min= None |
---|
| 1358 | param_max= None |
---|
| 1359 | if item[5]!= None: |
---|
[298b762] | 1360 | if item[5].GetValue().lstrip().rstrip()!="": |
---|
[77e23a2] | 1361 | param_min = float(item[5].GetValue()) |
---|
[cfc0913] | 1362 | |
---|
[77e23a2] | 1363 | ## check maximum value |
---|
| 1364 | if item[6]!= None: |
---|
[298b762] | 1365 | if item[6].GetValue().lstrip().rstrip()!="": |
---|
[77e23a2] | 1366 | param_max = float(item[6].GetValue()) |
---|
| 1367 | |
---|
| 1368 | from sans.guiframe.utils import check_value |
---|
| 1369 | if param_min != None and param_max !=None: |
---|
[87a43fe] | 1370 | if not check_value(item[5], item[6]): |
---|
[77e23a2] | 1371 | msg= "Wrong Fit range entered for parameter " |
---|
| 1372 | msg+= "name %s of model %s "%(name, self.model.name) |
---|
| 1373 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[cfc0913] | 1374 | if name in self.model.details.keys(): |
---|
| 1375 | self.model.details[name][1:]= param_min,param_max |
---|
[87a43fe] | 1376 | |
---|
[77e23a2] | 1377 | ## hide statictext +/- |
---|
[0a518e4c] | 1378 | if item[3]!=None: |
---|
| 1379 | item[3].Hide() |
---|
[77e23a2] | 1380 | ## hide textcrtl for error after fit |
---|
[0a518e4c] | 1381 | if item[4]!=None: |
---|
| 1382 | item[4].Clear() |
---|
| 1383 | item[4].Hide() |
---|
[69bee6d] | 1384 | |
---|
[0a518e4c] | 1385 | value= float(item[2].GetValue()) |
---|
[69bee6d] | 1386 | |
---|
[0a518e4c] | 1387 | # If the value of the parameter has changed, |
---|
[1328e03] | 1388 | # +update the model and set the is_modified flag |
---|
[0a518e4c] | 1389 | if value != self.model.getParam(name): |
---|
| 1390 | self.model.setParam(name,value) |
---|
[69bee6d] | 1391 | is_modified = True |
---|
| 1392 | |
---|
[c77d859] | 1393 | except: |
---|
[1328e03] | 1394 | msg= "Model Drawing Error:wrong value entered : %s"% sys.exc_value |
---|
| 1395 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1396 | return |
---|
[0a518e4c] | 1397 | |
---|
[c77d859] | 1398 | return is_modified |
---|
| 1399 | |
---|
| 1400 | |
---|
| 1401 | def _set_dipers_Param(self, event): |
---|
| 1402 | """ |
---|
| 1403 | Add more item to select user dispersity |
---|
| 1404 | """ |
---|
[1c1436d] | 1405 | self._reset_dispersity() |
---|
[f20767b] | 1406 | |
---|
[70c57ebf] | 1407 | if self.model ==None: |
---|
| 1408 | self.model_disp.Hide() |
---|
| 1409 | self.disp_box.Hide() |
---|
| 1410 | self.sizer4_4.Clear(True) |
---|
[240b9966] | 1411 | ## save the state of the dispersity |
---|
| 1412 | #self.save_current_state() |
---|
[70c57ebf] | 1413 | return |
---|
| 1414 | |
---|
[1c1436d] | 1415 | if self.enable_disp.GetValue(): |
---|
| 1416 | self.model_disp.Show(True) |
---|
| 1417 | self.disp_box.Show(True) |
---|
| 1418 | ## layout for model containing no dispersity parameters |
---|
[f20767b] | 1419 | |
---|
[71f0373] | 1420 | self.disp_list= self.model.getDispParamList() |
---|
[f20767b] | 1421 | |
---|
| 1422 | if len(self.disp_list)==0 and len(self.disp_cb_dict)==0: |
---|
[1c1436d] | 1423 | self._layout_sizer_noDipers() |
---|
[c77d859] | 1424 | else: |
---|
[1c1436d] | 1425 | ## set gaussian sizer |
---|
| 1426 | self._on_select_Disp(event=None) |
---|
| 1427 | else: |
---|
| 1428 | self.model_disp.Hide() |
---|
| 1429 | self.disp_box.Hide() |
---|
[71f0373] | 1430 | self.disp_box.SetSelection(0) |
---|
[1c1436d] | 1431 | self.sizer4_4.Clear(True) |
---|
[f20767b] | 1432 | |
---|
[240b9966] | 1433 | ## post state to fit panel |
---|
[1c1436d] | 1434 | self.save_current_state() |
---|
[240b9966] | 1435 | if event !=None: |
---|
[3595309d] | 1436 | self._undo.Enable(True) |
---|
[240b9966] | 1437 | event = PageInfoEvent(page = self) |
---|
| 1438 | wx.PostEvent(self.parent, event) |
---|
[f20767b] | 1439 | |
---|
| 1440 | self._draw_model() |
---|
[71f0373] | 1441 | self.sizer4_4.Layout() |
---|
| 1442 | self.sizer4.Layout() |
---|
| 1443 | self.Layout() |
---|
| 1444 | self.Refresh() |
---|
| 1445 | self.SetScrollbars(20,20,200,100) |
---|
[3b605bb] | 1446 | |
---|
[c77d859] | 1447 | |
---|
| 1448 | def _layout_sizer_noDipers(self): |
---|
| 1449 | """ |
---|
| 1450 | Draw a sizer with no dispersity info |
---|
| 1451 | """ |
---|
| 1452 | ix=0 |
---|
| 1453 | iy=1 |
---|
| 1454 | self.fittable_param=[] |
---|
| 1455 | self.fixed_param=[] |
---|
[1c1436d] | 1456 | self.orientation_params_disp=[] |
---|
| 1457 | |
---|
[c77d859] | 1458 | self.model_disp.Hide() |
---|
| 1459 | self.disp_box.Hide() |
---|
| 1460 | self.sizer4_4.Clear(True) |
---|
| 1461 | model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model') |
---|
| 1462 | self.sizer4_4.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[dcf29d7] | 1463 | self.sizer4_4.Layout() |
---|
[c77d859] | 1464 | self.sizer4.Layout() |
---|
| 1465 | self.SetScrollbars(20,20,200,100) |
---|
[3b605bb] | 1466 | |
---|
[c77d859] | 1467 | |
---|
| 1468 | def _reset_dispersity(self): |
---|
| 1469 | """ |
---|
| 1470 | put gaussian dispersity into current model |
---|
| 1471 | """ |
---|
[1c1436d] | 1472 | if len(self.param_toFit)>0: |
---|
| 1473 | for item in self.fittable_param: |
---|
[513115c] | 1474 | if item in self.param_toFit: |
---|
[1c1436d] | 1475 | self.param_toFit.remove(item) |
---|
| 1476 | for item in self.orientation_params_disp: |
---|
[513115c] | 1477 | if item in self.param_toFit: |
---|
[1c1436d] | 1478 | self.param_toFit.remove(item) |
---|
[513115c] | 1479 | |
---|
[c77d859] | 1480 | self.fittable_param=[] |
---|
| 1481 | self.fixed_param=[] |
---|
[5812a55] | 1482 | self.orientation_params_disp=[] |
---|
[71f0373] | 1483 | self.values=[] |
---|
| 1484 | self.weights=[] |
---|
[1c1436d] | 1485 | |
---|
[f20767b] | 1486 | |
---|
| 1487 | from sans.models.dispersion_models import GaussianDispersion, ArrayDispersion |
---|
[c77d859] | 1488 | if len(self.disp_cb_dict)==0: |
---|
[3b605bb] | 1489 | self.sizer4_4.Clear(True) |
---|
| 1490 | self.sizer4_4.Layout() |
---|
| 1491 | self.sizer4.Layout() |
---|
| 1492 | self.Layout() |
---|
| 1493 | self.Refresh() |
---|
| 1494 | self.SetScrollbars(20,20,200,100) |
---|
[c77d859] | 1495 | return |
---|
[f20767b] | 1496 | if (len(self.disp_cb_dict)>0) : |
---|
| 1497 | for p in self.disp_cb_dict: |
---|
| 1498 | # The parameter was un-selected. Go back to Gaussian model (with 0 pts) |
---|
| 1499 | disp_model = GaussianDispersion() |
---|
| 1500 | |
---|
| 1501 | self._disp_obj_dict[p] = disp_model |
---|
| 1502 | # Set the new model as the dispersion object for the selected parameter |
---|
| 1503 | try: |
---|
| 1504 | self.model.set_dispersion(p, disp_model) |
---|
| 1505 | except: |
---|
| 1506 | pass |
---|
| 1507 | # Redraw the model |
---|
| 1508 | self._draw_model() |
---|
[240b9966] | 1509 | ## save state into |
---|
| 1510 | self.save_current_state() |
---|
[3b605bb] | 1511 | self.sizer4_4.Layout() |
---|
| 1512 | self.sizer4.Layout() |
---|
| 1513 | self.Layout() |
---|
| 1514 | self.SetScrollbars(20,20,200,100) |
---|
| 1515 | self.Refresh() |
---|
| 1516 | |
---|
| 1517 | |
---|
[c77d859] | 1518 | |
---|
| 1519 | def _on_select_Disp(self,event): |
---|
| 1520 | """ |
---|
| 1521 | allow selecting different dispersion |
---|
| 1522 | self.disp_list should change type later .now only gaussian |
---|
| 1523 | """ |
---|
[f20767b] | 1524 | |
---|
[b787e68c] | 1525 | n = self.disp_box.GetCurrentSelection() |
---|
[30d103a] | 1526 | name = self.disp_box.GetValue() |
---|
[b787e68c] | 1527 | dispersity= self.disp_box.GetClientData(n) |
---|
[30d103a] | 1528 | |
---|
[f20767b] | 1529 | self.disp_name = name |
---|
[30d103a] | 1530 | |
---|
| 1531 | if name.lower() == "array": |
---|
[c77d859] | 1532 | self._set_sizer_arraydispersion() |
---|
[30d103a] | 1533 | else: |
---|
| 1534 | self._set_sizer_dispersion(dispersity= dispersity) |
---|
[3b605bb] | 1535 | |
---|
[3b9e023] | 1536 | |
---|
[b787e68c] | 1537 | self.state.disp_box= n |
---|
| 1538 | |
---|
[3b9e023] | 1539 | self._undo.Enable(True) |
---|
| 1540 | event = PageInfoEvent(page = self) |
---|
| 1541 | wx.PostEvent(self.parent, event) |
---|
| 1542 | |
---|
[3b605bb] | 1543 | self.sizer4_4.Layout() |
---|
| 1544 | self.sizer4.Layout() |
---|
| 1545 | self.Layout() |
---|
| 1546 | self.SetScrollbars(20,20,200,100) |
---|
| 1547 | self.Refresh() |
---|
| 1548 | |
---|
[c77d859] | 1549 | def _set_sizer_arraydispersion(self): |
---|
| 1550 | """ |
---|
| 1551 | draw sizer with array dispersity parameters |
---|
| 1552 | """ |
---|
[f20767b] | 1553 | |
---|
[513115c] | 1554 | if len(self.param_toFit)>0: |
---|
| 1555 | for item in self.fittable_param: |
---|
| 1556 | if item in self.param_toFit: |
---|
| 1557 | self.param_toFit.remove(item) |
---|
| 1558 | for item in self.orientation_params_disp: |
---|
| 1559 | if item in self.param_toFit: |
---|
| 1560 | self.param_toFit.remove(item) |
---|
[f20767b] | 1561 | |
---|
| 1562 | |
---|
[1c1436d] | 1563 | self.fittable_param=[] |
---|
| 1564 | self.fixed_param=[] |
---|
[60132ef] | 1565 | self.orientation_params_disp=[] |
---|
[c77d859] | 1566 | self.sizer4_4.Clear(True) |
---|
[f20767b] | 1567 | self._reset_dispersity() |
---|
[c77d859] | 1568 | ix=0 |
---|
| 1569 | iy=1 |
---|
| 1570 | disp1 = wx.StaticText(self, -1, 'Array Dispersion') |
---|
| 1571 | self.sizer4_4.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1572 | |
---|
| 1573 | # Look for model parameters to which we can apply an ArrayDispersion model |
---|
| 1574 | # Add a check box for each parameter. |
---|
| 1575 | self.disp_cb_dict = {} |
---|
| 1576 | |
---|
[f20767b] | 1577 | for p in self.model.dispersion.keys(): |
---|
| 1578 | if not p in self.model.orientation_params: |
---|
| 1579 | ix+=1 |
---|
| 1580 | self.disp_cb_dict[p] = wx.CheckBox(self, -1, p, (10, 10)) |
---|
| 1581 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
| 1582 | |
---|
| 1583 | wx.EVT_CHECKBOX(self, self.disp_cb_dict[p].GetId(), self.select_disp_angle) |
---|
| 1584 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1585 | for p in self.model.dispersion.keys(): |
---|
| 1586 | if p in self.model.orientation_params: |
---|
| 1587 | ix+=1 |
---|
| 1588 | self.disp_cb_dict[p] = wx.CheckBox(self, -1, p, (10, 10)) |
---|
| 1589 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
[30d103a] | 1590 | #print "self.enable2D",self.enable2D |
---|
[6dc9ad8] | 1591 | if not (self.enable2D or self.data.__class__.__name__ =="Data2D"): |
---|
| 1592 | self.disp_cb_dict[p].Hide() |
---|
[f20767b] | 1593 | self.disp_cb_dict[p].Disable() |
---|
| 1594 | else: |
---|
[6dc9ad8] | 1595 | self.disp_cb_dict[p].Show(True) |
---|
[f20767b] | 1596 | self.disp_cb_dict[p].Enable() |
---|
| 1597 | |
---|
| 1598 | wx.EVT_CHECKBOX(self, self.disp_cb_dict[p].GetId(), self.select_disp_angle) |
---|
| 1599 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1600 | |
---|
| 1601 | |
---|
[c77d859] | 1602 | ix =0 |
---|
| 1603 | iy +=1 |
---|
| 1604 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1605 | self.sizer4_4.Layout() |
---|
| 1606 | self.sizer4.Layout() |
---|
| 1607 | self.SetScrollbars(20,20,200,100) |
---|
[240b9966] | 1608 | ## save state into |
---|
[f20767b] | 1609 | |
---|
| 1610 | self.state.orientation_params =[] |
---|
| 1611 | self.state.orientation_params_disp =[] |
---|
| 1612 | self.state.parameters =[] |
---|
| 1613 | self.state.fittable_param =[] |
---|
| 1614 | self.state.fixed_param =[] |
---|
| 1615 | |
---|
| 1616 | ## save checkbutton state and txtcrtl values |
---|
| 1617 | |
---|
| 1618 | self._copy_parameters_state(self.orientation_params, |
---|
| 1619 | self.state.orientation_params) |
---|
| 1620 | |
---|
[240b9966] | 1621 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 1622 | self.state.orientation_params_disp) |
---|
[f20767b] | 1623 | |
---|
| 1624 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
[240b9966] | 1625 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 1626 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[3b9e023] | 1627 | |
---|
[f20767b] | 1628 | |
---|
[3b9e023] | 1629 | ## post state to fit panel |
---|
| 1630 | event = PageInfoEvent(page = self) |
---|
| 1631 | wx.PostEvent(self.parent, event) |
---|
| 1632 | |
---|
[f20767b] | 1633 | |
---|
| 1634 | |
---|
| 1635 | |
---|
[70c57ebf] | 1636 | |
---|
[c77d859] | 1637 | def _set_range_sizer(self, title, object1=None,object=None): |
---|
| 1638 | """ |
---|
[f20767b] | 1639 | Fill the |
---|
[c77d859] | 1640 | """ |
---|
| 1641 | self.sizer5.Clear(True) |
---|
| 1642 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
| 1643 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 1644 | #-------------------------------------------------------------- |
---|
[6f2c919] | 1645 | self.qmin = BasicPage.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
[b5e98540] | 1646 | self.qmin.SetValue(str(self.qmin_x)) |
---|
[c77d859] | 1647 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
[f20767b] | 1648 | #self.qmin.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
| 1649 | #self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 1650 | #self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
[c77d859] | 1651 | |
---|
[6f2c919] | 1652 | self.qmax = BasicPage.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
[b5e98540] | 1653 | self.qmax.SetValue(str(self.qmax_x)) |
---|
[c77d859] | 1654 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
[f20767b] | 1655 | #self.qmax.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
| 1656 | #self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 1657 | #self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
[c77d859] | 1658 | |
---|
| 1659 | sizer_horizontal=wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1660 | sizer= wx.GridSizer(3, 3,5, 5) |
---|
| 1661 | |
---|
| 1662 | sizer.Add((5,5)) |
---|
| 1663 | sizer.Add(wx.StaticText(self, -1, 'Min')) |
---|
| 1664 | sizer.Add(wx.StaticText(self, -1, 'Max')) |
---|
| 1665 | sizer.Add(wx.StaticText(self, -1, 'Q range')) |
---|
| 1666 | |
---|
| 1667 | sizer.Add(self.qmin) |
---|
| 1668 | sizer.Add(self.qmax) |
---|
| 1669 | sizer_horizontal.Add(sizer) |
---|
| 1670 | if object!=None: |
---|
| 1671 | sizer_horizontal.Add(object) |
---|
| 1672 | |
---|
| 1673 | if object1!=None: |
---|
| 1674 | boxsizer1.Add(object1) |
---|
| 1675 | boxsizer1.Add((10,10)) |
---|
| 1676 | boxsizer1.Add(sizer_horizontal) |
---|
[cfc0913] | 1677 | ## save state |
---|
| 1678 | self.save_current_state() |
---|
[c77d859] | 1679 | #---------------------------------------------------------------- |
---|
| 1680 | self.sizer5.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 1681 | self.sizer5.Layout() |
---|
[dcf29d7] | 1682 | self.Layout() |
---|
[c77d859] | 1683 | self.SetScrollbars(20,20,200,100) |
---|
| 1684 | |
---|
[cfc0913] | 1685 | |
---|
[00c3aac] | 1686 | def _fill_save_sizer(self): |
---|
| 1687 | """ |
---|
| 1688 | Draw the layout for saving option |
---|
| 1689 | """ |
---|
[6d1235b] | 1690 | # Skipping save state functionality for release 0.9.0 |
---|
[dad49a0] | 1691 | #return |
---|
[6d1235b] | 1692 | |
---|
[00c3aac] | 1693 | self.sizer6.Clear(True) |
---|
[45ed4dad] | 1694 | box_description= wx.StaticBox(self, -1,"Save Status") |
---|
[00c3aac] | 1695 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 1696 | sizer_save = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1697 | |
---|
[45ed4dad] | 1698 | self.btSave_title = wx.StaticText(self, -1, 'Save the current panel status') |
---|
[00c3aac] | 1699 | self.btSave = wx.Button(self,wx.NewId(),'Save') |
---|
| 1700 | self.btSave.Bind(wx.EVT_BUTTON, self.onSave,id= self.btSave.GetId()) |
---|
[45ed4dad] | 1701 | self.btSave.SetToolTipString("Save current panel status") |
---|
| 1702 | |
---|
| 1703 | sizer_save.Add(self.btSave_title) |
---|
| 1704 | sizer_save.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,45) |
---|
| 1705 | |
---|
[00c3aac] | 1706 | sizer_save.Add(self.btSave) |
---|
| 1707 | |
---|
| 1708 | boxsizer1.Add(sizer_save) |
---|
| 1709 | self.sizer6.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 1710 | self.sizer6.Layout() |
---|
| 1711 | self.SetScrollbars(20,20,200,100) |
---|
| 1712 | |
---|
[c77d859] | 1713 | |
---|
| 1714 | |
---|