Changeset 41e3f36 in sasview


Ignore:
Timestamp:
Aug 2, 2018 11:59:34 AM (3 weeks ago)
Author:
tcbennun
Branches:
ESS_GUI_beta_approx
Children:
ea578f6
Parents:
00077cf
Message:

add so-called functional constraint functionality, demonstrate with radius_effective

Location:
src/sas/qtgui/Perspectives/Fitting
Files:
1 added
1 edited

Legend:

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

    r00077cf r41e3f36  
    4848from sas.qtgui.Perspectives.Fitting.MultiConstraint import MultiConstraint 
    4949from sas.qtgui.Perspectives.Fitting.ReportPageLogic import ReportPageLogic 
     50from sas.qtgui.Perspectives.Fitting.AssociatedComboBox import AssociatedComboBox 
    5051 
    5152 
     
    734735        self.communicate.statusBarUpdateSignal.emit('Constraint added') 
    735736 
     737    def addFunctionalConstraintToRow(self, row): 
     738        """Add functional constraint (i.e. set parameter to be the return value of a function in some model) 
     739        with GUI option to keep the parameter free/fittable instead.""" 
     740        assert(0 <= row < self._model_model.rowCount()) 
     741 
     742        self._model_model.blockSignals(True) 
     743 
     744        child_row = [QtGui.QStandardItem("Constrained to")] + [QtGui.QStandardItem() for i in range(4)] 
     745        for i in [0, 2, 3, 4]: 
     746            child_row[i].setEditable(False) 
     747        self._model_model.item(row, 0).appendRow(child_row) 
     748 
     749        item = child_row[1] 
     750        idx = item.index() 
     751        cbox = AssociatedComboBox(item) 
     752        cbox.addItems(["(free fitting)", "some_func"]) 
     753        cbox.setCurrentIndex(0) 
     754        self.lstParams.setIndexWidget(idx, cbox) 
     755        child_row[1].setData(cbox) 
     756 
     757        self._model_model.blockSignals(False) 
     758 
    736759    def deleteConstraint(self): 
    737760        """ 
     
    20032026        for row in new_rows: 
    20042027            self._model_model.appendRow(row) 
     2028            row_num = self._model_model.rowCount() - 1 
     2029 
    20052030            # disable fitting of parameters not listed in self.kernel_module (probably radius_effective) 
    2006             if row[0].text() not in self.kernel_module.params.keys(): 
    2007                 row_num = self._model_model.rowCount() - 1 
    2008                 FittingUtilities.markParameterDisabled(self._model_model, row_num) 
     2031            #if row[0].text() not in self.kernel_module.params.keys(): 
     2032            #    FittingUtilities.markParameterDisabled(self._model_model, row_num) 
     2033 
     2034            # TODO this needs actual checks; this is just for a demo 
     2035            if row[0].text() == "radius_effective": 
     2036                self.addFunctionalConstraintToRow(row_num) 
    20092037 
    20102038        # Update the counter used for multishell display 
     
    20372065        Callback method for updating the sasmodel parameters with the GUI values 
    20382066        """ 
     2067        # Handle functional constraint changes 
     2068        parent = item.parent() 
     2069        if parent is not None: 
     2070            data = item.data() 
     2071            if type(data) is AssociatedComboBox: 
     2072 
     2073                # TODO handle the change here properly (and probably refactor it somewhere else) 
     2074                max = 4 if self.has_error_column else 5 
     2075                if item.text() == "(free fitting)": 
     2076                    txt = "1337" 
     2077                    parent.setForeground(QtGui.QBrush(QtGui.QColor(0, 0, 0))) 
     2078                    parent.setFont(QtGui.QFont()) 
     2079                else: 
     2080                    txt = "" 
     2081                    parent.setForeground(QtGui.QBrush(QtGui.QColor(0, 0, 255))) 
     2082                    font = QtGui.QFont() 
     2083                    font.setBold(True) 
     2084                    font.setItalic(True) 
     2085                    parent.setFont(font) 
     2086 
     2087                # TODO have to block signals for now, because radius_effective breaks onMainParamsChange... 
     2088                self._model_model.blockSignals(True) 
     2089                for i in range(1, max): 
     2090                    self._model_model.item(parent.row(), i).setText(txt) 
     2091                self._model_model.blockSignals(False) 
     2092 
    20392093        model_column = item.column() 
    20402094 
Note: See TracChangeset for help on using the changeset viewer.