Changes in src/sas/perspectives/fitting/simfitpage.py [acf8e4a5:662d8d87] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/fitting/simfitpage.py
racf8e4a5 r662d8d87 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 from sas.guiframe.documentation_window import DocumentationWindow 16 10 17 #Control panel width 11 18 if sys.platform.count("darwin") == 0: … … 17 24 18 25 26 # Each constraint requires five widgets and sizer. Package them in 27 # a named tuple for easy access. 28 ConstraintLine = namedtuple('ConstraintLine', 29 'model_cbox param_cbox egal_txt constraint btRemove sizer') 30 19 31 def get_fittableParam(model): 20 32 """ 21 return list of fittable parameters name ofa model33 return list of fittable parameters from a model 22 34 23 35 :param model: the model used … … 34 46 35 47 return fittable_param 36 37 48 38 49 class SimultaneousFitPage(ScrolledPanel, PanelBase): … … 46 57 ## Title to appear on top of the window 47 58 window_caption = "Simultaneous Fit Page" 48 49 def __init__(self, parent, page_finder={}, id= -1, batch_on=False, 50 *args, **kwargs): 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): 51 67 ScrolledPanel.__init__(self, parent, id=id, 52 68 style=wx.FULL_REPAINT_ON_RESIZE, … … 56 72 Simultaneous page display 57 73 """ 74 self._ids = iter(self._id_pool) 58 75 self.SetupScrolling() 59 76 ##Font size … … 64 81 ## store page_finder 65 82 self.page_finder = page_finder 66 ## list conta ning info to set constraint83 ## list containing info to set constraint 67 84 ## look like self.constraint_dict[page_id]= page 68 85 self.constraint_dict = {} 69 86 ## item list 70 # self.constraints_list=[combobox1, combobox2,=,textcrtl, button ]87 ## self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 71 88 self.constraints_list = [] 72 89 ## list of current model … … 78 95 self.model_cbox_left = None 79 96 self.model_cbox_right = None 80 self.uid = wx.NewId()81 97 ## draw page 82 98 self.define_page_structure() 83 99 self.draw_page() 84 self.set_layout()85 100 self._set_save_flag(False) 86 101 87 102 def define_page_structure(self): 88 103 """ 89 Create empty sizer for apanel104 Create empty sizers, their hierarchy and set the sizer for the panel 90 105 """ 91 106 self.vbox = wx.BoxSizer(wx.VERTICAL) … … 100 115 self.vbox.Add(self.sizer2) 101 116 self.vbox.Add(self.sizer3) 102 103 def set_scroll(self):104 """105 """106 self.Layout()107 108 def set_layout(self):109 """110 layout111 """112 self.vbox.Layout()113 self.vbox.Fit(self)114 117 self.SetSizer(self.vbox) 115 self.set_scroll()116 118 self.Centre() 119 120 def draw_page(self): 121 """ 122 Construct the Simultaneous/Constrained fit page. fills the first 123 region (sizer1) with the list of available fit page pairs of data 124 and models. Then fills sizer2 with the checkbox for adding 125 constraints, and finally fills sizer3 with the fit button and 126 instructions. 127 """ 128 129 # create blank list of constraints 130 self.model_list = [] 131 self.model_toFit = [] 132 self.constraints_list = [] 133 self.constraint_dict = {} 134 self.nb_constraint = 0 135 self.model_cbox_left = None 136 self.model_cbox_right = None 137 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 4 152 #Leave it here for now as no time to thoroughly test. However if no 153 #fit page is found the menu item that calls this page is inactive 154 # Nov. 22 2015 --PDB 155 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 model 162 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 names 174 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 the 183 ## buttons (fit, help etc) sizer at the bottom of the page. 184 ## Note: the if statement should be removed along with the above 185 ## if statement as soon as it can be properly tested. 186 ## Nov. 22 2015 --PDB 187 if len(self.page_finder) > 0: 188 ## draw the sizer containing constraint info 189 if not self.batch_on: 190 self._fill_sizer_constraint() 191 ## draw fit button sizer 192 self._fill_sizer_fit() 193 194 195 def _fill_sizer_model_list(self, sizer): 196 """ 197 Receive a dictionary containing information to display model name 198 """ 199 ix = 0 200 iy = 0 201 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 += 2 211 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 += 1 217 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 += 1 223 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 continue 231 232 if self.batch_on != self.parent.get_page_by_id(id).batch_on: 233 continue 234 235 data_list = [] 236 model_list = [] 237 # get data name and model objetta 238 for fitproblem in value.get_fit_problem(): 239 240 data = fitproblem.get_fit_data() 241 if not data.is_data: 242 continue 243 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 continue 251 model_list.append(model) 252 253 if len(model_list) == 0: 254 continue 255 # Draw sizer 256 ix = 0 257 iy += 1 258 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 += 2 269 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 += 1 281 sizer.Add(data_used, (iy, ix), (1, 1), 282 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 283 ix += 1 284 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 += 1 292 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 info 298 """ 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 return 307 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 button 363 """ 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 button 370 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 button 375 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 line 380 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) 117 394 118 395 def onRemove(self, event): … … 126 403 if len(self.constraints_list) == 0: 127 404 return 405 wx.CallAfter(self._remove_after, event.GetId()) 406 #self._onAdd_constraint(None) 407 408 def _remove_after(self, id): 128 409 for item in self.constraints_list: 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) 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) 135 414 self.constraints_list.remove(item) 136 415 self.nb_constraint -= 1 137 416 self.sizer2.Layout() 138 self. Layout()417 self.FitInside() 139 418 break 140 141 #self._onAdd_constraint(None)142 419 143 420 def onFit(self, event): … … 171 448 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 172 449 450 def _onHelp(self, event): 451 """ 452 Bring up the simultaneous Fitting Documentation whenever the HELP 453 button is clicked. 454 455 Calls DocumentationWindow with the path of the location within the 456 documentation tree (after /doc/ ....". Note that when using old 457 versions of Wx (before 2.9) and thus not the release version of 458 installers, the help comes up at the top level of the file as 459 webbrowser does not pass anything past the # to the browser when it is 460 running "file:///...." 461 462 :param evt: Triggers on clicking the help button 463 """ 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 173 470 def set_manager(self, manager): 174 471 """ … … 195 492 if not self.batch_on: 196 493 ## display constraint fields 197 if self.show_constraint.GetValue() and\198 len(self.constraints_list) == 0 :494 if (self.show_constraint.GetValue() and 495 len(self.constraints_list) == 0): 199 496 self._show_all_constraint() 200 497 self._show_constraint() … … 203 500 item[0].SetValue(False) 204 501 205 self.model_toFit = []206 502 if not self.batch_on: 207 503 ##constraint info … … 209 505 210 506 self._update_easy_setup_cb() 211 self. Layout()212 self.Refresh() 507 self.FitInside() 508 213 509 214 510 def check_model_name(self, event): … … 242 538 if len(self.model_list) == len(self.model_toFit): 243 539 self.cb1.SetValue(True) 244 self. Layout()540 self.FitInside() 245 541 return 246 542 else: 247 543 self.cb1.SetValue(False) 248 self. Layout()544 self.FitInside() 249 545 250 546 def _update_easy_setup_cb(self): … … 252 548 Update easy setup combobox on selecting a model 253 549 """ 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) 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: 274 559 self.model_cbox_left.SetSelection(0) 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() 560 self.sizer2.Layout() 336 561 337 562 def _store_model(self): … … 359 584 self._show_all_constraint() 360 585 self._show_constraint() 361 self. Layout()586 self.FitInside() 362 587 return 363 588 else: 364 589 self._hide_constraint() 365 self.Layout()366 590 return 367 591 … … 370 594 Show constraint fields 371 595 """ 372 box_description = wx.StaticBox(self, -1, "Easy Setup ")596 box_description = wx.StaticBox(self, wx.ID_ANY, "Easy Setup ") 373 597 boxsizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL) 374 598 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 375 self.model_cbox_left = wx.ComboBox(self, -1, style=wx.CB_READONLY)599 self.model_cbox_left = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 376 600 self.model_cbox_left.Clear() 377 self.model_cbox_right = wx.ComboBox(self, -1, style=wx.CB_READONLY)601 self.model_cbox_right = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 378 602 self.model_cbox_right.Clear() 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')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') 383 607 self.set_button.Bind(wx.EVT_BUTTON, self._on_set_all_equal, 384 608 id=self.set_button.GetId()) … … 399 623 boxsizer.Add(self.model_cbox_left, 400 624 flag=wx.RIGHT | wx.EXPAND, border=10) 401 boxsizer.Add(wx.StaticText(self, -1, ".parameters"),402 flag=wx.RIGHT | wx.EXPAND, border=5)625 #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 626 # flag=wx.RIGHT | wx.EXPAND, border=5) 403 627 boxsizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 404 628 boxsizer.Add(self.model_cbox_right, 405 629 flag=wx.RIGHT | wx.EXPAND, border=10) 406 boxsizer.Add(wx.StaticText(self, -1, ".parameters"),407 flag=wx.RIGHT | wx.EXPAND, border=5)630 #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 631 # flag=wx.RIGHT | wx.EXPAND, border=5) 408 632 boxsizer.Add((20, -1)) 409 633 boxsizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5) … … 412 636 item=sizer_constraint, 413 637 flag=wx.TOP | wx.BOTTOM | wx.EXPAND, border=5) 414 415 self.sizer_all_constraints.Layout() 416 self.sizer2.Layout() 417 #self.SetScrollbars(20,20,25,65) 638 self.FitInside() 418 639 419 640 def _on_select_modelcb(self, event): … … 427 648 if self.model_cbox_right.GetValue().strip() == '': 428 649 flag = False 429 if self.model_cbox_left.GetValue() == \430 self.model_cbox_right.GetValue() :650 if (self.model_cbox_left.GetValue() == 651 self.model_cbox_right.GetValue()): 431 652 flag = False 432 653 self.set_button.Enable(flag) … … 460 681 num_cbox += 1 461 682 if param in param_listB: 462 self.model_cbox.SetStringSelection(model_left) 683 item = self.constraints_list[-1] 684 item.model_cbox.SetStringSelection(model_left) 463 685 self._on_select_model(None) 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)))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))) 468 690 has_param = True 469 691 if num_cbox == (len(param_list) + 1): … … 471 693 self._show_constraint() 472 694 473 self.sizer_constraints.Layout() 474 self.sizer2.Layout() 475 self.SetScrollbars(20, 20, 25, 65) 476 self.Layout() 695 self.FitInside() 477 696 if not has_param: 478 697 msg = " There is no adjustable parameter (checked to fit)" … … 496 715 ##Don't add anymore 497 716 if len(self.constraints_list) == nb_fit_param: 498 msg = "Cannot add another constraint .Maximum of number "717 msg = "Cannot add another constraint. Maximum of number " 499 718 msg += "Parameters name reached %s" % str(nb_fit_param) 500 719 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) … … 510 729 511 730 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 512 model_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 731 732 # Model list 733 model_cbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 513 734 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_cbox519 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()530 735 for id, model in self.constraint_dict.iteritems(): 531 736 ## check if all parameters have been selected for constraint 532 737 ## then do not allow add constraint on parameters 533 738 model_cbox.Append(str(model.name), model) 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) 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 539 764 sizer_constraint.Add((5, -1)) 540 765 sizer_constraint.Add(model_cbox, flag=wx.RIGHT | wx.EXPAND, border=10) 541 766 sizer_constraint.Add(param_cbox, flag=wx.RIGHT | wx.EXPAND, border=5) 542 767 sizer_constraint.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 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)768 sizer_constraint.Add(constraint, flag=wx.RIGHT | wx.EXPAND, border=10) 769 sizer_constraint.Add(btRemove, flag=wx.RIGHT | wx.EXPAND, border=10) 545 770 546 771 self.sizer_constraints.Insert(before=self.nb_constraint, 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]) 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) 551 777 552 778 self.nb_constraint += 1 553 779 self.sizer_constraints.Layout() 554 780 self.sizer2.Layout() 781 self.Layout 555 782 556 783 def _hide_constraint(self): … … 558 785 hide buttons related constraint 559 786 """ 560 for id in 787 for id in self.page_finder.iterkeys(): 561 788 self.page_finder[id].clear_model_param() 562 789 … … 566 793 self.btAdd.Hide() 567 794 self._store_model() 568 if self.model_cbox_left != None: 569 try: 570 self.model_cbox_left.Clear() 571 except: 572 pass 795 if self.model_cbox_left is not None: 796 self.model_cbox_left.Clear() 573 797 self.model_cbox_left = None 574 if self.model_cbox_right != None: 575 try: 576 self.model_cbox_right.Clear() 577 except: 578 pass 798 if self.model_cbox_right is not None: 799 self.model_cbox_right.Clear() 579 800 self.model_cbox_right = None 580 801 self.constraints_list = [] … … 584 805 self.sizer_constraints.Layout() 585 806 self.sizer2.Layout() 807 self.Layout 808 self.FitInside() 586 809 587 810 def _on_select_model(self, event): … … 589 812 fill combox box with list of parameters 590 813 """ 814 if not self.constraints_list: 815 return 816 817 ##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) 591 824 param_list = [] 592 ##This way PC/MAC both work, instead of using event.GetClientData().593 n = self.model_cbox.GetCurrentSelection()594 model = self.model_cbox.GetClientData(n)595 825 for id, dic_model in self.constraint_dict.iteritems(): 596 826 if model == dic_model: 597 827 param_list = self.page_finder[id].get_param2fit() 598 #break 599 length = len(self.constraints_list) 600 if length < 1: 601 return 602 param_cbox = self.constraints_list[length - 1][1] 828 break 829 830 param_cbox = self.constraints_list[-1].param_cbox 603 831 param_cbox.Clear() 604 832 ## insert only fittable paramaters 605 833 for param in param_list: 606 834 param_cbox.Append(str(param), model) 607 608 835 param_cbox.Show(True) 609 self.btRemove.Show(True) 836 837 btRemove = self.constraints_list[-1].btRemove 838 btRemove.Show(True) 610 839 self.btAdd.Show(True) 611 self.sizer2.Layout() 840 # self.Layout() 841 self.FitInside() 612 842 613 843 def _on_select_param(self, event): … … 620 850 #param = event.GetString() 621 851 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) 852 if self.constraints_list: 853 self.constraints_list[-1].egal_txt.Show(True) 854 self.constraints_list[-1].constraint.Show(True) 630 855 631 856 def _onAdd_constraint(self, event): … … 640 865 # before allow to add another constraint 641 866 for item in self.constraints_list: 642 model_cbox = item[0] 643 if model_cbox.GetString(0) == "": 867 if item.model_cbox.GetString(0) == "": 644 868 msg = " Select a model Name! " 645 869 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 646 870 return 647 param_cbox = item[1] 648 if param_cbox.GetString(0) == "": 871 if item.param_cbox.GetString(0) == "": 649 872 msg = " Select a parameter Name! " 650 873 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 651 874 return 652 ctl2 = item[3] 653 if ctl2.GetValue().lstrip().rstrip() == "": 654 model = param_cbox.GetClientData(\ 655 param_cbox.GetCurrentSelection()) 875 if item.constraint.GetValue().lstrip().rstrip() == "": 876 model = item.param_cbox.GetClientData( 877 item.param_cbox.GetCurrentSelection()) 656 878 if model != None: 657 879 msg = " Enter a constraint for %s.%s! " % (model.name, 658 880 item.param_cbox.GetString(0)) 659 881 else: 660 882 msg = " Enter a constraint" 661 883 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 662 884 return 663 885 ## some model or parameters can be constrained 664 886 self._show_constraint() 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) 887 self.FitInside() 759 888 760 889 def _set_constraint(self): 761 890 """ 762 get values from the constrain st textcrtl ,parses them into model name891 get values from the constraint textcrtl ,parses them into model name 763 892 parameter name and parameters values. 764 893 store them in a list self.params .when when params is not empty … … 767 896 """ 768 897 for item in self.constraints_list: 769 select0 = item [0].GetSelection()898 select0 = item.model_cbox.GetSelection() 770 899 if select0 == wx.NOT_FOUND: 771 900 continue 772 model = item [0].GetClientData(select0)773 select1 = item [1].GetSelection()901 model = item.model_cbox.GetClientData(select0) 902 select1 = item.param_cbox.GetSelection() 774 903 if select1 == wx.NOT_FOUND: 775 904 continue 776 param = item [1].GetString(select1)777 constraint = item [3].GetValue().lstrip().rstrip()905 param = item.param_cbox.GetString(select1) 906 constraint = item.constraint.GetValue().lstrip().rstrip() 778 907 if param.lstrip().rstrip() == "": 779 908 param = None … … 808 937 # wrap in param/constraint in str() to remove unicode 809 938 self.page_finder[id].set_model_param(str(param), 810 939 str(constraint), fid=fid) 811 940 break 812 941 return True 813 814 def _fill_sizer_model_list(self, sizer):815 """816 Receive a dictionary containing information to display model name817 """818 ix = 0819 iy = 0820 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 += 2830 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 += 1836 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 += 1842 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 continue850 851 if self.batch_on != self.parent.get_page_by_id(id).batch_on:852 continue853 854 data_list = []855 model_list = []856 # get data name and model objetta857 for fitproblem in value.get_fit_problem():858 859 data = fitproblem.get_fit_data()860 if not data.is_data:861 continue862 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 continue870 model_list.append(model)871 872 if len(model_list) == 0:873 continue874 # Draw sizer875 ix = 0876 iy += 1877 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 += 2888 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 += 1900 sizer.Add(data_used, (iy, ix), (1, 1),901 wx.EXPAND | wx.ADJUST_MINSIZE, 0)902 ix += 1903 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 += 1911 sizer.Add((20, 20), (iy, ix), (1, 1),912 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)913 sizer.Layout()914 942 915 943 def on_set_focus(self, event=None): … … 921 949 wx.PostEvent(self.parent.parent, PanelOnFocusEvent(panel=self)) 922 950 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.