Ignore:
Timestamp:
Nov 26, 2018 7:07:55 AM (5 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:
9c207f5
Parents:
9c05f22
Message:

Redone the widget slightly, to fit with requirements in trac#1135.
Added comboboxes for all available fitpage names
Removed constraint of needing two selected fitpages
Removed the "Swap" button - it is redundant now.
Added context dependence on the "Select All" action.
Removed immediate constraint validation to allow for more complex
formulas

File:
1 edited

Legend:

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

    rd72ac57 r2e5081b  
    3737        self.operator = '=' 
    3838        self._constraint = Constraint() 
     39        self.all_menu   = None 
    3940 
    4041        self.warning = self.lblWarning.text() 
     
    6061        self.cmdOK.clicked.connect(self.onApply) 
    6162        self.cmdHelp.clicked.connect(self.onHelp) 
    62         self.cmdRevert.clicked.connect(self.onRevert) 
    6363        self.txtConstraint.editingFinished.connect(self.validateFormula) 
     64        self.cbModel1.currentIndexChanged.connect(self.onModelIndexChange) 
     65        self.cbModel2.currentIndexChanged.connect(self.onModelIndexChange) 
    6466 
    6567        self.cbParam1.currentIndexChanged.connect(self.onParamIndexChange) 
     
    7173        Setup widgets based on current parameters 
    7274        """ 
    73         self.txtName1.setText(self.tab_names[0]) 
    74         self.txtName2.setText(self.tab_names[1]) 
     75        self.cbModel1.insertItems(0, self.tab_names) 
     76        self.cbModel2.insertItems(0, self.tab_names) 
    7577 
    7678        self.setupParamWidgets() 
    7779 
    78         # Add menu to the Apply button 
    79         all_menu   = QtWidgets.QMenu() 
     80        self.setupMenu() 
     81 
     82    def setupMenu(self): 
     83        # Add menu to the Apply button, if necessary 
     84        if self.cbModel1.currentText() ==self.cbModel2.currentText(): 
     85            self.cmdOK.setArrowType(QtCore.Qt.NoArrow) 
     86            self.cmdOK.setPopupMode(QtWidgets.QToolButton.DelayedPopup) 
     87            self.cmdOK.setMenu(None) 
     88            return 
     89        self.all_menu   = QtWidgets.QMenu() 
    8090        self.actionAddAll = QtWidgets.QAction(self) 
    8191        self.actionAddAll.setObjectName("actionAddAll") 
     
    8494        self.actionAddAll.setToolTip(ttip) 
    8595        self.actionAddAll.triggered.connect(self.onSetAll) 
    86         all_menu.addAction(self.actionAddAll) 
     96        self.all_menu.addAction(self.actionAddAll) 
    8797        # https://bugreports.qt.io/browse/QTBUG-13663 
    88         all_menu.setToolTipsVisible(True) 
    89         self.cmdOK.setMenu(all_menu) 
     98        self.all_menu.setToolTipsVisible(True) 
     99        self.cmdOK.setPopupMode(QtWidgets.QToolButton.MenuButtonPopup) 
     100        self.cmdOK.setArrowType(QtCore.Qt.DownArrow) 
     101        self.cmdOK.setMenu(self.all_menu) 
    90102 
    91103    def setupParamWidgets(self): 
     
    94106        """ 
    95107        self.cbParam1.clear() 
    96         items1 = [param for param in self.params[0] if not self.tabs[0].paramHasConstraint(param)] 
     108        tab_index1 = self.cbModel1.currentIndex() 
     109        items1 = [param for param in self.params[tab_index1] if not self.tabs[tab_index1].paramHasConstraint(param)] 
    97110        self.cbParam1.addItems(items1) 
    98111 
    99112        # M2 doesn't have to be non-constrained 
    100113        self.cbParam2.clear() 
    101         #items2 = [param for param in self.params[1] if not self.tabs[1].paramHasConstraint(param)] 
    102         items2 = [param for param in self.params[1]] 
     114        tab_index2 = self.cbModel2.currentIndex() 
     115        items2 = [param for param in self.params[tab_index2]] 
    103116        self.cbParam2.addItems(items2) 
    104117 
    105         self.txtParam.setText(self.tab_names[0] + ":" + self.cbParam1.currentText()) 
     118        self.txtParam.setText(self.tab_names[tab_index1] + ":" + self.cbParam1.currentText()) 
    106119 
    107120        self.cbOperator.clear() 
     
    109122        self.txtOperator.setText(self.cbOperator.currentText()) 
    110123 
    111         self.txtConstraint.setText(self.tab_names[1]+"."+self.cbParam2.currentText()) 
     124        self.txtConstraint.setText(self.tab_names[tab_index2]+"."+self.cbParam2.currentText()) 
    112125 
    113126        # disable Apply if no parameters available 
     
    155168        self.lblWarning.setText(txt) 
    156169 
     170    def onModelIndexChange(self, index): 
     171        """ 
     172        Respond to mode combo box changes 
     173        """ 
     174        # disable/enable Add All 
     175        self.setupMenu() 
     176        # Reload parameters 
     177        self.setupParamWidgets() 
    157178 
    158179    def onOperatorChange(self, index): 
     
    162183        self.txtOperator.setText(self.cbOperator.currentText()) 
    163184 
    164     def onRevert(self): 
    165         """ 
    166         switch M1 <-> M2 
    167         """ 
    168         # Switch parameters 
    169         self.params[1], self.params[0] = self.params[0], self.params[1] 
    170         self.tab_names[1], self.tab_names[0] = self.tab_names[0], self.tab_names[1] 
    171         self.tabs[1], self.tabs[0] = self.tabs[0], self.tabs[1] 
    172         # Try to swap parameter names in the line edit 
    173         current_text = self.txtConstraint.text() 
    174         new_text = current_text.replace(self.cbParam1.currentText(), self.cbParam2.currentText()) 
    175         self.txtConstraint.setText(new_text) 
    176         # Update labels and tooltips 
    177         index1 = self.cbParam1.currentIndex() 
    178         index2 = self.cbParam2.currentIndex() 
    179         indexOp = self.cbOperator.currentIndex() 
    180         self.setupWidgets() 
    181  
    182         # Original indices 
    183         index2 = index2 if index2 >= 0 else 0 
    184         index1 = index1 if index1 >= 0 else 0 
    185         self.cbParam1.setCurrentIndex(index2) 
    186         self.cbParam2.setCurrentIndex(index1) 
    187         self.cbOperator.setCurrentIndex(indexOp) 
    188         self.setupTooltip() 
    189  
    190185    def validateFormula(self): 
    191186        """ 
    192187        Add visual cues when formula is incorrect 
    193188        """ 
     189        # temporarily disable validation 
     190        return 
     191        # 
    194192        formula_is_valid = self.validateConstraint(self.txtConstraint.text()) 
    195193        if not formula_is_valid: 
     
    208206            return False 
    209207 
    210         # M1.scale  --> model_str='M1', constraint_text='scale' 
     208        # M1.scale --> model_str='M1', constraint_text='scale' 
    211209        param_str = self.cbParam2.currentText() 
    212210        constraint_text = constraint_text.strip() 
    213         model_str = self.txtName2.text() 
     211        model_str = self.cbModel2.currentText() 
    214212 
    215213        # 0. Has to contain the model name 
    216         if model_str != self.txtName2.text(): 
     214        if model_str != model_str: 
    217215            return False 
    218216 
     
    249247        value = self.cbParam2.currentText() 
    250248        func = self.txtConstraint.text() 
    251         value_ex = self.txtName2.text() + "." + self.cbParam2.currentText() 
    252         model1 = self.txtName1.text() 
     249        value_ex = self.cbModel2.currentText() + "." + self.cbParam2.currentText() 
     250        model1 = self.cbModel1.currentText() 
    253251        operator = self.cbOperator.currentText() 
    254252 
     
    284282            param = item 
    285283            value = item 
    286             func = self.txtName2.text() + "." + param 
    287             value_ex = self.txtName1.text() + "." + param 
    288             model1 = self.txtName1.text() 
     284            func = self.cbModel2.currentText() + "." + param 
     285            value_ex = self.cbModel1.currentText() + "." + param 
     286            model1 = self.cbModel1.currentText() 
    289287            operator = self.cbOperator.currentText() 
    290288 
Note: See TracChangeset for help on using the changeset viewer.