Ignore:
Timestamp:
Oct 19, 2018 5:25:25 AM (6 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
b8dccb8
Parents:
10d57f6
Message:

Working version of Save/Load? Analysis. SASVIEW-983.
Changed the default behaviour of Category/Model? combos:
Selecting a category does not pre-select the first model now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r9a42ea1 r2eeda93  
    5252TAB_POLY = 3 
    5353CATEGORY_DEFAULT = "Choose category..." 
     54MODEL_DEFAULT = "Choose model..." 
    5455CATEGORY_STRUCTURE = "Structure Factor" 
    5556CATEGORY_CUSTOM = "Plugin Models" 
     
    566567        # Signals from other widgets 
    567568        self.communicate.customModelDirectoryChanged.connect(self.onCustomModelChange) 
    568         self.communicate.saveAnalysisSignal.connect(self.savePageState) 
    569         #self.communicate.loadAnalysisSignal.connect(self.loadPageState) 
    570569        self.smearing_widget.smearingChangedSignal.connect(self.onSmearingOptionsUpdate) 
    571570 
     
    10191018        model = self.cbModel.currentText() 
    10201019 
     1020        if model == MODEL_DEFAULT: 
     1021            # if the previous category was not the default, keep it. 
     1022            # Otherwise, just return 
     1023            if self._previous_model_index != 0: 
     1024                # We need to block signals, or else state changes on perceived unchanged conditions 
     1025                self.cbModel.blockSignals(True) 
     1026                self.cbModel.setCurrentIndex(self._previous_model_index) 
     1027                self.cbModel.blockSignals(False) 
     1028            return 
     1029 
    10211030        # Assure the control is active 
    10221031        if not self.cbModel.isEnabled(): 
     
    10261035            return 
    10271036        self.chkMagnetism.setEnabled(self.canHaveMagnetism()) 
     1037        self.chkMagnetism.setEnabled(self.canHaveMagnetism()) 
    10281038        self.tabFitting.setTabEnabled(TAB_MAGNETISM, self.chkMagnetism.isChecked() and self.canHaveMagnetism()) 
     1039        self._previous_model_index = self.cbModel.currentIndex() 
    10291040 
    10301041        # Reset parameters to fit 
     
    12001211            self._model_model.clear() 
    12011212            return 
    1202  
     1213        # Wipe out the parameter model 
     1214        self._model_model.clear() 
    12031215        # Safely clear and enable the model combo 
    12041216        self.cbModel.blockSignals(True) 
     
    12121224        model_list = self.master_category_dict[category] 
    12131225        # Populate the models combobox 
     1226        self.cbModel.blockSignals(True) 
     1227        self.cbModel.addItem(MODEL_DEFAULT) 
    12141228        self.cbModel.addItems(sorted([model for (model, _) in model_list])) 
     1229        self.cbModel.blockSignals(False) 
    12151230 
    12161231    def onPolyModelChange(self, top, bottom): 
     
    33663381        return report_logic.reportList() 
    33673382 
    3368     def savePageState(self): 
    3369         """ 
    3370         Create and serialize local PageState 
    3371         """ 
    3372         filepath = self.saveAsAnalysisFile() 
    3373         if filepath is None or filepath == "": 
    3374             return 
    3375  
    3376         fitpage_state = self.getFitPage() 
    3377         fitpage_state += self.getFitModel() 
    3378  
    3379         with open(filepath, 'w') as statefile: 
    3380             for line in fitpage_state: 
    3381                 statefile.write(str(line)) 
    3382  
    3383         self.communicate.statusBarUpdateSignal.emit('Analysis saved.') 
    3384  
    3385     def saveAsAnalysisFile(self): 
    3386         """ 
    3387         Show the save as... dialog and return the chosen filepath 
    3388         """ 
    3389         default_name = "FitPage"+str(self.tab_id)+".fitv" 
    3390  
    3391         wildcard = "fitv files (*.fitv)" 
    3392         kwargs = { 
    3393             'caption'   : 'Save As', 
    3394             'directory' : default_name, 
    3395             'filter'    : wildcard, 
    3396             'parent'    : None, 
    3397         } 
    3398         # Query user for filename. 
    3399         filename_tuple = QtWidgets.QFileDialog.getSaveFileName(**kwargs) 
    3400         filename = filename_tuple[0] 
    3401         return filename 
    3402  
    34033383    def loadPageStateCallback(self,state=None, datainfo=None, format=None): 
    34043384        """ 
     
    35193499        """ 
    35203500        param_list = [] 
     3501        if self.kernel_module is None: 
     3502            return param_list 
     3503 
    35213504        param_list.append(['model_name', str(self.cbModel.currentText())]) 
    35223505 
     
    36233606        cb_text = cb.text() 
    36243607 
    3625         context = {} 
    36263608        lines = cb_text.split(':') 
    36273609        if lines[0] != 'sasview_parameter_values': 
     
    36353617                line_dict[content[0]] = content[1:] 
    36363618 
     3619        self.updatePageWithParameters(line_dict) 
     3620 
     3621    def createPageForParameters(self, line_dict): 
     3622        """ 
     3623        Sets up page with requested model/str factor 
     3624        and fills it up with sent parameters 
     3625        """ 
     3626        if 'fitpage_category' in line_dict: 
     3627            self.cbCategory.setCurrentIndex(self.cbCategory.findText(line_dict['fitpage_category'][0])) 
     3628        if 'fitpage_model' in line_dict: 
     3629            self.cbModel.setCurrentIndex(self.cbModel.findText(line_dict['fitpage_model'][0])) 
     3630        if 'fitpage_structure' in line_dict: 
     3631            self.cbStructureFactor.setCurrentIndex(self.cbStructureFactor.findText(line_dict['fitpage_structure'][0])) 
     3632 
     3633        # Now that the page is ready for parameters, fill it up 
     3634        self.updatePageWithParameters(line_dict) 
     3635 
     3636    def updatePageWithParameters(self, line_dict): 
     3637        """ 
     3638        Update FitPage with parameters in line_dict 
     3639        """ 
     3640        if 'model_name' not in line_dict.keys(): 
     3641            return 
    36373642        model = line_dict['model_name'][0] 
    3638  
    3639         if 'model_name' not in line_dict.keys(): 
    3640             return False 
     3643        context = {} 
    36413644 
    36423645        if 'multiplicity' in line_dict.keys(): 
Note: See TracChangeset for help on using the changeset viewer.