Changeset 2f60121 in sasview for theoryview/perspectives
- Timestamp:
- Jan 10, 2011 2:22:39 PM (14 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 015d109
- Parents:
- 340c2b3
- Location:
- theoryview/perspectives/theory
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
theoryview/perspectives/theory/basepage.py
rda9ac4e6 r2f60121 1 1 2 import sys, os 2 import sys 3 import os 3 4 import wx 4 5 import numpy … … 7 8 import math 8 9 import string 9 from sans.guiframe.utils import format_number,check_float 10 from sans.guiframe.utils import format_number 11 from sans.guiframe.utils import check_float 10 12 from sans.guicomm.events import StatusEvent 11 13 import pagestate 12 14 from pagestate import PageState 13 (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() 14 (PreviousStateEvent, EVT_PREVIOUS_STATE) = wx.lib.newevent.NewEvent() 15 (NextStateEvent, EVT_NEXT_STATE) = wx.lib.newevent.NewEvent() 15 16 (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() 17 (PreviousStateEvent, EVT_PREVIOUS_STATE)= wx.lib.newevent.NewEvent() 18 (NextStateEvent, EVT_NEXT_STATE) = wx.lib.newevent.NewEvent() 19 16 20 _BOX_WIDTH = 76 17 21 _QMIN_DEFAULT = 0.001 … … 19 23 _NPTS_DEFAULT = 50 20 24 #Control panel width 21 if sys.platform.count("darwin") ==0:25 if sys.platform.count("darwin") == 0: 22 26 PANEL_WIDTH = 450 23 27 FONT_VARIANT = 0 … … 38 42 window_caption = "Basic page " 39 43 40 def __init__(self,parent, page_info= 44 def __init__(self,parent, page_info=None, model_list_box=None): 41 45 wx.ScrolledWindow.__init__(self, parent, 42 style= wx.FULL_REPAINT_ON_RESIZE)46 style=wx.FULL_REPAINT_ON_RESIZE) 43 47 #Set window's font size 44 48 self.SetWindowVariant(variant=FONT_VARIANT) 45 46 49 ## parent of the page 47 50 self.parent = parent … … 52 55 ## owner of the page (fitting plugin) 53 56 self.event_owner = None 54 55 57 if page_info is not None: 56 58 ## manager is the fitting plugin 57 self.manager = page_info.manager59 self.manager = page_info.manager 58 60 ## owner of the page (fitting plugin) 59 self.event_owner = page_info.event_owner61 self.event_owner = page_info.event_owner 60 62 ## current model 61 63 self.model = page_info.model … … 71 73 self._disp_obj_dict = {} 72 74 ## selected parameters to apply dispersion 73 self.disp_cb_dict ={} 74 75 self.disp_cb_dict = {} 75 76 ## smearer object 76 77 self.smearer = None 77 78 78 ##list of model parameters. each item must have same length 79 79 ## each item related to a given parameters 80 80 ##[cb state, name, value, "+/-", error of fit, min, max , units] 81 self.parameters =[]81 self.parameters = [] 82 82 # non-fittable parameter whose value is astring 83 83 self.str_parameters = [] 84 84 ## list of parameters to fit , must be like self.parameters 85 self.param_toFit =[]85 self.param_toFit = [] 86 86 ## list of looking like parameters but with non fittable parameters info 87 self.fixed_param =[]87 self.fixed_param = [] 88 88 ## list of looking like parameters but with fittable parameters info 89 self.fittable_param =[]89 self.fittable_param = [] 90 90 ##list of dispersion parameters 91 self.disp_list =[]92 self.disp_name =""91 self.disp_list = [] 92 self.disp_name = "" 93 93 ## list of orientation parameters 94 self.orientation_params =[]95 self.orientation_params_disp =[]94 self.orientation_params = [] 95 self.orientation_params_disp = [] 96 96 if self.model != None: 97 self.disp_list = self.model.getDispParamList()97 self.disp_list = self.model.getDispParamList() 98 98 self.multi_factor = None 99 99 ##enable model 2D draw 100 self.enable2D = False100 self.enable2D = False 101 101 ## check that the fit range is correct to plot the model again 102 self.fitrange= True 103 102 self.fitrange = True 104 103 ## Q range 105 self.qmin_x= _QMIN_DEFAULT 106 self.qmax_x= _QMAX_DEFAULT 107 self.num_points= _NPTS_DEFAULT 108 104 self.qmin_x = _QMIN_DEFAULT 105 self.qmax_x = _QMAX_DEFAULT 106 self.num_points = _NPTS_DEFAULT 109 107 ## Create memento to save the current state 110 self.state= PageState(parent= self.parent,model=self.model, data=self.data) 108 self.state = PageState(parent=self.parent, 109 model=self.model, data=self.data) 111 110 ## flag to determine if state has change 112 self.state_change = False111 self.state_change = False 113 112 ## save customized array 114 self.values =[]115 self.weights =[]113 self.values = [] 114 self.weights = [] 116 115 ## retrieve saved state 117 self.number_saved_state = 0116 self.number_saved_state = 0 118 117 ## dictionary of saved state 119 self.saved_states ={}118 self.saved_states = {} 120 119 121 120 ## Create context menu for page 122 121 self.popUpMenu = wx.Menu() 123 122 #id = wx.NewId() 124 #self._undo = wx.MenuItem(self.popUpMenu,id, "Undo","cancel the previous action") 123 #self._undo = wx.MenuItem(self.popUpMenu,id, "Undo" 124 #,"cancel the previous action") 125 125 #self.popUpMenu.AppendItem(self._undo) 126 126 #self._undo.Enable(False) … … 128 128 129 129 #id = wx.NewId() 130 #self._redo = wx.MenuItem(self.popUpMenu,id,"Redo"," Restore the previous action") 130 #self._redo = wx.MenuItem(self.popUpMenu,id,"Redo", 131 #" Restore the previous action") 131 132 #self.popUpMenu.AppendItem(self._redo) 132 133 #self._redo.Enable(False) … … 135 136 #if sys.platform.count("win32")>0: 136 137 id = wx.NewId() 137 self._keep = wx.MenuItem(self.popUpMenu,id,"BookMark"," Keep the panel status to recall it later") 138 self._keep = wx.MenuItem(self.popUpMenu, id, "BookMark", 139 " Keep the panel status to recall it later") 138 140 self.popUpMenu.AppendItem(self._keep) 139 141 self._keep.Enable(True) 140 142 wx.EVT_MENU(self, id, self.onSave) 141 143 self.popUpMenu.AppendSeparator() 142 143 144 ## Default locations 144 145 self._default_save_location = os.getcwd() … … 167 168 168 169 """ 169 ## Set to True when the mouse is clicked while the whole string is selected 170 ## Set to True when the mouse is clicked 171 #while the whole string is selected 170 172 full_selection = False 171 173 ## Call back for EVT_SET_FOCUS events 172 174 _on_set_focus_callback = None 173 175 174 def __init__(self, parent, id=-1, value=wx.EmptyString, pos=wx.DefaultPosition, 175 size=wx.DefaultSize, style=0, validator=wx.DefaultValidator, name=wx.TextCtrlNameStr, 176 kill_focus_callback = None, set_focus_callback = None, 177 mouse_up_callback = None, text_enter_callback = None): 176 def __init__(self, parent, id=-1, value=wx.EmptyString, 177 pos=wx.DefaultPosition, 178 size=wx.DefaultSize, style=0, 179 validator=wx.DefaultValidator, name=wx.TextCtrlNameStr, 180 kill_focus_callback=None, set_focus_callback=None, 181 mouse_up_callback=None, text_enter_callback=None): 178 182 179 wx.TextCtrl.__init__(self, parent, id, value, pos, size, style, validator, name) 183 wx.TextCtrl.__init__(self, parent, id, value, pos, size, style, 184 validator, name) 180 185 181 186 # Bind appropriate events … … 198 203 :param event: mouse event 199 204 """ 200 201 205 event.Skip() 202 206 self.full_selection = True 203 207 return self._on_set_focus_callback(event) 204 205 206 208 207 209 def _highlight_text(self, event): 208 210 """ … … 223 225 (start, end) = control.GetSelection() 224 226 if start==end: 225 control.SetSelection(-1, -1)227 control.SetSelection(-1, -1) 226 228 227 229 def onContextMenu(self, event): … … 239 241 240 242 """ 241 event = PreviousStateEvent(page =self)243 event = PreviousStateEvent(page=self) 242 244 wx.PostEvent(self.parent, event) 243 245 … … 247 249 248 250 """ 249 event = NextStateEvent(page= 251 event = NextStateEvent(page=self) 250 252 wx.PostEvent(self.parent, event) 251 253 … … 263 265 self.sizer5 = wx.BoxSizer(wx.VERTICAL) 264 266 self.sizer6 = wx.BoxSizer(wx.VERTICAL) 265 266 267 self.sizer0.SetMinSize((PANEL_WIDTH,-1)) 267 268 self.sizer1.SetMinSize((PANEL_WIDTH,-1)) … … 271 272 self.sizer5.SetMinSize((PANEL_WIDTH,-1)) 272 273 #self.sizer6.SetMinSize((375,-1)) 273 274 274 self.vbox.Add(self.sizer0) 275 275 self.vbox.Add(self.sizer1) … … 280 280 #self.vbox.Add(self.sizer6) 281 281 282 283 282 def set_layout(self): 284 283 """ … … 295 294 """ 296 295 """ 297 self.SetScrollbars(20, 20,25,65)296 self.SetScrollbars(20, 20, 25, 65) 298 297 self.Layout() 299 298 self.SetAutoLayout(True) … … 333 332 self.sizer4.Clear(True) 334 333 name = "Polydispersity and Orientational Distribution" 335 box_description= wx.StaticBox(self, -1, name)334 box_description= wx.StaticBox(self, -1, name) 336 335 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 337 336 #---------------------------------------------------- 338 self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), style=wx.RB_GROUP) 337 self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), 338 style=wx.RB_GROUP) 339 339 self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) 340 340 341 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.disable_disp.GetId()) 342 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.enable_disp.GetId()) 341 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 342 id=self.disable_disp.GetId()) 343 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 344 id=self.enable_disp.GetId()) 343 345 #MAC needs SetValue 344 346 self.disable_disp.SetValue(True) 345 347 sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) 346 sizer_dispersion.Add((20, 20))348 sizer_dispersion.Add((20, 20)) 347 349 name=""#Polydispersity and \nOrientational Distribution " 348 sizer_dispersion.Add(wx.StaticText(self, -1,name))350 sizer_dispersion.Add(wx.StaticText(self, -1, name)) 349 351 sizer_dispersion.Add(self.enable_disp ) 350 sizer_dispersion.Add((20, 20))351 sizer_dispersion.Add(self.disable_disp 352 sizer_dispersion.Add((10, 10))352 sizer_dispersion.Add((20, 20)) 353 sizer_dispersion.Add(self.disable_disp) 354 sizer_dispersion.Add((10, 10)) 353 355 354 356 ## fill a sizer with the combobox to select dispersion type … … 364 366 self.disp_box.Append(name,value) 365 367 self.disp_box.SetStringSelection("gaussian") 366 wx.EVT_COMBOBOX(self.disp_box, -1, self._on_select_Disp)368 wx.EVT_COMBOBOX(self.disp_box, -1, self._on_select_Disp) 367 369 368 sizer_select_dispers.Add((10, 10))370 sizer_select_dispers.Add((10, 10)) 369 371 sizer_select_dispers.Add(self.model_disp) 370 sizer_select_dispers.Add(self.disp_box,0, 371 wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) 372 372 sizer_select_dispers.Add(self.disp_box, 0, 373 wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, border=5) 373 374 self.model_disp.Hide() 374 375 self.disp_box.Hide() 375 376 boxsizer1.Add( sizer_dispersion,0, 377 wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) 378 #boxsizer1.Add( (10,10) ) 379 boxsizer1.Add( sizer_select_dispers ) 380 self.sizer4_4 = wx.GridBagSizer(5,5) 381 boxsizer1.Add( self.sizer4_4 ) 376 boxsizer1.Add(sizer_dispersion, 0, 377 wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, border=5) 378 #boxsizer1.Add((10, 10)) 379 boxsizer1.Add(sizer_select_dispers) 380 self.sizer4_4 = wx.GridBagSizer(5, 5) 381 boxsizer1.Add(self.sizer4_4) 382 382 #----------------------------------------------------- 383 self.sizer4.Add(boxsizer1, 0, wx.EXPAND |wx.ALL, 10)383 self.sizer4.Add(boxsizer1, 0, wx.EXPAND|wx.ALL, 10) 384 384 self.sizer4_4.Layout() 385 385 self.sizer4.Layout() 386 386 self.Layout() 387 self.SetScrollbars(20, 20,25,65)387 self.SetScrollbars(20, 20, 25, 65) 388 388 self.Refresh() 389 389 ## saving the state of enable dispersity button … … 391 391 self.state.disable_disp= self.disable_disp.GetValue() 392 392 393 394 393 def select_disp_angle(self, event): 395 394 """ … … 398 397 :param event: radiobutton event 399 398 """ 400 self.values =[]401 self.weights =[]402 if event.GetEventObject() ==self.noDisper_rbox:399 self.values = [] 400 self.weights = [] 401 if event.GetEventObject() == self.noDisper_rbox: 403 402 if self.noDisper_rbox.GetValue(): 404 403 #No array dispersity apply yet … … 406 405 ## Redraw the model ??? 407 406 self._draw_model() 408 # Go through the list of dispersion check boxes to identify which one has changed 407 # Go through the list of dispersion check boxes to 408 #identify which one has changed 409 409 for p in self.disp_cb_dict: 410 self.state.disp_cb_dict[p] =self.disp_cb_dict[p].GetValue()410 self.state.disp_cb_dict[p] = self.disp_cb_dict[p].GetValue() 411 411 # Catch which one of the box was just checked or unchecked. 412 412 if event.GetEventObject() == self.disp_cb_dict[p]: 413 413 if self.disp_cb_dict[p].GetValue() == True: 414 415 ##Temp. FIX for V1.0 regarding changing checkbox to radiobutton. 416 ##This (self._reset_dispersity) should be removed when the array dispersion is fixed. 414 ##Temp. FIX for V1.0 regarding changing 415 #checkbox to radiobutton. 416 ##This (self._reset_dispersity) should be removed 417 #when the array dispersion is fixed. 417 418 self._reset_dispersity() 418 419 419 # The user wants this parameter to be averaged. 420 420 # Pop up the file selection dialog. 421 421 path = self._selectDlg() 422 423 422 # If nothing was selected, just return 424 423 if path is None: … … 431 430 pass 432 431 try: 433 self.values, self.weights = self.read_file(path)432 self.values, self.weights = self.read_file(path) 434 433 except: 435 msg ="Could not read input file"436 wx.PostEvent(self.parent, StatusEvent(status= 434 msg = "Could not read input file" 435 wx.PostEvent(self.parent, StatusEvent(status=msg)) 437 436 return 438 439 # If any of the two arrays is empty, notify the user that we won't 440 # proceed 437 # If any of the two arrays is empty, notify the user 438 # that we won't proceed 441 439 if self.values is None or self.weights is None or \ 442 self.values ==[] or self.weights ==[]: 443 wx.PostEvent(self.parent, StatusEvent(status=\ 444 "The loaded %s distrubtion is corrupted or empty" % p)) 440 self.values == [] or self.weights == []: 441 msg = "The loaded %s distrubtion is corrupted" 442 msg += " or empty" % p 443 wx.PostEvent(self.parent, StatusEvent(status=msg)) 445 444 return 446 447 445 # Tell the user that we are about to apply the distribution 448 wx.PostEvent(self.parent, StatusEvent(status=\449 "Applying loaded %s distribution: %s" % (p, path)))446 msg = "Applying loaded %s distribution: %s" % (p, path) 447 wx.PostEvent(self.parent, StatusEvent(status=msg)) 450 448 451 449 # Create the dispersion objects … … 454 452 disp_model.set_weights(self.values, self.weights) 455 453 456 # Store the object to make it persist outside the scope of this method 454 # Store the object to make it persist outside the scope 455 #of this method 457 456 #TODO: refactor model to clean this up? 458 457 self._disp_obj_dict[p] = disp_model 459 self.state._disp_obj_dict [p] = disp_model460 self.state.values =[]461 self.state.weights =[]458 self.state._disp_obj_dict [p] = disp_model 459 self.state.values = [] 460 self.state.weights = [] 462 461 self.state.values = copy.deepcopy(self.values) 463 462 self.state.weights = copy.deepcopy(self.weights) 464 # Set the new model as the dispersion object for the selected parameter 463 # Set the new model as the dispersion object for the 464 #selected parameter 465 465 self.model.set_dispersion(p, disp_model) 466 # Store a reference to the weights in the model object so that 466 # Store a reference to the weights in the model object 467 #so that 467 468 # it's not lost when we use the model within another thread. 468 469 #TODO: total hack - fix this … … 470 471 471 472 self.model._persistency_dict = {} 472 self.model._persistency_dict[p] = [self.values, self.weights] 473 self.state.model._persistency_dict[p] = [self.values, self.weights] 473 self.model._persistency_dict[p] = [self.values, 474 self.weights] 475 self.state.model._persistency_dict[p] = [self.values, 476 self.weights] 474 477 else: 475 478 self._reset_dispersity() … … 479 482 480 483 ## post state to fit panel 481 event = PageInfoEvent(page =self)484 event = PageInfoEvent(page=self) 482 485 wx.PostEvent(self.parent, event) 483 486 … … 489 492 ## post help message for the selected model 490 493 msg = self.popUpMenu.GetHelpString(event.GetId()) 491 msg += " reloaded"492 wx.PostEvent(self.parent, StatusEvent(status = msg))493 494 name = self.popUpMenu.GetLabel(event.GetId())494 msg += " reloaded" 495 wx.PostEvent(self.parent, StatusEvent(status=msg)) 496 497 name = self.popUpMenu.GetLabel(event.GetId()) 495 498 self._on_select_model_helper() 496 499 … … 500 503 self.reset_page(previous_state) 501 504 502 503 505 def onSave(self, event): 504 506 """ … … 506 508 507 509 """ 508 if self.model ==None:510 if self.model == None: 509 511 return 510 512 self.save_current_state() … … 524 526 self.number_saved_state += 1 525 527 #name= self.model.name+"[%g]"%self.number_saved_state 526 name= self.model.__class__.__name__+"[%g]"%self.number_saved_state 527 self.saved_states[name]= new_state 528 528 name = self.model.__class__.__name__ + "[%g]" % self.number_saved_state 529 self.saved_states[name] = new_state 529 530 ## Add item in the context menu 530 531 year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() 532 my_time= str(hour)+" : "+str(minute)+" : "+str(second)+" " 533 date= str( month)+"|"+str(day)+"|"+str(year) 534 msg= "Model saved at %s on %s"%(my_time, date) 531 year, month, day, hour, minute, second, _, _, _ = time.localtime() 532 my_time = str(hour) + " : " + str(minute) + " : " + str(second) + " " 533 date = str( month) + "|" + str(day) + "|" + str(year) 534 msg = "Model saved at %s on %s" % (my_time, date) 535 535 ## post help message for the selected model 536 msg += " Saved! right click on this page to retrieve this model"537 wx.PostEvent(self.parent, StatusEvent(status = msg))536 msg += " Saved! right click on this page to retrieve this model" 537 wx.PostEvent(self.parent, StatusEvent(status=msg)) 538 538 539 539 id = wx.NewId() 540 self.popUpMenu.Append(id, name,str(msg))540 self.popUpMenu.Append(id, name, str(msg)) 541 541 wx.EVT_MENU(self, id, self.onResetModel) 542 542 … … 556 556 """ 557 557 try: 558 if path ==None:559 wx.PostEvent(self.parent, StatusEvent(status=\560 " Selected Distribution was not loaded: %s"%path))558 if path == None: 559 msg = " Selected Distribution was not loaded: %s" % path 560 wx.PostEvent(self.parent, StatusEvent(status=msg)) 561 561 return None, None 562 562 input_f = open(path, 'r') 563 563 buff = input_f.read() 564 564 lines = buff.split('\n') 565 566 565 angles = [] 567 weights =[]566 weights = [] 568 567 for line in lines: 569 568 toks = line.split() … … 580 579 raise 581 580 582 583 581 def createMemento(self): 584 582 """ … … 587 585 return self.state.clone() 588 586 589 590 587 def save_current_state(self): 591 588 """ … … 594 591 """ 595 592 ## save model option 596 if self.model != None:597 self.disp_list = self.model.getDispParamList()598 self.state.disp_list = copy.deepcopy(self.disp_list)593 if self.model != None: 594 self.disp_list = self.model.getDispParamList() 595 self.state.disp_list = copy.deepcopy(self.disp_list) 599 596 self.state.model = self.model.clone() 600 601 597 self.state.enable2D = copy.deepcopy(self.enable2D) 602 self.state.values = copy.deepcopy(self.values)598 self.state.values = copy.deepcopy(self.values) 603 599 self.state.weights = copy.deepcopy( self.weights) 604 600 ## save data 605 self.state.data = copy.deepcopy(self.data)601 self.state.data = copy.deepcopy(self.data) 606 602 try: 607 603 n = self.disp_box.GetCurrentSelection() 608 604 dispersity= self.disp_box.GetClientData(n) 609 name = dispersity.__name__605 name = dispersity.__name__ 610 606 self.disp_name = name 611 if name == "GaussianDispersion" 607 if name == "GaussianDispersion": 612 608 if hasattr(self,"cb1"): 613 self.state.cb1 = self.cb1.GetValue()609 self.state.cb1 = self.cb1.GetValue() 614 610 except: 615 611 pass 616 617 if hasattr(self,"enable_disp"): 618 self.state.enable_disp= self.enable_disp.GetValue() 612 if hasattr(self, "enable_disp"): 613 self.state.enable_disp = self.enable_disp.GetValue() 619 614 self.state.disable_disp = self.disable_disp.GetValue() 620 621 615 self.state.smearer = copy.deepcopy(self.smearer) 622 if hasattr(self, "enable_smearer"):616 if hasattr(self, "enable_smearer"): 623 617 self.state.enable_smearer = copy.deepcopy(self.enable_smearer.GetValue()) 624 618 self.state.disable_smearer = copy.deepcopy(self.disable_smearer.GetValue()) 625 626 if hasattr(self,"disp_box"): 619 if hasattr(self, "disp_box"): 627 620 self.state.disp_box = self.disp_box.GetCurrentSelection() 628 629 if len(self.disp_cb_dict)>0: 630 for k , v in self.disp_cb_dict.iteritems(): 631 632 if v ==None : 633 self.state.disp_cb_dict[k]= v 621 if len(self.disp_cb_dict) > 0: 622 for k, v in self.disp_cb_dict.iteritems(): 623 if v == None : 624 self.state.disp_cb_dict[k] = v 634 625 else: 635 626 try: 636 self.state.disp_cb_dict[k] =v.GetValue()627 self.state.disp_cb_dict[k] = v.GetValue() 637 628 except: 638 self.state.disp_cb_dict[k]= None 639 640 if len(self._disp_obj_dict)>0: 641 for k , v in self._disp_obj_dict.iteritems(): 642 643 self.state._disp_obj_dict[k]= v 644 645 629 self.state.disp_cb_dict[k] = None 630 if len(self._disp_obj_dict) > 0: 631 for k, v in self._disp_obj_dict.iteritems(): 632 self.state._disp_obj_dict[k] = v 646 633 self.state.values = copy.deepcopy(self.values) 647 634 self.state.weights = copy.deepcopy(self.weights) 648 635 ## save plotting range 649 636 self._save_plotting_range() 650 651 self.state.orientation_params =[] 652 self.state.orientation_params_disp =[] 653 self.state.parameters =[] 654 self.state.fittable_param =[] 655 self.state.fixed_param =[] 656 657 637 self.state.orientation_params = [] 638 self.state.orientation_params_disp = [] 639 self.state.parameters = [] 640 self.state.fittable_param = [] 641 self.state.fixed_param = [] 658 642 ## save checkbutton state and txtcrtl values 659 643 self._copy_parameters_state(self.orientation_params, … … 661 645 self._copy_parameters_state(self.orientation_params_disp, 662 646 self.state.orientation_params_disp) 663 664 647 self._copy_parameters_state(self.parameters, self.state.parameters) 665 self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 648 self._copy_parameters_state(self.fittable_param, 649 self.state.fittable_param) 666 650 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 667 651 … … 675 659 state of the graphic interface 676 660 """ 677 if state == None:661 if state == None: 678 662 #self._undo.Enable(False) 679 663 return 680 681 self.model= state.model 664 self.model = state.model 682 665 self.data = state.data 683 if self.data != None:666 if self.data != None: 684 667 from DataLoader.qsmearing import smear_selection 685 self.smearer= smear_selection( self.data)686 self.enable2D = state.enable2D668 self.smearer= smear_selection(self.data) 669 self.enable2D = state.enable2D 687 670 self.engine_type = state.engine_type 688 689 671 self.disp_cb_dict = state.disp_cb_dict 690 672 self.disp_list = state.disp_list 691 692 673 ## set the state of the radio box 693 self.shape_rbutton.SetValue(state.shape_rbutton 674 self.shape_rbutton.SetValue(state.shape_rbutton) 694 675 self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) 695 self.struct_rbutton.SetValue(state.struct_rbutton 676 self.struct_rbutton.SetValue(state.struct_rbutton) 696 677 self.plugin_rbutton.SetValue(state.plugin_rbutton) 697 678 ##draw sizer containing model parameters value for the current model 698 self._set_model_sizer_selection( self.model)679 self._set_model_sizer_selection(self.model) 699 680 self.set_model_param_sizer(self.model) 700 701 681 ## reset value of combox box 702 self.structurebox.SetSelection(state.structurecombobox 682 self.structurebox.SetSelection(state.structurecombobox) 703 683 self.formfactorbox.SetSelection(state.formfactorcombobox) 704 684 if state.multi_factor != None: … … 706 686 #draw the pnael according to the new model parameter 707 687 self._on_select_model(event=None) 708 709 688 ## enable the view 2d button if this is a modelpage type 710 if hasattr(self, "model_view"):689 if hasattr(self, "model_view"): 711 690 if self.enable2D: 712 691 self.model_view.Disable() … … 716 695 if hasattr(self, "cb1"): 717 696 self.cb1.SetValue(state.cb1) 718 719 697 ## reset state of checkbox,textcrtl and regular parameters value 720 721 698 self._reset_parameters_state(self.orientation_params_disp, 722 699 state.orientation_params_disp) … … 725 702 self._reset_parameters_state(self.str_parameters, 726 703 state.str_parameters) 727 self._reset_parameters_state(self.parameters, state.parameters)704 self._reset_parameters_state(self.parameters, state.parameters) 728 705 ## display dispersion info layer 729 706 self.enable_disp.SetValue(state.enable_disp) 730 707 self.disable_disp.SetValue(state.disable_disp) 731 732 708 if hasattr(self, "disp_box"): 733 734 709 self.disp_box.SetSelection(state.disp_box) 735 n= self.disp_box.GetCurrentSelection() 736 dispersity= self.disp_box.GetClientData(n) 737 name= dispersity.__name__ 738 710 n = self.disp_box.GetCurrentSelection() 711 dispersity = self.disp_box.GetClientData(n) 712 name = dispersity.__name__ 739 713 self._set_dipers_Param(event=None) 740 741 if name=="ArrayDispersion": 742 714 if name == "ArrayDispersion": 743 715 for item in self.disp_cb_dict.keys(): 744 745 if hasattr(self.disp_cb_dict[item],"SetValue") : 716 if hasattr(self.disp_cb_dict[item], "SetValue") : 746 717 self.disp_cb_dict[item].SetValue(state.disp_cb_dict[item]) 747 718 # Create the dispersion objects 748 719 from sans.models.dispersion_models import ArrayDispersion 749 720 disp_model = ArrayDispersion() 750 if hasattr(state,"values")and self.disp_cb_dict[item].GetValue()==True: 751 if len(state.values)>0: 752 self.values=state.values 753 self.weights=state.weights 754 disp_model.set_weights(self.values, state.weights) 721 if hasattr(state, "values") and \ 722 self.disp_cb_dict[item].GetValue() == True: 723 if len(state.values) > 0: 724 self.values = state.values 725 self.weights = state.weights 726 disp_model.set_weights(self.values, 727 state.weights) 755 728 else: 756 729 self._reset_dispersity() 757 758 730 self._disp_obj_dict[item] = disp_model 759 # Set the new model as the dispersion object for the selected parameter 731 # Set the new model as the dispersion object for 732 #the selected parameter 760 733 self.model.set_dispersion(item, disp_model) 761 762 self.model._persistency_dict[item] = [state.values, state.weights] 763 734 self.model._persistency_dict[item] = [state.values, 735 state.weights] 764 736 else: 765 737 keys = self.model.getParamList() 766 738 for item in keys: 767 if item in self.disp_list and not self.model.details.has_key(item): 768 self.model.details[item]=["",None,None] 769 for k,v in self.state.disp_cb_dict.iteritems(): 739 if item in self.disp_list and \ 740 not self.model.details.has_key(item): 741 self.model.details[item]=["", None, None] 742 for k, v in self.state.disp_cb_dict.iteritems(): 770 743 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 771 744 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 772 773 745 ##plotting range restore 774 746 self._reset_plotting_range(state) 775 776 747 ## smearing info restore 777 if hasattr(self,"enable_smearer"): 778 ## set smearing value whether or not the data contain the smearing info 748 if hasattr(self, "enable_smearer"): 749 ## set smearing value whether or not the data contain 750 #the smearing info 779 751 self.enable_smearer.SetValue(state.enable_smearer) 780 752 self.disable_smearer.SetValue(state.disable_smearer) 781 753 self.onSmear(event=None) 782 783 754 ## reset state of checkbox,textcrtl and dispersity parameters value 784 self._reset_parameters_state(self.fittable_param,state.fittable_param) 785 self._reset_parameters_state(self.fixed_param,state.fixed_param) 786 755 self._reset_parameters_state(self.fittable_param, state.fittable_param) 756 self._reset_parameters_state(self.fixed_param, state.fixed_param) 787 757 ## draw the model with previous parameters value 788 758 self._onparamEnter_helper() 789 790 759 ## reset context menu items 791 760 self._reset_context_menu() … … 799 768 800 769 """ 801 import os770 #import os 802 771 dlg = wx.FileDialog(self, "Choose a weight file", 803 self._default_save_location, "", "*.*", wx.OPEN)772 self._default_save_location, "", "*.*", wx.OPEN) 804 773 path = None 805 774 if dlg.ShowModal() == wx.ID_OK: … … 817 786 ## Add item in the context menu 818 787 id = wx.NewId() 819 self.popUpMenu.Append(id,name, 'Save model and state %g'%self.number_saved_state) 788 hint_msg = 'Save model and state %g' % self.number_saved_state 789 self.popUpMenu.Append(id, name, hint_msg) 820 790 wx.EVT_MENU(self, id, self.onResetModel) 821 822 791 823 792 def _reset_plotting_range(self, state): 824 793 """ … … 828 797 self.qmin.SetValue(str(state.qmin)) 829 798 self.qmax.SetValue(str(state.qmax)) 830 if self.state.npts !=None:799 if self.state.npts != None: 831 800 self.npts.SetValue(str(state.npts)) 832 833 801 834 802 def _save_typeOfmodel(self): … … 841 809 self.state.struct_rbutton = self.struct_rbutton.GetValue() 842 810 self.state.plugin_rbutton = self.plugin_rbutton.GetValue() 843 self.state.structurebox = self.structurebox.GetCurrentSelection()811 self.state.structurebox = self.structurebox.GetCurrentSelection() 844 812 self.state.formfactorbox = self.formfactorbox.GetCurrentSelection() 845 846 813 #self._undo.Enable(True) 847 814 ## post state to fit panel 848 event = PageInfoEvent(page =self)815 event = PageInfoEvent(page=self) 849 816 wx.PostEvent(self.parent, event) 850 817 851 852 def _save_plotting_range(self ): 818 def _save_plotting_range(self): 853 819 """ 854 820 save the state of plotting range … … 857 823 self.state.qmin = self.qmin_x 858 824 self.state.qmax = self.qmax_x 859 if self.npts!=None: 860 self.state.npts= self.num_points 861 825 if self.npts != None: 826 self.state.npts = self.num_points 862 827 863 828 def _onparamEnter_helper(self): … … 871 836 is_modified = False 872 837 #self._undo.Enable(True) 873 if self.model != None:838 if self.model != None: 874 839 try: 875 is_modified =self._check_value_enter( self.fittable_param ,is_modified) 876 is_modified =self._check_value_enter( self.fixed_param ,is_modified) 877 is_modified =self._check_value_enter( self.parameters ,is_modified) 840 is_modified = self._check_value_enter(self.fittable_param, 841 is_modified) 842 is_modified = self._check_value_enter(self.fixed_param, 843 is_modified) 844 is_modified = self._check_value_enter(self.parameters, 845 is_modified) 878 846 except: 879 847 pass … … 901 869 is_modified = True 902 870 else: 903 msg= "Cannot Plot :Must enter a number!!! " 904 wx.PostEvent(self.parent, StatusEvent(status = msg )) 905 906 871 msg = "Cannot Plot :Must enter a number!!! " 872 wx.PostEvent(self.parent, StatusEvent(status=msg)) 907 873 ## if any value is modify draw model with new value 908 874 if is_modified: 909 self.state_change = True875 self.state_change = True 910 876 self._draw_model() 911 877 self.Refresh() 912 878 return is_modified 913 879 914 915 880 def _is_modified(self, is_modified): 916 881 """ … … 920 885 return is_modified 921 886 922 def _reset_parameters_state(self, listtorestore, statelist):887 def _reset_parameters_state(self, listtorestore, statelist): 923 888 """ 924 889 Reset the parameters at the given state 925 890 926 891 """ 927 if len(statelist) ==0 or len(listtorestore)==0:892 if len(statelist) == 0 or len(listtorestore) == 0: 928 893 return 929 if len(statelist) != len(listtorestore):894 if len(statelist) != len(listtorestore): 930 895 return 931 896 … … 934 899 item_page_info = statelist[j] 935 900 ##change the state of the check box for simple parameters 936 if item_page[0] !=None:901 if item_page[0] != None: 937 902 item_page[0].SetValue(item_page_info[0]) 938 939 if item_page[2]!=None: 903 if item_page[2] != None: 940 904 item_page[2].SetValue(item_page_info[2]) 941 942 if item_page[3]!=None: 905 if item_page[3] != None: 943 906 ## show or hide text +/- 944 907 if item_page_info[2]: … … 946 909 else: 947 910 item_page[3].Hide() 948 if item_page[4] !=None:911 if item_page[4] != None: 949 912 ## show of hide the text crtl for fitting error 950 913 if item_page_info[4][0]: … … 953 916 else: 954 917 item_page[3].Hide() 955 if item_page[5] !=None:918 if item_page[5] != None: 956 919 ## show of hide the text crtl for fitting error 957 920 if item_page_info[5][0]: … … 960 923 else: 961 924 item_page[5].Hide() 962 963 if item_page[6]!=None: 925 if item_page[6] != None: 964 926 ## show of hide the text crtl for fitting error 965 927 if item_page_info[6][0]: … … 977 939 978 940 """ 979 if len(listtocopy) ==0:941 if len(listtocopy) == 0: 980 942 return 981 982 943 for item in listtocopy: 983 984 944 checkbox_state = None 985 if item[0] != None:986 checkbox_state = item[0].GetValue()945 if item[0] != None: 946 checkbox_state = item[0].GetValue() 987 947 parameter_name = item[1] 988 948 parameter_value = None 989 if item[2] !=None:949 if item[2] != None: 990 950 parameter_value = item[2].GetValue() 991 951 static_text = None 992 if item[3] !=None:952 if item[3] != None: 993 953 static_text = item[3].IsShown() 994 954 error_value = None 995 955 error_state = None 996 if item[4] != None:956 if item[4] != None: 997 957 error_value = item[4].GetValue() 998 958 error_state = item[4].IsShown() 999 1000 959 min_value = None 1001 960 min_state = None 1002 if item[5] != None:961 if item[5] != None: 1003 962 min_value = item[5].GetValue() 1004 963 min_state = item[5].IsShown() 1005 1006 964 max_value = None 1007 965 max_state = None 1008 if item[6] != None:966 if item[6] != None: 1009 967 max_value = item[6].GetValue() 1010 968 max_state = item[6].IsShown() 1011 unit =None1012 if item[7] !=None:969 unit = None 970 if item[7] != None: 1013 971 unit = item[7].GetLabel() 1014 1015 972 statelist.append([checkbox_state, parameter_name, parameter_value, 1016 static_text , [error_state,error_value],1017 [min_state,min_value],[max_state , max_value],unit])973 static_text , [error_state, error_value], 974 [min_state, min_value], [max_state, max_value], unit]) 1018 975 1019 976 def _set_model_sizer_selection(self, model): … … 1022 979 1023 980 """ 1024 if model == None:981 if model == None: 1025 982 return 1026 if hasattr(model ,"s_model"): 1027 1028 class_name= model.s_model.__class__ 1029 name= model.s_model.name 1030 flag= name != "NoStructure" 983 if hasattr(model, "s_model"): 984 class_name = model.s_model.__class__ 985 name = model.s_model.name 986 flag = (name != "NoStructure") 1031 987 if flag and (class_name in self.model_list_box["Structure Factors"]): 1032 988 self.structurebox.Show() … … 1036 992 items = self.structurebox.GetItems() 1037 993 self.sizer1.Layout() 1038 self.SetScrollbars(20, 20,25,65)994 self.SetScrollbars(20, 20, 25, 65) 1039 995 for i in range(len(items)): 1040 if items[i] == str(name):996 if items[i] == str(name): 1041 997 self.structurebox.SetSelection(i) 1042 998 break 1043 1044 if hasattr(model ,"p_model"): 999 if hasattr(model, "p_model"): 1045 1000 class_name = model.p_model.__class__ 1046 1001 name = model.p_model.name 1047 1002 self.formfactorbox.Clear() 1048 1049 1003 for k, list in self.model_list_box.iteritems(): 1050 if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: 1004 if k in ["P(Q)*S(Q)", "Shapes" ] and \ 1005 class_name in self.model_list_box["Shapes"]: 1051 1006 self.shape_rbutton.SetValue(True) 1052 1007 ## fill the form factor list with new model 1053 self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) 1008 self._populate_box(self.formfactorbox, 1009 self.model_list_box["Shapes"]) 1054 1010 items = self.formfactorbox.GetItems() 1055 1011 ## set comboxbox to the selected item 1056 1012 for i in range(len(items)): 1057 if items[i] == str(name):1013 if items[i] == str(name): 1058 1014 self.formfactorbox.SetSelection(i) 1059 1015 break … … 1067 1023 else: 1068 1024 self.plugin_rbutton.SetValue(True) 1069 1070 1025 if class_name in list: 1071 1026 ## fill the form factor list with new model … … 1074 1029 ## set comboxbox to the selected item 1075 1030 for i in range(len(items)): 1076 if items[i] == str(name):1031 if items[i] == str(name): 1077 1032 self.formfactorbox.SetSelection(i) 1078 1033 break … … 1087 1042 1088 1043 for k, list in self.model_list_box.iteritems(): 1089 if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: 1044 if k in["P(Q)*S(Q)","Shapes" ] and \ 1045 class_name in self.model_list_box["Shapes"]: 1090 1046 if class_name in self.model_list_box["P(Q)*S(Q)"]: 1091 1047 self.structurebox.Show() … … 1103 1059 self.shape_rbutton.SetValue(True) 1104 1060 ## fill the form factor list with new model 1105 self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) 1061 self._populate_box(self.formfactorbox, 1062 self.model_list_box["Shapes"]) 1106 1063 items = self.formfactorbox.GetItems() 1107 1064 ## set comboxbox to the selected item 1108 1065 for i in range(len(items)): 1109 if items[i] == str(name):1066 if items[i] == str(name): 1110 1067 self.formfactorbox.SetSelection(i) 1111 1068 break … … 1128 1085 ## set comboxbox to the selected item 1129 1086 for i in range(len(items)): 1130 if items[i] == str(name):1087 if items[i] == str(name): 1131 1088 self.formfactorbox.SetSelection(i) 1132 1089 break … … 1142 1099 1143 1100 """ 1144 if self.model != None:1145 temp_smear =None1101 if self.model != None: 1102 temp_smear = None 1146 1103 if hasattr(self, "enable_smearer"): 1147 1104 if self.enable_smearer.GetValue(): … … 1164 1121 ##For MAC, this should defined here. 1165 1122 if box_sizer == None: 1166 box_description = wx.StaticBox(self, -1,str(title))1123 box_description = wx.StaticBox(self, -1, str(title)) 1167 1124 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 1168 1125 else: … … 1170 1127 sizer_buttons = wx.BoxSizer(wx.HORIZONTAL) 1171 1128 #-------------------------------------------------------- 1172 self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', style=wx.RB_GROUP) 1173 self.shape_indep_rbutton = wx.RadioButton(self, -1, "Shape-Independent") 1129 self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', 1130 style=wx.RB_GROUP) 1131 self.shape_indep_rbutton = wx.RadioButton(self, -1, 1132 "Shape-Independent") 1174 1133 self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") 1175 1134 self.plugin_rbutton = wx.RadioButton(self, -1, "Customized Models") 1176 1177 self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, 1178 id= self.shape_rbutton.GetId() ) 1179 self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, 1180 id= self.shape_indep_rbutton.GetId() ) 1181 self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, 1182 id= self.struct_rbutton.GetId() ) 1183 self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, 1184 id= self.plugin_rbutton.GetId() ) 1135 self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 1136 id=self.shape_rbutton.GetId()) 1137 self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 1138 id=self.shape_indep_rbutton.GetId()) 1139 self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 1140 id=self.struct_rbutton.GetId()) 1141 self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 1142 id=self.plugin_rbutton.GetId()) 1185 1143 #MAC needs SetValue 1186 1144 self.shape_rbutton.SetValue(True) 1187 1188 sizer_radiobutton = wx.GridSizer(2, 2,5, 5) 1145 sizer_radiobutton = wx.GridSizer(2, 2, 5, 5) 1189 1146 sizer_radiobutton.Add(self.shape_rbutton) 1190 1147 sizer_radiobutton.Add(self.shape_indep_rbutton) 1191 1148 sizer_radiobutton.Add(self.plugin_rbutton) 1192 1149 sizer_radiobutton.Add(self.struct_rbutton) 1193 1194 1150 sizer_buttons.Add(sizer_radiobutton) 1195 1151 # detail button 1196 if object != None:1197 sizer_buttons.Add((50, 0))1152 if object != None: 1153 sizer_buttons.Add((50, 0)) 1198 1154 sizer_buttons.Add(object) 1199 1200 1155 sizer_selection = wx.BoxSizer(wx.HORIZONTAL) 1201 1156 mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) 1202 self.text1 = wx.StaticText( self,-1,"")1203 self.text2 = wx.StaticText( self,-1,"P(Q)*S(Q)")1204 self.mutifactor_text = wx.StaticText( self,-1,"No. of Shells: ")1205 self.mutifactor_text1 = wx.StaticText( self,-1,"")1206 self.show_sld_button = wx.Button( self,-1,"Show SLD Profile")1157 self.text1 = wx.StaticText(self, -1, "") 1158 self.text2 = wx.StaticText(self, -1, "P(Q)*S(Q)") 1159 self.mutifactor_text = wx.StaticText(self, -1, "No. of Shells: ") 1160 self.mutifactor_text1 = wx.StaticText(self, -1, "") 1161 self.show_sld_button = wx.Button(self, -1, "Show SLD Profile") 1207 1162 self.show_sld_button.Bind(wx.EVT_BUTTON,self._on_show_sld) 1208 self.formfactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY)1209 if self.model!= None:1163 self.formfactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 1164 if self.model!= None: 1210 1165 self.formfactorbox.SetValue(self.model.name) 1211 1212 1213 self.structurebox = wx.ComboBox(self, -1,style=wx.CB_READONLY) 1214 self.multifactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) 1215 wx.EVT_COMBOBOX(self.formfactorbox,-1, self._on_select_model) 1216 wx.EVT_COMBOBOX(self.structurebox,-1, self._on_select_model) 1217 wx.EVT_COMBOBOX(self.multifactorbox,-1, self._on_select_model) 1218 1166 self.structurebox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 1167 self.multifactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 1168 wx.EVT_COMBOBOX(self.formfactorbox, -1, self._on_select_model) 1169 wx.EVT_COMBOBOX(self.structurebox, -1, self._on_select_model) 1170 wx.EVT_COMBOBOX(self.multifactorbox, -1, self._on_select_model) 1219 1171 ## fill combox box 1220 if len(self.model_list_box) >0:1221 self._populate_box( self.formfactorbox,self.model_list_box["Shapes"])1222 1223 if len(self.model_list_box) >0:1224 self._populate_box( 1172 if len(self.model_list_box) > 0: 1173 self._populate_box(self.formfactorbox, 1174 self.model_list_box["Shapes"]) 1175 if len(self.model_list_box) > 0: 1176 self._populate_box(self.structurebox, 1225 1177 self.model_list_box["Structure Factors"]) 1226 self.structurebox.Insert("None", 0, None)1178 self.structurebox.Insert("None", 0, None) 1227 1179 self.structurebox.SetSelection(0) 1228 1180 self.structurebox.Hide() … … 1230 1182 self.structurebox.Disable() 1231 1183 self.text2.Disable() 1232 1233 1184 if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: 1234 1185 self.structurebox.Show() … … 1236 1187 self.structurebox.Enable() 1237 1188 self.text2.Enable() 1238 1239 1189 ## check model type to show sizer 1240 if self.model !=None: 1241 self._set_model_sizer_selection( self.model ) 1242 1190 if self.model != None: 1191 self._set_model_sizer_selection(self.model) 1243 1192 sizer_selection.Add(self.text1) 1244 sizer_selection.Add((5, 5))1193 sizer_selection.Add((5, 5)) 1245 1194 sizer_selection.Add(self.formfactorbox) 1246 sizer_selection.Add((5, 5))1195 sizer_selection.Add((5, 5)) 1247 1196 sizer_selection.Add(self.text2) 1248 sizer_selection.Add((5, 5))1197 sizer_selection.Add((5, 5)) 1249 1198 sizer_selection.Add(self.structurebox) 1250 #sizer_selection.Add((5, 5))1251 mutifactor_selection.Add((10, 5))1199 #sizer_selection.Add((5, 5)) 1200 mutifactor_selection.Add((10, 5)) 1252 1201 mutifactor_selection.Add(self.mutifactor_text) 1253 1202 mutifactor_selection.Add(self.multifactorbox) 1254 mutifactor_selection.Add((5, 5))1203 mutifactor_selection.Add((5, 5)) 1255 1204 mutifactor_selection.Add(self.mutifactor_text1) 1256 mutifactor_selection.Add((10, 5))1205 mutifactor_selection.Add((10, 5)) 1257 1206 mutifactor_selection.Add(self.show_sld_button) 1258 1259 boxsizer1.Add( sizer_buttons ) 1260 boxsizer1.Add( (15,15)) 1261 boxsizer1.Add( sizer_selection ) 1262 boxsizer1.Add( (10,10)) 1207 boxsizer1.Add(sizer_buttons) 1208 boxsizer1.Add((15, 15)) 1209 boxsizer1.Add(sizer_selection) 1210 boxsizer1.Add((10,10)) 1263 1211 boxsizer1.Add(mutifactor_selection) 1264 1265 1212 self._set_multfactor_combobox() 1266 1213 self.multifactorbox.SetSelection(1) 1267 1214 self.show_sld_button.Hide() 1268 1269 1215 #-------------------------------------------------------- 1270 sizer.Add(boxsizer1, 0, wx.EXPAND |wx.ALL, 10)1216 sizer.Add(boxsizer1, 0, wx.EXPAND|wx.ALL, 10) 1271 1217 sizer.Layout() 1272 self.SetScrollbars(20, 20,25,65)1218 self.SetScrollbars(20, 20, 25, 65) 1273 1219 1274 1220 def _on_show_sld(self, event=None): … … 1277 1223 """ 1278 1224 # get profile data 1279 x,y=self.model.getProfile() 1280 1225 x, y = self.model.getProfile() 1281 1226 from danse.common.plottools import Data1D 1282 1227 #from profile_dialog import SLDPanel 1283 1228 from sans.guiframe.local_perspectives.plotting.profile_dialog \ 1284 1229 import SLDPanel 1285 sld_data = Data1D(x, y)1230 sld_data = Data1D(x, y) 1286 1231 sld_data.name = 'SLD' 1287 1232 sld_data.axes = self.sld_axes 1288 self.panel = SLDPanel(self, data=sld_data, axes =self.sld_axes,id =-1)1233 self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id=-1) 1289 1234 self.panel.ShowModal() 1290 1235 … … 1295 1240 """ 1296 1241 # build content of the combobox 1297 for idx in range(0, multiplicity):1298 self.multifactorbox.Append(str(idx), int(idx))1242 for idx in range(0, multiplicity): 1243 self.multifactorbox.Append(str(idx), int(idx)) 1299 1244 #self.multifactorbox.SetSelection(1) 1300 1245 self._hide_multfactor_combobox() … … 1320 1265 self.multifactorbox.Hide() 1321 1266 1322 1323 1267 def _show_combox(self, event): 1324 1268 """ … … 1327 1271 """ 1328 1272 ## Don't want to populate combo box again if the event comes from check box 1329 if self.shape_rbutton.GetValue() and\1330 event.GetEventObject() ==self.shape_rbutton:1273 if self.shape_rbutton.GetValue() and \ 1274 event.GetEventObject() == self.shape_rbutton: 1331 1275 ##fill the combobox with form factor list 1332 1276 self.structurebox.SetSelection(0) 1333 1277 self.structurebox.Disable() 1334 1278 self.formfactorbox.Clear() 1335 self._populate_box( self.formfactorbox,self.model_list_box["Shapes"])1336 1337 if self.shape_indep_rbutton.GetValue() and\1338 event.GetEventObject() ==self.shape_indep_rbutton:1279 self._populate_box(self.formfactorbox, 1280 self.model_list_box["Shapes"]) 1281 if self.shape_indep_rbutton.GetValue() and \ 1282 event.GetEventObject() == self.shape_indep_rbutton: 1339 1283 ##fill the combobox with shape independent factor list 1340 1284 self.structurebox.SetSelection(0) 1341 1285 self.structurebox.Disable() 1342 1286 self.formfactorbox.Clear() 1343 self._populate_box( 1287 self._populate_box(self.formfactorbox, 1344 1288 self.model_list_box["Shape-Independent"]) 1345 1346 if self.struct_rbutton.GetValue() and\ 1347 event.GetEventObject()==self.struct_rbutton: 1289 if self.struct_rbutton.GetValue() and \ 1290 event.GetEventObject() == self.struct_rbutton: 1348 1291 ##fill the combobox with structure factor list 1349 1292 self.structurebox.SetSelection(0) 1350 1293 self.structurebox.Disable() 1351 1294 self.formfactorbox.Clear() 1352 self._populate_box( 1295 self._populate_box(self.formfactorbox, 1353 1296 self.model_list_box["Structure Factors"]) 1354 1355 if self.plugin_rbutton.GetValue()and\ 1356 event.GetEventObject()==self.plugin_rbutton: 1357 1297 if self.plugin_rbutton.GetValue() and \ 1298 event.GetEventObject() == self.plugin_rbutton: 1358 1299 ##fill the combobox with form factor list 1359 1300 self.structurebox.Disable() 1360 1301 self.formfactorbox.Clear() 1361 self._populate_box( 1302 self._populate_box(self.formfactorbox, 1362 1303 self.model_list_box["Customized Models"]) 1363 1364 1304 self._on_select_model(event=None) 1365 1305 self._save_typeOfmodel() … … 1368 1308 self.Layout() 1369 1309 self.Refresh() 1370 self.SetScrollbars(20, 20,25,65)1310 self.SetScrollbars(20, 20, 25, 65) 1371 1311 1372 1312 def _populate_box(self, combobox, list): … … 1378 1318 """ 1379 1319 for models in list: 1380 model = models()1320 model = models() 1381 1321 name = model.__class__.__name__ 1382 1322 if models.__name__!="NoStructure": 1383 1323 if hasattr(model, "name"): 1384 1324 name = model.name 1385 combobox.Append(name,models) 1386 1325 combobox.Append(name, models) 1387 1326 return 0 1388 1327 … … 1392 1331 1393 1332 """ 1394 tcrtl= event.GetEventObject() 1395 1333 tcrtl = event.GetEventObject() 1396 1334 #Clear msg if previously shown. 1397 msg= "" 1398 wx.PostEvent(self.parent, StatusEvent(status = msg )) 1399 1335 msg = "" 1336 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1400 1337 ## save current state 1401 1338 self.save_current_state() 1402 if event != None:1339 if event != None: 1403 1340 #self._undo.Enable(True) 1404 event = PageInfoEvent(page =self)1341 event = PageInfoEvent(page=self) 1405 1342 wx.PostEvent(self.parent, event) 1406 1407 1343 if check_float(tcrtl): 1408 1409 1344 self._onparamEnter_helper() 1410 1345 #event.Skip() 1411 1346 else: 1412 msg = "Cannot Plot :Must enter a number!!! "1413 wx.PostEvent(self.parent, StatusEvent(status = msg))1347 msg = "Cannot Plot :Must enter a number!!! " 1348 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1414 1349 #event.Skip() 1415 1350 return … … 1420 1355 1421 1356 """ 1422 1423 tcrtl= event.GetEventObject() 1357 tcrtl = event.GetEventObject() 1424 1358 #Clear msg if previously shown. 1425 msg = ""1426 wx.PostEvent(self.parent, StatusEvent(status = msg))1359 msg = "" 1360 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1427 1361 # Flag to register when a parameter has changed. 1428 1362 is_modified = False 1429 if tcrtl.GetValue().lstrip().rstrip() !="":1363 if tcrtl.GetValue().lstrip().rstrip() != "": 1430 1364 try: 1431 1365 value = float(tcrtl.GetValue()) 1432 1366 tcrtl.SetBackgroundColour(wx.WHITE) 1433 1434 1367 # If qmin and qmax have been modified, update qmin and qmax 1435 if self._validate_qrange( 1368 if self._validate_qrange(self.qmin, self.qmax): 1436 1369 tempmin = float(self.qmin.GetValue()) 1437 1370 if tempmin != self.qmin_x: … … 1442 1375 else: 1443 1376 tcrtl.SetBackgroundColour("pink") 1444 msg = "Model Error:wrong value entered : %s"% sys.exc_value1445 wx.PostEvent(self.parent, StatusEvent(status = msg))1377 msg = "Model Error:wrong value entered : %s" % sys.exc_value 1378 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1446 1379 return 1447 1448 1380 except: 1449 1381 tcrtl.SetBackgroundColour("pink") 1450 msg = "Model Error:wrong value entered : %s"% sys.exc_value1451 wx.PostEvent(self.parent, StatusEvent(status = msg))1382 msg = "Model Error:wrong value entered : %s" % sys.exc_value 1383 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1452 1384 return 1453 1385 #Check if # of points for theory model are valid(>0). … … 1459 1391 is_modified = True 1460 1392 else: 1461 msg= "Cannot Plot :No npts in that Qrange!!! " 1462 wx.PostEvent(self.parent, StatusEvent(status = msg )) 1463 1393 msg = "Cannot Plot :No npts in that Qrange!!! " 1394 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1464 1395 else: 1465 1396 tcrtl.SetBackgroundColour("pink") 1466 msg= "Model Error:wrong value entered!!!" 1467 wx.PostEvent(self.parent, StatusEvent(status = msg )) 1468 1397 msg = "Model Error:wrong value entered!!!" 1398 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1469 1399 #self._undo.Enable(True) 1470 1400 self.save_current_state() 1471 event = PageInfoEvent(page =self)1401 event = PageInfoEvent(page=self) 1472 1402 wx.PostEvent(self.parent, event) 1473 self.state_change = False1403 self.state_change = False 1474 1404 #Draw the model for a different range 1475 1405 self._draw_model() … … 1482 1412 ## reset dictionary containing reference to dispersion 1483 1413 self._disp_obj_dict = {} 1484 self.disp_cb_dict ={} 1485 1414 self.disp_cb_dict = {} 1486 1415 f_id = self.formfactorbox.GetCurrentSelection() 1487 1416 #For MAC 1488 1417 form_factor = None 1489 1418 if f_id >= 0: 1490 form_factor = self.formfactorbox.GetClientData( f_id ) 1491 1419 form_factor = self.formfactorbox.GetClientData(f_id) 1492 1420 if not form_factor in self.model_list_box["multiplication"]: 1493 1421 self.structurebox.Hide() … … 1501 1429 self.structurebox.Enable() 1502 1430 self.text2.Enable() 1503 1504 1431 if form_factor != None: 1505 1432 # set multifactor for Mutifunctional models … … 1517 1444 1518 1445 # Check max value 1519 if m_id > multiplicity - 1:1446 if m_id > multiplicity - 1: 1520 1447 # default value 1521 1448 m_id = 1 1522 1449 self.multi_factor = self.multifactorbox.GetClientData(m_id) 1523 if self.multi_factor == None: self.multi_factor =1 1450 if self.multi_factor == None: 1451 self.multi_factor =1 1524 1452 form_factor = form_factor(int(self.multi_factor)) 1525 1453 self.multifactorbox.SetSelection(m_id) … … 1544 1472 self.show_sld_button.Hide() 1545 1473 self.multi_factor = None 1546 1547 1474 s_id = self.structurebox.GetCurrentSelection() 1548 struct_factor = self.structurebox.GetClientData( s_id ) 1549 1550 if struct_factor !=None: 1475 struct_factor = self.structurebox.GetClientData(s_id) 1476 if struct_factor != None: 1551 1477 from sans.models.MultiplicationModel import MultiplicationModel 1552 self.model= MultiplicationModel(form_factor,struct_factor()) 1553 1478 self.model = MultiplicationModel(form_factor, struct_factor()) 1554 1479 else: 1555 1480 if form_factor != None: 1556 self.model = form_factor1481 self.model = form_factor 1557 1482 else: 1558 1483 self.model = None 1559 1484 return self.model 1560 1561 1485 ## post state to fit panel 1562 self.state.parameters = []1563 self.state.model = self.model1486 self.state.parameters = [] 1487 self.state.model = self.model 1564 1488 self.state.qmin = self.qmin_x 1565 1489 self.state.multi_factor = self.multi_factor 1566 self.disp_list = self.model.getDispParamList()1490 self.disp_list = self.model.getDispParamList() 1567 1491 self.state.disp_list = self.disp_list 1568 1492 self.Layout() … … 1598 1522 qmax_ctrl.Refresh() 1599 1523 msg= "Invalid Q range: Q min must be smaller than Q max" 1600 wx.PostEvent(self.parent, StatusEvent(status =msg))1524 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1601 1525 return False 1602 1526 return True … … 1611 1535 """ 1612 1536 is_modified = modified 1613 if len(list) ==0:1537 if len(list) == 0: 1614 1538 return is_modified 1615 1539 for item in list: … … 1620 1544 #try: 1621 1545 name = str(item[1]) 1622 1623 1546 try: 1624 value = float(item[2].GetValue())1547 value = float(item[2].GetValue()) 1625 1548 # If the value of the parameter has changed, 1626 1549 # +update the model and set the is_modified flag … … 1630 1553 except: 1631 1554 msg = "Wrong parameter value entered " 1632 wx.PostEvent(self.parent, StatusEvent(status = msg)) 1633 1555 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1634 1556 return is_modified 1635 1557 … … 1638 1560 respond to self.enable_disp and self.disable_disp radio box. 1639 1561 The dispersity object is reset inside the model into Gaussian. 1640 When the user select yes , this method display a combo box for more selection 1562 When the user select yes , this method display a combo box 1563 for more selection 1641 1564 when the user selects No,the combo box disappears. 1642 1565 Redraw the model with the default dispersity (Gaussian) 1643 1566 1644 1567 """ 1645 1646 1568 self._reset_dispersity() 1647 1648 if self.model ==None: 1569 if self.model == None: 1649 1570 self.model_disp.Hide() 1650 1571 self.disp_box.Hide() 1651 1572 self.sizer4_4.Clear(True) 1652 1573 return 1653 1654 1574 if self.enable_disp.GetValue(): 1655 1575 self.model_disp.Show(True) 1656 1576 self.disp_box.Show(True) 1657 1577 ## layout for model containing no dispersity parameters 1658 1659 self.disp_list= self.model.getDispParamList() 1660 1661 if len(self.disp_list)==0 and len(self.disp_cb_dict)==0: 1578 self.disp_list = self.model.getDispParamList() 1579 if len(self.disp_list) == 0 and len(self.disp_cb_dict) == 0: 1662 1580 self._layout_sizer_noDipers() 1663 1581 else: … … 1669 1587 self.disp_box.SetSelection(0) 1670 1588 self.sizer4_4.Clear(True) 1671 1672 1589 ## post state to fit panel 1673 1590 self.save_current_state() 1674 if event != None:1591 if event != None: 1675 1592 #self._undo.Enable(True) 1676 event = PageInfoEvent(page =self)1593 event = PageInfoEvent(page=self) 1677 1594 wx.PostEvent(self.parent, event) 1678 1595 #draw the model with the current dispersity … … 1683 1600 self.Refresh() 1684 1601 1685 1686 1602 def _layout_sizer_noDipers(self): 1687 1603 """ … … 1689 1605 1690 1606 """ 1691 ix=0 1692 iy=1 1693 self.fittable_param=[] 1694 self.fixed_param=[] 1695 self.orientation_params_disp=[] 1696 1607 ix = 0 1608 iy = 1 1609 self.fittable_param = [] 1610 self.fixed_param = [] 1611 self.orientation_params_disp = [] 1697 1612 self.model_disp.Hide() 1698 1613 self.disp_box.Hide() 1699 1614 self.sizer4_4.Clear(True) 1700 1615 model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model') 1701 self.sizer4_4.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1616 self.sizer4_4.Add(model_disp,(iy, ix), (1,1), 1617 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1702 1618 self.sizer4_4.Layout() 1703 1619 self.sizer4.Layout() 1704 self.SetScrollbars(20, 20,25,65)1620 self.SetScrollbars(20, 20, 25, 65) 1705 1621 1706 1707 1622 def _reset_dispersity(self): 1708 1623 """ … … 1710 1625 1711 1626 """ 1712 if len(self.param_toFit) >0:1627 if len(self.param_toFit) > 0: 1713 1628 for item in self.fittable_param: 1714 1629 if item in self.param_toFit: 1715 1630 self.param_toFit.remove(item) 1716 1717 1631 for item in self.orientation_params_disp: 1718 1632 if item in self.param_toFit: 1719 1633 self.param_toFit.remove(item) 1720 1721 self.fittable_param=[] 1722 self.fixed_param=[] 1723 self.orientation_params_disp=[] 1724 self.values=[] 1725 self.weights=[] 1726 1727 from sans.models.dispersion_models import GaussianDispersion, ArrayDispersion 1728 if len(self.disp_cb_dict)==0: 1634 self.fittable_param = [] 1635 self.fixed_param = [] 1636 self.orientation_params_disp = [] 1637 self.values = [] 1638 self.weights = [] 1639 from sans.models.dispersion_models import GaussianDispersion 1640 from sans.models.dispersion_models import ArrayDispersion 1641 if len(self.disp_cb_dict) == 0: 1729 1642 self.save_current_state() 1730 1643 self.sizer4_4.Clear(True) 1731 1644 self.Layout() 1732 1733 1645 return 1734 if (len(self.disp_cb_dict) >0) :1646 if (len(self.disp_cb_dict) > 0) : 1735 1647 for p in self.disp_cb_dict: 1736 # The parameter was un-selected. Go back to Gaussian model (with 0 pts) 1648 # The parameter was un-selected. 1649 # Go back to Gaussian model (with 0 pts) 1737 1650 disp_model = GaussianDispersion() 1738 1739 1651 self._disp_obj_dict[p] = disp_model 1740 # Set the new model as the dispersion object for the selected parameter 1652 # Set the new model as the dispersion object 1653 # for the selected parameter 1741 1654 try: 1742 1655 self.model.set_dispersion(p, disp_model) 1743 1656 except: 1744 1745 1657 pass 1746 1747 1658 ## save state into 1748 1659 self.save_current_state() … … 1750 1661 self.Refresh() 1751 1662 1752 1753 def _on_select_Disp(self,event): 1663 def _on_select_Disp(self, event): 1754 1664 """ 1755 1665 allow selecting different dispersion … … 1759 1669 n = self.disp_box.GetCurrentSelection() 1760 1670 name = self.disp_box.GetValue() 1761 dispersity = self.disp_box.GetClientData(n)1671 dispersity = self.disp_box.GetClientData(n) 1762 1672 self.disp_name = name 1763 1764 1673 if name.lower() == "array": 1765 1674 self._set_sizer_arraydispersion() 1766 1675 else: 1767 self._set_sizer_dispersion(dispersity= dispersity) 1768 1769 self.state.disp_box= n 1676 self._set_sizer_dispersion(dispersity=dispersity) 1677 self.state.disp_box = n 1770 1678 ## Redraw the model 1771 1679 self._draw_model() 1772 1680 #self._undo.Enable(True) 1773 event = PageInfoEvent(page =self)1681 event = PageInfoEvent(page=self) 1774 1682 wx.PostEvent(self.parent, event) 1775 1776 1683 self.sizer4_4.Layout() 1777 1684 self.sizer4.Layout() 1778 self.SetScrollbars(20, 20,25,65)1685 self.SetScrollbars(20, 20, 25, 65) 1779 1686 1780 1687 def _set_sizer_arraydispersion(self): 1781 1688 """ 1782 1689 draw sizer with array dispersity parameters 1783 1784 """ 1785 1786 if len(self.param_toFit)>0: 1690 """ 1691 if len(self.param_toFit) > 0: 1787 1692 for item in self.fittable_param: 1788 1693 if item in self.param_toFit: … … 1794 1699 if item in self.model.fixed: 1795 1700 del self.model.details [item] 1796 1797 self.fittable_param=[] 1798 self.fixed_param=[] 1799 self.orientation_params_disp=[] 1701 self.fittable_param = [] 1702 self.fixed_param = [] 1703 self.orientation_params_disp = [] 1800 1704 self.sizer4_4.Clear(True) 1801 1705 self._reset_dispersity() 1802 ix =01803 iy =11706 ix = 0 1707 iy = 1 1804 1708 disp1 = wx.StaticText(self, -1, 'Array Dispersion') 1805 self.sizer4_4.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1806 1807 # Look for model parameters to which we can apply an ArrayDispersion model 1709 self.sizer4_4.Add(disp1, (iy, ix), (1, 1), 1710 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1711 # Look for model parameters to which we can apply 1712 # an ArrayDispersion model 1808 1713 # Add a check box for each parameter. 1809 1714 self.disp_cb_dict = {} 1810 1715 ix+=1 1811 self.noDisper_rbox = wx.RadioButton(self, -1,"None", (10, 10),style= wx.RB_GROUP) 1812 self.Bind(wx.EVT_RADIOBUTTON,self.select_disp_angle , id=self.noDisper_rbox.GetId()) 1716 self.noDisper_rbox = wx.RadioButton(self, -1, "None", 1717 (10, 10), style=wx.RB_GROUP) 1718 self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, 1719 id=self.noDisper_rbox.GetId()) 1813 1720 #MAC needs SetValue 1814 1721 self.noDisper_rbox.SetValue(True) 1815 1722 self.sizer4_4.Add(self.noDisper_rbox, (iy, ix), 1816 (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1817 1723 (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1818 1724 for p in self.model.dispersion.keys(): 1819 1725 if not p in self.model.orientation_params: 1820 ix +=11726 ix += 1 1821 1727 self.disp_cb_dict[p] = wx.RadioButton(self, -1, p, (10, 10)) 1822 self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() 1823 self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, id=self.disp_cb_dict[p].GetId()) 1824 self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1825 1728 self.state.disp_cb_dict[p] = self.disp_cb_dict[p].GetValue() 1729 self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, 1730 id=self.disp_cb_dict[p].GetId()) 1731 self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), 1732 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1826 1733 for p in self.model.dispersion.keys(): 1827 1734 if p in self.model.orientation_params: 1828 ix +=11735 ix += 1 1829 1736 self.disp_cb_dict[p] = wx.RadioButton(self, -1, p, (10, 10)) 1830 self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() 1831 if not (self.enable2D or self.data.__class__.__name__ =="Data2D"): 1737 self.state.disp_cb_dict[p] = self.disp_cb_dict[p].GetValue() 1738 if not (self.enable2D or \ 1739 self.data.__class__.__name__ == "Data2D"): 1832 1740 self.disp_cb_dict[p].Hide() 1833 1741 else: 1834 1742 self.disp_cb_dict[p].Show(True) 1835 self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, id=self.disp_cb_dict[p].GetId()) 1836 self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1837 1838 1839 ix =0 1840 iy +=1 1841 self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1743 self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, 1744 id=self.disp_cb_dict[p].GetId()) 1745 self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), 1746 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1747 ix = 0 1748 iy += 1 1749 self.sizer4_4.Add((20, 20), (iy, ix), (1, 1), 1750 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 1842 1751 self.Layout() 1843 1844 self.state.orientation_params =[] 1845 self.state.orientation_params_disp =[] 1846 self.state.parameters =[] 1847 self.state.fittable_param =[] 1848 self.state.fixed_param =[] 1849 1752 self.state.orientation_params = [] 1753 self.state.orientation_params_disp = [] 1754 self.state.parameters = [] 1755 self.state.fittable_param = [] 1756 self.state.fixed_param = [] 1850 1757 ## save checkbutton state and txtcrtl values 1851 1758 self._copy_parameters_state(self.orientation_params, 1852 1759 self.state.orientation_params) 1853 1854 1760 self._copy_parameters_state(self.orientation_params_disp, 1855 1761 self.state.orientation_params_disp) 1856 1857 1762 self._copy_parameters_state(self.parameters, self.state.parameters) 1858 self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 1763 self._copy_parameters_state(self.fittable_param, 1764 self.state.fittable_param) 1859 1765 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 1860 1861 1766 ## post state to fit panel 1862 event = PageInfoEvent(page =self)1767 event = PageInfoEvent(page=self) 1863 1768 wx.PostEvent(self.parent, event) 1864 1769 … … 1871 1776 #-------------------------------------------------------------- 1872 1777 if box_sizer == None: 1873 box_description= wx.StaticBox(self, -1, str(title))1778 box_description= wx.StaticBox(self, -1, str(title)) 1874 1779 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 1875 1780 else: … … 1877 1782 boxsizer1 = box_sizer 1878 1783 1879 self.qmin = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER, 1880 kill_focus_callback = self._onQrangeEnter, 1881 text_enter_callback = self._onQrangeEnter) 1784 self.qmin = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH, 20), 1785 style=wx. TE_PROCESS_ENTER, 1786 kill_focus_callback=self._onQrangeEnter, 1787 text_enter_callback=self._onQrangeEnter) 1882 1788 self.qmin.SetValue(str(self.qmin_x)) 1883 1789 self.qmin.SetToolTipString("Minimun value of Q in linear scale.") 1884 1790 1885 self.qmax = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER, 1886 kill_focus_callback = self._onQrangeEnter, 1887 text_enter_callback = self._onQrangeEnter) 1791 self.qmax = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 1792 style=wx.TE_PROCESS_ENTER, 1793 kill_focus_callback=self._onQrangeEnter, 1794 text_enter_callback=self._onQrangeEnter) 1888 1795 self.qmax.SetValue(str(self.qmax_x)) 1889 1796 self.qmax.SetToolTipString("Maximum value of Q in linear scale.") 1890 1891 1797 id = wx.NewId() 1892 self.reset_qrange =wx.Button(self,id,'Reset',size=(70,23)) 1893 1894 self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked,id=id) 1798 self.reset_qrange = wx.Button(self, id, 'Reset', size=(70, 23)) 1799 self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked, id=id) 1895 1800 self.reset_qrange.SetToolTipString("Reset Q range to the default values") 1896 1897 sizer_horizontal=wx.BoxSizer(wx.HORIZONTAL) 1898 sizer= wx.GridSizer(3, 3,2, 5) 1899 1801 sizer_horizontal = wx.BoxSizer(wx.HORIZONTAL) 1802 sizer = wx.GridSizer(3, 3, 2, 5) 1900 1803 sizer.Add(wx.StaticText(self, -1, ' Q range')) 1901 1804 sizer.Add(wx.StaticText(self, -1, ' Min')) 1902 1805 sizer.Add(wx.StaticText(self, -1, ' Max')) 1903 1806 sizer.Add(self.reset_qrange) 1904 1905 1807 sizer.Add(self.qmin) 1906 1808 sizer.Add(self.qmax) 1907 1809 sizer_horizontal.Add(sizer) 1908 if object !=None:1810 if object != None: 1909 1811 sizer_horizontal.Add(object) 1910 1911 if object1!=None: 1812 if object1 != None: 1912 1813 boxsizer1.Add(object1) 1913 boxsizer1.Add((10, 10))1814 boxsizer1.Add((10, 10)) 1914 1815 boxsizer1.Add(sizer_horizontal) 1915 1816 ## save state 1916 1817 self.save_current_state() 1917 1818 #---------------------------------------------------------------- 1918 self.sizer5.Add(boxsizer1, 0, wx.EXPAND |wx.ALL, 10)1819 self.sizer5.Add(boxsizer1, 0, wx.EXPAND|wx.ALL, 10) 1919 1820 self.sizer5.Layout() 1920 1821 … … 1926 1827 # Skipping save state functionality for release 0.9.0 1927 1828 return 1928 1929 1829 self.sizer6.Clear(True) 1930 box_description= wx.StaticBox(self, -1, "Save Model")1830 box_description= wx.StaticBox(self, -1, "Save Model") 1931 1831 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 1932 1832 sizer_save = wx.BoxSizer(wx.HORIZONTAL) … … 1934 1834 self.btSave_title = wx.StaticText(self, -1, 'Save the current Model') 1935 1835 self.btSave = wx.Button(self,wx.NewId(),'Save') 1936 self.btSave.Bind(wx.EVT_BUTTON, self.onSave,id= 1836 self.btSave.Bind(wx.EVT_BUTTON, self.onSave,id=self.btSave.GetId()) 1937 1837 self.btSave.SetToolTipString("Save the current Model") 1938 1939 1838 sizer_save.Add(self.btSave_title) 1940 sizer_save.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,45) 1941 1839 sizer_save.Add((20, 20), 0, wx.LEFT|wx.RIGHT|wx.EXPAND, 45) 1942 1840 sizer_save.Add(self.btSave) 1943 1944 1841 boxsizer1.Add(sizer_save) 1945 self.sizer6.Add(boxsizer1, 0, wx.EXPAND |wx.ALL, 10)1842 self.sizer6.Add(boxsizer1, 0, wx.EXPAND|wx.ALL, 10) 1946 1843 self.sizer6.Layout() 1947 self.SetScrollbars(20, 20,25,65)1844 self.SetScrollbars(20, 20, 25, 65) 1948 1845 1949 1846 def _lay_out(self): … … 1971 1868 time.sleep(1) 1972 1869 1973 def on_reset_clicked(self, event):1870 def on_reset_clicked(self, event): 1974 1871 """ 1975 1872 On 'Reset' button for Q range clicked … … 1978 1875 ##For 3 different cases: Data2D, Data1D, and theory 1979 1876 if self.data.__class__.__name__ == "Data2D": 1980 data_min = 01981 x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax))1982 y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax))1877 data_min = 0 1878 x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) 1879 y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) 1983 1880 self.qmin_x = data_min 1984 self.qmax_x = math.sqrt(x *x + y*y)1881 self.qmax_x = math.sqrt(x * x + y * y) 1985 1882 elif self.data.__class__.__name__ == "Data1D": 1986 1883 self.qmin_x = min(self.data.x) … … 1991 1888 self.num_points = _NPTS_DEFAULT 1992 1889 self.state.npts = self.num_points 1993 1994 1890 self.state.qmin = self.qmin_x 1995 1891 self.state.qmax = self.qmax_x 1996 1997 1892 #reset the q range values 1998 1893 self._reset_plotting_range(self.state) -
theoryview/perspectives/theory/help_panel.py
r74755ff r2f60121 7 7 8 8 class HelpWindow(wx.Frame): 9 def __init__(self, parent, id, title= 9 def __init__(self, parent, id, title='HelpWindow', pageToOpen=None): 10 10 wx.Frame.__init__(self, parent, id, title, size=(850, 500)) 11 11 """ … … 16 16 splitter = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE) 17 17 rpanel = wx.Panel(splitter, -1) 18 lpanel = wx.Panel(splitter, -1, style=wx.BORDER_SUNKEN)18 lpanel = wx.Panel(splitter, -1, style=wx.BORDER_SUNKEN) 19 19 20 20 vbox = wx.BoxSizer(wx.VERTICAL) … … 27 27 font.SetPointSize(10) 28 28 st.SetFont(font) 29 hbox.Add(st, 1, wx.TOP | wx.BOTTOM |wx.LEFT, 5)29 hbox.Add(st, 1, wx.TOP|wx.BOTTOM|wx.LEFT, 5) 30 30 header.SetSizer(hbox) 31 31 vbox.Add(header, 0, wx.EXPAND) … … 41 41 fontl.SetPointSize(10) 42 42 lst.SetFont(fontl) 43 hboxl.Add(lst, 1, wx.TOP | wx.BOTTOM |wx.LEFT, 5)43 hboxl.Add(lst, 1, wx.TOP|wx.BOTTOM|wx.LEFT, 5) 44 44 headerl.SetSizer(hboxl) 45 45 vboxl.Add(headerl, 0, wx.EXPAND) 46 46 self.lhelp = html.HtmlWindow(lpanel, -1, style=wx.NO_BORDER) 47 self.rhelp = html.HtmlWindow(rpanel, -1, style=wx.NO_BORDER, size=(500,-1)) 48 page1="""<html> 47 self.rhelp = html.HtmlWindow(rpanel, -1, 48 style=wx.NO_BORDER, size=(500, -1)) 49 page1 = """<html> 49 50 <body> 50 51 <p>Select topic on Menu</p> 51 52 </body> 52 53 </html>""" 53 page ="""<html>54 page = """<html> 54 55 <body> 55 56 <ul> … … 60 61 self.rhelp.SetPage(page1) 61 62 self.lhelp.SetPage(page) 62 self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED,self.OnLinkClicked ) 63 63 self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.OnLinkClicked) 64 64 #open the help frame a the current page 65 if pageToOpen!= None: 66 self.rhelp.LoadPage(str( pageToOpen)) 67 68 vbox.Add(self.rhelp,1, wx.EXPAND) 65 if pageToOpen != None: 66 self.rhelp.LoadPage(str(pageToOpen)) 67 vbox.Add(self.rhelp, 1, wx.EXPAND) 69 68 vboxl.Add(self.lhelp, 1, wx.EXPAND) 70 69 rpanel.SetSizer(vbox) 71 70 lpanel.SetSizer(vboxl) 72 71 lpanel.SetFocus() 73 74 72 vbox1 = wx.BoxSizer(wx.HORIZONTAL) 75 vbox1.Add(splitter, 1,wx.EXPAND)73 vbox1.Add(splitter, 1, wx.EXPAND) 76 74 splitter.AppendWindow(lpanel, 200) 77 75 splitter.AppendWindow(rpanel) 78 76 self.SetSizer(vbox1) 79 80 77 self.Centre() 81 78 self.Show(True) -
theoryview/perspectives/theory/model_panel.py
rd7b7156 r2f60121 5 5 import copy 6 6 import math 7 from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion 8 7 from sans.guiframe.panel_base import PanelBase 8 from sans.models.dispersion_models import ArrayDispersion 9 from sans.models.dispersion_models import GaussianDispersion 9 10 from sans.guicomm.events import StatusEvent 10 11 from sans.guiframe.utils import format_number 11 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent()12 _BOX_WIDTH = 7613 14 12 import basepage 15 13 from basepage import BasicPage 16 14 from basepage import PageInfoEvent 17 18 class ModelPanel(BasicPage): 15 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 16 17 _BOX_WIDTH = 76 18 19 20 class ModelPanel(BasicPage, PanelBase): 19 21 """ 20 22 FitPanel class contains fields allowing to display results when … … 30 32 ## Title to appear on top of the window 31 33 window_caption = "Theory Model" 32 def __init__(self,parent, page_info, model_list_box): 33 BasicPage.__init__(self, parent, page_info , model_list_box) 34 35 def __init__(self, parent, page_info, model_list_box): 36 BasicPage.__init__(self, parent, page_info, model_list_box) 37 PanelBase.__init__(self) 34 38 """ 35 39 Initialization of the Panel … … 38 42 self._fill_range_sizer() 39 43 self.engine_type = None 40 41 description="" 42 if self.model!=None: 43 44 description = "" 45 if self.model != None: 44 46 description = self.model.description 45 46 47 self.select_model(self.model) 47 self.set_model_description(description, self.sizer2)48 self.set_model_description(description, self.sizer2) 48 49 49 50 def _on_display_description(self, event): … … 55 56 """ 56 57 self._on_display_description_helper() 57 58 self.SetScrollbars(20,20,25,65) 58 self.SetScrollbars(20, 20, 25, 65) 59 59 self.Refresh() 60 60 … … 69 69 if self.description_hide.GetValue(): 70 70 self.sizer_description.Clear(True) 71 72 71 else: 73 72 description="Model contains no description" 74 if self.model !=None:73 if self.model != None: 75 74 description = self.model.description 76 if description.lstrip().rstrip() == "":75 if description.lstrip().rstrip() == "": 77 76 description="Model contains no description" 78 self.description = wx.StaticText( self,-1,str(description))79 self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 )80 77 self.description = wx.StaticText(self, -1, str(description)) 78 self.sizer_description.Add(self.description, 1, 79 wx.EXPAND|wx.ALL, 10) 81 80 self.Layout() 82 83 81 84 82 def _fill_range_sizer(self): … … 90 88 ##The following 3 lines are for Mac. Let JHC know before modifying.. 91 89 title = "Plotted Q Range" 92 box_description = wx.StaticBox(self, -1,str(title))90 box_description = wx.StaticBox(self, -1, str(title)) 93 91 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 94 92 95 sizer_npts= wx.GridSizer(1, 1,5, 5) 96 self.npts = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) 93 sizer_npts= wx.GridSizer(1, 1, 5, 5) 94 self.npts = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 95 style=wx.TE_PROCESS_ENTER) 97 96 self.npts.SetValue(format_number(self.num_points)) 98 97 self.npts.SetToolTipString("Number of point to plot.") 99 100 sizer_npts.Add(wx.StaticText(self, -1, 'Npts'),1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 13) 101 102 sizer_npts.Add(self.npts,1,wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) 103 self._set_range_sizer( title=title, box_sizer=boxsizer1, object= sizer_npts) 104 105 98 sizer_npts.Add(wx.StaticText(self, -1, 'Npts'), 1, 99 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 13) 100 sizer_npts.Add(self.npts, 1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) 101 self._set_range_sizer(title=title, box_sizer=boxsizer1, 102 object=sizer_npts) 103 106 104 def _on_select_model(self, event): 107 105 """ … … 114 112 self.select_model(self.model) 115 113 116 117 114 def _fill_model_sizer(self, sizer): 118 115 """ … … 122 119 ##The following 3 lines are for Mac. Let JHC know before modifying.. 123 120 title = "Model" 124 box_description = wx.StaticBox(self, -1,str(title))121 box_description = wx.StaticBox(self, -1, str(title)) 125 122 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 126 127 123 id = wx.NewId() 128 self.model_view = wx.Button(self,id,'View 2D', size=(80,23))129 self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=id)124 self.model_view = wx.Button(self, id,'View 2D', size=(80, 23)) 125 self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=id) 130 126 self.model_view.SetToolTipString("View model in 2D") 131 132 127 ## class base method to add view 2d button 133 self._set_model_sizer(sizer=sizer, box_sizer=boxsizer1, title=title,object= self.model_view )134 135 128 self._set_model_sizer(sizer=sizer, box_sizer=boxsizer1, 129 title=title, object=self.model_view) 130 136 131 #def _set_sizer_gaussian(self): 137 132 def _set_sizer_dispersion(self, dispersity): … … 140 135 141 136 """ 142 self.fittable_param =[]143 self.fixed_param =[]144 self.orientation_params_disp =[]137 self.fittable_param = [] 138 self.fixed_param = [] 139 self.orientation_params_disp = [] 145 140 #self.temp=[] 146 147 141 self.sizer4_4.Clear(True) 148 if self.model ==None:142 if self.model == None: 149 143 ##no model is selected 150 144 return … … 159 153 self._disp_obj_dict[item] = disp_model 160 154 self.model.set_dispersion(item, disp_model) 161 self.state._disp_obj_dict[item]= disp_model 162 163 164 ix=0 165 iy=1 155 self.state._disp_obj_dict[item] = disp_model 156 ix = 0 157 iy = 1 166 158 disp = wx.StaticText(self, -1, ' ') 167 self.sizer4_4.Add(disp,( iy, ix),(1,1),159 self.sizer4_4.Add(disp,(iy, ix), (1, 1), 168 160 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 169 161 ix += 1 170 162 values = wx.StaticText(self, -1, 'Sigma [A]') 171 values.SetToolTipString(\ 172 "Sigma(STD) in the A unit; the standard deviation from the mean value.") 173 174 self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 175 0) 176 163 hint_msg = "Sigma(STD) in the A unit; the standard " 164 hint_msg += "deviation from the mean value." 165 values.SetToolTipString(hint_msg) 166 self.sizer4_4.Add(values, (iy, ix), (1, 1), 167 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 177 168 ix += 1 178 169 npts = wx.StaticText(self, -1, 'Npts') 179 npts.SetToolTipString("Number of sampling points for the numerical\n\ 180 integration over the distribution function.") 181 self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 170 hint_msg = "Number of sampling points for the numerical\n" 171 hint_msg += "integration over the distribution function." 172 npts.SetToolTipString(hint_msg) 173 self.sizer4_4.Add(npts, (iy, ix), (1, 1), 174 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 182 175 ix += 1 183 176 nsigmas = wx.StaticText(self, -1, 'Nsigmas') 184 nsigmas.SetToolTipString(" Number of sigmas between which the range\n\185 of the distribution function will be used for weighting. \n\186 The value '3' covers 99.5% for Gaussian distribution \n\187 function.")188 self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE,189 0)190 177 hint_msg = "Number of sigmas between which the range\n" 178 hint_msg += "of the distribution function will be used for " 179 hint_msg += "weighting.\n The value '3' covers 99.5% for Gaussian " 180 hint_msg += " distribution \n function." 181 nsigmas.SetToolTipString(hint_msg) 182 self.sizer4_4.Add(nsigmas, (iy, ix), 183 (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 191 184 for item in self.model.dispersion.keys(): 192 185 if not item in self.model.orientation_params: 193 self.disp_cb_dict[item] = None194 name0 ="Distribution of " + item195 name1 =item+".width"186 self.disp_cb_dict[item] = None 187 name0 = "Distribution of " + item 188 name1 = item + ".width" 196 189 name2=item+".npts" 197 190 name3=item+".nsigmas" 198 191 iy += 1 199 192 for p in self.model.dispersion[item].keys(): 200 if p =="width":193 if p == "width": 201 194 ix = 0 202 195 name = wx.StaticText(self, -1, name0) … … 489 482 490 483 sizer_selection=wx.BoxSizer(wx.HORIZONTAL) 491 self.description_hide = wx.RadioButton(self, -1, 'Hide', style=wx.RB_GROUP) 484 self.description_hide = wx.RadioButton(self, -1, 'Hide', 485 style=wx.RB_GROUP) 492 486 self.description_show = wx.RadioButton(self, -1, 'Show') 493 487 494 488 495 if description =="":489 if description == "": 496 490 self.description_hide.SetValue(True) 497 description =" Description unavailable. Click for details"491 description = " Description unavailable. Click for details" 498 492 499 493 self.description = wx.StaticText( self,-1,str(description) ) -
theoryview/perspectives/theory/theory.py
r9e2cfee r2f60121 9 9 import model_panel 10 10 from model_panel import ModelPanel 11 from sans.guicomm.events import NewPlotEvent, StatusEvent 11 from sans.guicomm.events import NewPlotEvent 12 from sans.guicomm.events import StatusEvent 12 13 from sans.guiframe.dataFitting import Data2D 13 14 from sans.guiframe.dataFitting import Theory1D … … 17 18 DEFAULT_QMAX = 0.13 18 19 DEFAULT_NPTS = 50 20 19 21 20 22 class PlotInfo: … … 32 34 info= None 33 35 34 class Plugin: 36 from sans.guiframe.plugin_base import PluginBase 37 38 class Plugin(PluginBase): 35 39 """ 36 40 This class defines the interface for a Plugin class … … 40 44 41 45 def __init__(self, standalone=True): 42 """ 43 Abstract class for gui_manager Plugins. 44 45 """ 46 ## Plug-in name. It will appear on the application menu. 47 self.sub_menu = "Theory" 48 49 ## Reference to the parent window. Filled by get_panels() below. 50 self.parent = None 51 52 ## List of panels that you would like to open in AUI windows 53 # for your plug-in. This defines your plug-in "perspective" 54 self.perspective = [] 46 PluginBase.__init__(self, name="Theory", standalone=standalone) 47 55 48 # Log startup 56 49 logging.info("Theory plug-in started") … … 59 52 self.menu_mng = models.ModelManager() 60 53 # reference to the current running thread 61 self.calc_2D= None 62 self.calc_1D= None 63 64 def populate_menu(self, id, owner): 65 """ 66 Create and return the list of application menu 67 items for the plug-in. 68 69 :param id: deprecated. Un-used. 70 :param parent: parent window 71 72 :return: plug-in menu 73 """ 74 return [] 75 54 self.calc_2D = None 55 self.calc_1D = None 56 76 57 def get_panels(self, parent): 77 58 """ … … 99 80 return [self.model_panel] 100 81 101 def get_context_menu(self, graph=None): 102 """ 103 This method is optional. 104 105 When the context menu of a plot is rendered, the 106 get_context_menu method will be called to give you a 107 chance to add a menu item to the context menu. 108 109 A ref to a Graph object is passed so that you can 110 investigate the plot content and decide whether you 111 need to add items to the context menu. 112 113 This method returns a list of menu items. 114 Each item is itself a list defining the text to 115 appear in the menu, a tool-tip help text, and a 116 call-back method. 117 118 :param graph: the Graph object to which we attach the context menu 119 120 :return: a list of menu items with call-back function 121 122 """ 123 return [] 124 125 def get_perspective(self): 126 """ 127 Get the list of panel names for this perspective 128 129 """ 130 return self.perspective 131 132 def on_perspective(self, event): 133 """ 134 Call back function for the perspective menu item. 135 We notify the parent window that the perspective 136 has changed. 137 138 :param event: menu event 139 140 """ 141 self.parent.set_perspective(self.perspective) 142 143 def post_init(self): 144 """ 145 Post initialization call back to close the loose ends 146 147 """ 148 pass 149 82 150 83 def draw_model(self, model, data= None,smearer= None, 151 84 enable1D= True, enable2D= False,
Note: See TracChangeset
for help on using the changeset viewer.