[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() |
---|
[c77d859] | 12 | _BOX_WIDTH = 80 |
---|
| 13 | |
---|
| 14 | class BasicPage(wx.ScrolledWindow): |
---|
| 15 | """ |
---|
| 16 | This class provide general structure of fitpanel page |
---|
| 17 | """ |
---|
[b787e68c] | 18 | ## Internal name for the AUI manager |
---|
| 19 | window_name = "Basic Page" |
---|
| 20 | ## Title to appear on top of the window |
---|
| 21 | window_caption = "Basic page " |
---|
[59a7f2d] | 22 | |
---|
[cfc0913] | 23 | def __init__(self,parent, page_info): |
---|
[c77d859] | 24 | wx.ScrolledWindow.__init__(self, parent) |
---|
[cfc0913] | 25 | ##window_name |
---|
| 26 | self.window_name = page_info.window_name |
---|
| 27 | ##window_caption |
---|
| 28 | self.window_caption = page_info.window_caption |
---|
[c77d859] | 29 | ## parent of the page |
---|
| 30 | self.parent = parent |
---|
[77e23a2] | 31 | ## manager is the fitting plugin |
---|
[cfc0913] | 32 | self.manager= page_info.manager |
---|
[c77d859] | 33 | ## owner of the page (fitting plugin) |
---|
[cfc0913] | 34 | self.event_owner= page_info.event_owner |
---|
| 35 | ## current model |
---|
| 36 | self.model = page_info.model |
---|
| 37 | ## data |
---|
| 38 | self.data = page_info.data |
---|
[c77d859] | 39 | ## dictionary containing list of models |
---|
[cfc0913] | 40 | self.model_list_box = page_info.model_list_box |
---|
[c77d859] | 41 | ## Data member to store the dispersion object created |
---|
| 42 | self._disp_obj_dict = {} |
---|
[cfc0913] | 43 | ## selected parameters to apply dispersion |
---|
[c77d859] | 44 | self.disp_cb_dict ={} |
---|
[997131a] | 45 | ## smearer object |
---|
| 46 | self.smearer = None |
---|
[c77d859] | 47 | ##list of model parameters. each item must have same length |
---|
| 48 | ## each item related to a given parameters |
---|
| 49 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 50 | self.parameters=[] |
---|
| 51 | ## list of parameters to fit , must be like self.parameters |
---|
| 52 | self.param_toFit=[] |
---|
| 53 | ## list of looking like parameters but with non fittable parameters info |
---|
| 54 | self.fixed_param=[] |
---|
| 55 | ## list of looking like parameters but with fittable parameters info |
---|
| 56 | self.fittable_param=[] |
---|
| 57 | ##list of dispersion parameters |
---|
| 58 | self.disp_list=[] |
---|
[780d095] | 59 | ## list of orientation parameters |
---|
| 60 | self.orientation_params=[] |
---|
[60132ef] | 61 | self.orientation_params_disp=[] |
---|
[cfc0913] | 62 | if self.model !=None: |
---|
| 63 | self.disp_list= self.model.getDispParamList() |
---|
[c77d859] | 64 | ##enable model 2D draw |
---|
| 65 | self.enable2D= False |
---|
| 66 | ## check that the fit range is correct to plot the model again |
---|
| 67 | self.fitrange= True |
---|
| 68 | ## Q range |
---|
| 69 | self.qmin_x= 0.001 |
---|
[45ed4dad] | 70 | self.qmax_x= 0.13 |
---|
[c77d859] | 71 | self.num_points= 100 |
---|
[cfc0913] | 72 | ## Create memento to save the current state |
---|
| 73 | |
---|
| 74 | self.state= PageState(parent= self.parent,model=self.model, data=self.data) |
---|
[a074145] | 75 | |
---|
| 76 | ## retrieve saved state |
---|
| 77 | self.number_saved_state= 0 |
---|
| 78 | ## dictionary of saved state |
---|
| 79 | self.saved_states={} |
---|
| 80 | self.slicerpop = wx.Menu() |
---|
[60132ef] | 81 | ## Default locations |
---|
| 82 | self._default_save_location = os.getcwd() |
---|
[a074145] | 83 | ## save initial state on context menu |
---|
| 84 | self.onSave(event=None) |
---|
| 85 | self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) |
---|
| 86 | |
---|
[cfc0913] | 87 | ## create the basic structure of the panel with empty sizer |
---|
| 88 | self.define_page_structure() |
---|
[c77d859] | 89 | ## drawing Initial dispersion parameters sizer |
---|
| 90 | self.set_dispers_sizer() |
---|
[00c3aac] | 91 | self._fill_save_sizer() |
---|
[c77d859] | 92 | ## layout |
---|
| 93 | self.set_layout() |
---|
| 94 | |
---|
[a074145] | 95 | |
---|
| 96 | def onContextMenu(self, event): |
---|
| 97 | """ |
---|
| 98 | Retrieve the state selected state |
---|
| 99 | """ |
---|
| 100 | pos = event.GetPosition() |
---|
| 101 | pos = self.ScreenToClient(pos) |
---|
| 102 | self.PopupMenu(self.slicerpop, pos) |
---|
| 103 | |
---|
| 104 | |
---|
[c77d859] | 105 | |
---|
| 106 | def define_page_structure(self): |
---|
| 107 | """ |
---|
| 108 | Create empty sizer for a panel |
---|
| 109 | """ |
---|
| 110 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 111 | self.sizer0 = wx.BoxSizer(wx.VERTICAL) |
---|
| 112 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
| 113 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
| 114 | self.sizer3 = wx.BoxSizer(wx.VERTICAL) |
---|
| 115 | self.sizer4 = wx.BoxSizer(wx.VERTICAL) |
---|
| 116 | self.sizer5 = wx.BoxSizer(wx.VERTICAL) |
---|
[0a518e4c] | 117 | self.sizer6 = wx.BoxSizer(wx.VERTICAL) |
---|
[c77d859] | 118 | |
---|
[8bd4dc0] | 119 | self.sizer0.SetMinSize((375,-1)) |
---|
| 120 | self.sizer1.SetMinSize((375,-1)) |
---|
| 121 | self.sizer2.SetMinSize((375,-1)) |
---|
| 122 | self.sizer3.SetMinSize((375,-1)) |
---|
| 123 | self.sizer4.SetMinSize((375,-1)) |
---|
| 124 | self.sizer5.SetMinSize((375,-1)) |
---|
[0a518e4c] | 125 | self.sizer6.SetMinSize((375,-1)) |
---|
[8bd4dc0] | 126 | |
---|
[c77d859] | 127 | self.vbox.Add(self.sizer0) |
---|
| 128 | self.vbox.Add(self.sizer1) |
---|
| 129 | self.vbox.Add(self.sizer2) |
---|
| 130 | self.vbox.Add(self.sizer3) |
---|
| 131 | self.vbox.Add(self.sizer4) |
---|
| 132 | self.vbox.Add(self.sizer5) |
---|
[0a518e4c] | 133 | self.vbox.Add(self.sizer6) |
---|
[c77d859] | 134 | |
---|
[a074145] | 135 | |
---|
[c77d859] | 136 | def set_layout(self): |
---|
| 137 | """ |
---|
| 138 | layout |
---|
| 139 | """ |
---|
| 140 | self.vbox.Layout() |
---|
| 141 | self.vbox.Fit(self) |
---|
| 142 | self.SetSizer(self.vbox) |
---|
| 143 | |
---|
| 144 | self.set_scroll() |
---|
| 145 | self.Centre() |
---|
| 146 | |
---|
[a074145] | 147 | |
---|
[c77d859] | 148 | def set_scroll(self): |
---|
| 149 | self.SetScrollbars(20,20,200,100) |
---|
| 150 | self.Layout() |
---|
[0a518e4c] | 151 | self.SetAutoLayout(True) |
---|
[c77d859] | 152 | |
---|
[a074145] | 153 | |
---|
[c77d859] | 154 | def set_owner(self,owner): |
---|
| 155 | """ |
---|
| 156 | set owner of fitpage |
---|
| 157 | @param owner: the class responsible of plotting |
---|
| 158 | """ |
---|
| 159 | self.event_owner = owner |
---|
[cfc0913] | 160 | self.state.event_owner = owner |
---|
[c77d859] | 161 | |
---|
| 162 | def set_manager(self, manager): |
---|
| 163 | """ |
---|
| 164 | set panel manager |
---|
| 165 | @param manager: instance of plugin fitting |
---|
| 166 | """ |
---|
| 167 | self.manager = manager |
---|
[cfc0913] | 168 | self.state.manager = manager |
---|
[c77d859] | 169 | |
---|
| 170 | def populate_box(self, dict): |
---|
| 171 | """ |
---|
| 172 | Store list of model |
---|
| 173 | @param dict: dictionary containing list of models |
---|
| 174 | """ |
---|
| 175 | self.model_list_box = dict |
---|
[cfc0913] | 176 | self.state.model_list_box = self.model_list_box |
---|
[c77d859] | 177 | |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | def set_dispers_sizer(self): |
---|
| 181 | """ |
---|
| 182 | fill sizer containing dispersity info |
---|
| 183 | """ |
---|
| 184 | self.sizer4.Clear(True) |
---|
[87fbc60] | 185 | name="Polydispersity and Orientational Distribution" |
---|
| 186 | box_description= wx.StaticBox(self, -1,name) |
---|
[c77d859] | 187 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 188 | #---------------------------------------------------- |
---|
[fa58441] | 189 | self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), style=wx.RB_GROUP) |
---|
| 190 | self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) |
---|
[cfc0913] | 191 | ## saving the state of enable dispersity button |
---|
| 192 | self.state.enable_disp= self.enable_disp.GetValue() |
---|
| 193 | |
---|
[c77d859] | 194 | self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.disable_disp.GetId()) |
---|
| 195 | self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.enable_disp.GetId()) |
---|
| 196 | |
---|
| 197 | sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 198 | sizer_dispersion.Add((20,20)) |
---|
[fa58441] | 199 | name=""#Polydispersity and \nOrientational Distribution " |
---|
[a074145] | 200 | sizer_dispersion.Add(wx.StaticText(self,-1,name)) |
---|
[c77d859] | 201 | sizer_dispersion.Add(self.enable_disp ) |
---|
| 202 | sizer_dispersion.Add((20,20)) |
---|
| 203 | sizer_dispersion.Add(self.disable_disp ) |
---|
| 204 | sizer_dispersion.Add((10,10)) |
---|
| 205 | |
---|
| 206 | ## fill a sizer with the combobox to select dispersion type |
---|
| 207 | sizer_select_dispers = wx.BoxSizer(wx.HORIZONTAL) |
---|
[fa58441] | 208 | self.model_disp = wx.StaticText(self, -1, 'Distribution Function ') |
---|
[c77d859] | 209 | |
---|
| 210 | import sans.models.dispersion_models |
---|
| 211 | self.polydisp= sans.models.dispersion_models.models |
---|
[0a518e4c] | 212 | self.disp_box = wx.ComboBox(self, -1) |
---|
[b787e68c] | 213 | |
---|
[c77d859] | 214 | for key in self.polydisp.iterkeys(): |
---|
| 215 | name = str(key.__name__) |
---|
| 216 | if name=="ArrayDispersion": |
---|
| 217 | # Remove the option until the rest of the code is ready for it |
---|
| 218 | self.disp_box.Append("Select customized Model",key) |
---|
[b787e68c] | 219 | |
---|
[c77d859] | 220 | else: |
---|
[b787e68c] | 221 | self.disp_box.Append(name,key) |
---|
| 222 | self.disp_box.SetSelection(0) |
---|
| 223 | |
---|
[c77d859] | 224 | wx.EVT_COMBOBOX(self.disp_box,-1, self._on_select_Disp) |
---|
| 225 | |
---|
| 226 | sizer_select_dispers.Add((10,10)) |
---|
| 227 | sizer_select_dispers.Add(self.model_disp) |
---|
[997131a] | 228 | sizer_select_dispers.Add(self.disp_box,0, |
---|
| 229 | wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
| 230 | #sizer_select_dispers.Add((10,10)) |
---|
[c77d859] | 231 | self.model_disp.Hide() |
---|
| 232 | self.disp_box.Hide() |
---|
| 233 | |
---|
[997131a] | 234 | boxsizer1.Add( sizer_dispersion,0, |
---|
| 235 | wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
| 236 | #boxsizer1.Add( (10,10) ) |
---|
[c77d859] | 237 | boxsizer1.Add( sizer_select_dispers ) |
---|
| 238 | self.sizer4_4 = wx.GridBagSizer(5,5) |
---|
| 239 | boxsizer1.Add( self.sizer4_4 ) |
---|
| 240 | #----------------------------------------------------- |
---|
| 241 | self.sizer4.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
[3b605bb] | 242 | self.sizer4_4.Layout() |
---|
[c77d859] | 243 | self.sizer4.Layout() |
---|
[3b605bb] | 244 | self.Layout() |
---|
[c77d859] | 245 | self.SetScrollbars(20,20,200,100) |
---|
[3b605bb] | 246 | self.Refresh() |
---|
[0a518e4c] | 247 | |
---|
[c77d859] | 248 | |
---|
| 249 | def select_disp_angle(self, event): |
---|
| 250 | """ |
---|
| 251 | Event for when a user select a parameter to average over. |
---|
| 252 | @param event: check box event |
---|
| 253 | """ |
---|
| 254 | |
---|
| 255 | |
---|
| 256 | # Go through the list of dispersion check boxes to identify which one has changed |
---|
| 257 | for p in self.disp_cb_dict: |
---|
| 258 | # Catch which one of the box was just checked or unchecked. |
---|
| 259 | if event.GetEventObject() == self.disp_cb_dict[p]: |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | if self.disp_cb_dict[p].GetValue() == True: |
---|
| 263 | # The user wants this parameter to be averaged. |
---|
| 264 | # Pop up the file selection dialog. |
---|
| 265 | path = self._selectDlg() |
---|
| 266 | |
---|
| 267 | # If nothing was selected, just return |
---|
| 268 | if path is None: |
---|
| 269 | self.disp_cb_dict[p].SetValue(False) |
---|
| 270 | return |
---|
[60132ef] | 271 | try: |
---|
| 272 | self._default_save_location = os.path.dirname(path) |
---|
| 273 | except: |
---|
| 274 | pass |
---|
[c77d859] | 275 | try: |
---|
| 276 | values,weights = self.read_file(path) |
---|
| 277 | except: |
---|
| 278 | msg="Could not read input file" |
---|
| 279 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg)) |
---|
| 280 | return |
---|
| 281 | |
---|
| 282 | # If any of the two arrays is empty, notify the user that we won't |
---|
| 283 | # proceed |
---|
| 284 | if values is None or weights is None: |
---|
| 285 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
| 286 | "The loaded %s distrubtion is corrupted or empty" % p)) |
---|
| 287 | return |
---|
| 288 | |
---|
| 289 | # Tell the user that we are about to apply the distribution |
---|
| 290 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
| 291 | "Applying loaded %s distribution: %s" % (p, path))) |
---|
| 292 | |
---|
| 293 | # Create the dispersion objects |
---|
| 294 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 295 | disp_model = ArrayDispersion() |
---|
| 296 | disp_model.set_weights(values, weights) |
---|
| 297 | # Store the object to make it persist outside the scope of this method |
---|
| 298 | #TODO: refactor model to clean this up? |
---|
| 299 | self._disp_obj_dict[p] = disp_model |
---|
| 300 | # Set the new model as the dispersion object for the selected parameter |
---|
| 301 | self.model.set_dispersion(p, disp_model) |
---|
[9e6c27f] | 302 | # Store a reference to the weights in the model object so that |
---|
| 303 | # it's not lost when we use the model within another thread. |
---|
| 304 | #TODO: total hack - fix this |
---|
| 305 | if not hasattr(self.model, "_persistency_dict"): |
---|
| 306 | self.model._persistency_dict = {} |
---|
| 307 | self.model._persistency_dict[p] = [values, weights] |
---|
[c77d859] | 308 | else: |
---|
| 309 | # The parameter was un-selected. Go back to Gaussian model (with 0 pts) |
---|
| 310 | self._reset_dispersity() |
---|
| 311 | |
---|
| 312 | ## Redraw the model |
---|
| 313 | self._draw_model() |
---|
| 314 | return |
---|
| 315 | |
---|
[a074145] | 316 | |
---|
| 317 | def onResetModel(self, event): |
---|
| 318 | """ |
---|
| 319 | Reset model state |
---|
| 320 | """ |
---|
| 321 | ## post help message for the selected model |
---|
| 322 | msg = self.slicerpop.GetHelpString(event.GetId()) |
---|
| 323 | msg +=" reloaded" |
---|
| 324 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 325 | |
---|
| 326 | name= self.slicerpop.GetLabel(event.GetId()) |
---|
| 327 | if name in self.saved_states.keys(): |
---|
| 328 | previous_state = self.saved_states[name] |
---|
| 329 | self.reset_page(previous_state) |
---|
| 330 | |
---|
| 331 | |
---|
[00c3aac] | 332 | def onSave(self, event): |
---|
| 333 | """ |
---|
| 334 | save history of the data and model |
---|
| 335 | """ |
---|
[a074145] | 336 | if self.model==None: |
---|
| 337 | return |
---|
| 338 | if hasattr(self,"enable_disp"): |
---|
[fc6ea43] | 339 | self.state.enable_disp = copy.deepcopy(self.enable_disp.GetValue()) |
---|
[a074145] | 340 | if hasattr(self, "disp_box"): |
---|
[fc6ea43] | 341 | self.state.disp_box = copy.deepcopy(self.disp_box.GetSelection()) |
---|
[a074145] | 342 | |
---|
| 343 | self.state.model = self.model.clone() |
---|
| 344 | new_state = self.state.clone() |
---|
[d2d0cfdf] | 345 | ## save checkbutton state and txtcrtl values |
---|
| 346 | self._copy_parameters_state(self.orientation_params, |
---|
| 347 | self.state.orientation_params) |
---|
| 348 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 349 | self.state.orientation_params_disp) |
---|
| 350 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
| 351 | |
---|
| 352 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 353 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[a074145] | 354 | |
---|
| 355 | ##Add model state on context menu |
---|
| 356 | self.number_saved_state += 1 |
---|
| 357 | name= self.model.name+"[%g]"%self.number_saved_state |
---|
| 358 | self.saved_states[name]= new_state |
---|
| 359 | |
---|
| 360 | ## Add item in the context menu |
---|
[fc6ea43] | 361 | |
---|
| 362 | year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() |
---|
| 363 | my_time= str(hour)+" : "+str(minute)+" : "+str(second)+" " |
---|
[a074145] | 364 | date= str( month)+"|"+str(day)+"|"+str(year) |
---|
| 365 | msg= "Model saved at %s on %s"%(my_time, date) |
---|
| 366 | ## post help message for the selected model |
---|
| 367 | msg +=" Saved! right click on this page to retrieve this model" |
---|
| 368 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 369 | |
---|
| 370 | id = wx.NewId() |
---|
| 371 | self.slicerpop.Append(id,name,str(msg)) |
---|
| 372 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
| 373 | |
---|
[1328e03] | 374 | def onSetFocus(self, evt): |
---|
[77e23a2] | 375 | """ |
---|
| 376 | highlight the current textcrtl and hide the error text control shown |
---|
| 377 | after fitting |
---|
| 378 | """ |
---|
[cfc0913] | 379 | |
---|
[77e23a2] | 380 | if hasattr(self,"text2_3"): |
---|
| 381 | self.text2_3.Hide() |
---|
| 382 | if len(self.parameters)>0: |
---|
| 383 | for item in self.parameters: |
---|
| 384 | ## hide statictext +/- |
---|
| 385 | if item[3]!=None: |
---|
| 386 | item[3].Hide() |
---|
| 387 | ## hide textcrtl for error after fit |
---|
| 388 | if item[4]!=None: |
---|
| 389 | item[4].Clear() |
---|
| 390 | item[4].Hide() |
---|
| 391 | if len(self.fittable_param)>0: |
---|
| 392 | for item in self.fittable_param: |
---|
| 393 | ## hide statictext +/- |
---|
| 394 | if item[3]!=None: |
---|
| 395 | item[3].Hide() |
---|
| 396 | ## hide textcrtl for error after fit |
---|
| 397 | if item[4]!=None: |
---|
| 398 | item[4].Clear() |
---|
| 399 | item[4].Hide() |
---|
| 400 | self.Layout() |
---|
[1328e03] | 401 | # Get a handle to the TextCtrl |
---|
| 402 | widget = evt.GetEventObject() |
---|
| 403 | # Select the whole control, after this event resolves |
---|
[77e23a2] | 404 | wx.CallAfter(widget.SetSelection, -1,-1) |
---|
[1328e03] | 405 | return |
---|
[c77d859] | 406 | |
---|
[60d6c23] | 407 | |
---|
[c77d859] | 408 | def read_file(self, path): |
---|
| 409 | """ |
---|
| 410 | Read two columns file |
---|
| 411 | @param path: the path to the file to read |
---|
| 412 | """ |
---|
| 413 | try: |
---|
| 414 | if path==None: |
---|
| 415 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
| 416 | " Selected Distribution was not loaded: %s"%path)) |
---|
| 417 | return None, None |
---|
| 418 | input_f = open(path, 'r') |
---|
| 419 | buff = input_f.read() |
---|
| 420 | lines = buff.split('\n') |
---|
| 421 | |
---|
| 422 | angles = [] |
---|
| 423 | weights=[] |
---|
| 424 | for line in lines: |
---|
| 425 | toks = line.split() |
---|
[502de0a] | 426 | try: |
---|
| 427 | angle = float(toks[0]) |
---|
| 428 | weight = float(toks[1]) |
---|
| 429 | except: |
---|
| 430 | # Skip non-data lines |
---|
| 431 | pass |
---|
| 432 | angles.append(angle) |
---|
| 433 | weights.append(weight) |
---|
[c77d859] | 434 | return numpy.array(angles), numpy.array(weights) |
---|
| 435 | except: |
---|
| 436 | raise |
---|
[00c3aac] | 437 | |
---|
[cfc0913] | 438 | |
---|
| 439 | def createMemento(self): |
---|
| 440 | """ |
---|
| 441 | return the current state of the page |
---|
| 442 | """ |
---|
| 443 | return self.state.clone() |
---|
| 444 | |
---|
| 445 | |
---|
| 446 | def save_current_state(self): |
---|
| 447 | """ |
---|
| 448 | Store current state |
---|
| 449 | """ |
---|
[87fbc60] | 450 | if self.model!= None: |
---|
| 451 | self.state.model = self.model.clone() |
---|
[cfc0913] | 452 | self.state.save_data(self.data) |
---|
| 453 | |
---|
| 454 | if hasattr(self,"cb1"): |
---|
| 455 | self.state.cb1= self.cb1.GetValue() |
---|
[60132ef] | 456 | |
---|
[cfc0913] | 457 | if hasattr(self,"enable_disp"): |
---|
| 458 | self.state.enable_disp= self.enable_disp.GetValue() |
---|
[fc6ea43] | 459 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
| 460 | |
---|
[3370922] | 461 | self.state.smearer = copy.deepcopy(self.smearer) |
---|
[cfc0913] | 462 | if hasattr(self,"enable_smearer"): |
---|
[3370922] | 463 | self.state.enable_smearer = copy.deepcopy(self.enable_smearer.GetValue()) |
---|
[fc6ea43] | 464 | self.state.disable_smearer = copy.deepcopy(self.disable_smearer.GetValue()) |
---|
| 465 | |
---|
[b787e68c] | 466 | |
---|
| 467 | if hasattr(self,"disp_box"): |
---|
| 468 | self.state.disp_box = self.disp_box.GetCurrentSelection() |
---|
| 469 | self._save_plotting_range() |
---|
[d2d0cfdf] | 470 | |
---|
| 471 | self.state.orientation_params =[] |
---|
| 472 | self.state.orientation_params_disp =[] |
---|
| 473 | self.state.parameters =[] |
---|
| 474 | self.state.fittable_param =[] |
---|
| 475 | self.state.fixed_param =[] |
---|
| 476 | |
---|
[cfc0913] | 477 | ## save checkbutton state and txtcrtl values |
---|
[fc6ea43] | 478 | self._copy_parameters_state(self.orientation_params, |
---|
| 479 | self.state.orientation_params) |
---|
| 480 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 481 | self.state.orientation_params_disp) |
---|
[d2d0cfdf] | 482 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
| 483 | |
---|
| 484 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 485 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[1c1436d] | 486 | |
---|
[cfc0913] | 487 | ## post state to fit panel |
---|
| 488 | event = PageInfoEvent(page = self) |
---|
| 489 | wx.PostEvent(self.parent, event) |
---|
| 490 | |
---|
[a074145] | 491 | |
---|
[7c845cb] | 492 | def reset_page_helper(self, state): |
---|
[cfc0913] | 493 | """ |
---|
[b787e68c] | 494 | Use page_state and change the state of existing page |
---|
[cfc0913] | 495 | """ |
---|
| 496 | self.state = state.clone() |
---|
| 497 | self.model= self.state.model |
---|
| 498 | self.data = self.state.data |
---|
[3370922] | 499 | self.smearer= self.state.smearer |
---|
| 500 | self.state.enable_smearer=state.enable_smearer |
---|
[b787e68c] | 501 | |
---|
| 502 | ##model parameter values restore |
---|
[cfc0913] | 503 | self._set_model_sizer_selection( self.model ) |
---|
| 504 | self.set_model_param_sizer(self.model) |
---|
[998b6b8] | 505 | if hasattr(self, "cb1"): |
---|
| 506 | self.cb1.SetValue(self.state.cb1) |
---|
[b787e68c] | 507 | ## display dispersion info layer |
---|
[cfc0913] | 508 | self.enable_disp.SetValue(self.state.enable_disp) |
---|
[fc6ea43] | 509 | self.disable_disp.SetValue(self.state.disable_disp) |
---|
[b787e68c] | 510 | if hasattr(self, "disp_box"): |
---|
| 511 | self.disp_box.SetSelection(self.state.disp_box) |
---|
[cfc0913] | 512 | self._set_dipers_Param(event=None) |
---|
[3370922] | 513 | ##plotting range restore |
---|
| 514 | self._reset_plotting_range() |
---|
[b787e68c] | 515 | ## smearing info restore |
---|
[cfc0913] | 516 | if hasattr(self,"enable_smearer"): |
---|
[3370922] | 517 | ## set smearing value whether or not the data contain the smearing info |
---|
[b787e68c] | 518 | self.enable_smearer.SetValue(state.enable_smearer) |
---|
[fc6ea43] | 519 | self.disable_smearer.SetValue(state.disable_smearer) |
---|
[3370922] | 520 | self.compute_chisqr(smearer= self.smearer) |
---|
| 521 | |
---|
[d2d0cfdf] | 522 | |
---|
[3370922] | 523 | ## reset state of checkbox,textcrtl and parameters value |
---|
[fc6ea43] | 524 | self._reset_parameters_state(self.orientation_params_disp, |
---|
| 525 | state.orientation_params_disp) |
---|
| 526 | self._reset_parameters_state(self.orientation_params, |
---|
| 527 | state.orientation_params) |
---|
[d2d0cfdf] | 528 | self._reset_parameters_state(self.parameters,state.parameters) |
---|
| 529 | self._reset_parameters_state(self.fittable_param,state.fittable_param) |
---|
| 530 | self._reset_parameters_state(self.fixed_param,state.fixed_param) |
---|
| 531 | |
---|
| 532 | ## reset context menu items |
---|
| 533 | self._reset_context_menu() |
---|
[b787e68c] | 534 | ## draw the model with previous parameters value |
---|
[cfc0913] | 535 | self._draw_model() |
---|
| 536 | |
---|
[a074145] | 537 | |
---|
| 538 | |
---|
| 539 | |
---|
[cfc0913] | 540 | |
---|
[c77d859] | 541 | def _selectDlg(self): |
---|
| 542 | """ |
---|
| 543 | open a dialog file to selected the customized dispersity |
---|
| 544 | """ |
---|
| 545 | import os |
---|
[60132ef] | 546 | dlg = wx.FileDialog(self, "Choose a weight file", |
---|
| 547 | self._default_save_location , "", "*.*", wx.OPEN) |
---|
[c77d859] | 548 | path = None |
---|
| 549 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 550 | path = dlg.GetPath() |
---|
| 551 | dlg.Destroy() |
---|
| 552 | return path |
---|
| 553 | |
---|
[cfc0913] | 554 | |
---|
[a074145] | 555 | def _reset_context_menu(self): |
---|
| 556 | """ |
---|
| 557 | reset the context menu |
---|
| 558 | """ |
---|
| 559 | for name, state in self.state.saved_states.iteritems(): |
---|
| 560 | self.number_saved_state += 1 |
---|
| 561 | ## Add item in the context menu |
---|
| 562 | id = wx.NewId() |
---|
| 563 | self.slicerpop.Append(id,name, 'Save model and state %g'%self.number_saved_state) |
---|
| 564 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
| 565 | |
---|
[cfc0913] | 566 | def _reset_plotting_range(self): |
---|
| 567 | """ |
---|
| 568 | Reset the plotting range to a given state |
---|
| 569 | """ |
---|
| 570 | |
---|
[b5e98540] | 571 | #self.qmin.SetValue(format_number(self.state.qmin)) |
---|
| 572 | #self.qmax.SetValue(format_number(self.state.qmax)) |
---|
| 573 | self.qmin.SetValue(str(self.state.qmin)) |
---|
| 574 | self.qmax.SetValue(str(self.state.qmax)) |
---|
[cfc0913] | 575 | if self.state.npts!=None: |
---|
[b787e68c] | 576 | self.npts.SetValue(format_number(self.state.npts)) |
---|
| 577 | self.num_points = float(self.state.npts) |
---|
[cfc0913] | 578 | |
---|
| 579 | self.qmin_x = float(self.qmin.GetValue()) |
---|
| 580 | self.qmax_x = float(self.qmax.GetValue()) |
---|
| 581 | |
---|
| 582 | |
---|
| 583 | def _save_plotting_range(self ): |
---|
| 584 | """ |
---|
| 585 | save the state of plotting range |
---|
| 586 | """ |
---|
[b787e68c] | 587 | self.state.qmin = self.qmin_x |
---|
| 588 | self.state.qmax = self.qmax_x |
---|
[cfc0913] | 589 | if self.npts!=None: |
---|
[b787e68c] | 590 | self.state.npts= self.num_points |
---|
[cfc0913] | 591 | |
---|
| 592 | |
---|
[c77d859] | 593 | def _onparamEnter_helper(self): |
---|
| 594 | """ |
---|
| 595 | check if values entered by the user are changed and valid to replot |
---|
| 596 | model |
---|
| 597 | use : _check_value_enter |
---|
| 598 | """ |
---|
| 599 | if self.model !=None: |
---|
[a074145] | 600 | ## save current state |
---|
| 601 | self.save_current_state() |
---|
[c77d859] | 602 | # Flag to register when a parameter has changed. |
---|
| 603 | is_modified = False |
---|
| 604 | is_modified =self._check_value_enter( self.fittable_param ,is_modified) |
---|
| 605 | is_modified =self._check_value_enter( self.fixed_param ,is_modified) |
---|
| 606 | is_modified =self._check_value_enter( self.parameters ,is_modified) |
---|
| 607 | |
---|
[0a518e4c] | 608 | self.Layout() |
---|
[c77d859] | 609 | # Here we should check whether the boundaries have been modified. |
---|
| 610 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
| 611 | # set the is_modified flag to True |
---|
[69bee6d] | 612 | from sans.guiframe.utils import check_value |
---|
[c77d859] | 613 | if check_value( self.qmin, self.qmax): |
---|
| 614 | if float(self.qmin.GetValue()) != self.qmin_x: |
---|
| 615 | self.qmin_x = float(self.qmin.GetValue()) |
---|
| 616 | is_modified = True |
---|
| 617 | if float(self.qmax.GetValue()) != self.qmax_x: |
---|
| 618 | self.qmax_x = float(self.qmax.GetValue()) |
---|
| 619 | is_modified = True |
---|
| 620 | self.fitrange = True |
---|
| 621 | else: |
---|
| 622 | self.fitrange = False |
---|
| 623 | if self.npts != None: |
---|
[69bee6d] | 624 | if check_float(self.npts): |
---|
| 625 | if float(self.npts.GetValue()) != self.num_points: |
---|
| 626 | self.num_points = float(self.npts.GetValue()) |
---|
| 627 | is_modified = True |
---|
| 628 | else: |
---|
| 629 | msg= "Cannot Plot :Must enter a number!!! " |
---|
| 630 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 631 | |
---|
[b787e68c] | 632 | |
---|
[c77d859] | 633 | ## if any value is modify draw model with new value |
---|
| 634 | if is_modified: |
---|
| 635 | self._draw_model() |
---|
| 636 | |
---|
| 637 | |
---|
[cfc0913] | 638 | def _reset_parameters_state(self, listtorestore,statelist): |
---|
| 639 | """ |
---|
| 640 | Reset the parameters at the given state |
---|
| 641 | """ |
---|
[6999659] | 642 | if len(statelist)==0 or len(listtorestore)==0 : |
---|
| 643 | return |
---|
| 644 | if len(statelist)!= len(listtorestore) : |
---|
[cfc0913] | 645 | return |
---|
| 646 | for j in range(len(listtorestore)): |
---|
| 647 | item_page = listtorestore[j] |
---|
| 648 | item_page_info = statelist[j] |
---|
| 649 | ##change the state of the check box for simple parameters |
---|
| 650 | if item_page[0]!=None: |
---|
| 651 | item_page[0].SetValue(item_page_info[0]) |
---|
| 652 | |
---|
| 653 | if item_page[2]!=None: |
---|
| 654 | item_page[2].SetValue(item_page_info[2]) |
---|
| 655 | |
---|
| 656 | if item_page[3]!=None: |
---|
| 657 | ## show or hide text +/- |
---|
| 658 | if item_page_info[2]: |
---|
| 659 | item_page[3].Show(True) |
---|
| 660 | else: |
---|
| 661 | item_page[3].Hide() |
---|
| 662 | if item_page[4]!=None: |
---|
| 663 | ## show of hide the text crtl for fitting error |
---|
| 664 | if item_page_info[4][0]: |
---|
| 665 | item_page[4].Show(True) |
---|
| 666 | item_page[4].SetValue(item_page_info[4][1]) |
---|
| 667 | else: |
---|
| 668 | item_page[3].Hide() |
---|
| 669 | if item_page[5]!=None: |
---|
| 670 | ## show of hide the text crtl for fitting error |
---|
| 671 | if item_page_info[5][0]: |
---|
| 672 | item_page[5].Show(True) |
---|
| 673 | item_page[5].SetValue(item_page_info[4][1]) |
---|
| 674 | else: |
---|
| 675 | item_page[5].Hide() |
---|
| 676 | |
---|
| 677 | if item_page[6]!=None: |
---|
| 678 | ## show of hide the text crtl for fitting error |
---|
| 679 | if item_page_info[6][0]: |
---|
| 680 | item_page[6].Show(True) |
---|
| 681 | item_page[6].SetValue(item_page_info[6][1]) |
---|
| 682 | else: |
---|
| 683 | item_page[6].Hide() |
---|
| 684 | |
---|
[b787e68c] | 685 | |
---|
[cfc0913] | 686 | def _copy_parameters_state(self, listtocopy, statelist): |
---|
| 687 | """ |
---|
| 688 | copy the state of button |
---|
| 689 | @param listtocopy: the list of check button to copy |
---|
| 690 | @param statelist: list of state object to store the current state |
---|
| 691 | """ |
---|
[d2d0cfdf] | 692 | |
---|
[cfc0913] | 693 | if len(listtocopy)==0: |
---|
| 694 | return |
---|
[1c1436d] | 695 | |
---|
[cfc0913] | 696 | for item in listtocopy: |
---|
| 697 | checkbox_state = None |
---|
| 698 | if item[0]!= None: |
---|
| 699 | checkbox_state= item[0].GetValue() |
---|
| 700 | parameter_name = item[1] |
---|
| 701 | parameter_value = None |
---|
| 702 | if item[2]!=None: |
---|
| 703 | parameter_value = item[2].GetValue() |
---|
| 704 | static_text = None |
---|
| 705 | if item[3]!=None: |
---|
| 706 | static_text = item[3].IsShown() |
---|
| 707 | error_value = None |
---|
| 708 | error_state = None |
---|
| 709 | if item[4]!= None: |
---|
| 710 | error_value = item[4].GetValue() |
---|
| 711 | error_state = item[4].IsShown() |
---|
| 712 | |
---|
| 713 | min_value = None |
---|
| 714 | min_state = None |
---|
| 715 | if item[5]!= None: |
---|
| 716 | min_value = item[5].GetValue() |
---|
| 717 | min_state = item[5].IsShown() |
---|
| 718 | |
---|
| 719 | max_value = None |
---|
| 720 | max_state = None |
---|
| 721 | if item[6]!= None: |
---|
| 722 | max_value = item[6].GetValue() |
---|
| 723 | max_state = item[6].IsShown() |
---|
| 724 | |
---|
| 725 | statelist.append([checkbox_state, parameter_name, parameter_value, |
---|
| 726 | static_text ,[error_state,error_value], |
---|
| 727 | [min_state,min_value],[max_state , max_value],None]) |
---|
| 728 | |
---|
| 729 | |
---|
| 730 | |
---|
[c77d859] | 731 | def _set_model_sizer_selection(self, model): |
---|
| 732 | """ |
---|
| 733 | Display the sizer according to the type of the current model |
---|
| 734 | """ |
---|
| 735 | if hasattr(model ,"model2"): |
---|
| 736 | |
---|
| 737 | class_name= model.model2.__class__ |
---|
| 738 | name= model.model2.name |
---|
| 739 | flag= name != "NoStructure" |
---|
| 740 | if flag and (class_name in self.model_list_box["Structure Factors"]): |
---|
[3b605bb] | 741 | self.structurebox.Enable() |
---|
[c77d859] | 742 | items = self.structurebox.GetItems() |
---|
| 743 | self.sizer1.Layout() |
---|
| 744 | self.SetScrollbars(20,20,200,100) |
---|
| 745 | for i in range(len(items)): |
---|
| 746 | if items[i]== str(name): |
---|
| 747 | self.structurebox.SetSelection(i) |
---|
| 748 | break |
---|
| 749 | |
---|
| 750 | if hasattr(model ,"model1"): |
---|
| 751 | class_name = model.model1.__class__ |
---|
| 752 | name = model.model1.name |
---|
| 753 | self.formfactorbox.Clear() |
---|
| 754 | |
---|
| 755 | for k, list in self.model_list_box.iteritems(): |
---|
[376916c] | 756 | if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: |
---|
[c77d859] | 757 | self.shape_rbutton.SetValue(True) |
---|
[376916c] | 758 | ## fill the form factor list with new model |
---|
| 759 | self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) |
---|
| 760 | items = self.formfactorbox.GetItems() |
---|
| 761 | ## set comboxbox to the selected item |
---|
| 762 | for i in range(len(items)): |
---|
| 763 | if items[i]== str(name): |
---|
| 764 | self.formfactorbox.SetSelection(i) |
---|
| 765 | break |
---|
| 766 | return |
---|
| 767 | elif k == "Shape-Independent": |
---|
[c77d859] | 768 | self.shape_indep_rbutton.SetValue(True) |
---|
| 769 | elif k == "Structure Factors": |
---|
| 770 | self.struct_rbutton.SetValue(True) |
---|
| 771 | else: |
---|
| 772 | self.plugin_rbutton.SetValue(True) |
---|
[376916c] | 773 | |
---|
[c77d859] | 774 | if class_name in list: |
---|
| 775 | ## fill the form factor list with new model |
---|
| 776 | self._populate_box(self.formfactorbox, list) |
---|
| 777 | items = self.formfactorbox.GetItems() |
---|
| 778 | ## set comboxbox to the selected item |
---|
| 779 | for i in range(len(items)): |
---|
| 780 | if items[i]== str(name): |
---|
| 781 | self.formfactorbox.SetSelection(i) |
---|
| 782 | break |
---|
| 783 | break |
---|
| 784 | else: |
---|
[376916c] | 785 | ## Select the model from the combobox |
---|
[c77d859] | 786 | class_name = model.__class__ |
---|
| 787 | name = model.name |
---|
| 788 | self.formfactorbox.Clear() |
---|
| 789 | items = self.formfactorbox.GetItems() |
---|
[376916c] | 790 | |
---|
[c77d859] | 791 | for k, list in self.model_list_box.iteritems(): |
---|
[376916c] | 792 | if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: |
---|
[3b605bb] | 793 | |
---|
| 794 | if class_name in self.model_list_box["P(Q)*S(Q)"]: |
---|
| 795 | self.structurebox.Enable() |
---|
| 796 | else: |
---|
| 797 | self.structurebox.Disable() |
---|
| 798 | self.structurebox.SetSelection(0) |
---|
| 799 | |
---|
[c77d859] | 800 | self.shape_rbutton.SetValue(True) |
---|
[376916c] | 801 | ## fill the form factor list with new model |
---|
| 802 | self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) |
---|
| 803 | items = self.formfactorbox.GetItems() |
---|
| 804 | ## set comboxbox to the selected item |
---|
| 805 | for i in range(len(items)): |
---|
| 806 | if items[i]== str(name): |
---|
| 807 | self.formfactorbox.SetSelection(i) |
---|
| 808 | break |
---|
| 809 | return |
---|
| 810 | elif k == "Shape-Independent": |
---|
[c77d859] | 811 | self.shape_indep_rbutton.SetValue(True) |
---|
| 812 | elif k == "Structure Factors": |
---|
| 813 | self.struct_rbutton.SetValue(True) |
---|
| 814 | else: |
---|
| 815 | self.plugin_rbutton.SetValue(True) |
---|
| 816 | if class_name in list: |
---|
[3b605bb] | 817 | self.structurebox.SetSelection(0) |
---|
| 818 | self.structurebox.Disable() |
---|
[376916c] | 819 | ## fill the form factor list with new model |
---|
[c77d859] | 820 | self._populate_box(self.formfactorbox, list) |
---|
| 821 | items = self.formfactorbox.GetItems() |
---|
| 822 | ## set comboxbox to the selected item |
---|
| 823 | for i in range(len(items)): |
---|
| 824 | if items[i]== str(name): |
---|
| 825 | self.formfactorbox.SetSelection(i) |
---|
| 826 | break |
---|
| 827 | break |
---|
| 828 | |
---|
| 829 | |
---|
| 830 | def _draw_model(self): |
---|
| 831 | """ |
---|
| 832 | Method to draw or refresh a plotted model. |
---|
| 833 | The method will use the data member from the model page |
---|
| 834 | to build a call to the fitting perspective manager. |
---|
| 835 | |
---|
| 836 | [Note to coder: This way future changes will be done in only one place.] |
---|
| 837 | """ |
---|
| 838 | if self.model !=None: |
---|
[fca9cbd9] | 839 | temp_smear=None |
---|
| 840 | if hasattr(self, "enable_smearer"): |
---|
| 841 | if self.enable_smearer.GetValue(): |
---|
| 842 | temp_smear= self.smearer |
---|
[c77d859] | 843 | self.manager.draw_model(self.model, data=self.data, |
---|
[c16557c] | 844 | smearer= temp_smear, |
---|
[4e6b5939] | 845 | qmin=float(self.qmin_x), qmax=float(self.qmax_x), |
---|
| 846 | qstep= float(self.num_points), |
---|
[c77d859] | 847 | enable2D=self.enable2D) |
---|
| 848 | |
---|
| 849 | def _set_model_sizer(self, sizer, title="", object=None): |
---|
| 850 | """ |
---|
| 851 | Use lists to fill a sizer for model info |
---|
| 852 | """ |
---|
| 853 | |
---|
| 854 | sizer.Clear(True) |
---|
| 855 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
| 856 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 857 | #-------------------------------------------------------- |
---|
[376916c] | 858 | self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', style=wx.RB_GROUP) |
---|
| 859 | self.shape_indep_rbutton = wx.RadioButton(self, -1, "Shape-Independent") |
---|
| 860 | self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") |
---|
| 861 | self.plugin_rbutton = wx.RadioButton(self, -1, "Customized Models") |
---|
[c77d859] | 862 | |
---|
| 863 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 864 | id= self.shape_rbutton.GetId() ) |
---|
| 865 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 866 | id= self.shape_indep_rbutton.GetId() ) |
---|
| 867 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 868 | id= self.struct_rbutton.GetId() ) |
---|
| 869 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 870 | id= self.plugin_rbutton.GetId() ) |
---|
[3b605bb] | 871 | |
---|
[cfc0913] | 872 | |
---|
[3b605bb] | 873 | sizer_radiobutton = wx.GridSizer(2, 2,5, 5) |
---|
[c77d859] | 874 | sizer_radiobutton.Add(self.shape_rbutton) |
---|
| 875 | sizer_radiobutton.Add(self.shape_indep_rbutton) |
---|
| 876 | sizer_radiobutton.Add(self.plugin_rbutton) |
---|
| 877 | sizer_radiobutton.Add(self.struct_rbutton) |
---|
| 878 | |
---|
| 879 | sizer_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 880 | |
---|
[fa58441] | 881 | self.text1 = wx.StaticText( self,-1,"" ) |
---|
| 882 | self.text2 = wx.StaticText( self,-1,"P(Q)*S(Q)" ) |
---|
[c77d859] | 883 | |
---|
| 884 | |
---|
[8bd4dc0] | 885 | self.formfactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
[c77d859] | 886 | if self.model!=None: |
---|
| 887 | self.formfactorbox.SetValue(self.model.name) |
---|
[59a7f2d] | 888 | |
---|
| 889 | |
---|
[8bd4dc0] | 890 | self.structurebox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
[c77d859] | 891 | wx.EVT_COMBOBOX(self.formfactorbox,-1, self._on_select_model) |
---|
| 892 | wx.EVT_COMBOBOX(self.structurebox,-1, self._on_select_model) |
---|
[3b605bb] | 893 | |
---|
| 894 | |
---|
[c77d859] | 895 | |
---|
| 896 | ## fill combox box |
---|
| 897 | if len(self.model_list_box)>0: |
---|
[376916c] | 898 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
[c77d859] | 899 | |
---|
| 900 | if len(self.model_list_box)>0: |
---|
| 901 | self._populate_box( self.structurebox, |
---|
| 902 | self.model_list_box["Structure Factors"]) |
---|
[3b605bb] | 903 | self.structurebox.Insert("None", 0,None) |
---|
| 904 | self.structurebox.SetSelection(0) |
---|
| 905 | self.structurebox.Disable() |
---|
| 906 | |
---|
| 907 | if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: |
---|
| 908 | self.structurebox.Enable() |
---|
| 909 | |
---|
[c77d859] | 910 | |
---|
[59a7f2d] | 911 | ## check model type to show sizer |
---|
[c77d859] | 912 | if self.model !=None: |
---|
| 913 | self._set_model_sizer_selection( self.model ) |
---|
| 914 | |
---|
| 915 | sizer_selection.Add(self.text1) |
---|
| 916 | sizer_selection.Add((5,5)) |
---|
| 917 | sizer_selection.Add(self.formfactorbox) |
---|
| 918 | sizer_selection.Add((5,5)) |
---|
| 919 | sizer_selection.Add(self.text2) |
---|
| 920 | sizer_selection.Add((5,5)) |
---|
| 921 | sizer_selection.Add(self.structurebox) |
---|
| 922 | sizer_selection.Add((5,5)) |
---|
| 923 | |
---|
| 924 | boxsizer1.Add( sizer_radiobutton ) |
---|
| 925 | boxsizer1.Add( (20,20)) |
---|
| 926 | boxsizer1.Add( sizer_selection ) |
---|
| 927 | if object !=None: |
---|
[f6b65b8] | 928 | boxsizer1.Add( (-72,-72)) |
---|
| 929 | boxsizer1.Add( object, 0, wx.ALIGN_RIGHT| wx.RIGHT, 10) |
---|
| 930 | boxsizer1.Add( (60,60)) |
---|
[c77d859] | 931 | #-------------------------------------------------------- |
---|
| 932 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 933 | sizer.Layout() |
---|
| 934 | self.SetScrollbars(20,20,200,100) |
---|
| 935 | |
---|
| 936 | |
---|
| 937 | def _show_combox(self, event): |
---|
| 938 | """ |
---|
| 939 | Show combox box associate with type of model selected |
---|
| 940 | """ |
---|
[376916c] | 941 | ## Don't want to populate combo box again if the event comes from check box |
---|
| 942 | if self.shape_rbutton.GetValue()and\ |
---|
| 943 | event.GetEventObject()==self.shape_rbutton: |
---|
| 944 | ##fill the combobox with form factor list |
---|
[3b605bb] | 945 | self.structurebox.SetSelection(0) |
---|
| 946 | self.structurebox.Disable() |
---|
[c77d859] | 947 | self.formfactorbox.Clear() |
---|
[376916c] | 948 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
[c77d859] | 949 | |
---|
[376916c] | 950 | if self.shape_indep_rbutton.GetValue()and\ |
---|
| 951 | event.GetEventObject()==self.shape_indep_rbutton: |
---|
| 952 | ##fill the combobox with shape independent factor list |
---|
[3b605bb] | 953 | self.structurebox.SetSelection(0) |
---|
| 954 | self.structurebox.Disable() |
---|
[c77d859] | 955 | self.formfactorbox.Clear() |
---|
| 956 | self._populate_box( self.formfactorbox, |
---|
[376916c] | 957 | self.model_list_box["Shape-Independent"]) |
---|
[c77d859] | 958 | |
---|
[376916c] | 959 | if self.struct_rbutton.GetValue() and\ |
---|
| 960 | event.GetEventObject()==self.struct_rbutton: |
---|
| 961 | ##fill the combobox with structure factor list |
---|
[3b605bb] | 962 | self.structurebox.SetSelection(0) |
---|
| 963 | self.structurebox.Disable() |
---|
[c77d859] | 964 | self.formfactorbox.Clear() |
---|
| 965 | self._populate_box( self.formfactorbox, |
---|
| 966 | self.model_list_box["Structure Factors"]) |
---|
| 967 | |
---|
[376916c] | 968 | if self.plugin_rbutton.GetValue()and\ |
---|
| 969 | event.GetEventObject()==self.plugin_rbutton: |
---|
| 970 | |
---|
| 971 | ##fill the combobox with form factor list |
---|
[3b605bb] | 972 | self.structurebox.Disable() |
---|
[c77d859] | 973 | self.formfactorbox.Clear() |
---|
| 974 | self._populate_box( self.formfactorbox, |
---|
[376916c] | 975 | self.model_list_box["Customized Models"]) |
---|
| 976 | |
---|
[77e23a2] | 977 | self._on_select_model(event=None) |
---|
[3b605bb] | 978 | self.sizer4_4.Layout() |
---|
[9853ad0] | 979 | self.sizer4.Layout() |
---|
[3b605bb] | 980 | self.Layout() |
---|
| 981 | self.Refresh() |
---|
| 982 | self.SetScrollbars(20,20,200,100) |
---|
[c77d859] | 983 | |
---|
| 984 | def _populate_box(self, combobox, list): |
---|
| 985 | """ |
---|
| 986 | fill combox box with dict item |
---|
| 987 | @param list: contains item to fill the combox |
---|
| 988 | item must model class |
---|
| 989 | """ |
---|
| 990 | for models in list: |
---|
| 991 | model= models() |
---|
| 992 | name = model.__class__.__name__ |
---|
[0a518e4c] | 993 | if models.__name__!="NoStructure": |
---|
| 994 | if hasattr(model, "name"): |
---|
| 995 | name = model.name |
---|
| 996 | combobox.Append(name,models) |
---|
[9853ad0] | 997 | try: |
---|
[376916c] | 998 | |
---|
[9853ad0] | 999 | combobox.SetSelection(0) |
---|
[59a7f2d] | 1000 | |
---|
[9853ad0] | 1001 | except: |
---|
| 1002 | pass |
---|
[cfc0913] | 1003 | |
---|
[c77d859] | 1004 | return 0 |
---|
| 1005 | |
---|
| 1006 | |
---|
[59a7f2d] | 1007 | def _on_select_model_helper(self): |
---|
[c77d859] | 1008 | """ |
---|
| 1009 | call back for model selection |
---|
| 1010 | """ |
---|
[376916c] | 1011 | ## reset dictionary containing reference to dispersion |
---|
| 1012 | self._disp_obj_dict = {} |
---|
| 1013 | self.disp_cb_dict ={} |
---|
[c77d859] | 1014 | f_id = self.formfactorbox.GetCurrentSelection() |
---|
| 1015 | form_factor = self.formfactorbox.GetClientData( f_id ) |
---|
[376916c] | 1016 | if not form_factor in self.model_list_box["multiplication"]: |
---|
[3b605bb] | 1017 | self.structurebox.Disable() |
---|
| 1018 | self.structurebox.SetSelection(0) |
---|
[87fbc60] | 1019 | else: |
---|
| 1020 | self.structurebox.Enable() |
---|
[a074145] | 1021 | |
---|
[3b605bb] | 1022 | s_id = self.structurebox.GetCurrentSelection() |
---|
| 1023 | struct_factor = self.structurebox.GetClientData( s_id ) |
---|
[a074145] | 1024 | |
---|
[3b605bb] | 1025 | if struct_factor !=None: |
---|
[9853ad0] | 1026 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
| 1027 | self.model= MultiplicationModel(form_factor(),struct_factor()) |
---|
[c77d859] | 1028 | else: |
---|
[9853ad0] | 1029 | self.model= form_factor() |
---|
[a074145] | 1030 | |
---|
[cfc0913] | 1031 | ## post state to fit panel |
---|
[fc6ea43] | 1032 | self.state.model =self.model |
---|
| 1033 | ## post state to fit panel |
---|
| 1034 | event = PageInfoEvent(page = self) |
---|
| 1035 | wx.PostEvent(self.parent, event) |
---|
| 1036 | |
---|
[3b605bb] | 1037 | self.sizer4_4.Layout() |
---|
| 1038 | self.sizer4.Layout() |
---|
| 1039 | self.Layout() |
---|
| 1040 | self.SetScrollbars(20,20,200,100) |
---|
| 1041 | self.Refresh() |
---|
| 1042 | |
---|
[c77d859] | 1043 | |
---|
| 1044 | |
---|
| 1045 | def _onparamEnter(self,event): |
---|
| 1046 | """ |
---|
| 1047 | when enter value on panel redraw model according to changed |
---|
| 1048 | """ |
---|
[69bee6d] | 1049 | tcrtl= event.GetEventObject() |
---|
| 1050 | if check_float(tcrtl): |
---|
| 1051 | self._onparamEnter_helper() |
---|
| 1052 | else: |
---|
| 1053 | msg= "Cannot Plot :Must enter a number!!! " |
---|
| 1054 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1055 | return |
---|
[c77d859] | 1056 | |
---|
| 1057 | |
---|
| 1058 | def _check_value_enter(self, list, modified): |
---|
| 1059 | """ |
---|
| 1060 | @param list: model parameter and panel info |
---|
| 1061 | each item of the list should be as follow: |
---|
| 1062 | item=[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 1063 | """ |
---|
| 1064 | is_modified = modified |
---|
| 1065 | if len(list)==0: |
---|
| 1066 | return is_modified |
---|
| 1067 | for item in list: |
---|
| 1068 | try: |
---|
[77e23a2] | 1069 | name = str(item[1]) |
---|
[0a518e4c] | 1070 | if hasattr(self,"text2_3"): |
---|
| 1071 | self.text2_3.Hide() |
---|
[77e23a2] | 1072 | ## check model parameters range |
---|
| 1073 | ## check minimun value |
---|
| 1074 | param_min= None |
---|
| 1075 | param_max= None |
---|
| 1076 | if item[5]!= None: |
---|
[298b762] | 1077 | if item[5].GetValue().lstrip().rstrip()!="": |
---|
[77e23a2] | 1078 | param_min = float(item[5].GetValue()) |
---|
[cfc0913] | 1079 | |
---|
[77e23a2] | 1080 | ## check maximum value |
---|
| 1081 | if item[6]!= None: |
---|
[298b762] | 1082 | if item[6].GetValue().lstrip().rstrip()!="": |
---|
[77e23a2] | 1083 | param_max = float(item[6].GetValue()) |
---|
| 1084 | |
---|
| 1085 | from sans.guiframe.utils import check_value |
---|
| 1086 | if param_min != None and param_max !=None: |
---|
[87a43fe] | 1087 | if not check_value(item[5], item[6]): |
---|
[77e23a2] | 1088 | msg= "Wrong Fit range entered for parameter " |
---|
| 1089 | msg+= "name %s of model %s "%(name, self.model.name) |
---|
| 1090 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[cfc0913] | 1091 | if name in self.model.details.keys(): |
---|
| 1092 | self.model.details[name][1:]= param_min,param_max |
---|
[87a43fe] | 1093 | |
---|
[77e23a2] | 1094 | ## hide statictext +/- |
---|
[0a518e4c] | 1095 | if item[3]!=None: |
---|
| 1096 | item[3].Hide() |
---|
[77e23a2] | 1097 | ## hide textcrtl for error after fit |
---|
[0a518e4c] | 1098 | if item[4]!=None: |
---|
| 1099 | item[4].Clear() |
---|
| 1100 | item[4].Hide() |
---|
[69bee6d] | 1101 | |
---|
| 1102 | |
---|
[0a518e4c] | 1103 | value= float(item[2].GetValue()) |
---|
[69bee6d] | 1104 | |
---|
[0a518e4c] | 1105 | # If the value of the parameter has changed, |
---|
[1328e03] | 1106 | # +update the model and set the is_modified flag |
---|
[0a518e4c] | 1107 | if value != self.model.getParam(name): |
---|
| 1108 | self.model.setParam(name,value) |
---|
[69bee6d] | 1109 | is_modified = True |
---|
| 1110 | |
---|
[c77d859] | 1111 | except: |
---|
[1328e03] | 1112 | msg= "Model Drawing Error:wrong value entered : %s"% sys.exc_value |
---|
| 1113 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1114 | return |
---|
[0a518e4c] | 1115 | |
---|
[c77d859] | 1116 | return is_modified |
---|
| 1117 | |
---|
| 1118 | |
---|
| 1119 | def _set_dipers_Param(self, event): |
---|
| 1120 | """ |
---|
| 1121 | Add more item to select user dispersity |
---|
| 1122 | """ |
---|
[1c1436d] | 1123 | self._reset_dispersity() |
---|
| 1124 | |
---|
| 1125 | if self.enable_disp.GetValue(): |
---|
| 1126 | self.model_disp.Show(True) |
---|
| 1127 | self.disp_box.Show(True) |
---|
| 1128 | ## layout for model containing no dispersity parameters |
---|
| 1129 | if len(self.disp_list)==0: |
---|
| 1130 | self._layout_sizer_noDipers() |
---|
[c77d859] | 1131 | else: |
---|
[1c1436d] | 1132 | ## set gaussian sizer |
---|
| 1133 | self._on_select_Disp(event=None) |
---|
| 1134 | else: |
---|
| 1135 | self.model_disp.Hide() |
---|
| 1136 | self.disp_box.Hide() |
---|
| 1137 | self.sizer4_4.Clear(True) |
---|
| 1138 | self._reset_dispersity() |
---|
| 1139 | |
---|
| 1140 | |
---|
| 1141 | ## post state to fit panel |
---|
| 1142 | self.save_current_state() |
---|
[c77d859] | 1143 | |
---|
[3b605bb] | 1144 | |
---|
[0a518e4c] | 1145 | |
---|
[c77d859] | 1146 | |
---|
| 1147 | def _layout_sizer_noDipers(self): |
---|
| 1148 | """ |
---|
| 1149 | Draw a sizer with no dispersity info |
---|
| 1150 | """ |
---|
| 1151 | ix=0 |
---|
| 1152 | iy=1 |
---|
| 1153 | self.fittable_param=[] |
---|
| 1154 | self.fixed_param=[] |
---|
[1c1436d] | 1155 | self.orientation_params_disp=[] |
---|
| 1156 | |
---|
[c77d859] | 1157 | self.model_disp.Hide() |
---|
| 1158 | self.disp_box.Hide() |
---|
| 1159 | self.sizer4_4.Clear(True) |
---|
| 1160 | model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model') |
---|
| 1161 | self.sizer4_4.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[dcf29d7] | 1162 | self.sizer4_4.Layout() |
---|
[c77d859] | 1163 | self.sizer4.Layout() |
---|
| 1164 | self.SetScrollbars(20,20,200,100) |
---|
[3b605bb] | 1165 | |
---|
[c77d859] | 1166 | |
---|
| 1167 | def _reset_dispersity(self): |
---|
| 1168 | """ |
---|
| 1169 | put gaussian dispersity into current model |
---|
| 1170 | """ |
---|
[1c1436d] | 1171 | if len(self.param_toFit)>0: |
---|
| 1172 | for item in self.fittable_param: |
---|
[513115c] | 1173 | if item in self.param_toFit: |
---|
[1c1436d] | 1174 | self.param_toFit.remove(item) |
---|
| 1175 | for item in self.orientation_params_disp: |
---|
[513115c] | 1176 | if item in self.param_toFit: |
---|
[1c1436d] | 1177 | self.param_toFit.remove(item) |
---|
[513115c] | 1178 | |
---|
[c77d859] | 1179 | self.fittable_param=[] |
---|
| 1180 | self.fixed_param=[] |
---|
[5812a55] | 1181 | self.orientation_params_disp=[] |
---|
[1c1436d] | 1182 | |
---|
[c77d859] | 1183 | from sans.models.dispersion_models import GaussianDispersion |
---|
| 1184 | if len(self.disp_cb_dict)==0: |
---|
[3b605bb] | 1185 | self.sizer4_4.Clear(True) |
---|
| 1186 | self.sizer4_4.Layout() |
---|
| 1187 | self.sizer4.Layout() |
---|
| 1188 | self.Layout() |
---|
| 1189 | self.Refresh() |
---|
| 1190 | self.SetScrollbars(20,20,200,100) |
---|
[c77d859] | 1191 | return |
---|
| 1192 | |
---|
| 1193 | for p in self.disp_cb_dict: |
---|
| 1194 | # The parameter was un-selected. Go back to Gaussian model (with 0 pts) |
---|
| 1195 | disp_model = GaussianDispersion() |
---|
| 1196 | # Store the object to make it persist outside the scope of this method |
---|
| 1197 | #TODO: refactor model to clean this up? |
---|
| 1198 | self._disp_obj_dict[p] = disp_model |
---|
| 1199 | # Set the new model as the dispersion object for the selected parameter |
---|
| 1200 | self.model.set_dispersion(p, disp_model) |
---|
| 1201 | # Redraw the model |
---|
[376916c] | 1202 | self._draw_model() |
---|
[c77d859] | 1203 | |
---|
[3b605bb] | 1204 | self.sizer4_4.Layout() |
---|
| 1205 | self.sizer4.Layout() |
---|
| 1206 | self.Layout() |
---|
| 1207 | self.SetScrollbars(20,20,200,100) |
---|
| 1208 | self.Refresh() |
---|
| 1209 | |
---|
| 1210 | |
---|
[c77d859] | 1211 | |
---|
| 1212 | def _on_select_Disp(self,event): |
---|
| 1213 | """ |
---|
| 1214 | allow selecting different dispersion |
---|
| 1215 | self.disp_list should change type later .now only gaussian |
---|
| 1216 | """ |
---|
[b787e68c] | 1217 | |
---|
| 1218 | n = self.disp_box.GetCurrentSelection() |
---|
| 1219 | dispersity= self.disp_box.GetClientData(n) |
---|
[c77d859] | 1220 | name= dispersity.__name__ |
---|
[376916c] | 1221 | if name == "GaussianDispersion": |
---|
[c77d859] | 1222 | self._set_sizer_gaussian() |
---|
| 1223 | |
---|
| 1224 | if name=="ArrayDispersion": |
---|
| 1225 | self._set_sizer_arraydispersion() |
---|
[3b605bb] | 1226 | |
---|
[b787e68c] | 1227 | self.state.disp_box= n |
---|
| 1228 | ## post state to fit panel |
---|
| 1229 | event = PageInfoEvent(page = self) |
---|
| 1230 | wx.PostEvent(self.parent, event) |
---|
| 1231 | |
---|
[3b605bb] | 1232 | self.sizer4_4.Layout() |
---|
| 1233 | self.sizer4.Layout() |
---|
| 1234 | self.Layout() |
---|
| 1235 | self.SetScrollbars(20,20,200,100) |
---|
| 1236 | self.Refresh() |
---|
| 1237 | |
---|
| 1238 | |
---|
| 1239 | |
---|
[b787e68c] | 1240 | |
---|
[c77d859] | 1241 | def _set_sizer_arraydispersion(self): |
---|
| 1242 | """ |
---|
| 1243 | draw sizer with array dispersity parameters |
---|
| 1244 | """ |
---|
[513115c] | 1245 | if len(self.param_toFit)>0: |
---|
| 1246 | for item in self.fittable_param: |
---|
| 1247 | if item in self.param_toFit: |
---|
| 1248 | self.param_toFit.remove(item) |
---|
| 1249 | for item in self.orientation_params_disp: |
---|
| 1250 | if item in self.param_toFit: |
---|
| 1251 | self.param_toFit.remove(item) |
---|
[1c1436d] | 1252 | self.fittable_param=[] |
---|
| 1253 | self.fixed_param=[] |
---|
[60132ef] | 1254 | self.orientation_params_disp=[] |
---|
[c77d859] | 1255 | self.sizer4_4.Clear(True) |
---|
| 1256 | ix=0 |
---|
| 1257 | iy=1 |
---|
| 1258 | disp1 = wx.StaticText(self, -1, 'Array Dispersion') |
---|
| 1259 | self.sizer4_4.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1260 | |
---|
| 1261 | # Look for model parameters to which we can apply an ArrayDispersion model |
---|
| 1262 | # Add a check box for each parameter. |
---|
| 1263 | self.disp_cb_dict = {} |
---|
| 1264 | for p in self.model.dispersion.keys(): |
---|
| 1265 | ix+=1 |
---|
| 1266 | self.disp_cb_dict[p] = wx.CheckBox(self, -1, p, (10, 10)) |
---|
| 1267 | |
---|
| 1268 | wx.EVT_CHECKBOX(self, self.disp_cb_dict[p].GetId(), self.select_disp_angle) |
---|
| 1269 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1270 | |
---|
| 1271 | ix =0 |
---|
| 1272 | iy +=1 |
---|
| 1273 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1274 | self.sizer4_4.Layout() |
---|
| 1275 | self.sizer4.Layout() |
---|
| 1276 | self.SetScrollbars(20,20,200,100) |
---|
| 1277 | |
---|
| 1278 | |
---|
| 1279 | def _set_range_sizer(self, title, object1=None,object=None): |
---|
| 1280 | """ |
---|
| 1281 | Fill the |
---|
| 1282 | """ |
---|
| 1283 | self.sizer5.Clear(True) |
---|
| 1284 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
| 1285 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 1286 | #-------------------------------------------------------------- |
---|
| 1287 | self.qmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
[b5e98540] | 1288 | #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.) |
---|
| 1289 | #self.qmin.SetValue(format_number(self.qmin_x)) |
---|
| 1290 | self.qmin.SetValue(str(self.qmin_x)) |
---|
[c77d859] | 1291 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
[1328e03] | 1292 | self.qmin.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
[dcf29d7] | 1293 | self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
[c77d859] | 1294 | self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
| 1295 | |
---|
| 1296 | self.qmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
[b5e98540] | 1297 | #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.) |
---|
| 1298 | #self.qmax.SetValue(format_number(self.qmax_x)) |
---|
| 1299 | self.qmax.SetValue(str(self.qmax_x)) |
---|
[c77d859] | 1300 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
[1328e03] | 1301 | self.qmax.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
[dcf29d7] | 1302 | self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
[c77d859] | 1303 | self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
| 1304 | |
---|
| 1305 | sizer_horizontal=wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1306 | sizer= wx.GridSizer(3, 3,5, 5) |
---|
| 1307 | |
---|
| 1308 | sizer.Add((5,5)) |
---|
| 1309 | sizer.Add(wx.StaticText(self, -1, 'Min')) |
---|
| 1310 | sizer.Add(wx.StaticText(self, -1, 'Max')) |
---|
| 1311 | sizer.Add(wx.StaticText(self, -1, 'Q range')) |
---|
| 1312 | |
---|
| 1313 | sizer.Add(self.qmin) |
---|
| 1314 | sizer.Add(self.qmax) |
---|
| 1315 | sizer_horizontal.Add(sizer) |
---|
| 1316 | if object!=None: |
---|
| 1317 | sizer_horizontal.Add(object) |
---|
| 1318 | |
---|
| 1319 | if object1!=None: |
---|
| 1320 | boxsizer1.Add(object1) |
---|
| 1321 | boxsizer1.Add((10,10)) |
---|
| 1322 | boxsizer1.Add(sizer_horizontal) |
---|
[cfc0913] | 1323 | ## save state |
---|
| 1324 | self.save_current_state() |
---|
[c77d859] | 1325 | #---------------------------------------------------------------- |
---|
| 1326 | self.sizer5.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 1327 | self.sizer5.Layout() |
---|
[dcf29d7] | 1328 | self.Layout() |
---|
[c77d859] | 1329 | self.SetScrollbars(20,20,200,100) |
---|
| 1330 | |
---|
[cfc0913] | 1331 | |
---|
[00c3aac] | 1332 | def _fill_save_sizer(self): |
---|
| 1333 | """ |
---|
| 1334 | Draw the layout for saving option |
---|
| 1335 | """ |
---|
| 1336 | self.sizer6.Clear(True) |
---|
[45ed4dad] | 1337 | box_description= wx.StaticBox(self, -1,"Save Status") |
---|
[00c3aac] | 1338 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 1339 | sizer_save = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 1340 | |
---|
[45ed4dad] | 1341 | self.btSave_title = wx.StaticText(self, -1, 'Save the current panel status') |
---|
[00c3aac] | 1342 | self.btSave = wx.Button(self,wx.NewId(),'Save') |
---|
| 1343 | self.btSave.Bind(wx.EVT_BUTTON, self.onSave,id= self.btSave.GetId()) |
---|
[45ed4dad] | 1344 | self.btSave.SetToolTipString("Save current panel status") |
---|
| 1345 | |
---|
| 1346 | sizer_save.Add(self.btSave_title) |
---|
| 1347 | sizer_save.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,45) |
---|
| 1348 | |
---|
[00c3aac] | 1349 | sizer_save.Add(self.btSave) |
---|
| 1350 | |
---|
| 1351 | boxsizer1.Add(sizer_save) |
---|
| 1352 | self.sizer6.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 1353 | self.sizer6.Layout() |
---|
| 1354 | self.SetScrollbars(20,20,200,100) |
---|
| 1355 | |
---|
[c77d859] | 1356 | |
---|
| 1357 | |
---|