Changes in / [1dbdb83:be4cb41] in sasview
- Location:
- src/sas/sasgui/perspectives/fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/fitpanel.py
ra95ae9a r05228b0 13 13 from sas.sasgui.guiframe.events import StatusEvent 14 14 from sas.sasgui.guiframe.dataFitting import check_data_validity 15 from sas.sasgui.perspectives.fitting.simfitpage import SimultaneousFitPage16 15 17 16 import basepage … … 19 18 _BOX_WIDTH = 80 20 19 21 22 20 class FitPanel(nb, PanelBase): 23 21 """ … … 28 26 29 27 """ 30 # Internal name for the AUI manager28 ## Internal name for the AUI manager 31 29 window_name = "Fit panel" 32 # Title to appear on top of the window30 ## Title to appear on top of the window 33 31 window_caption = "Fit Panel " 34 32 CENTER_PANE = True … … 42 40 wx.CLIP_CHILDREN) 43 41 PanelBase.__init__(self, parent) 44 # 42 #self.SetWindowStyleFlag(style=nb.FNB_FANCY_TABS) 45 43 self._manager = manager 46 44 self.parent = parent 47 45 self.event_owner = None 48 # 46 #dictionary of miodel {model class name, model class} 49 47 self.menu_mng = models.ModelManager() 50 48 self.model_list_box = self.menu_mng.get_model_list() 51 # 49 #pageClosedEvent = nb.EVT_FLATNOTEBOOK_PAGE_CLOSING 52 50 self.model_dictionary = self.menu_mng.get_model_dictionary() 53 51 self.pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE 54 52 55 53 self.Bind(self.pageClosedEvent, self.on_close_page) 56 # save the title of the last page tab added54 ## save the title of the last page tab added 57 55 self.fit_page_name = {} 58 # list of existing fit page56 ## list of existing fit page 59 57 self.opened_pages = {} 60 # 58 #index of fit page 61 59 self.fit_page_index = 0 62 # 60 #index of batch page 63 61 self.batch_page_index = 0 64 # 62 #page of simultaneous fit 65 63 self.sim_page = None 66 64 self.batch_page = None 67 # get the state of a page65 ## get the state of a page 68 66 self.Bind(basepage.EVT_PAGE_INFO, self._onGetstate) 69 67 self.Bind(basepage.EVT_PREVIOUS_STATE, self._onUndo) … … 82 80 """ 83 81 return an xml node containing state of the panel 84 that guiframe can write to file 85 """ 86 # Iterate through all pages and check for batch fitting 87 batch_state = None 88 if self.sim_page is not None: 89 batch_state = self.sim_page.set_state() 90 82 that guiframe can write to file 83 """ 84 msg = "" 91 85 for uid, page in self.opened_pages.iteritems(): 92 data = page.get_data() 93 # state must be cloned 94 state = page.get_state().clone() 95 if data is not None or page.model is not None: 96 new_doc = self._manager.state_reader.write_toXML(data, 97 state, 98 batch_state) 99 if doc is not None and hasattr(doc, "firstChild"): 100 child = new_doc.firstChild.firstChild 101 doc.firstChild.appendChild(child) 102 else: 103 doc = new_doc 104 86 if page.batch_on: 87 pos = self.GetPageIndex(page) 88 if pos != -1 and page not in [self.sim_page, self.batch_page]: 89 msg += "%s .\n" % str(self.GetPageText(pos)) 90 else: 91 data = page.get_data() 92 # state must be cloned 93 state = page.get_state().clone() 94 if data is not None and page.model is not None: 95 new_doc = self._manager.state_reader.write_toXML(data, 96 state) 97 if doc != None and hasattr(doc, "firstChild"): 98 child = new_doc.firstChild.firstChild 99 doc.firstChild.appendChild(child) 100 else: 101 doc = new_doc 102 if msg.strip() != "": 103 temp = "Save Project is not supported for Batch page.\n" 104 temp += "The following pages will not be save:\n" 105 message = temp + msg 106 wx.PostEvent(self._manager.parent, StatusEvent(status=message, 107 info="warning")) 105 108 return doc 106 109 … … 360 363 panel.set_index_model(self.batch_page_index) 361 364 else: 362 # 365 #Increment index of fit page 363 366 panel = FitPage(parent=self) 364 367 self.fit_page_index += 1 … … 523 526 self.SetSelection(pos) 524 527 return page 525 # 528 #create new page and add data 526 529 page = self.add_empty_page() 527 530 pos = self.GetPageIndex(page) -
src/sas/sasgui/perspectives/fitting/fitting.py
re89aed5 rca4d985 593 593 : param datainfo: data 594 594 """ 595 from pagestate import PageState 596 from simfitpage import SimFitPageState 597 if isinstance(state, PageState): 595 #state = self.state_reader.get_state() 596 if state != None: 598 597 state = state.clone() 598 # store fitting state in temp_state 599 599 self.temp_state.append(state) 600 elif isinstance(state, SimFitPageState):601 state.load_from_save_state(self)602 600 else: 603 601 self.temp_state = [] -
src/sas/sasgui/perspectives/fitting/pagestate.py
re89aed5 r6c382da 2 2 Class that holds a fit page state 3 3 """ 4 # 4 #TODO: Refactor code so we don't need to use getattr/setattr 5 5 ################################################################################ 6 # 7 # 8 # 6 #This software was developed by the University of Tennessee as part of the 7 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 8 #project funded by the US National Science Foundation. 9 9 # 10 # 10 #See the license text in license.txt 11 11 # 12 # 12 #copyright 2009, University of Tennessee 13 13 ################################################################################ 14 14 import time … … 30 30 from sas.sascalc.dataloader.readers.cansas_reader import Reader as CansasReader 31 31 from sas.sascalc.dataloader.readers.cansas_reader import get_content, write_node 32 from sas.sascalc.dataloader.data_info import Data2D, Collimation, Detector 33 from sas.sascalc.dataloader.data_info import Process, Aperture 34 # Information to read/write state as xml 32 from sas.sascalc.dataloader.data_info import Data2D 33 from sas.sascalc.dataloader.data_info import Collimation 34 from sas.sascalc.dataloader.data_info import Detector 35 from sas.sascalc.dataloader.data_info import Process 36 from sas.sascalc.dataloader.data_info import Aperture 37 #Information to read/write state as xml 35 38 FITTING_NODE_NAME = 'fitting_plug_in' 36 39 CANSAS_NS = "cansas1d/1.0" … … 120 123 try: 121 124 return node.get(item[0]).strip() == "True" 125 122 126 except: 123 127 return None … … 142 146 """ 143 147 self.file = None 144 # 148 #Time of state creation 145 149 self.timestamp = time.time() 146 # Data member to store the dispersion object created150 ## Data member to store the dispersion object created 147 151 self._disp_obj_dict = {} 148 # 149 # 152 #------------------------ 153 #Data used for fitting 150 154 self.data = data 151 155 # model data 152 156 self.theory_data = None 153 # 157 #Is 2D 154 158 self.is_2D = False 155 159 self.images = None 156 160 157 # save additional information on data that dataloader.reader 158 # does not read 161 #save additional information on data that dataloader.reader does not read 159 162 self.is_data = None 160 163 self.data_name = "" … … 169 172 self.data_group_id = self.data.group_id 170 173 171 # reset True change the state of existing button174 ## reset True change the state of exsiting button 172 175 self.reset = False 173 176 … … 177 180 self.model = model 178 181 self.m_name = None 179 # 182 #list of process done to model 180 183 self.process = [] 181 # 184 #fit page manager 182 185 self.manager = None 183 # 186 #Store the parent of this panel parent 184 187 # For this application fitpanel is the parent 185 188 self.parent = parent 186 189 # Event_owner is the owner of model event 187 190 self.event_owner = None 188 # 191 ##page name 189 192 self.page_name = "" 190 193 # Contains link between model, all its parameters, and panel organization … … 193 196 self.str_parameters = [] 194 197 # Contains list of parameters that cannot be fitted and reference to 195 # 198 #panel objects 196 199 self.fixed_param = [] 197 200 # Contains list of parameters with dispersity and reference to 198 # 201 #panel objects 199 202 self.fittable_param = [] 200 # orientation parameters203 ## orientation parameters 201 204 self.orientation_params = [] 202 # orientation parameters for gaussian dispersity205 ## orientation parameters for gaussian dispersity 203 206 self.orientation_params_disp = [] 204 # smearer info207 ## smearer info 205 208 self.smearer = None 206 209 self.smear_type = None … … 211 214 self.dxl = None 212 215 self.dxw = None 213 # 216 #list of dispersion parameters 214 217 self.disp_list = [] 215 218 if self.model is not None: … … 220 223 self.weights = {} 221 224 222 # 225 #contains link between a model and selected parameters to fit 223 226 self.param_toFit = [] 224 # 227 ##dictionary of model type and model class 225 228 self.model_list_box = None 226 # save the state of the context menu229 ## save the state of the context menu 227 230 self.saved_states = {} 228 # save selection of combobox231 ## save selection of combobox 229 232 self.formfactorcombobox = None 230 233 self.categorycombobox = None 231 234 self.structurecombobox = None 232 235 233 # radio box to select type of model234 # 235 # 236 # 237 # 238 # the indice of the current selection236 ## radio box to select type of model 237 #self.shape_rbutton = False 238 #self.shape_indep_rbutton = False 239 #self.struct_rbutton = False 240 #self.plugin_rbutton = False 241 ## the indice of the current selection 239 242 self.disp_box = 0 240 # Qrange241 # Q range243 ## Qrange 244 ## Q range 242 245 self.qmin = 0.001 243 246 self.qmax = 0.1 244 # 247 #reset data range 245 248 self.qmax_x = None 246 249 self.qmin_x = None … … 250 253 self.multi_factor = None 251 254 self.magnetic_on = False 252 # enable smearering state255 ## enable smearering state 253 256 self.enable_smearer = False 254 257 self.disable_smearer = True … … 260 263 self.dI_sqrdata = False 261 264 self.dI_idata = False 262 # disperity selection265 ## disperity selection 263 266 self.enable_disp = False 264 267 self.disable_disp = True 265 268 266 # state of selected all check button269 ## state of selected all check button 267 270 self.cb1 = False 268 # store value of chisqr271 ## store value of chisqr 269 272 self.tcChi = None 270 273 … … 290 293 obj.structurecombobox = self.structurecombobox 291 294 292 # 293 # 294 # 295 # 295 #obj.shape_rbutton = self.shape_rbutton 296 #obj.shape_indep_rbutton = self.shape_indep_rbutton 297 #obj.struct_rbutton = self.struct_rbutton 298 #obj.plugin_rbutton = self.plugin_rbutton 296 299 297 300 obj.manager = self.manager … … 383 386 rep += "data's name : %s\n" % self.data_name 384 387 rep += "data's id : %s\n" % self.data_id 385 if self.model is notNone:388 if self.model != None: 386 389 m_name = self.model.__class__.__name__ 387 390 if m_name == 'Model': … … 394 397 rep += "model type (Category) selected: %s\n" % self.categorycombobox 395 398 rep += "data : %s\n" % str(self.data) 396 rep += "Plotting Range: min: %s, max: %s, steps: %s\n" % \397 (str(self.qmin),str(self.qmax), str(self.npts))399 rep += "Plotting Range: min: %s, max: %s, steps: %s\n" % (str(self.qmin), 400 str(self.qmax), str(self.npts)) 398 401 rep += "Dispersion selection : %s\n" % str(self.disp_box) 399 402 rep += "Smearing enable : %s\n" % str(self.enable_smearer) … … 411 414 412 415 rep += "2D enable : %s\n" % str(self.enable2D) 413 rep += "All parameters checkbox selected: %s\n" % str(self.cb1)416 rep += "All parameters checkbox selected: %s\n" % (self.cb1) 414 417 rep += "Value of Chisqr : %s\n" % str(self.tcChi) 415 418 rep += "Smear object : %s\n" % str(self.smearer) 416 rep += "Smear type : %s\n" % str(self.smear_type)419 rep += "Smear type : %s\n" % (self.smear_type) 417 420 rep += "dq_l : %s\n" % self.dq_l 418 421 rep += "dq_r : %s\n" % self.dq_r … … 431 434 if not self.is_2D: 432 435 for item in self.parameters: 433 if item notin self.orientation_params:436 if not item in self.orientation_params: 434 437 temp_parameters.append(item) 435 438 for item in self.fittable_param: 436 if item notin self.orientation_params_disp:439 if not item in self.orientation_params_disp: 437 440 temp_fittable_param.append(item) 438 441 else: … … 440 443 temp_fittable_param = self.fittable_param 441 444 442 rep += "number parameters(self.parameters): %s\n" % \ 443 len(temp_parameters) 445 rep += "number parameters(self.parameters): %s\n" % len(temp_parameters) 444 446 rep = self._repr_helper(list=temp_parameters, rep=rep) 445 rep += "number str_parameters(self.str_parameters): %s\n" % \ 446 len(self.str_parameters) 447 rep += "number str_parameters(self.str_parameters): %s\n" % len(self.str_parameters) 447 448 rep = self._repr_helper(list=self.str_parameters, rep=rep) 448 rep += "number fittable_param(self.fittable_param): %s\n" % \ 449 len(temp_fittable_param) 449 rep += "number fittable_param(self.fittable_param): %s\n" % len(temp_fittable_param) 450 450 rep = self._repr_helper(list=temp_fittable_param, rep=rep) 451 451 return rep … … 551 551 paramval_string += CENTRE % param + "\n" 552 552 553 text_string = "\n\n\n%s\n\n%s\n%s\n%s\n\n%s" % \ 554 (title, file, q_name, chi2, paramval) 553 text_string = "\n\n\n%s\n\n%s\n%s\n%s\n\n%s" % (title, file, q_name, chi2, paramval) 555 554 556 555 title_name = self._check_html_format(title_name) … … 633 632 element.appendChild(sub_element) 634 633 635 def toXML(self, file="fitting_state.fitv", doc=None, 636 entry_node=None, batch_fit_state=None): 637 """ 638 Writes the state of the fit panel to file, as XML. 634 def toXML(self, file="fitting_state.fitv", doc=None, entry_node=None): 635 """ 636 Writes the state of the InversionControl panel to file, as XML. 639 637 640 638 Compatible with standalone writing, or appending to an … … 693 691 element.setAttributeNode(attr) 694 692 top_element.appendChild(element) 695 696 693 # Inputs 697 694 inputs = newdoc.createElement("Attributes") … … 746 743 self._toXML_helper(thelist=getattr(self, item[1]), element=element, newdoc=newdoc) 747 744 inputs.appendChild(element) 748 749 # Combined and Simultaneous Fit Parameters750 if batch_fit_state is not None:751 batch_combo = newdoc.createElement('simultaneous_fit')752 top_element.appendChild(batch_combo)753 754 # Simultaneous Fit Number For Linking Later755 element = newdoc.createElement('sim_fit_number')756 element.setAttribute('fit_number', str(batch_fit_state.fit_page_no))757 batch_combo.appendChild(element)758 759 # Save constraints760 constraints = newdoc.createElement('constraints')761 batch_combo.appendChild(constraints)762 for constraint in batch_fit_state.constraints_list:763 # model_cbox, param_cbox, egal_txt, constraint, btRemove, sizer764 doc_cons = newdoc.createElement('constraint')765 doc_cons.setAttribute('model_cbox',766 str(constraint.model_cbox.GetValue()))767 doc_cons.setAttribute('param_cbox',768 str(constraint.param_cbox.GetValue()))769 doc_cons.setAttribute('egal_txt',770 str(constraint.egal_txt.GetLabel()))771 doc_cons.setAttribute('constraint',772 str(constraint.constraint.GetValue()))773 constraints.appendChild(doc_cons)774 775 # Save all models776 models = newdoc.createElement('model_list')777 batch_combo.appendChild(models)778 for model in batch_fit_state.model_list:779 doc_model = newdoc.createElement('model_list_item')780 doc_model.setAttribute('checked', str(model[0].GetValue()))781 keys = model[1].keys()782 doc_model.setAttribute('name', str(keys[0]))783 values = model[1].get(keys[0])784 doc_model.setAttribute('fit_number', str(model[2]))785 doc_model.setAttribute('fit_page_source', str(model[3]))786 doc_model.setAttribute('model_name', str(values.model.id))787 models.appendChild(doc_model)788 789 # Select All Checkbox790 element = newdoc.createElement('select_all')791 if batch_fit_state.select_all:792 element.setAttribute('checked', 'True')793 else:794 element.setAttribute('checked', 'False')795 batch_combo.appendChild(element)796 745 797 746 # Save the file … … 860 809 :param file: .fitv file 861 810 :param node: node of a XML document to read from 811 862 812 """ 863 813 if file is not None: … … 866 816 raise RuntimeError, msg 867 817 868 if node.get('version') 818 if node.get('version')and node.get('version') == '1.0': 869 819 870 820 # Get file name … … 1010 960 self.cansas = cansas 1011 961 self.state = None 1012 # batch fitting params for saving1013 self.batchfit_params = []1014 962 1015 963 def get_state(self): … … 1271 1219 1272 1220 :param entry: XML node to read from 1221 1273 1222 :return: PageState object 1274 1223 """ … … 1279 1228 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, 1280 1229 namespaces={'ns': CANSAS_NS}) 1281 if nodes :1230 if nodes != []: 1282 1231 # Create an empty state 1283 1232 state = PageState() … … 1289 1238 1290 1239 return state 1291 1292 def _parse_simfit_state(self, entry):1293 """1294 Parses the saved data for a simultaneous fit1295 :param entry: XML object to read from1296 :return: XML object for a simultaneous fit or None1297 """1298 nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME,1299 namespaces={'ns': CANSAS_NS})1300 if nodes:1301 simfitstate = nodes[0].xpath('ns:simultaneous_fit',1302 namespaces={'ns': CANSAS_NS})1303 if simfitstate:1304 from simfitpage import SimFitPageState1305 sim_fit_state = SimFitPageState()1306 simfitstate_0 = simfitstate[0]1307 all = simfitstate_0.xpath('ns:select_all',1308 namespaces={'ns': CANSAS_NS})1309 atts = all[0].attrib1310 checked = atts.get('checked')1311 sim_fit_state.select_all = bool(checked)1312 model_list = simfitstate_0.xpath('ns:model_list',1313 namespaces={'ns': CANSAS_NS})1314 model_list_items = model_list[0].xpath('ns:model_list_item',1315 namespaces={'ns': CANSAS_NS})1316 for model in model_list_items:1317 attrs = model.attrib1318 sim_fit_state.model_list.append(attrs)1319 constraints = simfitstate_0.xpath('ns:constraints',1320 namespaces={'ns': CANSAS_NS})1321 constraint_list = constraints[0].xpath('ns:constraint',1322 namespaces={'ns': CANSAS_NS})1323 for constraint in constraint_list:1324 attrs = constraint.attrib1325 sim_fit_state.constraints_list.append(attrs)1326 1327 return sim_fit_state1328 else:1329 return None1330 1240 1331 1241 def _parse_save_state_entry(self, dom): … … 1566 1476 nodes = dom.xpath('ns:SASdata', namespaces={'ns': CANSAS_NS}) 1567 1477 if len(nodes) > 1: 1568 raise RuntimeError, "CanSAS reader is not compatible with" + \ 1569 " multiple SASdata entries" 1478 raise RuntimeError, "CanSAS reader is not compatible with multiple SASdata entries" 1570 1479 1571 1480 for entry in nodes: … … 1589 1498 def _read_cansas(self, path): 1590 1499 """ 1591 Load data and fittinginformation from a CanSAS XML file.1500 Load data and P(r) information from a CanSAS XML file. 1592 1501 1593 1502 :param path: file path 1503 1594 1504 :return: Data1D object if a single SASentry was found, 1595 1505 or a list of Data1D objects if multiple entries were found, 1596 1506 or None of nothing was found 1507 1597 1508 :raise RuntimeError: when the file can't be opened 1598 1509 :raise ValueError: when the length of the data vectors are inconsistent 1510 1599 1511 """ 1600 1512 output = [] 1601 simfitstate = None1602 1513 basename = os.path.basename(path) 1603 1514 root, extension = os.path.splitext(basename) … … 1605 1516 try: 1606 1517 if os.path.isfile(path): 1607 if ext in self.ext or ext == '.xml': 1518 1519 #TODO: eventually remove the check for .xml once 1520 # the P(r) writer/reader is truly complete. 1521 if ext in self.ext or \ 1522 ext == '.xml': 1523 1608 1524 tree = etree.parse(path, parser=etree.ETCompatXMLParser()) 1609 1525 # Check the format version number 1610 # Specifying the namespace will take care of the file 1611 # format version 1526 # Specifying the namespace will take care of the file format version 1612 1527 root = tree.getroot() 1613 1528 entry_list = root.xpath('ns:SASentry', … … 1619 1534 raise 1620 1535 fitstate = self._parse_state(entry) 1621 simfitstate = self._parse_simfit_state(entry) 1622 1623 # state could be None when .svs file is loaded 1624 # in this case, skip appending to output 1625 if fitstate is not None: 1536 1537 #state could be None when .svs file is loaded 1538 #in this case, skip appending to output 1539 if fitstate != None: 1626 1540 sas_entry.meta_data['fitstate'] = fitstate 1627 1541 sas_entry.filename = fitstate.file 1628 1542 output.append(sas_entry) 1629 1630 1543 else: 1631 1544 self.call_back(format=ext) … … 1667 1580 name = original_fname 1668 1581 state.data.group_id = name 1669 # 1582 #store state in fitting 1670 1583 self.call_back(state=state, 1671 1584 datainfo=output[ind], format=ext) 1672 1585 self.state = state 1673 if simfitstate is not None:1674 self.call_back(state=simfitstate)1675 1676 1586 return output 1677 1587 except: … … 1689 1599 """ 1690 1600 # Sanity check 1691 if self.cansas :1601 if self.cansas == True: 1692 1602 # Add fitting information to the XML document 1693 1603 doc = self.write_toXML(datainfo, fitstate) … … 1701 1611 fd.close() 1702 1612 1703 def write_toXML(self, datainfo=None, state=None , batchfit=None):1613 def write_toXML(self, datainfo=None, state=None): 1704 1614 """ 1705 1615 Write toXML, a helper for write(), … … 1709 1619 """ 1710 1620 1711 self.batchfit_params = batchfit1712 if state.data is None or not state.data.is_data:1621 if state.data is None: 1622 data = sas.sascalc.dataloader.data_info.Data1D(x=[], y=[]) 1713 1623 return None 1714 # make sure title and data run are filled. 1715 if state.data.title is None or state.data.title == '': 1716 state.data.title = state.data.name 1717 if state.data.run_name is None or state.data.run_name == {}: 1718 state.data.run = [str(state.data.name)] 1719 state.data.run_name[0] = state.data.name 1720 1721 if issubclass(state.data.__class__, 1722 sas.sascalc.dataloader.data_info.Data1D): 1723 data = state.data 1724 doc, sasentry = self._to_xml_doc(data) 1624 elif not state.data.is_data: 1625 return None 1725 1626 else: 1726 data = state.data 1727 doc, sasentry = self._data2d_to_xml_doc(data) 1627 #make sure title and data run is filled up. 1628 if state.data.title == None or state.data.title == '': 1629 state.data.title = state.data.name 1630 if state.data.run_name == None or state.data.run_name == {}: 1631 state.data.run = [str(state.data.name)] 1632 state.data.run_name[0] = state.data.name 1633 1634 if issubclass(state.data.__class__, 1635 sas.sascalc.dataloader.data_info.Data1D): 1636 data = state.data 1637 doc, sasentry = self._to_xml_doc(data) 1638 else: 1639 data = state.data 1640 doc, sasentry = self._data2d_to_xml_doc(data) 1728 1641 1729 1642 if state is not None: 1730 doc = state.toXML(doc=doc, file=data.filename, entry_node=sasentry, 1731 batch_fit_state=self.batchfit_params) 1643 doc = state.toXML(doc=doc, file=data.filename, entry_node=sasentry) 1732 1644 1733 1645 return doc 1646 1647 # Simple html report templet 1648 HEADER = "<html>\n" 1649 HEADER += "<head>\n" 1650 HEADER += "<meta http-equiv=Content-Type content='text/html; " 1651 HEADER += "charset=windows-1252'> \n" 1652 HEADER += "<meta name=Generator >\n" 1653 HEADER += "</head>\n" 1654 HEADER += "<body lang=EN-US>\n" 1655 HEADER += "<div class=WordSection1>\n" 1656 HEADER += "<p class=MsoNormal><b><span ><center><font size='4' >" 1657 HEADER += "%s</font></center></span></center></b></p>" 1658 HEADER += "<p class=MsoNormal> </p>" 1659 PARA = "<p class=MsoNormal><font size='4' > %s \n" 1660 PARA += "</font></p>" 1661 CENTRE = "<p class=MsoNormal><center><font size='4' > %s \n" 1662 CENTRE += "</font></center></p>" 1663 FEET_1 = \ 1664 """ 1665 <p class=MsoNormal> </p> 1666 <br> 1667 <p class=MsoNormal><b><span ><center> <font size='4' > Graph 1668 </font></span></center></b></p> 1669 <p class=MsoNormal> </p> 1670 <center> 1671 <br><font size='4' >Model Computation</font> 1672 <br><font size='4' >Data: "%s"</font><br> 1673 """ 1674 FEET_2 = \ 1675 """ 1676 <img src="%s" > 1677 </img> 1678 """ 1679 FEET_3 = \ 1680 """ 1681 </center> 1682 </div> 1683 </body> 1684 </html> 1685 """ 1686 ELINE = "<p class=MsoNormal> </p>" 1687 1688 if __name__ == "__main__": 1689 state = PageState(parent=None) 1690 #state.toXML() 1691 """ 1692 1693 file = open("test_state", "w") 1694 pickle.dump(state, file) 1695 print pickle.dumps(state) 1696 state.data_name = "hello---->" 1697 pickle.dump(state, file) 1698 file = open("test_state", "r") 1699 new_state= pickle.load(file) 1700 print "new state", new_state 1701 new_state= pickle.load(file) 1702 print "new state", new_state 1703 #print "state", state 1704 """ 1705 import bsddb 1706 import pickle 1707 db = bsddb.btopen('file_state.db', 'c') 1708 val = (pickle.dumps(state), "hello", "hi") 1709 db['state1'] = pickle.dumps(val) 1710 print pickle.loads(db['state1']) 1711 state.data_name = "hello---->22" 1712 db['state2'] = pickle.dumps(state) 1713 state.data_name = "hello---->2" 1714 db['state3'] = pickle.dumps(state) 1715 del db['state3'] 1716 state.data_name = "hello---->3" 1717 db['state4'] = pickle.dumps(state) 1718 new_state = pickle.loads(db['state1']) 1719 #print db.last() 1720 db.set_location('state2') 1721 state.data_name = "hello---->5" 1722 db['aastate5'] = pickle.dumps(state) 1723 db.keys().sort() 1724 print pickle.loads(db['state2']) 1725 1726 db.close() -
src/sas/sasgui/perspectives/fitting/simfitpage.py
re89aed5 r4cafdff 9 9 from wx.lib.scrolledpanel import ScrolledPanel 10 10 11 from sas.sasgui.guiframe.events import StatusEvent , PanelOnFocusEvent11 from sas.sasgui.guiframe.events import StatusEvent 12 12 from sas.sasgui.guiframe.panel_base import PanelBase 13 from sas.sasgui.guiframe.events import PanelOnFocusEvent 13 14 from sas.sasgui.guiframe.utils import IdList 14 15 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 15 16 16 # Control panel width17 #Control panel width 17 18 if sys.platform.count("darwin") == 0: 18 19 PANEL_WID = 420 … … 28 29 'model_cbox param_cbox egal_txt constraint btRemove sizer') 29 30 30 31 31 def get_fittableParam(model): 32 32 """ … … 47 47 return fittable_param 48 48 49 50 49 class SimultaneousFitPage(ScrolledPanel, PanelBase): 51 50 """ … … 54 53 two data members window_name and window_caption 55 54 """ 56 # Internal name for the AUI manager57 window_name = " Simultaneous Fit Page"58 # Title to appear on top of the window55 ## Internal name for the AUI manager 56 window_name = "simultaneous Fit page" 57 ## Title to appear on top of the window 59 58 window_caption = "Simultaneous Fit Page" 60 59 ID_DOC = wx.NewId() … … 75 74 self._ids = iter(self._id_pool) 76 75 self.SetupScrolling() 77 # 76 ##Font size 78 77 self.SetWindowVariant(variant=FONT_VARIANT) 79 78 self.uid = wx.NewId() 80 79 self.parent = parent 81 80 self.batch_on = batch_on 82 # store page_finder81 ## store page_finder 83 82 self.page_finder = page_finder 84 # list containing info to set constraint85 # look like self.constraint_dict[page_id]= page83 ## list containing info to set constraint 84 ## look like self.constraint_dict[page_id]= page 86 85 self.constraint_dict = {} 87 # item list88 # self.constraints_list=[combobox1, combobox2,=,textcrtl, button ]86 ## item list 87 ## self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 89 88 self.constraints_list = [] 90 # list of current model89 ## list of current model 91 90 self.model_list = [] 92 # selected model to fit93 self.model_to _fit = []94 # Control the fit state91 ## selected mdoel to fit 92 self.model_toFit = [] 93 ## Control the fit state 95 94 self.fit_started = False 96 # number of constraint95 ## number of constraint 97 96 self.nb_constraint = 0 98 self.state = SimFitPageState()99 97 self.model_cbox_left = None 100 98 self.model_cbox_right = None 101 # draw page99 ## draw page 102 100 self.define_page_structure() 103 101 self.draw_page() … … 109 107 """ 110 108 self.vbox = wx.BoxSizer(wx.VERTICAL) 111 self. data_selection_sizer= wx.BoxSizer(wx.VERTICAL)112 self. constraints_sizer= wx.BoxSizer(wx.VERTICAL)113 self. run_fit_sizer= wx.BoxSizer(wx.VERTICAL)114 115 self. data_selection_sizer.SetMinSize((PANEL_WID, -1))116 self. constraints_sizer.SetMinSize((PANEL_WID, -1))117 self. run_fit_sizer.SetMinSize((PANEL_WID, -1))118 self.vbox.Add(self. data_selection_sizer)119 self.vbox.Add(self. constraints_sizer)120 self.vbox.Add(self. run_fit_sizer)109 self.sizer1 = wx.BoxSizer(wx.VERTICAL) 110 self.sizer2 = wx.BoxSizer(wx.VERTICAL) 111 self.sizer3 = wx.BoxSizer(wx.VERTICAL) 112 113 self.sizer1.SetMinSize((PANEL_WID, -1)) 114 self.sizer2.SetMinSize((PANEL_WID, -1)) 115 self.sizer3.SetMinSize((PANEL_WID, -1)) 116 self.vbox.Add(self.sizer1) 117 self.vbox.Add(self.sizer2) 118 self.vbox.Add(self.sizer3) 121 119 self.SetSizer(self.vbox) 122 120 self.Centre() 123 124 def set_state(self):125 """126 Define a set of state parameters for saving simultaneous fits.127 """128 self._set_constraint()129 self.state.fit_page_no = self.uid130 self.state.select_all = self.cb1.GetValue()131 self.state.model_list = self.model_list132 self.state.model_to_fit = self.model_to_fit133 self.state.no_constraint = self.nb_constraint134 self.state.constraint_dict = self.constraint_dict135 self.state.constraints_list = self.constraints_list136 return self.get_state()137 138 def get_state(self):139 """140 Return the state of the current page141 :return: self.state142 """143 return self.state144 121 145 122 def draw_page(self): … … 154 131 # create blank list of constraints 155 132 self.model_list = [] 156 self.model_to _fit = []133 self.model_toFit = [] 157 134 self.constraints_list = [] 158 135 self.constraint_dict = {} … … 167 144 168 145 #------------------------------------------------------- 169 # setup sizer1 (which fitpages to include)170 self. data_selection_sizer.Clear(True)146 ## setup sizer1 (which fitpages to include) 147 self.sizer1.Clear(True) 171 148 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Combinations") 172 149 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) … … 174 151 sizer_couples = wx.GridBagSizer(5, 5) 175 152 176 # The wx GUI has a flag to enable a menu item, but can still be177 # reached via scripting. There is no guearantee future GUI178 # implementations force this check, either.179 # IMHO, this if statement should stay -- JRK 2016-OCT-05153 #This if statement should be obsolete and can be removed in version 4 154 #Leave it here for now as no time to thoroughly test. However if no 155 #fit page is found the menu item that calls this page is inactive 156 # Nov. 22 2015 --PDB 180 157 if len(self.page_finder) == 0: 181 158 msg = " No fit combinations are found! \n\n" … … 184 161 sizer_title.Add(wx.StaticText(self, wx.ID_ANY, msg)) 185 162 else: 186 # store model163 ## store model 187 164 self._store_model() 188 165 … … 194 171 wx.TOP | wx.BOTTOM | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 195 172 sizer_title.Add(self.cb1, 0, 196 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 197 border=5) 198 199 # draw list of model and data names 173 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 174 175 ## draw list of model and data names 200 176 self._fill_sizer_model_list(sizer_couples) 201 177 202 178 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=5) 203 179 boxsizer1.Add(sizer_couples, 1, flag=wx.TOP | wx.BOTTOM, border=5) 204 self. data_selection_sizer.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10)205 #self.sizer1.Layout()180 self.sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10) 181 # self.sizer1.Layout() 206 182 207 183 #-------------------------------------------------------- 208 # set up the other 2 sizers: the constraints list and the 209 # buttons (fit, help etc) sizer at the bottom of the page. 210 # Note: the if statement should be removed along with the above 211 # if statement as soon as it can be properly tested. 212 # Nov. 22 2015 --PDB 213 # As above, this page can be accessed through other means than the 214 # base SasView GUI. 215 # Oct. 5, 2016 --JRK 184 ## set up the other 2 sizers: the constraints list and the 185 ## buttons (fit, help etc) sizer at the bottom of the page. 186 ## Note: the if statement should be removed along with the above 187 ## if statement as soon as it can be properly tested. 188 ## Nov. 22 2015 --PDB 216 189 if len(self.page_finder) > 0: 217 # draw the sizer containing constraint info190 ## draw the sizer containing constraint info 218 191 if not self.batch_on: 219 192 self._fill_sizer_constraint() 220 # draw fit button sizer193 ## draw fit button sizer 221 194 self._fill_sizer_fit() 195 222 196 223 197 def _fill_sizer_model_list(self, sizer): … … 227 201 ix = 0 228 202 iy = 0 203 list = [] 229 204 sizer.Clear(True) 230 205 … … 234 209 new_name.SetForegroundColour(wx.WHITE) 235 210 sizer.Add(new_name, (iy, ix), (1, 1), 236 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)211 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 237 212 ix += 2 238 213 model_type = wx.StaticText(self, wx.ID_ANY, ' Model ') … … 240 215 model_type.SetForegroundColour(wx.WHITE) 241 216 sizer.Add(model_type, (iy, ix), (1, 1), 242 wx.EXPAND | wx.ADJUST_MINSIZE, 0)217 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 243 218 ix += 1 244 219 data_used = wx.StaticText(self, wx.ID_ANY, ' Data ') … … 246 221 data_used.SetForegroundColour(wx.WHITE) 247 222 sizer.Add(data_used, (iy, ix), (1, 1), 248 wx.EXPAND | wx.ADJUST_MINSIZE, 0)223 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 249 224 ix += 1 250 225 tab_used = wx.StaticText(self, wx.ID_ANY, ' FitPage ') … … 327 302 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 328 303 329 self. constraints_sizer.Clear(True)304 self.sizer2.Clear(True) 330 305 if self.batch_on: 331 if self. constraints_sizer.IsShown():332 self. constraints_sizer.Show(False)306 if self.sizer2.IsShown(): 307 self.sizer2.Show(False) 333 308 return 334 309 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Constraints") 335 box _sizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)310 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 336 311 sizer_title = wx.BoxSizer(wx.HORIZONTAL) 337 312 self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL) … … 363 338 364 339 self.btAdd = wx.Button(self, self.ID_ADD, 'Add') 365 self.btAdd.Bind(wx.EVT_BUTTON, self._on _add_constraint,340 self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint, 366 341 id=self.btAdd.GetId()) 367 342 self.btAdd.SetToolTipString("Add another constraint?") … … 369 344 370 345 text_hint = wx.StaticText(self, wx.ID_ANY, 371 "Example: [M0][param eter] = M1.parameter")346 "Example: [M0][paramter] = M1.parameter") 372 347 sizer_button.Add(text_hint, 0, 373 348 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) … … 375 350 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 376 351 377 box_sizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 378 box_sizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 379 border=10) 380 box_sizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 381 border=10) 382 box_sizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 383 384 self.constraints_sizer.Add(box_sizer1, 0, wx.EXPAND | wx.ALL, 10) 352 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 353 boxsizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 354 border=10) 355 boxsizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 356 border=10) 357 boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 358 359 self.sizer2.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 360 385 361 386 362 def _fill_sizer_fit(self): … … 388 364 Draw fit button 389 365 """ 390 self. run_fit_sizer.Clear(True)366 self.sizer3.Clear(True) 391 367 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit ") 392 368 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 393 369 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 394 370 395 # 371 #Fit button 396 372 self.btFit = wx.Button(self, self.ID_FIT, 'Fit', size=wx.DefaultSize) 397 self.btFit.Bind(wx.EVT_BUTTON, self.on _fit, id=self.btFit.GetId())373 self.btFit.Bind(wx.EVT_BUTTON, self.onFit, id=self.btFit.GetId()) 398 374 self.btFit.SetToolTipString("Perform fit.") 399 375 400 # 376 #General Help button 401 377 self.btHelp = wx.Button(self, wx.ID_HELP, 'HELP') 402 378 self.btHelp.SetToolTipString("Simultaneous/Constrained Fitting help.") 403 self.btHelp.Bind(wx.EVT_BUTTON, self._on _help)404 405 # 379 self.btHelp.Bind(wx.EVT_BUTTON, self._onHelp) 380 381 #hint text on button line 406 382 if self.batch_on: 407 383 text = " Fit in Parallel all Data sets\n" … … 417 393 418 394 boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 419 self. run_fit_sizer.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10)420 421 def on _remove(self, event):395 self.sizer3.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 396 397 def onRemove(self, event): 422 398 """ 423 399 Remove constraint fields … … 430 406 return 431 407 wx.CallAfter(self._remove_after, event.GetId()) 432 # 408 #self._onAdd_constraint(None) 433 409 434 410 def _remove_after(self, id): … … 440 416 self.constraints_list.remove(item) 441 417 self.nb_constraint -= 1 442 self. constraints_sizer.Layout()418 self.sizer2.Layout() 443 419 self.FitInside() 444 420 break 445 421 446 def on _fit(self, event):422 def onFit(self, event): 447 423 """ 448 424 signal for fitting … … 459 435 flag = (self._manager.sim_page.uid == self.uid) 460 436 461 # making sure all parameters content a constraint437 ## making sure all parameters content a constraint 462 438 if not self.batch_on and self.show_constraint.GetValue(): 463 439 if not self._set_constraint(): 464 440 return 465 # model was actually selected from this page to be fit466 if len(self.model_to _fit) >= 1:441 ## model was actually selected from this page to be fit 442 if len(self.model_toFit) >= 1: 467 443 self.manager._reset_schedule_problem(value=0) 468 444 for item in self.model_list: … … 480 456 msg = "Select at least one model check box to fit " 481 457 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 482 self.set_state()483 458 484 459 def _on_fit_complete(self): … … 492 467 """ 493 468 Attempt to stop the fitting thread 494 495 :param event: Event handler when stop fit is clicked 496 """ 497 if event is not None: 469 """ 470 if event != None: 498 471 event.Skip() 499 472 self.manager.stop_fit(self.uid) … … 512 485 self.btFit.Enable(True) 513 486 514 def _on _help(self, event):487 def _onHelp(self, event): 515 488 """ 516 489 Bring up the simultaneous Fitting Documentation whenever the HELP … … 521 494 versions of Wx (before 2.9) and thus not the release version of 522 495 installers, the help comes up at the top level of the file as 523 web 496 webbrowser does not pass anything past the # to the browser when it is 524 497 running "file:///...." 525 498 526 :param ev ent: Triggers on clicking the help button499 :param evt: Triggers on clicking the help button 527 500 """ 528 501 _TreeLocation = "user/sasgui/perspectives/fitting/fitting_help.html" … … 537 510 538 511 :param manager: instance of plugin fitting 512 539 513 """ 540 514 self.manager = manager … … 544 518 check all models names 545 519 """ 546 self.model_to _fit = []547 if self.cb1.GetValue() :520 self.model_toFit = [] 521 if self.cb1.GetValue() == True: 548 522 for item in self.model_list: 549 523 if item[0].IsEnabled(): 550 524 item[0].SetValue(True) 551 self.model_to _fit.append(item)552 553 # constraint info525 self.model_toFit.append(item) 526 527 ## constraint info 554 528 self._store_model() 555 529 if not self.batch_on: 556 # display constraint fields530 ## display constraint fields 557 531 if (self.show_constraint.GetValue() and 558 532 len(self.constraints_list) == 0): … … 564 538 565 539 if not self.batch_on: 566 # 540 ##constraint info 567 541 self._hide_constraint() 568 542 … … 570 544 self.FitInside() 571 545 546 572 547 def check_model_name(self, event): 573 548 """ 574 549 Save information related to checkbox and their states 575 550 """ 576 self.model_to_fit = [] 551 self.model_toFit = [] 552 cbox = event.GetEventObject() 577 553 for item in self.model_list: 578 if item[0].GetValue() :579 self.model_to _fit.append(item)554 if item[0].GetValue() == True: 555 self.model_toFit.append(item) 580 556 else: 581 if item in self.model_to _fit:582 self.model_to _fit.remove(item)557 if item in self.model_toFit: 558 self.model_toFit.remove(item) 583 559 self.cb1.SetValue(False) 584 560 585 # display constraint fields586 if len(self.model_to _fit) >= 1:561 ## display constraint fields 562 if len(self.model_toFit) >= 1: 587 563 self._store_model() 588 564 if not self.batch_on and self.show_constraint.GetValue() and\ … … 591 567 self._show_constraint() 592 568 593 elif len(self.model_to _fit) < 1:594 # 569 elif len(self.model_toFit) < 1: 570 ##constraint info 595 571 self._hide_constraint() 596 572 597 573 self._update_easy_setup_cb() 598 # set the value of the main check button599 if len(self.model_list) == len(self.model_to _fit):574 ## set the value of the main check button 575 if len(self.model_list) == len(self.model_toFit): 600 576 self.cb1.SetValue(True) 601 577 self.FitInside() … … 609 585 Update easy setup combobox on selecting a model 610 586 """ 611 if self.model_cbox_left is None or self.model_cbox_right isNone:612 return 613 614 models = [(item[3].name, item[3]) for item in self.model_to _fit]587 if self.model_cbox_left == None or self.model_cbox_right == None: 588 return 589 590 models = [(item[3].name, item[3]) for item in self.model_toFit] 615 591 setComboBoxItems(self.model_cbox_left, models) 616 592 setComboBoxItems(self.model_cbox_right, models) … … 619 595 if self.model_cbox_left.GetSelection() == wx.NOT_FOUND: 620 596 self.model_cbox_left.SetSelection(0) 621 self. constraints_sizer.Layout()597 self.sizer2.Layout() 622 598 623 599 def _store_model(self): … … 625 601 Store selected model 626 602 """ 627 if len(self.model_to _fit) < 1:628 return 629 for item in self.model_to _fit:603 if len(self.model_toFit) < 1: 604 return 605 for item in self.model_toFit: 630 606 model = item[3] 631 607 page_id = item[2] … … 636 612 Show fields to add constraint 637 613 """ 638 if len(self.model_to _fit) < 1:614 if len(self.model_toFit) < 1: 639 615 msg = "Select at least 1 model to add constraint " 640 616 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 641 # hide button617 ## hide button 642 618 self._hide_constraint() 643 619 return … … 656 632 """ 657 633 box_description = wx.StaticBox(self, wx.ID_ANY, "Easy Setup ") 658 box _sizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL)634 boxsizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL) 659 635 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 660 636 self.model_cbox_left = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) … … 674 650 675 651 for id, model in self.constraint_dict.iteritems(): 676 # check if all parameters have been selected for constraint677 # then do not allow add constraint on parameters652 ## check if all parameters have been selected for constraint 653 ## then do not allow add constraint on parameters 678 654 self.model_cbox_left.Append(str(model.name), model) 679 655 self.model_cbox_left.Select(0) 680 656 for id, model in self.constraint_dict.iteritems(): 681 # check if all parameters have been selected for constraint682 # then do not allow add constraint on parameters657 ## check if all parameters have been selected for constraint 658 ## then do not allow add constraint on parameters 683 659 self.model_cbox_right.Append(str(model.name), model) 684 box _sizer.Add(self.model_cbox_left,660 boxsizer.Add(self.model_cbox_left, 685 661 flag=wx.RIGHT | wx.EXPAND, border=10) 686 # box_sizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"),662 #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 687 663 # flag=wx.RIGHT | wx.EXPAND, border=5) 688 box _sizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5)689 box _sizer.Add(self.model_cbox_right,664 boxsizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 665 boxsizer.Add(self.model_cbox_right, 690 666 flag=wx.RIGHT | wx.EXPAND, border=10) 691 # box_sizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"),667 #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 692 668 # flag=wx.RIGHT | wx.EXPAND, border=5) 693 box _sizer.Add((20, -1))694 box _sizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5)695 sizer_constraint.Add(box _sizer, flag=wx.RIGHT | wx.EXPAND, border=5)669 boxsizer.Add((20, -1)) 670 boxsizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5) 671 sizer_constraint.Add(boxsizer, flag=wx.RIGHT | wx.EXPAND, border=5) 696 672 self.sizer_all_constraints.Insert(before=0, 697 673 item=sizer_constraint, … … 723 699 return 724 700 param_list = [] 725 param_list _b= []701 param_listB = [] 726 702 selection = self.model_cbox_left.GetCurrentSelection() 727 703 model_left = self.model_cbox_left.GetValue() 728 704 model = self.model_cbox_left.GetClientData(selection) 729 selection _b= self.model_cbox_right.GetCurrentSelection()705 selectionB = self.model_cbox_right.GetCurrentSelection() 730 706 model_right = self.model_cbox_right.GetValue() 731 model _b = self.model_cbox_right.GetClientData(selection_b)707 modelB = self.model_cbox_right.GetClientData(selectionB) 732 708 for id, dic_model in self.constraint_dict.iteritems(): 733 709 if model == dic_model: 734 710 param_list = self.page_finder[id].get_param2fit() 735 if model _b== dic_model:736 param_list _b= self.page_finder[id].get_param2fit()737 if len(param_list) > 0 and len(param_list _b) > 0:711 if modelB == dic_model: 712 param_listB = self.page_finder[id].get_param2fit() 713 if len(param_list) > 0 and len(param_listB) > 0: 738 714 break 739 715 num_cbox = 0 … … 741 717 for param in param_list: 742 718 num_cbox += 1 743 if param in param_list _b:719 if param in param_listB: 744 720 item = self.constraints_list[-1] 745 721 item.model_cbox.SetStringSelection(model_left) … … 768 744 """ 769 745 Show constraint fields 770 :param dict: dictionary mapping constraint values771 746 """ 772 747 self.btAdd.Show(True) … … 775 750 for id, model in self.constraint_dict.iteritems(): 776 751 nb_fit_param += len(self.page_finder[id].get_param2fit()) 777 # 752 ##Don't add anymore 778 753 if len(self.constraints_list) == nb_fit_param: 779 754 msg = "Cannot add another constraint. Maximum of number " … … 781 756 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 782 757 self.sizer_constraints.Layout() 783 self. constraints_sizer.Layout()758 self.sizer2.Layout() 784 759 return 785 if len(self.model_to _fit) < 1:760 if len(self.model_toFit) < 1: 786 761 msg = "Select at least 1 model to add constraint " 787 762 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 788 763 self.sizer_constraints.Layout() 789 self. constraints_sizer.Layout()764 self.sizer2.Layout() 790 765 return 791 766 … … 796 771 model_cbox.Clear() 797 772 for id, model in self.constraint_dict.iteritems(): 798 # check if all parameters have been selected for constraint799 # then do not allow add constraint on parameters773 ## check if all parameters have been selected for constraint 774 ## then do not allow add constraint on parameters 800 775 model_cbox.Append(str(model.name), model) 801 776 wx.EVT_COMBOBOX(model_cbox, wx.ID_ANY, self._on_select_model) … … 814 789 # Remove button 815 790 #btRemove = wx.Button(self, self.ID_REMOVE, 'Remove') 816 bt _remove = wx.Button(self, self._ids.next(), 'Remove')817 bt _remove.Bind(wx.EVT_BUTTON, self.on_remove,818 id=bt _remove.GetId())819 bt _remove.SetToolTipString("Remove constraint.")820 bt _remove.Hide()791 btRemove = wx.Button(self, self._ids.next(), 'Remove') 792 btRemove.Bind(wx.EVT_BUTTON, self.onRemove, 793 id=btRemove.GetId()) 794 btRemove.SetToolTipString("Remove constraint.") 795 btRemove.Hide() 821 796 822 797 # Hid the add button, if it exists … … 829 804 sizer_constraint.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 830 805 sizer_constraint.Add(constraint, flag=wx.RIGHT | wx.EXPAND, border=10) 831 sizer_constraint.Add(bt _remove, flag=wx.RIGHT | wx.EXPAND, border=10)806 sizer_constraint.Add(btRemove, flag=wx.RIGHT | wx.EXPAND, border=10) 832 807 833 808 self.sizer_constraints.Insert(before=self.nb_constraint, … … 835 810 border=5) 836 811 c = ConstraintLine(model_cbox, param_cbox, egal_txt, 837 constraint, bt _remove, sizer_constraint)812 constraint, btRemove, sizer_constraint) 838 813 self.constraints_list.append(c) 839 814 840 815 self.nb_constraint += 1 841 816 self.sizer_constraints.Layout() 842 self. constraints_sizer.Layout()843 self.Layout ()817 self.sizer2.Layout() 818 self.Layout 844 819 845 820 def _hide_constraint(self): … … 866 841 self.sizer_constraints.Clear(True) 867 842 self.sizer_constraints.Layout() 868 self. constraints_sizer.Layout()869 self.Layout ()843 self.sizer2.Layout() 844 self.Layout 870 845 self.FitInside() 871 846 872 847 def _on_select_model(self, event): 873 848 """ 874 fill combo box with list of parameters849 fill combox box with list of parameters 875 850 """ 876 851 if not self.constraints_list: 877 852 return 878 853 879 # 854 ##This way PC/MAC both work, instead of using event.GetClientData(). 880 855 model_cbox = self.constraints_list[-1].model_cbox 881 856 n = model_cbox.GetCurrentSelection() … … 892 867 param_cbox = self.constraints_list[-1].param_cbox 893 868 param_cbox.Clear() 894 # insert only fittable paramaters869 ## insert only fittable paramaters 895 870 for param in param_list: 896 871 param_cbox.Append(str(param), model) 897 872 param_cbox.Show(True) 898 873 899 bt _remove = self.constraints_list[-1].btRemove900 bt _remove.Show(True)874 btRemove = self.constraints_list[-1].btRemove 875 btRemove.Show(True) 901 876 self.btAdd.Show(True) 902 877 # self.Layout() … … 907 882 Store the appropriate constraint in the page_finder 908 883 """ 909 # 910 # 911 # 912 # 884 ##This way PC/MAC both work, instead of using event.GetClientData(). 885 #n = self.param_cbox.GetCurrentSelection() 886 #model = self.param_cbox.GetClientData(n) 887 #param = event.GetString() 913 888 914 889 if self.constraints_list: … … 916 891 self.constraints_list[-1].constraint.Show(True) 917 892 918 def _on _add_constraint(self, event):893 def _onAdd_constraint(self, event): 919 894 """ 920 895 Add another line for constraint … … 924 899 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 925 900 return 926 # check that a constraint is added901 ## check that a constraint is added 927 902 # before allow to add another constraint 928 903 for item in self.constraints_list: … … 938 913 model = item.param_cbox.GetClientData( 939 914 item.param_cbox.GetCurrentSelection()) 940 if model is notNone:915 if model != None: 941 916 msg = " Enter a constraint for %s.%s! " % (model.name, 942 917 item.param_cbox.GetString(0)) … … 945 920 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 946 921 return 947 # some model or parameters can be constrained922 ## some model or parameters can be constrained 948 923 self._show_constraint() 949 924 self.FitInside() … … 1005 980 def on_set_focus(self, event=None): 1006 981 """ 1007 The derivative class is on focus if implemented982 The derivative class is on focus if implemented 1008 983 """ 1009 984 if self.parent is not None: … … 1020 995 cbox.Append(name, value) 1021 996 cbox.SetStringSelection(selected) 1022 1023 1024 class SimFitPageState:1025 """1026 State of the simultaneous fit page for saving purposes1027 """1028 1029 def __init__(self):1030 # Sim Fit Page Number1031 self.fit_page_no = None1032 # Select all data1033 self.select_all = False1034 # Data sets sent to fit page1035 self.model_list = []1036 # Data sets to be fit1037 self.model_to_fit = []1038 # Number of constraints1039 self.no_constraint = 01040 # Dictionary of constraints1041 self.constraint_dict = {}1042 # List of constraints1043 self.constraints_list = []1044 1045 def load_from_save_state(self, fit):1046 """1047 Load in a simultaneous/constrained fit from a save state1048 :param fit: Fitpanel object1049 :return: None1050 """1051 1052 model_map = {}1053 fit.fit_panel.add_sim_page()1054 1055 # Process each model and associate old M# with new M#1056 i = 01057 for model in fit.fit_panel.sim_page.model_list:1058 model_id = self._format_id(model[1].keys()[0])1059 for saved_model in self.model_list:1060 save_id = saved_model.pop('name')1061 saved_model['name'] = save_id1062 save_id = self._format_id(save_id)1063 if save_id == model_id:1064 model_map[saved_model.pop('fit_page_source')] = \1065 model[3].name1066 check = bool(saved_model.pop('checked'))1067 fit.fit_panel.sim_page.model_list[i][0].SetValue(check)1068 continue1069 i += 11070 fit.fit_panel.sim_page.check_model_name(None)1071 1072 if len(self.constraints_list) > 0:1073 fit.fit_panel.sim_page.hide_constraint.SetValue(False)1074 fit.fit_panel.sim_page.show_constraint.SetValue(True)1075 fit.fit_panel.sim_page._display_constraint(None)1076 1077 for constraint in self.constraints_list:1078 model_cbox = constraint.pop('model_cbox')1079 constraint_value = constraint.pop('constraint')1080 for key, value in model_map.iteritems():1081 model_cbox.replace(key, value)1082 constraint_value.replace(key, value)1083 1084 bt_remove = wx.Button(fit.fit_panel.sim_page,1085 fit.fit_panel.sim_page._ids.next(), 'Remove')1086 bt_remove.Bind(wx.EVT_BUTTON, fit.fit_panel.sim_page.on_remove,1087 id=bt_remove.GetId())1088 bt_remove.SetToolTipString("Remove constraint.")1089 param_cbox = wx.ComboBox(fit.fit_panel.sim_page, wx.ID_ANY,1090 style=wx.CB_READONLY, size=(100, -1))1091 egal_txt = wx.StaticText(fit.fit_panel.sim_page, wx.ID_ANY, " = ")1092 # Model list1093 model_cbox_sizer = wx.ComboBox(fit.fit_panel.sim_page,1094 wx.ID_ANY, style=wx.CB_READONLY)1095 model_cbox_sizer.Clear()1096 wx.EVT_COMBOBOX(model_cbox_sizer, wx.ID_ANY,1097 fit.fit_panel.sim_page._on_select_model)1098 constraint_sizer = wx.TextCtrl(fit.fit_panel.sim_page, wx.ID_ANY)1099 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL)1100 sizer_constraint.Add((5, -1))1101 sizer_constraint.Add(model_cbox_sizer, flag=wx.RIGHT | wx.EXPAND,1102 border=10)1103 sizer_constraint.Add(param_cbox, flag=wx.RIGHT | wx.EXPAND,1104 border=5)1105 sizer_constraint.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5)1106 sizer_constraint.Add(constraint_sizer, flag=wx.RIGHT | wx.EXPAND,1107 border=10)1108 sizer_constraint.Add(bt_remove, flag=wx.RIGHT | wx.EXPAND,1109 border=10)1110 new_const = ConstraintLine(model_cbox=model_cbox_sizer,1111 param_cbox=constraint.pop('param_cbox'),1112 egal_txt=constraint.pop('egal_txt'),1113 constraint=constraint_value,1114 btRemove=bt_remove,1115 sizer=sizer_constraint1116 )1117 # ConstraintLine = namedtuple('ConstraintLine',1118 # 'model_cbox param_cbox egal_txt constraint btRemove sizer')1119 fit.fit_panel.sim_page.sizer_constraints.Insert(1120 before=fit.fit_panel.sim_page.nb_constraint,1121 item=sizer_constraint, flag=wx.TOP | wx.BOTTOM | wx.EXPAND,1122 border=5)1123 fit.fit_panel.sim_page.constraints_list.append(new_const)1124 1125 def _format_id(self, original_id):1126 original_id = original_id.rstrip('1234567890.')1127 new_id_list = original_id.split()1128 new_id = ' '.join(new_id_list)1129 return new_id
Note: See TracChangeset
for help on using the changeset viewer.