Changes in src/sas/sasgui/perspectives/fitting/simfitpage.py [4fea1df:4cafdff] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/simfitpage.py
r4fea1df r4cafdff 9 9 from wx.lib.scrolledpanel import ScrolledPanel 10 10 11 from sas.sasgui.guiframe.events import StatusEvent , PanelOnFocusEvent11 from sas.sasgui.guiframe.events import StatusEvent 12 12 from sas.sasgui.guiframe.panel_base import PanelBase 13 from sas.sasgui.guiframe.events import PanelOnFocusEvent 13 14 from sas.sasgui.guiframe.utils import IdList 14 15 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 15 16 16 # Control panel width17 #Control panel width 17 18 if sys.platform.count("darwin") == 0: 18 19 PANEL_WID = 420 … … 28 29 'model_cbox param_cbox egal_txt constraint btRemove sizer') 29 30 30 31 31 def get_fittableParam(model): 32 32 """ … … 47 47 return fittable_param 48 48 49 50 49 class SimultaneousFitPage(ScrolledPanel, PanelBase): 51 50 """ … … 54 53 two data members window_name and window_caption 55 54 """ 56 # Internal name for the AUI manager57 window_name = " Simultaneous Fit Page"58 # Title to appear on top of the window55 ## Internal name for the AUI manager 56 window_name = "simultaneous Fit page" 57 ## Title to appear on top of the window 59 58 window_caption = "Simultaneous Fit Page" 60 59 ID_DOC = wx.NewId() … … 75 74 self._ids = iter(self._id_pool) 76 75 self.SetupScrolling() 77 # 76 ##Font size 78 77 self.SetWindowVariant(variant=FONT_VARIANT) 79 78 self.uid = wx.NewId() 80 79 self.parent = parent 81 80 self.batch_on = batch_on 82 # store page_finder81 ## store page_finder 83 82 self.page_finder = page_finder 84 # list containing info to set constraint85 # look like self.constraint_dict[page_id]= page83 ## list containing info to set constraint 84 ## look like self.constraint_dict[page_id]= page 86 85 self.constraint_dict = {} 87 # item list88 # self.constraints_list=[combobox1, combobox2,=,textcrtl, button ]86 ## item list 87 ## self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 89 88 self.constraints_list = [] 90 # list of current model89 ## list of current model 91 90 self.model_list = [] 92 # selected model to fit93 self.model_to _fit = []94 # Control the fit state91 ## selected mdoel to fit 92 self.model_toFit = [] 93 ## Control the fit state 95 94 self.fit_started = False 96 # number of constraint95 ## number of constraint 97 96 self.nb_constraint = 0 98 self.state = SimFitPageState()99 97 self.model_cbox_left = None 100 98 self.model_cbox_right = None 101 # draw page99 ## draw page 102 100 self.define_page_structure() 103 101 self.draw_page() … … 109 107 """ 110 108 self.vbox = wx.BoxSizer(wx.VERTICAL) 111 self. data_selection_sizer= wx.BoxSizer(wx.VERTICAL)112 self. constraints_sizer= wx.BoxSizer(wx.VERTICAL)113 self. run_fit_sizer= wx.BoxSizer(wx.VERTICAL)114 115 self. data_selection_sizer.SetMinSize((PANEL_WID, -1))116 self. constraints_sizer.SetMinSize((PANEL_WID, -1))117 self. run_fit_sizer.SetMinSize((PANEL_WID, -1))118 self.vbox.Add(self. data_selection_sizer)119 self.vbox.Add(self. constraints_sizer)120 self.vbox.Add(self. run_fit_sizer)109 self.sizer1 = wx.BoxSizer(wx.VERTICAL) 110 self.sizer2 = wx.BoxSizer(wx.VERTICAL) 111 self.sizer3 = wx.BoxSizer(wx.VERTICAL) 112 113 self.sizer1.SetMinSize((PANEL_WID, -1)) 114 self.sizer2.SetMinSize((PANEL_WID, -1)) 115 self.sizer3.SetMinSize((PANEL_WID, -1)) 116 self.vbox.Add(self.sizer1) 117 self.vbox.Add(self.sizer2) 118 self.vbox.Add(self.sizer3) 121 119 self.SetSizer(self.vbox) 122 120 self.Centre() 123 124 def set_state(self):125 """126 Define a set of state parameters for saving simultaneous fits.127 """128 self._set_constraint()129 self.state.fit_page_no = self.uid130 self.state.select_all = self.cb1.GetValue()131 self.state.model_list = self.model_list132 self.state.model_to_fit = self.model_to_fit133 self.state.no_constraint = self.nb_constraint134 self.state.constraint_dict = self.constraint_dict135 self.state.constraints_list = self.constraints_list136 return self.get_state()137 138 def get_state(self):139 """140 Return the state of the current page141 :return: self.state142 """143 return self.state144 121 145 122 def draw_page(self): … … 154 131 # create blank list of constraints 155 132 self.model_list = [] 156 self.model_to _fit = []133 self.model_toFit = [] 157 134 self.constraints_list = [] 158 135 self.constraint_dict = {} … … 167 144 168 145 #------------------------------------------------------- 169 # setup sizer1 (which fitpages to include)170 self. data_selection_sizer.Clear(True)146 ## setup sizer1 (which fitpages to include) 147 self.sizer1.Clear(True) 171 148 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Combinations") 172 149 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) … … 174 151 sizer_couples = wx.GridBagSizer(5, 5) 175 152 176 # The wx GUI has a flag to enable a menu item, but can still be177 # reached via scripting. There is no guearantee future GUI178 # implementations force this check, either.179 # IMHO, this if statement should stay -- JRK 2016-OCT-05153 #This if statement should be obsolete and can be removed in version 4 154 #Leave it here for now as no time to thoroughly test. However if no 155 #fit page is found the menu item that calls this page is inactive 156 # Nov. 22 2015 --PDB 180 157 if len(self.page_finder) == 0: 181 158 msg = " No fit combinations are found! \n\n" … … 184 161 sizer_title.Add(wx.StaticText(self, wx.ID_ANY, msg)) 185 162 else: 186 # store model163 ## store model 187 164 self._store_model() 188 165 … … 194 171 wx.TOP | wx.BOTTOM | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 195 172 sizer_title.Add(self.cb1, 0, 196 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 197 border=5) 198 199 # draw list of model and data names 173 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 174 175 ## draw list of model and data names 200 176 self._fill_sizer_model_list(sizer_couples) 201 177 202 178 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=5) 203 179 boxsizer1.Add(sizer_couples, 1, flag=wx.TOP | wx.BOTTOM, border=5) 204 self. data_selection_sizer.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10)205 #self.sizer1.Layout()180 self.sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10) 181 # self.sizer1.Layout() 206 182 207 183 #-------------------------------------------------------- 208 # set up the other 2 sizers: the constraints list and the 209 # buttons (fit, help etc) sizer at the bottom of the page. 210 # Note: the if statement should be removed along with the above 211 # if statement as soon as it can be properly tested. 212 # Nov. 22 2015 --PDB 213 # As above, this page can be accessed through other means than the 214 # base SasView GUI. 215 # Oct. 5, 2016 --JRK 184 ## set up the other 2 sizers: the constraints list and the 185 ## buttons (fit, help etc) sizer at the bottom of the page. 186 ## Note: the if statement should be removed along with the above 187 ## if statement as soon as it can be properly tested. 188 ## Nov. 22 2015 --PDB 216 189 if len(self.page_finder) > 0: 217 # draw the sizer containing constraint info190 ## draw the sizer containing constraint info 218 191 if not self.batch_on: 219 192 self._fill_sizer_constraint() 220 # draw fit button sizer193 ## draw fit button sizer 221 194 self._fill_sizer_fit() 195 222 196 223 197 def _fill_sizer_model_list(self, sizer): … … 227 201 ix = 0 228 202 iy = 0 203 list = [] 229 204 sizer.Clear(True) 230 205 … … 234 209 new_name.SetForegroundColour(wx.WHITE) 235 210 sizer.Add(new_name, (iy, ix), (1, 1), 236 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)211 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 237 212 ix += 2 238 213 model_type = wx.StaticText(self, wx.ID_ANY, ' Model ') … … 240 215 model_type.SetForegroundColour(wx.WHITE) 241 216 sizer.Add(model_type, (iy, ix), (1, 1), 242 wx.EXPAND | wx.ADJUST_MINSIZE, 0)217 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 243 218 ix += 1 244 219 data_used = wx.StaticText(self, wx.ID_ANY, ' Data ') … … 246 221 data_used.SetForegroundColour(wx.WHITE) 247 222 sizer.Add(data_used, (iy, ix), (1, 1), 248 wx.EXPAND | wx.ADJUST_MINSIZE, 0)223 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 249 224 ix += 1 250 225 tab_used = wx.StaticText(self, wx.ID_ANY, ' FitPage ') … … 327 302 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 328 303 329 self. constraints_sizer.Clear(True)304 self.sizer2.Clear(True) 330 305 if self.batch_on: 331 if self. constraints_sizer.IsShown():332 self. constraints_sizer.Show(False)306 if self.sizer2.IsShown(): 307 self.sizer2.Show(False) 333 308 return 334 309 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Constraints") 335 box _sizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)310 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 336 311 sizer_title = wx.BoxSizer(wx.HORIZONTAL) 337 312 self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL) … … 363 338 364 339 self.btAdd = wx.Button(self, self.ID_ADD, 'Add') 365 self.btAdd.Bind(wx.EVT_BUTTON, self._on _add_constraint,340 self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint, 366 341 id=self.btAdd.GetId()) 367 342 self.btAdd.SetToolTipString("Add another constraint?") … … 369 344 370 345 text_hint = wx.StaticText(self, wx.ID_ANY, 371 "Example: [M0][param eter] = M1.parameter")346 "Example: [M0][paramter] = M1.parameter") 372 347 sizer_button.Add(text_hint, 0, 373 348 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) … … 375 350 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 376 351 377 box_sizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 378 box_sizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 379 border=10) 380 box_sizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 381 border=10) 382 box_sizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 383 384 self.constraints_sizer.Add(box_sizer1, 0, wx.EXPAND | wx.ALL, 10) 352 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 353 boxsizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 354 border=10) 355 boxsizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 356 border=10) 357 boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 358 359 self.sizer2.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 360 385 361 386 362 def _fill_sizer_fit(self): … … 388 364 Draw fit button 389 365 """ 390 self. run_fit_sizer.Clear(True)366 self.sizer3.Clear(True) 391 367 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit ") 392 368 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 393 369 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 394 370 395 # 371 #Fit button 396 372 self.btFit = wx.Button(self, self.ID_FIT, 'Fit', size=wx.DefaultSize) 397 self.btFit.Bind(wx.EVT_BUTTON, self.on _fit, id=self.btFit.GetId())373 self.btFit.Bind(wx.EVT_BUTTON, self.onFit, id=self.btFit.GetId()) 398 374 self.btFit.SetToolTipString("Perform fit.") 399 375 400 # 376 #General Help button 401 377 self.btHelp = wx.Button(self, wx.ID_HELP, 'HELP') 402 378 self.btHelp.SetToolTipString("Simultaneous/Constrained Fitting help.") 403 self.btHelp.Bind(wx.EVT_BUTTON, self._on _help)404 405 # 379 self.btHelp.Bind(wx.EVT_BUTTON, self._onHelp) 380 381 #hint text on button line 406 382 if self.batch_on: 407 383 text = " Fit in Parallel all Data sets\n" … … 417 393 418 394 boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 419 self. run_fit_sizer.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10)420 421 def on _remove(self, event):395 self.sizer3.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 396 397 def onRemove(self, event): 422 398 """ 423 399 Remove constraint fields … … 430 406 return 431 407 wx.CallAfter(self._remove_after, event.GetId()) 432 # 408 #self._onAdd_constraint(None) 433 409 434 410 def _remove_after(self, id): … … 440 416 self.constraints_list.remove(item) 441 417 self.nb_constraint -= 1 442 self. constraints_sizer.Layout()418 self.sizer2.Layout() 443 419 self.FitInside() 444 420 break 445 421 446 def on _fit(self, event):422 def onFit(self, event): 447 423 """ 448 424 signal for fitting … … 459 435 flag = (self._manager.sim_page.uid == self.uid) 460 436 461 # making sure all parameters content a constraint437 ## making sure all parameters content a constraint 462 438 if not self.batch_on and self.show_constraint.GetValue(): 463 439 if not self._set_constraint(): 464 440 return 465 # model was actually selected from this page to be fit466 if len(self.model_to _fit) >= 1:441 ## model was actually selected from this page to be fit 442 if len(self.model_toFit) >= 1: 467 443 self.manager._reset_schedule_problem(value=0) 468 444 for item in self.model_list: … … 480 456 msg = "Select at least one model check box to fit " 481 457 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 482 self.set_state()483 458 484 459 def _on_fit_complete(self): … … 492 467 """ 493 468 Attempt to stop the fitting thread 494 495 :param event: Event handler when stop fit is clicked 496 """ 497 if event is not None: 469 """ 470 if event != None: 498 471 event.Skip() 499 472 self.manager.stop_fit(self.uid) … … 512 485 self.btFit.Enable(True) 513 486 514 def _on _help(self, event):487 def _onHelp(self, event): 515 488 """ 516 489 Bring up the simultaneous Fitting Documentation whenever the HELP … … 521 494 versions of Wx (before 2.9) and thus not the release version of 522 495 installers, the help comes up at the top level of the file as 523 web 496 webbrowser does not pass anything past the # to the browser when it is 524 497 running "file:///...." 525 498 526 :param ev ent: Triggers on clicking the help button499 :param evt: Triggers on clicking the help button 527 500 """ 528 501 _TreeLocation = "user/sasgui/perspectives/fitting/fitting_help.html" … … 537 510 538 511 :param manager: instance of plugin fitting 512 539 513 """ 540 514 self.manager = manager … … 544 518 check all models names 545 519 """ 546 self.model_to _fit = []547 if self.cb1.GetValue() :520 self.model_toFit = [] 521 if self.cb1.GetValue() == True: 548 522 for item in self.model_list: 549 523 if item[0].IsEnabled(): 550 524 item[0].SetValue(True) 551 self.model_to _fit.append(item)552 553 # constraint info525 self.model_toFit.append(item) 526 527 ## constraint info 554 528 self._store_model() 555 529 if not self.batch_on: 556 # display constraint fields530 ## display constraint fields 557 531 if (self.show_constraint.GetValue() and 558 532 len(self.constraints_list) == 0): … … 564 538 565 539 if not self.batch_on: 566 # 540 ##constraint info 567 541 self._hide_constraint() 568 542 … … 570 544 self.FitInside() 571 545 546 572 547 def check_model_name(self, event): 573 548 """ 574 549 Save information related to checkbox and their states 575 550 """ 576 self.model_to_fit = [] 551 self.model_toFit = [] 552 cbox = event.GetEventObject() 577 553 for item in self.model_list: 578 if item[0].GetValue() :579 self.model_to _fit.append(item)554 if item[0].GetValue() == True: 555 self.model_toFit.append(item) 580 556 else: 581 if item in self.model_to _fit:582 self.model_to _fit.remove(item)557 if item in self.model_toFit: 558 self.model_toFit.remove(item) 583 559 self.cb1.SetValue(False) 584 560 585 # display constraint fields586 if len(self.model_to _fit) >= 1:561 ## display constraint fields 562 if len(self.model_toFit) >= 1: 587 563 self._store_model() 588 564 if not self.batch_on and self.show_constraint.GetValue() and\ … … 591 567 self._show_constraint() 592 568 593 elif len(self.model_to _fit) < 1:594 # 569 elif len(self.model_toFit) < 1: 570 ##constraint info 595 571 self._hide_constraint() 596 572 597 573 self._update_easy_setup_cb() 598 # set the value of the main check button599 if len(self.model_list) == len(self.model_to _fit):574 ## set the value of the main check button 575 if len(self.model_list) == len(self.model_toFit): 600 576 self.cb1.SetValue(True) 601 577 self.FitInside() … … 609 585 Update easy setup combobox on selecting a model 610 586 """ 611 if self.model_cbox_left is None or self.model_cbox_right isNone:612 return 613 614 models = [(item[3].name, item[3]) for item in self.model_to _fit]587 if self.model_cbox_left == None or self.model_cbox_right == None: 588 return 589 590 models = [(item[3].name, item[3]) for item in self.model_toFit] 615 591 setComboBoxItems(self.model_cbox_left, models) 616 592 setComboBoxItems(self.model_cbox_right, models) … … 619 595 if self.model_cbox_left.GetSelection() == wx.NOT_FOUND: 620 596 self.model_cbox_left.SetSelection(0) 621 self. constraints_sizer.Layout()597 self.sizer2.Layout() 622 598 623 599 def _store_model(self): … … 625 601 Store selected model 626 602 """ 627 if len(self.model_to _fit) < 1:628 return 629 for item in self.model_to _fit:603 if len(self.model_toFit) < 1: 604 return 605 for item in self.model_toFit: 630 606 model = item[3] 631 607 page_id = item[2] … … 636 612 Show fields to add constraint 637 613 """ 638 if len(self.model_to _fit) < 1:614 if len(self.model_toFit) < 1: 639 615 msg = "Select at least 1 model to add constraint " 640 616 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 641 # hide button617 ## hide button 642 618 self._hide_constraint() 643 619 return … … 656 632 """ 657 633 box_description = wx.StaticBox(self, wx.ID_ANY, "Easy Setup ") 658 box _sizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL)634 boxsizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL) 659 635 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 660 636 self.model_cbox_left = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) … … 674 650 675 651 for id, model in self.constraint_dict.iteritems(): 676 # check if all parameters have been selected for constraint677 # then do not allow add constraint on parameters652 ## check if all parameters have been selected for constraint 653 ## then do not allow add constraint on parameters 678 654 self.model_cbox_left.Append(str(model.name), model) 679 655 self.model_cbox_left.Select(0) 680 656 for id, model in self.constraint_dict.iteritems(): 681 # check if all parameters have been selected for constraint682 # then do not allow add constraint on parameters657 ## check if all parameters have been selected for constraint 658 ## then do not allow add constraint on parameters 683 659 self.model_cbox_right.Append(str(model.name), model) 684 box _sizer.Add(self.model_cbox_left,660 boxsizer.Add(self.model_cbox_left, 685 661 flag=wx.RIGHT | wx.EXPAND, border=10) 686 # box_sizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"),662 #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 687 663 # flag=wx.RIGHT | wx.EXPAND, border=5) 688 box _sizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5)689 box _sizer.Add(self.model_cbox_right,664 boxsizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 665 boxsizer.Add(self.model_cbox_right, 690 666 flag=wx.RIGHT | wx.EXPAND, border=10) 691 # box_sizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"),667 #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 692 668 # flag=wx.RIGHT | wx.EXPAND, border=5) 693 box _sizer.Add((20, -1))694 box _sizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5)695 sizer_constraint.Add(box _sizer, flag=wx.RIGHT | wx.EXPAND, border=5)669 boxsizer.Add((20, -1)) 670 boxsizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5) 671 sizer_constraint.Add(boxsizer, flag=wx.RIGHT | wx.EXPAND, border=5) 696 672 self.sizer_all_constraints.Insert(before=0, 697 673 item=sizer_constraint, … … 723 699 return 724 700 param_list = [] 725 param_list _b= []701 param_listB = [] 726 702 selection = self.model_cbox_left.GetCurrentSelection() 727 703 model_left = self.model_cbox_left.GetValue() 728 704 model = self.model_cbox_left.GetClientData(selection) 729 selection _b= self.model_cbox_right.GetCurrentSelection()705 selectionB = self.model_cbox_right.GetCurrentSelection() 730 706 model_right = self.model_cbox_right.GetValue() 731 model _b = self.model_cbox_right.GetClientData(selection_b)707 modelB = self.model_cbox_right.GetClientData(selectionB) 732 708 for id, dic_model in self.constraint_dict.iteritems(): 733 709 if model == dic_model: 734 710 param_list = self.page_finder[id].get_param2fit() 735 if model _b== dic_model:736 param_list _b= self.page_finder[id].get_param2fit()737 if len(param_list) > 0 and len(param_list _b) > 0:711 if modelB == dic_model: 712 param_listB = self.page_finder[id].get_param2fit() 713 if len(param_list) > 0 and len(param_listB) > 0: 738 714 break 739 715 num_cbox = 0 … … 741 717 for param in param_list: 742 718 num_cbox += 1 743 if param in param_list _b:719 if param in param_listB: 744 720 item = self.constraints_list[-1] 745 721 item.model_cbox.SetStringSelection(model_left) … … 768 744 """ 769 745 Show constraint fields 770 :param dict: dictionary mapping constraint values771 746 """ 772 747 self.btAdd.Show(True) … … 775 750 for id, model in self.constraint_dict.iteritems(): 776 751 nb_fit_param += len(self.page_finder[id].get_param2fit()) 777 # 752 ##Don't add anymore 778 753 if len(self.constraints_list) == nb_fit_param: 779 754 msg = "Cannot add another constraint. Maximum of number " … … 781 756 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 782 757 self.sizer_constraints.Layout() 783 self. constraints_sizer.Layout()758 self.sizer2.Layout() 784 759 return 785 if len(self.model_to _fit) < 1:760 if len(self.model_toFit) < 1: 786 761 msg = "Select at least 1 model to add constraint " 787 762 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 788 763 self.sizer_constraints.Layout() 789 self. constraints_sizer.Layout()764 self.sizer2.Layout() 790 765 return 791 766 … … 796 771 model_cbox.Clear() 797 772 for id, model in self.constraint_dict.iteritems(): 798 # check if all parameters have been selected for constraint799 # then do not allow add constraint on parameters773 ## check if all parameters have been selected for constraint 774 ## then do not allow add constraint on parameters 800 775 model_cbox.Append(str(model.name), model) 801 776 wx.EVT_COMBOBOX(model_cbox, wx.ID_ANY, self._on_select_model) … … 814 789 # Remove button 815 790 #btRemove = wx.Button(self, self.ID_REMOVE, 'Remove') 816 bt _remove = wx.Button(self, self._ids.next(), 'Remove')817 bt _remove.Bind(wx.EVT_BUTTON, self.on_remove,818 id=bt _remove.GetId())819 bt _remove.SetToolTipString("Remove constraint.")820 bt _remove.Hide()791 btRemove = wx.Button(self, self._ids.next(), 'Remove') 792 btRemove.Bind(wx.EVT_BUTTON, self.onRemove, 793 id=btRemove.GetId()) 794 btRemove.SetToolTipString("Remove constraint.") 795 btRemove.Hide() 821 796 822 797 # Hid the add button, if it exists … … 829 804 sizer_constraint.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 830 805 sizer_constraint.Add(constraint, flag=wx.RIGHT | wx.EXPAND, border=10) 831 sizer_constraint.Add(bt _remove, flag=wx.RIGHT | wx.EXPAND, border=10)806 sizer_constraint.Add(btRemove, flag=wx.RIGHT | wx.EXPAND, border=10) 832 807 833 808 self.sizer_constraints.Insert(before=self.nb_constraint, … … 835 810 border=5) 836 811 c = ConstraintLine(model_cbox, param_cbox, egal_txt, 837 constraint, bt _remove, sizer_constraint)812 constraint, btRemove, sizer_constraint) 838 813 self.constraints_list.append(c) 839 814 840 815 self.nb_constraint += 1 841 816 self.sizer_constraints.Layout() 842 self. constraints_sizer.Layout()843 self.Layout ()817 self.sizer2.Layout() 818 self.Layout 844 819 845 820 def _hide_constraint(self): … … 866 841 self.sizer_constraints.Clear(True) 867 842 self.sizer_constraints.Layout() 868 self. constraints_sizer.Layout()869 self.Layout ()843 self.sizer2.Layout() 844 self.Layout 870 845 self.FitInside() 871 846 872 847 def _on_select_model(self, event): 873 848 """ 874 fill combo box with list of parameters849 fill combox box with list of parameters 875 850 """ 876 851 if not self.constraints_list: 877 852 return 878 853 879 # 854 ##This way PC/MAC both work, instead of using event.GetClientData(). 880 855 model_cbox = self.constraints_list[-1].model_cbox 881 856 n = model_cbox.GetCurrentSelection() … … 892 867 param_cbox = self.constraints_list[-1].param_cbox 893 868 param_cbox.Clear() 894 # insert only fittable paramaters869 ## insert only fittable paramaters 895 870 for param in param_list: 896 871 param_cbox.Append(str(param), model) 897 872 param_cbox.Show(True) 898 873 899 bt _remove = self.constraints_list[-1].btRemove900 bt _remove.Show(True)874 btRemove = self.constraints_list[-1].btRemove 875 btRemove.Show(True) 901 876 self.btAdd.Show(True) 902 877 # self.Layout() … … 907 882 Store the appropriate constraint in the page_finder 908 883 """ 909 # 910 # 911 # 912 # 884 ##This way PC/MAC both work, instead of using event.GetClientData(). 885 #n = self.param_cbox.GetCurrentSelection() 886 #model = self.param_cbox.GetClientData(n) 887 #param = event.GetString() 913 888 914 889 if self.constraints_list: … … 916 891 self.constraints_list[-1].constraint.Show(True) 917 892 918 def _on _add_constraint(self, event):893 def _onAdd_constraint(self, event): 919 894 """ 920 895 Add another line for constraint … … 924 899 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 925 900 return 926 # check that a constraint is added901 ## check that a constraint is added 927 902 # before allow to add another constraint 928 903 for item in self.constraints_list: … … 938 913 model = item.param_cbox.GetClientData( 939 914 item.param_cbox.GetCurrentSelection()) 940 if model is notNone:915 if model != None: 941 916 msg = " Enter a constraint for %s.%s! " % (model.name, 942 917 item.param_cbox.GetString(0)) … … 945 920 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 946 921 return 947 # some model or parameters can be constrained922 ## some model or parameters can be constrained 948 923 self._show_constraint() 949 924 self.FitInside() … … 1005 980 def on_set_focus(self, event=None): 1006 981 """ 1007 The derivative class is on focus if implemented982 The derivative class is on focus if implemented 1008 983 """ 1009 984 if self.parent is not None: … … 1020 995 cbox.Append(name, value) 1021 996 cbox.SetStringSelection(selected) 1022 1023 1024 class SimFitPageState:1025 """1026 State of the simultaneous fit page for saving purposes1027 """1028 1029 def __init__(self):1030 # Sim Fit Page Number1031 self.fit_page_no = None1032 # Select all data1033 self.select_all = False1034 # Data sets sent to fit page1035 self.model_list = []1036 # Data sets to be fit1037 self.model_to_fit = []1038 # Number of constraints1039 self.no_constraint = 01040 # Dictionary of constraints1041 self.constraint_dict = {}1042 # List of constraints1043 self.constraints_list = []1044 1045 def load_from_save_state(self, fit):1046 """1047 Load in a simultaneous/constrained fit from a save state1048 :param fit: Fitpanel object1049 :return: None1050 """1051 1052 # FIXME: Not tracking data set name on loading ==> NECESSARY!1053 model_map = {}1054 if fit.fit_panel.sim_page is None:1055 fit.fit_panel.add_sim_page()1056 sim_page = fit.fit_panel.sim_page1057 1058 # Process each model and associate old M# with new M#1059 i = 01060 for model in sim_page.model_list:1061 model_id = self._format_id(model[1].keys()[0])1062 for saved_model in self.model_list:1063 save_id = saved_model.pop('name')1064 saved_model['name'] = save_id1065 save_id = self._format_id(save_id)1066 if save_id == model_id:1067 model_map[saved_model.pop('fit_page_source')] = \1068 model[3].name1069 check = bool(saved_model.pop('checked'))1070 sim_page.model_list[i][0].SetValue(check)1071 continue1072 i += 11073 sim_page.check_model_name(None)1074 1075 if len(self.constraints_list) > 0:1076 sim_page.hide_constraint.SetValue(False)1077 sim_page.show_constraint.SetValue(True)1078 sim_page._display_constraint(None)1079 1080 for index, item in enumerate(self.constraints_list):1081 model_cbox = item.pop('model_cbox')1082 constraint_value = item.pop('constraint')1083 param = item.pop('param_cbox')1084 equality = item.pop('egal_txt')1085 for key, value in model_map.iteritems():1086 model_cbox.replace(key, value)1087 constraint_value.replace(key, value)1088 1089 sim_page.constraints_list[index][0].SetValue(model_cbox)1090 sim_page._on_select_model(None)1091 sim_page.constraints_list[index][1].SetValue(param)1092 sim_page.constraints_list[index][2].SetLabel(equality)1093 sim_page.constraints_list[index][3].SetValue(constraint_value)1094 sim_page._on_add_constraint(None)1095 1096 def _format_id(self, original_id):1097 original_id = original_id.rstrip('1234567890.')1098 new_id_list = original_id.split()1099 new_id = ' '.join(new_id_list)1100 return new_id
Note: See TracChangeset
for help on using the changeset viewer.