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