Ignore:
Timestamp:
Oct 6, 2016 1:47:28 PM (8 years ago)
Author:
krzywon
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
1dbdb83
Parents:
ef3e09b
Message:

#189: Can now open the simultaneous and constrained fit panel through a save state, but the constraint loading is still broken.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/pagestate.py

    ra95ae9a re89aed5  
    860860        :param file: .fitv file 
    861861        :param node: node of a XML document to read from 
    862  
    863862        """ 
    864863        if file is not None: 
     
    867866            raise RuntimeError, msg 
    868867 
    869         if node.get('version')and node.get('version') == '1.0': 
     868        if node.get('version') and node.get('version') == '1.0': 
    870869 
    871870            # Get file name 
     
    12721271 
    12731272        :param entry: XML node to read from 
    1274  
    12751273        :return: PageState object 
    12761274        """ 
     
    12811279            nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, 
    12821280                                namespaces={'ns': CANSAS_NS}) 
    1283             if nodes != []: 
     1281            if nodes: 
    12841282                # Create an empty state 
    12851283                state = PageState() 
     
    12911289 
    12921290        return state 
     1291 
     1292    def _parse_simfit_state(self, entry): 
     1293        """ 
     1294        Parses the saved data for a simultaneous fit 
     1295        :param entry: XML object to read from 
     1296        :return: XML object for a simultaneous fit or None 
     1297        """ 
     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 SimFitPageState 
     1305                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].attrib 
     1310                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.attrib 
     1318                    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.attrib 
     1325                    sim_fit_state.constraints_list.append(attrs) 
     1326 
     1327                return sim_fit_state 
     1328            else: 
     1329                return None 
    12931330 
    12941331    def _parse_save_state_entry(self, dom): 
     
    15521589    def _read_cansas(self, path): 
    15531590        """ 
    1554         Load data and P(r) information from a CanSAS XML file. 
     1591        Load data and fitting information from a CanSAS XML file. 
    15551592 
    15561593        :param path: file path 
    1557  
    15581594        :return: Data1D object if a single SASentry was found, 
    15591595                    or a list of Data1D objects if multiple entries were found, 
    15601596                    or None of nothing was found 
    1561  
    15621597        :raise RuntimeError: when the file can't be opened 
    15631598        :raise ValueError: when the length of the data vectors are inconsistent 
    1564  
    15651599        """ 
    15661600        output = [] 
     1601        simfitstate = None 
    15671602        basename = os.path.basename(path) 
    15681603        root, extension = os.path.splitext(basename) 
     
    15841619                            raise 
    15851620                        fitstate = self._parse_state(entry) 
     1621                        simfitstate = self._parse_simfit_state(entry) 
    15861622 
    15871623                        # state could be None when .svs file is loaded 
     
    15911627                            sas_entry.filename = fitstate.file 
    15921628                            output.append(sas_entry) 
     1629 
    15931630            else: 
    15941631                self.call_back(format=ext) 
     
    16341671                                   datainfo=output[ind], format=ext) 
    16351672                    self.state = state 
     1673                if simfitstate is not None: 
     1674                    self.call_back(state=simfitstate) 
     1675 
    16361676                return output 
    16371677        except: 
Note: See TracChangeset for help on using the changeset viewer.