Changeset d7b4decd in sasview
- Timestamp:
- Oct 27, 2015 4:11:12 PM (9 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:
- 40c69b3
- Parents:
- 88d7032
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/fitting/simfitpage.py
r6f16e25 rd7b4decd 2 2 Simultaneous fit page 3 3 """ 4 import sys, re, string, wx 4 import sys 5 from collections import namedtuple 6 7 import wx 5 8 import wx.lib.newevent 9 from wx.lib.scrolledpanel import ScrolledPanel 10 6 11 from sas.guiframe.events import StatusEvent 7 12 from sas.guiframe.panel_base import PanelBase 8 from wx.lib.scrolledpanel import ScrolledPanel9 13 from sas.guiframe.events import PanelOnFocusEvent 14 from sas.guiframe.utils import IdList 15 10 16 #Control panel width 11 17 if sys.platform.count("darwin") == 0: … … 17 23 18 24 25 # Each constraint requires five widgets and sizer. Package them in 26 # a named tuple for easy access. 27 ConstraintLine = namedtuple('ConstraintLine', 28 'model_cbox param_cbox egal_txt constraint btRemove sizer') 29 19 30 def get_fittableParam(model): 20 31 """ … … 34 45 35 46 return fittable_param 36 37 47 38 48 class SimultaneousFitPage(ScrolledPanel, PanelBase): … … 47 57 window_caption = "Simultaneous Fit Page" 48 58 ID_SET_ALL = wx.NewId() 49 ID_REMOVE = wx.NewId()50 59 ID_FIT = wx.NewId() 51 60 ID_ADD = wx.NewId() 52 53 def __init__(self, parent, page_finder={}, id= wx.ID_ANY, batch_on=False, 54 *args, **kwargs): 61 _id_pool = IdList() 62 63 def __init__(self, parent, page_finder={}, id=wx.ID_ANY, batch_on=False, 64 *args, **kwargs): 55 65 ScrolledPanel.__init__(self, parent, id=id, 56 66 style=wx.FULL_REPAINT_ON_RESIZE, … … 60 70 Simultaneous page display 61 71 """ 72 self._ids = iter(self._id_pool) 62 73 self.SetupScrolling() 63 74 ##Font size … … 129 140 if len(self.constraints_list) == 0: 130 141 return 142 wx.CallAfter(self._remove_after, event.GetId()) 143 #self._onAdd_constraint(None) 144 145 def _remove_after(self, id): 131 146 for item in self.constraints_list: 132 length = len(item) 133 if event.GetId() == item[length - 2].GetId(): 134 sizer = item[length - 1] 135 sizer.Clear(True) 136 self.sizer_constraints.Remove(sizer) 137 #self.SetScrollbars(20,20,25,65) 147 if id == item.btRemove.GetId(): 148 self.sizer_constraints.Hide(item.sizer) 149 item.sizer.Clear(True) 150 self.sizer_constraints.Remove(item.sizer) 151 ##self.SetScrollbars(20,20,25,65) 138 152 self.constraints_list.remove(item) 139 153 self.nb_constraint -= 1 … … 141 155 self.Layout() 142 156 break 143 144 #self._onAdd_constraint(None)145 157 146 158 def onFit(self, event): … … 198 210 if not self.batch_on: 199 211 ## display constraint fields 200 if self.show_constraint.GetValue() and\201 len(self.constraints_list) == 0 :212 if (self.show_constraint.GetValue() and 213 len(self.constraints_list) == 0): 202 214 self._show_all_constraint() 203 215 self._show_constraint() … … 206 218 item[0].SetValue(False) 207 219 208 self.model_toFit = []209 220 if not self.batch_on: 210 221 ##constraint info … … 255 266 Update easy setup combobox on selecting a model 256 267 """ 257 if self.model_cbox_left != None and self.model_cbox_right != None: 258 try: 259 # when there is something 260 self.model_cbox_left.Clear() 261 self.model_cbox_right.Clear() 262 self.model_cbox.Clear() 263 except: 264 # when there is nothing 265 pass 266 #for id, model in self.constraint_dict.iteritems(): 267 for item in self.model_toFit: 268 model = item[3] 269 ## check if all parameters have been selected for constraint 270 ## then do not allow add constraint on parameters 271 if str(model.name) not in self.model_cbox_left.GetItems(): 272 self.model_cbox_left.Append(str(model.name), model) 273 if str(model.name) not in self.model_cbox_right.GetItems(): 274 self.model_cbox_right.Append(str(model.name), model) 275 if str(model.name) not in self.model_cbox.GetItems(): 276 self.model_cbox.Append(str(model.name), model) 268 if self.model_cbox_left == None or self.model_cbox_right == None: 269 return 270 271 models = [(item[3].name, item[3]) for item in self.model_toFit] 272 setComboBoxItems(self.model_cbox_left, models) 273 setComboBoxItems(self.model_cbox_right, models) 274 for item in self.constraints_list: 275 setComboBoxItems(item[0], models) 276 if self.model_cbox_left.GetSelection() == wx.NOT_FOUND: 277 277 self.model_cbox_left.SetSelection(0) 278 279 278 self.sizer2.Layout() 279 self.sizer3.Layout() 280 280 281 281 def draw_page(self): … … 402 402 boxsizer.Add(self.model_cbox_left, 403 403 flag=wx.RIGHT | wx.EXPAND, border=10) 404 boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"),405 flag=wx.RIGHT | wx.EXPAND, border=5)404 #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 405 # flag=wx.RIGHT | wx.EXPAND, border=5) 406 406 boxsizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 407 407 boxsizer.Add(self.model_cbox_right, 408 408 flag=wx.RIGHT | wx.EXPAND, border=10) 409 boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"),410 flag=wx.RIGHT | wx.EXPAND, border=5)409 #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 410 # flag=wx.RIGHT | wx.EXPAND, border=5) 411 411 boxsizer.Add((20, -1)) 412 412 boxsizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5) … … 430 430 if self.model_cbox_right.GetValue().strip() == '': 431 431 flag = False 432 if self.model_cbox_left.GetValue() == \433 self.model_cbox_right.GetValue() :432 if (self.model_cbox_left.GetValue() == 433 self.model_cbox_right.GetValue()): 434 434 flag = False 435 435 self.set_button.Enable(flag) … … 463 463 num_cbox += 1 464 464 if param in param_listB: 465 self.model_cbox.SetStringSelection(model_left) 465 item = self.constraints_list[-1] 466 item.model_cbox.SetStringSelection(model_left) 466 467 self._on_select_model(None) 467 self.param_cbox.Clear()468 self.param_cbox.Append(str(param), model)469 self.param_cbox.SetStringSelection(str(param))470 self.ctl2.SetValue(str(model_right + "." + str(param)))468 item.param_cbox.Clear() 469 item.param_cbox.Append(str(param), model) 470 item.param_cbox.SetStringSelection(str(param)) 471 item.constraint.SetValue(str(model_right + "." + str(param))) 471 472 has_param = True 472 473 if num_cbox == (len(param_list) + 1): … … 499 500 ##Don't add anymore 500 501 if len(self.constraints_list) == nb_fit_param: 501 msg = "Cannot add another constraint .Maximum of number "502 msg = "Cannot add another constraint. Maximum of number " 502 503 msg += "Parameters name reached %s" % str(nb_fit_param) 503 504 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) … … 513 514 514 515 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 516 517 # Model list 515 518 model_cbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 516 519 model_cbox.Clear() 517 param_cbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY, size=(100, -1),)518 param_cbox.Hide()519 520 #This is for GetCLientData() _on_select_param: Was None return on MAC.521 self.param_cbox = param_cbox522 523 wx.EVT_COMBOBOX(param_cbox, wx.ID_ANY, self._on_select_param)524 self.ctl2 = wx.TextCtrl(self, wx.ID_ANY)525 egal_txt = wx.StaticText(self, wx.ID_ANY, " = ")526 self.btRemove = wx.Button(self, self.ID_REMOVE, 'Remove')527 self.btRemove.Bind(wx.EVT_BUTTON, self.onRemove,528 id=self.btRemove.GetId())529 self.btRemove.SetToolTipString("Remove constraint.")530 self.btRemove.Hide()531 if hasattr(self, "btAdd"):532 self.btAdd.Hide()533 520 for id, model in self.constraint_dict.iteritems(): 534 521 ## check if all parameters have been selected for constraint 535 522 ## then do not allow add constraint on parameters 536 523 model_cbox.Append(str(model.name), model) 537 538 #This is for GetCLientData() passing to self._on_select_param: Was None return on MAC.539 self.model_cbox = model_cbox540 541 524 wx.EVT_COMBOBOX(model_cbox, wx.ID_ANY, self._on_select_model) 542 sizer_constraint.Add((5, wx.ID_ANY)) 525 526 # Parameters in model 527 param_cbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY, 528 size=(100, -1)) 529 param_cbox.Hide() 530 wx.EVT_COMBOBOX(param_cbox, wx.ID_ANY, self._on_select_param) 531 532 egal_txt = wx.StaticText(self, wx.ID_ANY, " = ") 533 534 # Parameter constraint 535 constraint = wx.TextCtrl(self, wx.ID_ANY) 536 537 # Remove button 538 #btRemove = wx.Button(self, self.ID_REMOVE, 'Remove') 539 btRemove = wx.Button(self, self._ids.next(), 'Remove') 540 btRemove.Bind(wx.EVT_BUTTON, self.onRemove, 541 id=btRemove.GetId()) 542 btRemove.SetToolTipString("Remove constraint.") 543 btRemove.Hide() 544 545 # Hid the add button, if it exists 546 if hasattr(self, "btAdd"): 547 self.btAdd.Hide() 548 549 sizer_constraint.Add((5, -1)) 543 550 sizer_constraint.Add(model_cbox, flag=wx.RIGHT | wx.EXPAND, border=10) 544 551 sizer_constraint.Add(param_cbox, flag=wx.RIGHT | wx.EXPAND, border=5) 545 552 sizer_constraint.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 546 sizer_constraint.Add( self.ctl2, flag=wx.RIGHT | wx.EXPAND, border=10)547 sizer_constraint.Add( self.btRemove, flag=wx.RIGHT | wx.EXPAND, border=10)553 sizer_constraint.Add(constraint, flag=wx.RIGHT | wx.EXPAND, border=10) 554 sizer_constraint.Add(btRemove, flag=wx.RIGHT | wx.EXPAND, border=10) 548 555 549 556 self.sizer_constraints.Insert(before=self.nb_constraint, 550 item=sizer_constraint, flag=wx.TOP | wx.BOTTOM | wx.EXPAND, 551 border=5) 552 self.constraints_list.append([model_cbox, param_cbox, egal_txt, 553 self.ctl2, self.btRemove, sizer_constraint]) 557 item=sizer_constraint, flag=wx.TOP | wx.BOTTOM | wx.EXPAND, 558 border=5) 559 c = ConstraintLine(model_cbox, param_cbox, egal_txt, 560 constraint, btRemove, sizer_constraint) 561 self.constraints_list.append(c) 554 562 555 563 self.nb_constraint += 1 … … 561 569 hide buttons related constraint 562 570 """ 563 for id in 571 for id in self.page_finder.iterkeys(): 564 572 self.page_finder[id].clear_model_param() 565 573 … … 569 577 self.btAdd.Hide() 570 578 self._store_model() 571 if self.model_cbox_left != None: 572 try: 573 self.model_cbox_left.Clear() 574 except: 575 pass 579 if self.model_cbox_left is not None: 580 self.model_cbox_left.Clear() 576 581 self.model_cbox_left = None 577 if self.model_cbox_right != None: 578 try: 579 self.model_cbox_right.Clear() 580 except: 581 pass 582 if self.model_cbox_right is not None: 583 self.model_cbox_right.Clear() 582 584 self.model_cbox_right = None 583 585 self.constraints_list = [] … … 592 594 fill combox box with list of parameters 593 595 """ 596 if not self.constraints_list: 597 return 598 599 ##This way PC/MAC both work, instead of using event.GetClientData(). 600 model_cbox = self.constraints_list[-1].model_cbox 601 n = model_cbox.GetCurrentSelection() 602 if n == wx.NOT_FOUND: 603 return 604 605 model = model_cbox.GetClientData(n) 594 606 param_list = [] 595 ##This way PC/MAC both work, instead of using event.GetClientData().596 n = self.model_cbox.GetCurrentSelection()597 model = self.model_cbox.GetClientData(n)598 607 for id, dic_model in self.constraint_dict.iteritems(): 599 608 if model == dic_model: 600 609 param_list = self.page_finder[id].get_param2fit() 601 #break 602 length = len(self.constraints_list) 603 if length < 1: 604 return 605 param_cbox = self.constraints_list[length - 1][1] 610 break 611 612 param_cbox = self.constraints_list[-1].param_cbox 606 613 param_cbox.Clear() 607 614 ## insert only fittable paramaters 608 615 for param in param_list: 609 616 param_cbox.Append(str(param), model) 610 611 617 param_cbox.Show(True) 612 self.btRemove.Show(True) 618 619 btRemove = self.constraints_list[-1].btRemove 620 btRemove.Show(True) 613 621 self.btAdd.Show(True) 614 622 self.sizer2.Layout() … … 623 631 #param = event.GetString() 624 632 625 length = len(self.constraints_list) 626 if length < 1: 627 return 628 egal_txt = self.constraints_list[length - 1][2] 629 egal_txt.Show(True) 630 631 ctl2 = self.constraints_list[length - 1][3] 632 ctl2.Show(True) 633 if self.constraints_list: 634 self.constraints_list[-1].egal_txt.Show(True) 635 self.constraints_list[-1].constraint.Show(True) 633 636 634 637 def _onAdd_constraint(self, event): … … 643 646 # before allow to add another constraint 644 647 for item in self.constraints_list: 645 model_cbox = item[0] 646 if model_cbox.GetString(0) == "": 648 if item.model_cbox.GetString(0) == "": 647 649 msg = " Select a model Name! " 648 650 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 649 651 return 650 param_cbox = item[1] 651 if param_cbox.GetString(0) == "": 652 if item.param_cbox.GetString(0) == "": 652 653 msg = " Select a parameter Name! " 653 654 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 654 655 return 655 ctl2 = item[3] 656 if ctl2.GetValue().lstrip().rstrip() == "": 657 model = param_cbox.GetClientData(\ 658 param_cbox.GetCurrentSelection()) 656 if item.constraint.GetValue().lstrip().rstrip() == "": 657 model = item.param_cbox.GetClientData( 658 item.param_cbox.GetCurrentSelection()) 659 659 if model != None: 660 660 msg = " Enter a constraint for %s.%s! " % (model.name, 661 661 item.param_cbox.GetString(0)) 662 662 else: 663 663 msg = " Enter a constraint" 664 664 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 665 665 return … … 746 746 text_hint = wx.StaticText(self, wx.ID_ANY, 747 747 "Example: [M0][paramter] = M1.parameter") 748 sizer_button.Add(text_hint, 0 , wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 749 sizer_button.Add(self.btAdd, 0, wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 748 sizer_button.Add(text_hint, 0, 749 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 750 sizer_button.Add(self.btAdd, 0, 751 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 750 752 751 753 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) … … 770 772 """ 771 773 for item in self.constraints_list: 772 select0 = item [0].GetSelection()774 select0 = item.model_cbox.GetSelection() 773 775 if select0 == wx.NOT_FOUND: 774 776 continue 775 model = item [0].GetClientData(select0)776 select1 = item [1].GetSelection()777 model = item.model_cbox.GetClientData(select0) 778 select1 = item.param_cbox.GetSelection() 777 779 if select1 == wx.NOT_FOUND: 778 780 continue 779 param = item [1].GetString(select1)780 constraint = item [3].GetValue().lstrip().rstrip()781 param = item.param_cbox.GetString(select1) 782 constraint = item.constraint.GetValue().lstrip().rstrip() 781 783 if param.lstrip().rstrip() == "": 782 784 param = None … … 811 813 # wrap in param/constraint in str() to remove unicode 812 814 self.page_finder[id].set_model_param(str(param), 813 815 str(constraint), fid=fid) 814 816 break 815 817 return True … … 847 849 tab_used.SetForegroundColour(wx.WHITE) 848 850 sizer.Add(tab_used, (iy, ix), (1, 1), 849 851 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 850 852 for id, value in self.page_finder.iteritems(): 851 853 if id not in self.parent.opened_pages: … … 886 888 cb.Enable(model is not None and data.is_data) 887 889 sizer.Add(cb, (iy, ix), (1, 1), 888 890 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 889 891 wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name) 890 892 ix += 2 891 type = model.__class__.__name__892 model_type = wx.StaticText(self, wx.ID_ANY, str(type))893 model_type = wx.StaticText(self, wx.ID_ANY, 894 model.__class__.__name__) 893 895 sizer.Add(model_type, (iy, ix), (1, 1), 894 896 wx.EXPAND | wx.ADJUST_MINSIZE, 0) … … 924 926 wx.PostEvent(self.parent.parent, PanelOnFocusEvent(panel=self)) 925 927 self.page_finder = self.parent._manager.get_page_finder() 928 929 930 def setComboBoxItems(cbox, items): 931 assert isinstance(cbox, wx.ComboBox) 932 selected = cbox.GetStringSelection() 933 cbox.Clear() 934 for k, (name, value) in enumerate(items): 935 cbox.Append(name, value) 936 cbox.SetStringSelection(selected)
Note: See TracChangeset
for help on using the changeset viewer.