Changes in src/sas/perspectives/fitting/simfitpage.py [662d8d87:acf8e4a5] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/fitting/simfitpage.py
r662d8d87 racf8e4a5 2 2 Simultaneous fit page 3 3 """ 4 import sys 5 from collections import namedtuple 6 7 import wx 4 import sys, re, string, wx 8 5 import wx.lib.newevent 9 from wx.lib.scrolledpanel import ScrolledPanel10 11 6 from sas.guiframe.events import StatusEvent 12 7 from sas.guiframe.panel_base import PanelBase 8 from wx.lib.scrolledpanel import ScrolledPanel 13 9 from sas.guiframe.events import PanelOnFocusEvent 14 from sas.guiframe.utils import IdList15 from sas.guiframe.documentation_window import DocumentationWindow16 17 10 #Control panel width 18 11 if sys.platform.count("darwin") == 0: … … 24 17 25 18 26 # Each constraint requires five widgets and sizer. Package them in27 # a named tuple for easy access.28 ConstraintLine = namedtuple('ConstraintLine',29 'model_cbox param_cbox egal_txt constraint btRemove sizer')30 31 19 def get_fittableParam(model): 32 20 """ 33 return list of fittable parameters froma model21 return list of fittable parameters name of a model 34 22 35 23 :param model: the model used … … 46 34 47 35 return fittable_param 36 48 37 49 38 class SimultaneousFitPage(ScrolledPanel, PanelBase): … … 57 46 ## Title to appear on top of the window 58 47 window_caption = "Simultaneous Fit Page" 59 ID_DOC = wx.NewId() 60 ID_SET_ALL = wx.NewId() 61 ID_FIT = wx.NewId() 62 ID_ADD = wx.NewId() 63 _id_pool = IdList() 64 65 def __init__(self, parent, page_finder={}, id=wx.ID_ANY, batch_on=False, 66 *args, **kwargs): 48 49 def __init__(self, parent, page_finder={}, id= -1, batch_on=False, 50 *args, **kwargs): 67 51 ScrolledPanel.__init__(self, parent, id=id, 68 52 style=wx.FULL_REPAINT_ON_RESIZE, … … 72 56 Simultaneous page display 73 57 """ 74 self._ids = iter(self._id_pool)75 58 self.SetupScrolling() 76 59 ##Font size … … 81 64 ## store page_finder 82 65 self.page_finder = page_finder 83 ## list conta ining info to set constraint66 ## list contaning info to set constraint 84 67 ## look like self.constraint_dict[page_id]= page 85 68 self.constraint_dict = {} 86 69 ## item list 87 # #self.constraints_list=[combobox1, combobox2,=,textcrtl, button ]70 # self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 88 71 self.constraints_list = [] 89 72 ## list of current model … … 95 78 self.model_cbox_left = None 96 79 self.model_cbox_right = None 80 self.uid = wx.NewId() 97 81 ## draw page 98 82 self.define_page_structure() 99 83 self.draw_page() 84 self.set_layout() 100 85 self._set_save_flag(False) 101 86 102 87 def define_page_structure(self): 103 88 """ 104 Create empty sizer s, their hierarchy and set the sizer for thepanel89 Create empty sizer for a panel 105 90 """ 106 91 self.vbox = wx.BoxSizer(wx.VERTICAL) … … 115 100 self.vbox.Add(self.sizer2) 116 101 self.vbox.Add(self.sizer3) 102 103 def set_scroll(self): 104 """ 105 """ 106 self.Layout() 107 108 def set_layout(self): 109 """ 110 layout 111 """ 112 self.vbox.Layout() 113 self.vbox.Fit(self) 117 114 self.SetSizer(self.vbox) 115 self.set_scroll() 118 116 self.Centre() 119 120 def draw_page(self):121 """122 Construct the Simultaneous/Constrained fit page. fills the first123 region (sizer1) with the list of available fit page pairs of data124 and models. Then fills sizer2 with the checkbox for adding125 constraints, and finally fills sizer3 with the fit button and126 instructions.127 """128 129 # create blank list of constraints130 self.model_list = []131 self.model_toFit = []132 self.constraints_list = []133 self.constraint_dict = {}134 self.nb_constraint = 0135 self.model_cbox_left = None136 self.model_cbox_right = None137 138 if len(self.model_list) > 0:139 for item in self.model_list:140 item[0].SetValue(False)141 self.manager.schedule_for_fit(value=0, uid=item[2])142 143 #-------------------------------------------------------144 ## setup sizer1 (which fitpages to include)145 self.sizer1.Clear(True)146 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Combinations")147 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)148 sizer_title = wx.BoxSizer(wx.HORIZONTAL)149 sizer_couples = wx.GridBagSizer(5, 5)150 151 #This if statement should be obsolete and can be removed in version 4152 #Leave it here for now as no time to thoroughly test. However if no153 #fit page is found the menu item that calls this page is inactive154 # Nov. 22 2015 --PDB155 if len(self.page_finder) == 0:156 msg = " No fit combinations are found! \n\n"157 msg += " Please load data and set up "158 msg += "at least one fit panels first..."159 sizer_title.Add(wx.StaticText(self, wx.ID_ANY, msg))160 else:161 ## store model162 self._store_model()163 164 self.cb1 = wx.CheckBox(self, wx.ID_ANY, 'Select all')165 self.cb1.SetValue(False)166 wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.check_all_model_name)167 168 sizer_title.Add((10, 10), 0,169 wx.TOP | wx.BOTTOM | wx.EXPAND | wx.ADJUST_MINSIZE, border=5)170 sizer_title.Add(self.cb1, 0,171 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, border=5)172 173 ## draw list of model and data names174 self._fill_sizer_model_list(sizer_couples)175 176 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=5)177 boxsizer1.Add(sizer_couples, 1, flag=wx.TOP | wx.BOTTOM, border=5)178 self.sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10)179 # self.sizer1.Layout()180 181 #--------------------------------------------------------182 ## set up the other 2 sizers: the constraints list and the183 ## buttons (fit, help etc) sizer at the bottom of the page.184 ## Note: the if statement should be removed along with the above185 ## if statement as soon as it can be properly tested.186 ## Nov. 22 2015 --PDB187 if len(self.page_finder) > 0:188 ## draw the sizer containing constraint info189 if not self.batch_on:190 self._fill_sizer_constraint()191 ## draw fit button sizer192 self._fill_sizer_fit()193 194 195 def _fill_sizer_model_list(self, sizer):196 """197 Receive a dictionary containing information to display model name198 """199 ix = 0200 iy = 0201 list = []202 sizer.Clear(True)203 204 new_name = wx.StaticText(self, wx.ID_ANY, ' Model Title ',205 style=wx.ALIGN_CENTER)206 new_name.SetBackgroundColour('orange')207 new_name.SetForegroundColour(wx.WHITE)208 sizer.Add(new_name, (iy, ix), (1, 1),209 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)210 ix += 2211 model_type = wx.StaticText(self, wx.ID_ANY, ' Model ')212 model_type.SetBackgroundColour('grey')213 model_type.SetForegroundColour(wx.WHITE)214 sizer.Add(model_type, (iy, ix), (1, 1),215 wx.EXPAND | wx.ADJUST_MINSIZE, 0)216 ix += 1217 data_used = wx.StaticText(self, wx.ID_ANY, ' Data ')218 data_used.SetBackgroundColour('grey')219 data_used.SetForegroundColour(wx.WHITE)220 sizer.Add(data_used, (iy, ix), (1, 1),221 wx.EXPAND | wx.ADJUST_MINSIZE, 0)222 ix += 1223 tab_used = wx.StaticText(self, wx.ID_ANY, ' FitPage ')224 tab_used.SetBackgroundColour('grey')225 tab_used.SetForegroundColour(wx.WHITE)226 sizer.Add(tab_used, (iy, ix), (1, 1),227 wx.EXPAND | wx.ADJUST_MINSIZE, 0)228 for id, value in self.page_finder.iteritems():229 if id not in self.parent.opened_pages:230 continue231 232 if self.batch_on != self.parent.get_page_by_id(id).batch_on:233 continue234 235 data_list = []236 model_list = []237 # get data name and model objetta238 for fitproblem in value.get_fit_problem():239 240 data = fitproblem.get_fit_data()241 if not data.is_data:242 continue243 name = '-'244 if data is not None and data.is_data:245 name = str(data.name)246 data_list.append(name)247 248 model = fitproblem.get_model()249 if model is None:250 continue251 model_list.append(model)252 253 if len(model_list) == 0:254 continue255 # Draw sizer256 ix = 0257 iy += 1258 model = model_list[0]259 name = '_'260 if model is not None:261 name = str(model.name)262 cb = wx.CheckBox(self, wx.ID_ANY, name)263 cb.SetValue(False)264 cb.Enable(model is not None and data.is_data)265 sizer.Add(cb, (iy, ix), (1, 1),266 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)267 wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name)268 ix += 2269 model_type = wx.StaticText(self, wx.ID_ANY,270 model.__class__.__name__)271 sizer.Add(model_type, (iy, ix), (1, 1),272 wx.EXPAND | wx.ADJUST_MINSIZE, 0)273 if self.batch_on:274 data_used = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY)275 data_used.AppendItems(data_list)276 data_used.SetSelection(0)277 else:278 data_used = wx.StaticText(self, wx.ID_ANY, data_list[0])279 280 ix += 1281 sizer.Add(data_used, (iy, ix), (1, 1),282 wx.EXPAND | wx.ADJUST_MINSIZE, 0)283 ix += 1284 caption = value.get_fit_tab_caption()285 tab_caption_used = wx.StaticText(self, wx.ID_ANY, str(caption))286 sizer.Add(tab_caption_used, (iy, ix), (1, 1),287 wx.EXPAND | wx.ADJUST_MINSIZE, 0)288 289 self.model_list.append([cb, value, id, model])290 291 iy += 1292 sizer.Add((20, 20), (iy, ix), (1, 1),293 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)294 295 def _fill_sizer_constraint(self):296 """297 Fill sizer containing constraint info298 """299 msg = "Select at least 1 model to add constraint "300 wx.PostEvent(self.parent.parent, StatusEvent(status=msg))301 302 self.sizer2.Clear(True)303 if self.batch_on:304 if self.sizer2.IsShown():305 self.sizer2.Show(False)306 return307 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Constraints")308 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)309 sizer_title = wx.BoxSizer(wx.HORIZONTAL)310 self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL)311 self.sizer_constraints = wx.BoxSizer(wx.VERTICAL)312 sizer_button = wx.BoxSizer(wx.HORIZONTAL)313 314 self.hide_constraint = wx.RadioButton(self, wx.ID_ANY, 'No', (10, 10),315 style=wx.RB_GROUP)316 self.show_constraint = wx.RadioButton(self, wx.ID_ANY, 'Yes', (10, 30))317 self.Bind(wx.EVT_RADIOBUTTON, self._display_constraint,318 id=self.hide_constraint.GetId())319 self.Bind(wx.EVT_RADIOBUTTON, self._display_constraint,320 id=self.show_constraint.GetId())321 if self.batch_on:322 self.hide_constraint.Enable(False)323 self.show_constraint.Enable(False)324 self.hide_constraint.SetValue(True)325 self.show_constraint.SetValue(False)326 327 sizer_title.Add(wx.StaticText(self, wx.ID_ANY, " Model"))328 sizer_title.Add((10, 10))329 sizer_title.Add(wx.StaticText(self, wx.ID_ANY, " Parameter"))330 sizer_title.Add((10, 10))331 sizer_title.Add(wx.StaticText(self, wx.ID_ANY, " Add Constraint?"))332 sizer_title.Add((10, 10))333 sizer_title.Add(self.show_constraint)334 sizer_title.Add(self.hide_constraint)335 sizer_title.Add((10, 10))336 337 self.btAdd = wx.Button(self, self.ID_ADD, 'Add')338 self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint,339 id=self.btAdd.GetId())340 self.btAdd.SetToolTipString("Add another constraint?")341 self.btAdd.Hide()342 343 text_hint = wx.StaticText(self, wx.ID_ANY,344 "Example: [M0][paramter] = M1.parameter")345 sizer_button.Add(text_hint, 0,346 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10)347 sizer_button.Add(self.btAdd, 0,348 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10)349 350 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10)351 boxsizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM,352 border=10)353 boxsizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM,354 border=10)355 boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10)356 357 self.sizer2.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10)358 359 360 def _fill_sizer_fit(self):361 """362 Draw fit button363 """364 self.sizer3.Clear(True)365 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit ")366 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)367 sizer_button = wx.BoxSizer(wx.HORIZONTAL)368 369 #Fit button370 self.btFit = wx.Button(self, self.ID_FIT, 'Fit', size=wx.DefaultSize)371 self.btFit.Bind(wx.EVT_BUTTON, self.onFit, id=self.btFit.GetId())372 self.btFit.SetToolTipString("Perform fit.")373 374 #General Help button375 self.btHelp = wx.Button(self, wx.ID_HELP, 'HELP')376 self.btHelp.SetToolTipString("Simultaneous/Constrained Fitting help.")377 self.btHelp.Bind(wx.EVT_BUTTON, self._onHelp)378 379 #hint text on button line380 if self.batch_on:381 text = " Fit in Parallel all Data sets\n"382 text += "and model selected."383 else:384 text = " At least one set of model and data\n"385 text += " must be selected for fitting."386 text_hint = wx.StaticText(self, wx.ID_ANY, text)387 388 sizer_button.Add(text_hint)389 sizer_button.Add(self.btFit, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10)390 sizer_button.Add(self.btHelp, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10)391 392 boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10)393 self.sizer3.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10)394 117 395 118 def onRemove(self, event): … … 403 126 if len(self.constraints_list) == 0: 404 127 return 405 wx.CallAfter(self._remove_after, event.GetId())406 #self._onAdd_constraint(None)407 408 def _remove_after(self, id):409 128 for item in self.constraints_list: 410 if id == item.btRemove.GetId(): 411 self.sizer_constraints.Hide(item.sizer) 412 item.sizer.Clear(True) 413 self.sizer_constraints.Remove(item.sizer) 129 length = len(item) 130 if event.GetId() == item[length - 2].GetId(): 131 sizer = item[length - 1] 132 sizer.Clear(True) 133 self.sizer_constraints.Remove(sizer) 134 #self.SetScrollbars(20,20,25,65) 414 135 self.constraints_list.remove(item) 415 136 self.nb_constraint -= 1 416 137 self.sizer2.Layout() 417 self. FitInside()138 self.Layout() 418 139 break 140 141 #self._onAdd_constraint(None) 419 142 420 143 def onFit(self, event): … … 448 171 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 449 172 450 def _onHelp(self, event):451 """452 Bring up the simultaneous Fitting Documentation whenever the HELP453 button is clicked.454 455 Calls DocumentationWindow with the path of the location within the456 documentation tree (after /doc/ ....". Note that when using old457 versions of Wx (before 2.9) and thus not the release version of458 installers, the help comes up at the top level of the file as459 webbrowser does not pass anything past the # to the browser when it is460 running "file:///...."461 462 :param evt: Triggers on clicking the help button463 """464 _TreeLocation = "user/perspectives/fitting/fitting_help.html"465 _PageAnchor = "#simultaneous-fit-mode"466 _doc_viewer = DocumentationWindow(self, self.ID_DOC, _TreeLocation,467 _PageAnchor,468 "Simultaneous/Constrained Fitting Help")469 470 173 def set_manager(self, manager): 471 174 """ … … 492 195 if not self.batch_on: 493 196 ## display constraint fields 494 if (self.show_constraint.GetValue() and495 len(self.constraints_list) == 0 ):197 if self.show_constraint.GetValue() and\ 198 len(self.constraints_list) == 0: 496 199 self._show_all_constraint() 497 200 self._show_constraint() … … 500 203 item[0].SetValue(False) 501 204 205 self.model_toFit = [] 502 206 if not self.batch_on: 503 207 ##constraint info … … 505 209 506 210 self._update_easy_setup_cb() 507 self. FitInside()508 211 self.Layout() 212 self.Refresh() 509 213 510 214 def check_model_name(self, event): … … 538 242 if len(self.model_list) == len(self.model_toFit): 539 243 self.cb1.SetValue(True) 540 self. FitInside()244 self.Layout() 541 245 return 542 246 else: 543 247 self.cb1.SetValue(False) 544 self. FitInside()248 self.Layout() 545 249 546 250 def _update_easy_setup_cb(self): … … 548 252 Update easy setup combobox on selecting a model 549 253 """ 550 if self.model_cbox_left == None or self.model_cbox_right == None: 551 return 552 553 models = [(item[3].name, item[3]) for item in self.model_toFit] 554 setComboBoxItems(self.model_cbox_left, models) 555 setComboBoxItems(self.model_cbox_right, models) 556 for item in self.constraints_list: 557 setComboBoxItems(item[0], models) 558 if self.model_cbox_left.GetSelection() == wx.NOT_FOUND: 254 if self.model_cbox_left != None and self.model_cbox_right != None: 255 try: 256 # when there is something 257 self.model_cbox_left.Clear() 258 self.model_cbox_right.Clear() 259 self.model_cbox.Clear() 260 except: 261 # when there is nothing 262 pass 263 #for id, model in self.constraint_dict.iteritems(): 264 for item in self.model_toFit: 265 model = item[3] 266 ## check if all parameters have been selected for constraint 267 ## then do not allow add constraint on parameters 268 if str(model.name) not in self.model_cbox_left.GetItems(): 269 self.model_cbox_left.Append(str(model.name), model) 270 if str(model.name) not in self.model_cbox_right.GetItems(): 271 self.model_cbox_right.Append(str(model.name), model) 272 if str(model.name) not in self.model_cbox.GetItems(): 273 self.model_cbox.Append(str(model.name), model) 559 274 self.model_cbox_left.SetSelection(0) 560 self.sizer2.Layout() 275 self.sizer2.Layout() 276 self.sizer3.Layout() 277 278 def draw_page(self): 279 """ 280 Draw a sizer containing couples of data and model 281 """ 282 self.model_list = [] 283 self.model_toFit = [] 284 self.constraints_list = [] 285 self.constraint_dict = {} 286 self.nb_constraint = 0 287 self.model_cbox_left = None 288 self.model_cbox_right = None 289 290 if len(self.model_list) > 0: 291 for item in self.model_list: 292 item[0].SetValue(False) 293 self.manager.schedule_for_fit(value=0, uid=item[2]) 294 295 self.sizer1.Clear(True) 296 box_description = wx.StaticBox(self, -1, "Fit Combinations") 297 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 298 sizer_title = wx.BoxSizer(wx.HORIZONTAL) 299 sizer_couples = wx.GridBagSizer(5, 5) 300 #------------------------------------------------------ 301 if len(self.page_finder) == 0: 302 msg = " No fit combinations are found! \n\n" 303 msg += " Please load data and set up " 304 msg += "at least two fit panels first..." 305 sizer_title.Add(wx.StaticText(self, -1, msg)) 306 else: 307 ## store model 308 self._store_model() 309 310 self.cb1 = wx.CheckBox(self, -1, 'Select all') 311 self.cb1.SetValue(False) 312 313 wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.check_all_model_name) 314 315 sizer_title.Add((10, 10), 0, 316 wx.TOP | wx.BOTTOM | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 317 sizer_title.Add(self.cb1, 0, 318 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 319 320 ## draw list of model and data name 321 self._fill_sizer_model_list(sizer_couples) 322 ## draw the sizer containing constraint info 323 if not self.batch_on: 324 self._fill_sizer_constraint() 325 ## draw fit button 326 self._fill_sizer_fit() 327 #-------------------------------------------------------- 328 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=5) 329 boxsizer1.Add(sizer_couples, 1, flag=wx.TOP | wx.BOTTOM, border=5) 330 331 self.sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10) 332 self.sizer1.Layout() 333 #self.SetScrollbars(20,20,25,65) 334 self.AdjustScrollbars() 335 self.Layout() 561 336 562 337 def _store_model(self): … … 584 359 self._show_all_constraint() 585 360 self._show_constraint() 586 self. FitInside()361 self.Layout() 587 362 return 588 363 else: 589 364 self._hide_constraint() 365 self.Layout() 590 366 return 591 367 … … 594 370 Show constraint fields 595 371 """ 596 box_description = wx.StaticBox(self, wx.ID_ANY, "Easy Setup ")372 box_description = wx.StaticBox(self, -1, "Easy Setup ") 597 373 boxsizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL) 598 374 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 599 self.model_cbox_left = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY)375 self.model_cbox_left = wx.ComboBox(self, -1, style=wx.CB_READONLY) 600 376 self.model_cbox_left.Clear() 601 self.model_cbox_right = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY)377 self.model_cbox_right = wx.ComboBox(self, -1, style=wx.CB_READONLY) 602 378 self.model_cbox_right.Clear() 603 wx.EVT_COMBOBOX(self.model_cbox_left, wx.ID_ANY, self._on_select_modelcb)604 wx.EVT_COMBOBOX(self.model_cbox_right, wx.ID_ANY, self._on_select_modelcb)605 egal_txt = wx.StaticText(self, wx.ID_ANY, " = ")606 self.set_button = wx.Button(self, self.ID_SET_ALL, 'Set All')379 wx.EVT_COMBOBOX(self.model_cbox_left, -1, self._on_select_modelcb) 380 wx.EVT_COMBOBOX(self.model_cbox_right, -1, self._on_select_modelcb) 381 egal_txt = wx.StaticText(self, -1, " = ") 382 self.set_button = wx.Button(self, wx.NewId(), 'Set All') 607 383 self.set_button.Bind(wx.EVT_BUTTON, self._on_set_all_equal, 608 384 id=self.set_button.GetId()) … … 623 399 boxsizer.Add(self.model_cbox_left, 624 400 flag=wx.RIGHT | wx.EXPAND, border=10) 625 #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"),626 #flag=wx.RIGHT | wx.EXPAND, border=5)401 boxsizer.Add(wx.StaticText(self, -1, ".parameters"), 402 flag=wx.RIGHT | wx.EXPAND, border=5) 627 403 boxsizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 628 404 boxsizer.Add(self.model_cbox_right, 629 405 flag=wx.RIGHT | wx.EXPAND, border=10) 630 #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"),631 #flag=wx.RIGHT | wx.EXPAND, border=5)406 boxsizer.Add(wx.StaticText(self, -1, ".parameters"), 407 flag=wx.RIGHT | wx.EXPAND, border=5) 632 408 boxsizer.Add((20, -1)) 633 409 boxsizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5) … … 636 412 item=sizer_constraint, 637 413 flag=wx.TOP | wx.BOTTOM | wx.EXPAND, border=5) 638 self.FitInside() 414 415 self.sizer_all_constraints.Layout() 416 self.sizer2.Layout() 417 #self.SetScrollbars(20,20,25,65) 639 418 640 419 def _on_select_modelcb(self, event): … … 648 427 if self.model_cbox_right.GetValue().strip() == '': 649 428 flag = False 650 if (self.model_cbox_left.GetValue() ==651 self.model_cbox_right.GetValue() ):429 if self.model_cbox_left.GetValue() == \ 430 self.model_cbox_right.GetValue(): 652 431 flag = False 653 432 self.set_button.Enable(flag) … … 681 460 num_cbox += 1 682 461 if param in param_listB: 683 item = self.constraints_list[-1] 684 item.model_cbox.SetStringSelection(model_left) 462 self.model_cbox.SetStringSelection(model_left) 685 463 self._on_select_model(None) 686 item.param_cbox.Clear()687 item.param_cbox.Append(str(param), model)688 item.param_cbox.SetStringSelection(str(param))689 item.constraint.SetValue(str(model_right + "." + str(param)))464 self.param_cbox.Clear() 465 self.param_cbox.Append(str(param), model) 466 self.param_cbox.SetStringSelection(str(param)) 467 self.ctl2.SetValue(str(model_right + "." + str(param))) 690 468 has_param = True 691 469 if num_cbox == (len(param_list) + 1): … … 693 471 self._show_constraint() 694 472 695 self.FitInside() 473 self.sizer_constraints.Layout() 474 self.sizer2.Layout() 475 self.SetScrollbars(20, 20, 25, 65) 476 self.Layout() 696 477 if not has_param: 697 478 msg = " There is no adjustable parameter (checked to fit)" … … 715 496 ##Don't add anymore 716 497 if len(self.constraints_list) == nb_fit_param: 717 msg = "Cannot add another constraint .Maximum of number "498 msg = "Cannot add another constraint .Maximum of number " 718 499 msg += "Parameters name reached %s" % str(nb_fit_param) 719 500 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) … … 729 510 730 511 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 731 732 # Model list 733 model_cbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 512 model_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 734 513 model_cbox.Clear() 514 param_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY, size=(100, -1),) 515 param_cbox.Hide() 516 517 #This is for GetCLientData() _on_select_param: Was None return on MAC. 518 self.param_cbox = param_cbox 519 520 wx.EVT_COMBOBOX(param_cbox, -1, self._on_select_param) 521 self.ctl2 = wx.TextCtrl(self, -1) 522 egal_txt = wx.StaticText(self, -1, " = ") 523 self.btRemove = wx.Button(self, wx.NewId(), 'Remove') 524 self.btRemove.Bind(wx.EVT_BUTTON, self.onRemove, 525 id=self.btRemove.GetId()) 526 self.btRemove.SetToolTipString("Remove constraint.") 527 self.btRemove.Hide() 528 if hasattr(self, "btAdd"): 529 self.btAdd.Hide() 735 530 for id, model in self.constraint_dict.iteritems(): 736 531 ## check if all parameters have been selected for constraint 737 532 ## then do not allow add constraint on parameters 738 533 model_cbox.Append(str(model.name), model) 739 wx.EVT_COMBOBOX(model_cbox, wx.ID_ANY, self._on_select_model) 740 741 # Parameters in model 742 param_cbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY, 743 size=(100, -1)) 744 param_cbox.Hide() 745 wx.EVT_COMBOBOX(param_cbox, wx.ID_ANY, self._on_select_param) 746 747 egal_txt = wx.StaticText(self, wx.ID_ANY, " = ") 748 749 # Parameter constraint 750 constraint = wx.TextCtrl(self, wx.ID_ANY) 751 752 # Remove button 753 #btRemove = wx.Button(self, self.ID_REMOVE, 'Remove') 754 btRemove = wx.Button(self, self._ids.next(), 'Remove') 755 btRemove.Bind(wx.EVT_BUTTON, self.onRemove, 756 id=btRemove.GetId()) 757 btRemove.SetToolTipString("Remove constraint.") 758 btRemove.Hide() 759 760 # Hid the add button, if it exists 761 if hasattr(self, "btAdd"): 762 self.btAdd.Hide() 763 534 535 #This is for GetCLientData() passing to self._on_select_param: Was None return on MAC. 536 self.model_cbox = model_cbox 537 538 wx.EVT_COMBOBOX(model_cbox, -1, self._on_select_model) 764 539 sizer_constraint.Add((5, -1)) 765 540 sizer_constraint.Add(model_cbox, flag=wx.RIGHT | wx.EXPAND, border=10) 766 541 sizer_constraint.Add(param_cbox, flag=wx.RIGHT | wx.EXPAND, border=5) 767 542 sizer_constraint.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 768 sizer_constraint.Add( constraint, flag=wx.RIGHT | wx.EXPAND, border=10)769 sizer_constraint.Add( btRemove, flag=wx.RIGHT | wx.EXPAND, border=10)543 sizer_constraint.Add(self.ctl2, flag=wx.RIGHT | wx.EXPAND, border=10) 544 sizer_constraint.Add(self.btRemove, flag=wx.RIGHT | wx.EXPAND, border=10) 770 545 771 546 self.sizer_constraints.Insert(before=self.nb_constraint, 772 item=sizer_constraint, flag=wx.TOP | wx.BOTTOM | wx.EXPAND, 773 border=5) 774 c = ConstraintLine(model_cbox, param_cbox, egal_txt, 775 constraint, btRemove, sizer_constraint) 776 self.constraints_list.append(c) 547 item=sizer_constraint, flag=wx.TOP | wx.BOTTOM | wx.EXPAND, 548 border=5) 549 self.constraints_list.append([model_cbox, param_cbox, egal_txt, 550 self.ctl2, self.btRemove, sizer_constraint]) 777 551 778 552 self.nb_constraint += 1 779 553 self.sizer_constraints.Layout() 780 554 self.sizer2.Layout() 781 self.Layout782 555 783 556 def _hide_constraint(self): … … 785 558 hide buttons related constraint 786 559 """ 787 for id in self.page_finder.iterkeys():560 for id in self.page_finder.iterkeys(): 788 561 self.page_finder[id].clear_model_param() 789 562 … … 793 566 self.btAdd.Hide() 794 567 self._store_model() 795 if self.model_cbox_left is not None: 796 self.model_cbox_left.Clear() 568 if self.model_cbox_left != None: 569 try: 570 self.model_cbox_left.Clear() 571 except: 572 pass 797 573 self.model_cbox_left = None 798 if self.model_cbox_right is not None: 799 self.model_cbox_right.Clear() 574 if self.model_cbox_right != None: 575 try: 576 self.model_cbox_right.Clear() 577 except: 578 pass 800 579 self.model_cbox_right = None 801 580 self.constraints_list = [] … … 805 584 self.sizer_constraints.Layout() 806 585 self.sizer2.Layout() 807 self.Layout808 self.FitInside()809 586 810 587 def _on_select_model(self, event): … … 812 589 fill combox box with list of parameters 813 590 """ 814 if not self.constraints_list: 815 return 816 591 param_list = [] 817 592 ##This way PC/MAC both work, instead of using event.GetClientData(). 818 model_cbox = self.constraints_list[-1].model_cbox 819 n = model_cbox.GetCurrentSelection() 820 if n == wx.NOT_FOUND: 821 return 822 823 model = model_cbox.GetClientData(n) 824 param_list = [] 593 n = self.model_cbox.GetCurrentSelection() 594 model = self.model_cbox.GetClientData(n) 825 595 for id, dic_model in self.constraint_dict.iteritems(): 826 596 if model == dic_model: 827 597 param_list = self.page_finder[id].get_param2fit() 828 break 829 830 param_cbox = self.constraints_list[-1].param_cbox 598 #break 599 length = len(self.constraints_list) 600 if length < 1: 601 return 602 param_cbox = self.constraints_list[length - 1][1] 831 603 param_cbox.Clear() 832 604 ## insert only fittable paramaters 833 605 for param in param_list: 834 606 param_cbox.Append(str(param), model) 607 835 608 param_cbox.Show(True) 836 837 btRemove = self.constraints_list[-1].btRemove 838 btRemove.Show(True) 609 self.btRemove.Show(True) 839 610 self.btAdd.Show(True) 840 # self.Layout() 841 self.FitInside() 611 self.sizer2.Layout() 842 612 843 613 def _on_select_param(self, event): … … 850 620 #param = event.GetString() 851 621 852 if self.constraints_list: 853 self.constraints_list[-1].egal_txt.Show(True) 854 self.constraints_list[-1].constraint.Show(True) 622 length = len(self.constraints_list) 623 if length < 1: 624 return 625 egal_txt = self.constraints_list[length - 1][2] 626 egal_txt.Show(True) 627 628 ctl2 = self.constraints_list[length - 1][3] 629 ctl2.Show(True) 855 630 856 631 def _onAdd_constraint(self, event): … … 865 640 # before allow to add another constraint 866 641 for item in self.constraints_list: 867 if item.model_cbox.GetString(0) == "": 642 model_cbox = item[0] 643 if model_cbox.GetString(0) == "": 868 644 msg = " Select a model Name! " 869 645 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 870 646 return 871 if item.param_cbox.GetString(0) == "": 647 param_cbox = item[1] 648 if param_cbox.GetString(0) == "": 872 649 msg = " Select a parameter Name! " 873 650 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 874 651 return 875 if item.constraint.GetValue().lstrip().rstrip() == "": 876 model = item.param_cbox.GetClientData( 877 item.param_cbox.GetCurrentSelection()) 652 ctl2 = item[3] 653 if ctl2.GetValue().lstrip().rstrip() == "": 654 model = param_cbox.GetClientData(\ 655 param_cbox.GetCurrentSelection()) 878 656 if model != None: 879 657 msg = " Enter a constraint for %s.%s! " % (model.name, 880 item.param_cbox.GetString(0))658 param_cbox.GetString(0)) 881 659 else: 882 msg = " Enter a constraint"660 msg = " Enter a constraint" 883 661 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 884 662 return 885 663 ## some model or parameters can be constrained 886 664 self._show_constraint() 887 self.FitInside() 665 self.sizer3.Layout() 666 self.Layout() 667 self.Refresh() 668 669 def _fill_sizer_fit(self): 670 """ 671 Draw fit button 672 """ 673 self.sizer3.Clear(True) 674 box_description = wx.StaticBox(self, -1, "Fit ") 675 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 676 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 677 678 self.btFit = wx.Button(self, wx.NewId(), 'Fit', size=wx.DefaultSize) 679 self.btFit.Bind(wx.EVT_BUTTON, self.onFit, id=self.btFit.GetId()) 680 self.btFit.SetToolTipString("Perform fit.") 681 if self.batch_on: 682 text = " Fit in Parallel all Data set and model selected.\n" 683 else: 684 text = " This page requires at least one FitPage with a data\n" 685 text = " and a model for fitting." 686 text_hint = wx.StaticText(self, -1, text) 687 688 sizer_button.Add(text_hint, wx.RIGHT | wx.EXPAND, 10) 689 sizer_button.Add(self.btFit, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10) 690 691 boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 692 self.sizer3.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 693 self.sizer3.Layout() 694 695 def _fill_sizer_constraint(self): 696 """ 697 Fill sizer containing constraint info 698 """ 699 msg = "Select at least 2 model to add constraint " 700 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 701 702 self.sizer2.Clear(True) 703 if self.batch_on: 704 if self.sizer2.IsShown(): 705 self.sizer2.Show(False) 706 return 707 box_description = wx.StaticBox(self, -1, "Fit Constraints") 708 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 709 sizer_title = wx.BoxSizer(wx.HORIZONTAL) 710 self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL) 711 self.sizer_constraints = wx.BoxSizer(wx.VERTICAL) 712 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 713 714 self.hide_constraint = wx.RadioButton(self, -1, 'No', (10, 10), 715 style=wx.RB_GROUP) 716 self.show_constraint = wx.RadioButton(self, -1, 'Yes', (10, 30)) 717 self.Bind(wx.EVT_RADIOBUTTON, self._display_constraint, 718 id=self.hide_constraint.GetId()) 719 self.Bind(wx.EVT_RADIOBUTTON, self._display_constraint, 720 id=self.show_constraint.GetId()) 721 if self.batch_on: 722 self.hide_constraint.Enable(False) 723 self.show_constraint.Enable(False) 724 self.hide_constraint.SetValue(True) 725 self.show_constraint.SetValue(False) 726 727 sizer_title.Add(wx.StaticText(self, -1, " Model")) 728 sizer_title.Add((10, 10)) 729 sizer_title.Add(wx.StaticText(self, -1, " Parameter")) 730 sizer_title.Add((10, 10)) 731 sizer_title.Add(wx.StaticText(self, -1, " Add Constraint?")) 732 sizer_title.Add((10, 10)) 733 sizer_title.Add(self.show_constraint) 734 sizer_title.Add(self.hide_constraint) 735 sizer_title.Add((10, 10)) 736 737 self.btAdd = wx.Button(self, wx.NewId(), 'Add') 738 self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint, 739 id=self.btAdd.GetId()) 740 self.btAdd.SetToolTipString("Add another constraint?") 741 self.btAdd.Hide() 742 743 text_hint = wx.StaticText(self, -1, 744 "Example: [M0][paramter] = M1.parameter") 745 sizer_button.Add(text_hint, 0 , wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 746 sizer_button.Add(self.btAdd, 0, wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 747 748 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 749 boxsizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 750 border=10) 751 boxsizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 752 border=10) 753 boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 754 755 self.sizer2.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 756 self.sizer2.Layout() 757 758 #self.SetScrollbars(20,20,25,65) 888 759 889 760 def _set_constraint(self): 890 761 """ 891 get values from the constrain t textcrtl ,parses them into model name762 get values from the constrainst textcrtl ,parses them into model name 892 763 parameter name and parameters values. 893 764 store them in a list self.params .when when params is not empty … … 896 767 """ 897 768 for item in self.constraints_list: 898 select0 = item .model_cbox.GetSelection()769 select0 = item[0].GetSelection() 899 770 if select0 == wx.NOT_FOUND: 900 771 continue 901 model = item .model_cbox.GetClientData(select0)902 select1 = item .param_cbox.GetSelection()772 model = item[0].GetClientData(select0) 773 select1 = item[1].GetSelection() 903 774 if select1 == wx.NOT_FOUND: 904 775 continue 905 param = item .param_cbox.GetString(select1)906 constraint = item .constraint.GetValue().lstrip().rstrip()776 param = item[1].GetString(select1) 777 constraint = item[3].GetValue().lstrip().rstrip() 907 778 if param.lstrip().rstrip() == "": 908 779 param = None … … 937 808 # wrap in param/constraint in str() to remove unicode 938 809 self.page_finder[id].set_model_param(str(param), 939 str(constraint), fid=fid)810 str(constraint), fid=fid) 940 811 break 941 812 return True 813 814 def _fill_sizer_model_list(self, sizer): 815 """ 816 Receive a dictionary containing information to display model name 817 """ 818 ix = 0 819 iy = 0 820 list = [] 821 sizer.Clear(True) 822 823 new_name = wx.StaticText(self, -1, ' Model Title ', 824 style=wx.ALIGN_CENTER) 825 new_name.SetBackgroundColour('orange') 826 new_name.SetForegroundColour(wx.WHITE) 827 sizer.Add(new_name, (iy, ix), (1, 1), 828 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 829 ix += 2 830 model_type = wx.StaticText(self, -1, ' Model ') 831 model_type.SetBackgroundColour('grey') 832 model_type.SetForegroundColour(wx.WHITE) 833 sizer.Add(model_type, (iy, ix), (1, 1), 834 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 835 ix += 1 836 data_used = wx.StaticText(self, -1, ' Data ') 837 data_used.SetBackgroundColour('grey') 838 data_used.SetForegroundColour(wx.WHITE) 839 sizer.Add(data_used, (iy, ix), (1, 1), 840 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 841 ix += 1 842 tab_used = wx.StaticText(self, -1, ' FitPage ') 843 tab_used.SetBackgroundColour('grey') 844 tab_used.SetForegroundColour(wx.WHITE) 845 sizer.Add(tab_used, (iy, ix), (1, 1), 846 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 847 for id, value in self.page_finder.iteritems(): 848 if id not in self.parent.opened_pages: 849 continue 850 851 if self.batch_on != self.parent.get_page_by_id(id).batch_on: 852 continue 853 854 data_list = [] 855 model_list = [] 856 # get data name and model objetta 857 for fitproblem in value.get_fit_problem(): 858 859 data = fitproblem.get_fit_data() 860 if not data.is_data: 861 continue 862 name = '-' 863 if data is not None and data.is_data: 864 name = str(data.name) 865 data_list.append(name) 866 867 model = fitproblem.get_model() 868 if model is None: 869 continue 870 model_list.append(model) 871 872 if len(model_list) == 0: 873 continue 874 # Draw sizer 875 ix = 0 876 iy += 1 877 model = model_list[0] 878 name = '_' 879 if model is not None: 880 name = str(model.name) 881 cb = wx.CheckBox(self, -1, name) 882 cb.SetValue(False) 883 cb.Enable(model is not None and data.is_data) 884 sizer.Add(cb, (iy, ix), (1, 1), 885 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 886 wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name) 887 ix += 2 888 type = model.__class__.__name__ 889 model_type = wx.StaticText(self, -1, str(type)) 890 sizer.Add(model_type, (iy, ix), (1, 1), 891 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 892 if self.batch_on: 893 data_used = wx.ComboBox(self, -1, style=wx.CB_READONLY) 894 data_used.AppendItems(data_list) 895 data_used.SetSelection(0) 896 else: 897 data_used = wx.StaticText(self, -1, data_list[0]) 898 899 ix += 1 900 sizer.Add(data_used, (iy, ix), (1, 1), 901 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 902 ix += 1 903 caption = value.get_fit_tab_caption() 904 tab_caption_used = wx.StaticText(self, -1, str(caption)) 905 sizer.Add(tab_caption_used, (iy, ix), (1, 1), 906 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 907 908 self.model_list.append([cb, value, id, model]) 909 910 iy += 1 911 sizer.Add((20, 20), (iy, ix), (1, 1), 912 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 913 sizer.Layout() 942 914 943 915 def on_set_focus(self, event=None): … … 949 921 wx.PostEvent(self.parent.parent, PanelOnFocusEvent(panel=self)) 950 922 self.page_finder = self.parent._manager.get_page_finder() 951 952 953 def setComboBoxItems(cbox, items):954 assert isinstance(cbox, wx.ComboBox)955 selected = cbox.GetStringSelection()956 cbox.Clear()957 for k, (name, value) in enumerate(items):958 cbox.Append(name, value)959 cbox.SetStringSelection(selected)
Note: See TracChangeset
for help on using the changeset viewer.