Ignore:
Timestamp:
May 9, 2017 1:38:40 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
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
Children:
f7f5796
Parents:
31e4bb8
Message:

Code review fixes for SASVIEW-273

File:
1 edited

Legend:

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

    r02ddfb4 r2add354  
    1212from PyQt4 import QtGui 
    1313from PyQt4 import QtCore 
     14from PyQt4 import QtWebKit 
    1415 
    1516from sasmodels import generate 
     
    3233from SmearingWidget import SmearingWidget 
    3334from OptionsWidget import OptionsWidget 
     35from FitPage import FitPage 
    3436 
    3537TAB_MAGNETISM = 4 
     
    7375        self.log_points = False 
    7476        self.weighting = 0 
     77        self.chi2 = None 
    7578 
    7679        # Data for chosen model 
     
    132135        """ 
    133136        self.lstParams.setStyleSheet(stylesheet) 
     137        self.lstParams.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) 
     138        self.lstParams.customContextMenuRequested.connect(self.showModelDescription) 
    134139 
    135140        # Poly model displayed in poly list 
     
    163168        self.initializeControls() 
    164169 
     170        # Display HTML content 
     171        self.helpView = QtWebKit.QWebView() 
     172 
    165173        self._index = None 
    166174        if data is not None: 
    167175            self.data = data 
     176 
     177    def close(self): 
     178        """ 
     179        Remember to kill off things on exit 
     180        """ 
     181        self.helpView.close() 
     182        del self.helpView 
    168183 
    169184    @property 
     
    197212        self.lblFilename.setText(self.logic.data.filename) 
    198213        self.updateQRange() 
    199         self.cmdFit.setEnabled(True) 
    200214        # Switch off Data2D control 
    201215        self.chk2DView.setEnabled(False) 
     
    285299        self.cmdFit.clicked.connect(self.onFit) 
    286300        self.cmdPlot.clicked.connect(self.onPlot) 
     301        self.cmdHelp.clicked.connect(self.onHelp) 
    287302 
    288303        # Respond to change in parameters from the UI 
     
    294309        # Signals from separate tabs asking for replot 
    295310        self.options_widget.plot_signal.connect(self.onOptionsUpdate) 
     311 
     312    def showModelDescription(self, position): 
     313        """ 
     314        Shows a window with model description, when right clicked in the treeview 
     315        """ 
     316        msg = 'Model description:\n' 
     317        info = "Info" 
     318        if self.kernel_module is not None: 
     319            if str(self.kernel_module.description).rstrip().lstrip() == '': 
     320                msg += "Sorry, no information is available for this model." 
     321            else: 
     322                msg += self.kernel_module.description + '\n' 
     323        else: 
     324            msg += "You must select a model to get information on this" 
     325 
     326        menu = QtGui.QMenu() 
     327        label = QtGui.QLabel(msg) 
     328        action = QtGui.QWidgetAction(self) 
     329        action.setDefaultWidget(label) 
     330        menu.addAction(action) 
     331        menu.exec_(self.lstParams.viewport().mapToGlobal(position)) 
    296332 
    297333    def onSelectModel(self): 
     
    321357            # Create default datasets if no data passed 
    322358            self.createDefaultDataset() 
     359 
     360        #state = self.currentState() 
    323361 
    324362    def onSelectStructureFactor(self): 
     
    403441        pass # debug anchor 
    404442 
     443    def onHelp(self): 
     444        """ 
     445        Show the "Fitting" section of help 
     446        """ 
     447        tree_location = self.parent.HELP_DIRECTORY_LOCATION +\ 
     448            "/user/sasgui/perspectives/fitting/fitting_help.html" 
     449        self.helpView.load(QtCore.QUrl(tree_location)) 
     450        self.helpView.show() 
     451 
    405452    def onFit(self): 
    406453        """ 
     
    438485        fitter.set_model(model, fit_id, params_to_fit, data=data, 
    439486                         constraints=constraints) 
     487 
    440488        fitter.set_data(data=data, id=fit_id, smearer=smearer, qmin=qmin, 
    441489                        qmax=qmax) 
     
    501549        self.communicate.statusBarUpdateSignal.emit(msg) 
    502550 
    503         fitness = res.fitness 
     551        self.chi2 = res.fitness 
    504552        param_list = res.param_list 
    505553        param_values = res.pvec 
     
    516564 
    517565        # Read only value - we can get away by just printing it here 
    518         chi2_repr = GuiUtils.formatNumber(fitness, high=True) 
     566        chi2_repr = GuiUtils.formatNumber(self.chi2, high=True) 
    519567        self.lblChi2Value.setText(chi2_repr) 
    520568 
     
    586634        # Regardless of previous state, this should now be `plot show` functionality only 
    587635        self.cmdPlot.setText("Show Plot") 
    588         self.recalculatePlotData() 
    589636        self.showPlot() 
    590637 
     
    685732        checked_list = ['background', '0.001', '-inf', 'inf', '1/cm'] 
    686733        FittingUtilities.addCheckedListToModel(model, checked_list) 
     734        last_row = model.rowCount()-1 
     735        model.item(last_row, 0).setEditable(False) 
     736        model.item(last_row, 4).setEditable(False) 
    687737 
    688738    def addScaleToModel(self, model): 
     
    693743        checked_list = ['scale', '1.0', '0.0', 'inf', ''] 
    694744        FittingUtilities.addCheckedListToModel(model, checked_list) 
     745        last_row = model.rowCount()-1 
     746        model.item(last_row, 0).setEditable(False) 
     747        model.item(last_row, 4).setEditable(False) 
    695748 
    696749    def addWeightingToData(self, data): 
     
    781834        if model_column == 0: 
    782835            self.checkboxSelected(item) 
     836            self.cmdFit.setEnabled(self.parameters_to_fit != [] and self.logic.data_is_loaded) 
    783837            return 
    784838 
     
    787841 
    788842        # Extract changed value. Assumes proper validation by QValidator/Delegate 
    789         value = float(item.text()) 
     843        # TODO: disable model update for uneditable cells/columns 
     844        try: 
     845            value = float(item.text()) 
     846        except ValueError: 
     847            # Unparsable field 
     848            return 
    790849        parameter_name = str(self._model_model.data(name_index).toPyObject()) # sld, background etc. 
    791850        property_name = str(self._model_model.headerData(1, model_column).toPyObject()) # Value, min, max, etc. 
     
    9441003        self.createNewIndex(fitted_data) 
    9451004        # Calculate difference between return_data and logic.data 
    946         chi2 = FittingUtilities.calculateChi2(fitted_data, self.logic.data) 
     1005        self.chi2 = FittingUtilities.calculateChi2(fitted_data, self.logic.data) 
    9471006        # Update the control 
    948         chi2_repr = "---" if chi2 is None else GuiUtils.formatNumber(chi2, high=True) 
     1007        chi2_repr = "---" if self.chi2 is None else GuiUtils.formatNumber(self.chi2, high=True) 
    9491008        self.lblChi2Value.setText(chi2_repr) 
    9501009 
Note: See TracChangeset for help on using the changeset viewer.