source: sasview/src/sas/qtgui/Perspectives/Fitting/ConstraintWidget.py @ 6ca0da0

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 6ca0da0 was 6ca0da0, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

More code review fixes

  • Property mode set to 100644
File size: 24.8 KB
Line 
1import logging
2
3from twisted.internet import threads
4
5import sas.qtgui.Utilities.GuiUtils as GuiUtils
6import sas.qtgui.Utilities.LocalConfig as LocalConfig
7
8from PyQt5 import QtGui, QtCore, QtWidgets
9
10from sas.sascalc.fit.BumpsFitting import BumpsFit as Fit
11
12import sas.qtgui.Utilities.ObjectLibrary as ObjectLibrary
13from sas.qtgui.Perspectives.Fitting.UI.ConstraintWidgetUI import Ui_ConstraintWidgetUI
14from sas.qtgui.Perspectives.Fitting.FittingWidget import FittingWidget
15from sas.qtgui.Perspectives.Fitting.FitThread import FitThread
16from sas.qtgui.Perspectives.Fitting.ConsoleUpdate import ConsoleUpdate
17from sas.qtgui.Perspectives.Fitting.ComplexConstraint import ComplexConstraint
18from sas.qtgui.Perspectives.Fitting.Constraint import Constraint
19
20class ConstraintWidget(QtWidgets.QWidget, Ui_ConstraintWidgetUI):
21    """
22    Constraints Dialog to select the desired parameter/model constraints.
23    """
24
25    def __init__(self, parent=None):
26        super(ConstraintWidget, self).__init__()
27        self.parent = parent
28        self.setupUi(self)
29        self.currentType = "FitPage"
30        # Page id for fitting
31        # To keep with previous SasView values, use 300 as the start offset
32        self.page_id = 301
33
34        # Remember previous content of modified cell
35        self.current_cell = ""
36
37        # Tabs used in simultaneous fitting
38        # tab_name : True/False
39        self.tabs_for_fitting = {}
40
41        # Set up the widgets
42        self.initializeWidgets()
43
44        # Set up signals/slots
45        self.initializeSignals()
46
47        # Create the list of tabs
48        self.initializeFitList()
49
50    def acceptsData(self):
51        """ Tells the caller this widget doesn't accept data """
52        return False
53
54    def initializeWidgets(self):
55        """
56        Set up various widget states
57        """
58        labels = ['FitPage', 'Model', 'Data', 'Mnemonic']
59        # tab widget - headers
60        self.editable_tab_columns = [labels.index('Mnemonic')]
61        self.tblTabList.setColumnCount(len(labels))
62        self.tblTabList.setHorizontalHeaderLabels(labels)
63        self.tblTabList.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
64
65        self.tblTabList.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
66        self.tblTabList.customContextMenuRequested.connect(self.showModelContextMenu)
67
68        # disabled constraint
69        labels = ['Constraint']
70        self.tblConstraints.setColumnCount(len(labels))
71        self.tblConstraints.setHorizontalHeaderLabels(labels)
72        self.tblConstraints.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
73        self.tblConstraints.setEnabled(False)
74
75        self.tblConstraints.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
76        self.tblConstraints.customContextMenuRequested.connect(self.showConstrContextMenu)
77
78    def initializeSignals(self):
79        """
80        Set up signals/slots for this widget
81        """
82        # simple widgets
83        self.btnSingle.toggled.connect(self.onFitTypeChange)
84        self.btnBatch.toggled.connect(self.onFitTypeChange)
85        self.cbCases.currentIndexChanged.connect(self.onSpecialCaseChange)
86        self.cmdFit.clicked.connect(self.onFit)
87        self.cmdHelp.clicked.connect(self.onHelp)
88
89        # QTableWidgets
90        self.tblTabList.cellChanged.connect(self.onTabCellEdit)
91        self.tblTabList.cellDoubleClicked.connect(self.onTabCellEntered)
92        self.tblConstraints.cellChanged.connect(self.onConstraintChange)
93
94        # External signals
95        self.parent.tabsModifiedSignal.connect(self.initializeFitList)
96
97    def updateSignalsFromTab(self, tab=None):
98        """
99        Intercept update signals from fitting tabs
100        """
101        if tab is None:
102            return
103        tab_object = ObjectLibrary.getObject(tab)
104
105        # Disconnect all local slots
106        tab_object.disconnect()
107
108        # Reconnect tab signals to local slots
109        tab_object.constraintAddedSignal.connect(self.initializeFitList)
110        tab_object.newModelSignal.connect(self.initializeFitList)
111
112    def onFitTypeChange(self, checked):
113        """
114        Respond to the fit type change
115        single fit/batch fit
116        """
117        source = self.sender().objectName()
118        self.currentType = "BatchPage" if source == "btnBatch" else "FitPage"
119        self.initializeFitList()
120
121    def onSpecialCaseChange(self, index):
122        """
123        Respond to the combobox change for special case constraint sets
124        """
125        pass
126
127    def getTabsForFit(self):
128        """
129        Returns list of tab names selected for fitting
130        """
131        return [tab for tab in self.tabs_for_fitting if self.tabs_for_fitting[tab]]
132
133    def onFit(self):
134        """
135        Perform the constrained/simultaneous fit
136        """
137        # Find out all tabs to fit
138        tabs_to_fit = self.getTabsForFit()
139
140        # Single fitter for the simultaneous run
141        fitter = Fit()
142        fitter.fitter_id = self.page_id
143
144        # Notify the parent about fitting started
145        self.parent.fittingStartedSignal.emit(tabs_to_fit)
146
147        # prepare fitting problems for each tab
148        #
149        page_ids = []
150        fitter_id = 0
151        sim_fitter_list=[fitter]
152        # Prepare the fitter object
153        try:
154            for tab in tabs_to_fit:
155                tab_object = ObjectLibrary.getObject(tab)
156                if tab_object is None:
157                    # No such tab!
158                    return
159                sim_fitter_list, fitter_id = tab_object.prepareFitters(fitter=sim_fitter_list[0], fit_id=fitter_id)
160                page_ids.append([tab_object.page_id])
161        except ValueError:
162            # No parameters selected in one of the tabs
163            no_params_msg = "Fitting can not be performed.\n" +\
164                            "Not all tabs chosen for fitting have parameters selected for fitting."
165            QtWidgets.QMessageBox.question(self,
166                                           'Warning',
167                                            no_params_msg,
168                                            QtWidgets.QMessageBox.Ok)
169
170            return
171
172        # Create the fitting thread, based on the fitter
173        completefn = self.onBatchFitComplete if self.currentType=='BatchPage' else self.onFitComplete
174
175        if LocalConfig.USING_TWISTED:
176            handler = None
177            updater = None
178        else:
179            handler = ConsoleUpdate(parent=self.parent,
180                                    manager=self,
181                                    improvement_delta=0.1)
182            updater = handler.update_fit
183
184        batch_inputs = {}
185        batch_outputs = {}
186
187        # new fit thread object
188        calc_fit = FitThread(handler=handler,
189                             fn=sim_fitter_list,
190                             batch_inputs=batch_inputs,
191                             batch_outputs=batch_outputs,
192                             page_id=page_ids,
193                             updatefn=updater,
194                             completefn=completefn)
195
196        if LocalConfig.USING_TWISTED:
197            # start the trhrhread with twisted
198            calc_thread = threads.deferToThread(calc_fit.compute)
199            calc_thread.addCallback(completefn)
200            calc_thread.addErrback(self.onFitFailed)
201        else:
202            # Use the old python threads + Queue
203            calc_fit.queue()
204            calc_fit.ready(2.5)
205
206
207        #disable the Fit button
208        self.cmdFit.setText('Running...')
209        self.parent.communicate.statusBarUpdateSignal.emit('Fitting started...')
210        self.cmdFit.setEnabled(False)
211
212    def onHelp(self):
213        """
214        Show the "Fitting" section of help
215        """
216        tree_location = "/user/sasgui/perspectives/fitting/"
217
218        helpfile = "fitting_help.html#simultaneous-fit-mode"
219        help_location = tree_location + helpfile
220
221        # OMG, really? Crawling up the object hierarchy...
222        self.parent.parent.showHelp(help_location)
223
224    def onTabCellEdit(self, row, column):
225        """
226        Respond to check/uncheck and to modify the model moniker actions
227        """
228        item = self.tblTabList.item(row, column)
229        if column == 0:
230            # Update the tabs for fitting list
231            tab_name = item.text()
232            self.tabs_for_fitting[tab_name] = (item.checkState() == QtCore.Qt.Checked)
233            # Enable fitting only when there are models to fit
234            self.cmdFit.setEnabled(any(self.tabs_for_fitting.values()))
235
236        if column not in self.editable_tab_columns:
237            return
238        new_moniker = item.data(0)
239
240        # The new name should be validated on the fly, with QValidator
241        # but let's just assure it post-factum
242        is_good_moniker = self.validateMoniker(new_moniker)
243        if not is_good_moniker:
244            self.tblTabList.blockSignals(True)
245            item.setBackground(QtCore.Qt.red)
246            self.tblTabList.blockSignals(False)
247            self.cmdFit.setEnabled(False)
248            return
249        self.tblTabList.blockSignals(True)
250        item.setBackground(QtCore.Qt.white)
251        self.tblTabList.blockSignals(False)
252        self.cmdFit.setEnabled(True)
253        if not self.current_cell:
254            return
255        # Remember the value
256        if self.current_cell not in self.available_tabs:
257            return
258        temp_tab = self.available_tabs[self.current_cell]
259        # Remove the key from the dictionaries
260        self.available_tabs.pop(self.current_cell, None)
261        # Change the model name
262        model = temp_tab.kernel_module
263        model.name = new_moniker
264        # Replace constraint name
265        temp_tab.replaceConstraintName(self.current_cell, new_moniker)
266        # Replace constraint name in the remaining tabs
267        for tab in self.available_tabs.values():
268            tab.replaceConstraintName(self.current_cell, new_moniker)
269        # Reinitialize the display
270        self.initializeFitList()
271
272    def onConstraintChange(self, row, column):
273        """
274        Modify the constraint's "active" instance variable.
275        """
276        item = self.tblConstraints.item(row, column)
277        if column == 0:
278            # Update the tabs for fitting list
279            constraint = self.available_constraints[row]
280            constraint.active = (item.checkState() == QtCore.Qt.Checked)
281
282    def onTabCellEntered(self, row, column):
283        """
284        Remember the original tab list cell data.
285        Needed for reverting back on bad validation
286        """
287        if column != 3:
288            return
289        self.current_cell = self.tblTabList.item(row, column).data(0)
290
291    def onFitComplete(self, result):
292        """
293        Respond to the successful fit complete signal
294        """
295        #re-enable the Fit button
296        self.cmdFit.setText("Fit")
297        self.cmdFit.setEnabled(True)
298
299        # Notify the parent about completed fitting
300        self.parent.fittingStoppedSignal.emit(self.getTabsForFit())
301
302        # Assure the fitting succeeded
303        if result is None or not result:
304            msg = "Fitting failed. Please ensure correctness of chosen constraints."
305            self.parent.communicate.statusBarUpdateSignal.emit(msg)
306            return
307
308        # get the elapsed time
309        elapsed = result[1]
310
311        # result list
312        results = result[0][0]
313
314        # Find out all tabs to fit
315        tabs_to_fit = [tab for tab in self.tabs_for_fitting if self.tabs_for_fitting[tab]]
316
317        # update all involved tabs
318        for i, tab in enumerate(tabs_to_fit):
319            tab_object = ObjectLibrary.getObject(tab)
320            if tab_object is None:
321                # No such tab. removed while job was running
322                return
323            # Make sure result and target objects are the same (same model moniker)
324            if tab_object.kernel_module.name == results[i].model.name:
325                tab_object.fitComplete(([[results[i]]], elapsed))
326
327        msg = "Fitting completed successfully in: %s s.\n" % GuiUtils.formatNumber(elapsed)
328        self.parent.communicate.statusBarUpdateSignal.emit(msg)
329
330    def onBatchFitComplete(self, result):
331        """
332        Respond to the successful batch fit complete signal
333        """
334        #re-enable the Fit button
335        self.cmdFit.setText("Fit")
336        self.cmdFit.setEnabled(True)
337
338        # Notify the parent about completed fitting
339        self.parent.fittingStoppedSignal.emit(self.getTabsForFit())
340
341        # get the elapsed time
342        elapsed = result[1]
343
344        # ADD THE BATCH FIT VIEW HERE
345        #
346
347        msg = "Fitting completed successfully in: %s s.\n" % GuiUtils.formatNumber(elapsed)
348        self.parent.communicate.statusBarUpdateSignal.emit(msg)
349
350        pass
351
352    def onFitFailed(self, reason):
353        """
354        Respond to fitting failure.
355        """
356        #re-enable the Fit button
357        self.cmdFit.setText("Fit")
358        self.cmdFit.setEnabled(True)
359
360        # Notify the parent about completed fitting
361        self.parent.fittingStoppedSignal.emit(self.getTabsForFit())
362
363        msg = "Fitting failed: %s s.\n" % reason
364        self.parent.communicate.statusBarUpdateSignal.emit(msg)
365        pass
366 
367    def isTabImportable(self, tab):
368        """
369        Determines if the tab can be imported and included in the widget
370        """
371        if not isinstance(tab, str): return False
372        if not self.currentType in tab: return False
373        object = ObjectLibrary.getObject(tab)
374        if not isinstance(object, FittingWidget): return False
375        if object.data is None: return False
376        return True
377
378    def showModelContextMenu(self, position):
379        """
380        Show context specific menu in the tab table widget.
381        """
382        menu = QtWidgets.QMenu()
383        rows = [s.row() for s in self.tblTabList.selectionModel().selectedRows()]
384        num_rows = len(rows)
385        if num_rows <= 0:
386            return
387        # Select for fitting
388        param_string = "Fit Page " if num_rows==1 else "Fit Pages "
389
390        self.actionSelect = QtWidgets.QAction(self)
391        self.actionSelect.setObjectName("actionSelect")
392        self.actionSelect.setText(QtCore.QCoreApplication.translate("self", "Select "+param_string+" for fitting"))
393        # Unselect from fitting
394        self.actionDeselect = QtWidgets.QAction(self)
395        self.actionDeselect.setObjectName("actionDeselect")
396        self.actionDeselect.setText(QtCore.QCoreApplication.translate("self", "De-select "+param_string+" from fitting"))
397
398        self.actionRemoveConstraint = QtWidgets.QAction(self)
399        self.actionRemoveConstraint.setObjectName("actionRemoveConstrain")
400        self.actionRemoveConstraint.setText(QtCore.QCoreApplication.translate("self", "Remove all constraints on selected models"))
401
402        self.actionMutualMultiConstrain = QtWidgets.QAction(self)
403        self.actionMutualMultiConstrain.setObjectName("actionMutualMultiConstrain")
404        self.actionMutualMultiConstrain.setText(QtCore.QCoreApplication.translate("self", "Mutual constrain of parameters in selected models..."))
405
406        menu.addAction(self.actionSelect)
407        menu.addAction(self.actionDeselect)
408        menu.addSeparator()
409
410        if num_rows >= 2:
411            menu.addAction(self.actionMutualMultiConstrain)
412
413        # Define the callbacks
414        self.actionMutualMultiConstrain.triggered.connect(self.showMultiConstraint)
415        self.actionSelect.triggered.connect(self.selectModels)
416        self.actionDeselect.triggered.connect(self.deselectModels)
417        try:
418            menu.exec_(self.tblTabList.viewport().mapToGlobal(position))
419        except AttributeError as ex:
420            logging.error("Error generating context menu: %s" % ex)
421        return
422
423    def showConstrContextMenu(self, position):
424        """
425        Show context specific menu in the tab table widget.
426        """
427        menu = QtWidgets.QMenu()
428        rows = [s.row() for s in self.tblConstraints.selectionModel().selectedRows()]
429        num_rows = len(rows)
430        if num_rows <= 0:
431            return
432        # Select for fitting
433        param_string = "constraint " if num_rows==1 else "constraints "
434
435        self.actionSelect = QtWidgets.QAction(self)
436        self.actionSelect.setObjectName("actionSelect")
437        self.actionSelect.setText(QtCore.QCoreApplication.translate("self", "Select "+param_string+" for fitting"))
438        # Unselect from fitting
439        self.actionDeselect = QtWidgets.QAction(self)
440        self.actionDeselect.setObjectName("actionDeselect")
441        self.actionDeselect.setText(QtCore.QCoreApplication.translate("self", "De-select "+param_string+" from fitting"))
442
443        self.actionRemoveConstraint = QtWidgets.QAction(self)
444        self.actionRemoveConstraint.setObjectName("actionRemoveConstrain")
445        self.actionRemoveConstraint.setText(QtCore.QCoreApplication.translate("self", "Remove "+param_string))
446
447        menu.addAction(self.actionSelect)
448        menu.addAction(self.actionDeselect)
449        menu.addSeparator()
450        menu.addAction(self.actionRemoveConstraint)
451
452        # Define the callbacks
453        self.actionRemoveConstraint.triggered.connect(self.deleteConstraint)
454        self.actionSelect.triggered.connect(self.selectConstraints)
455        self.actionDeselect.triggered.connect(self.deselectConstraints)
456        try:
457            menu.exec_(self.tblConstraints.viewport().mapToGlobal(position))
458        except AttributeError as ex:
459            logging.error("Error generating context menu: %s" % ex)
460        return
461
462    def selectConstraints(self):
463        """
464        Selected constraints are chosen for fitting
465        """
466        status = QtCore.Qt.Checked
467        self.setRowSelection(self.tblConstraints, status)
468
469    def deselectConstraints(self):
470        """
471        Selected constraints are removed for fitting
472        """
473        status = QtCore.Qt.Unchecked
474        self.setRowSelection(self.tblConstraints, status)
475
476    def selectModels(self):
477        """
478        Selected models are chosen for fitting
479        """
480        status = QtCore.Qt.Checked
481        self.setRowSelection(self.tblTabList, status)
482
483    def deselectModels(self):
484        """
485        Selected models are removed for fitting
486        """
487        status = QtCore.Qt.Unchecked
488        self.setRowSelection(self.tblTabList, status)
489
490    def selectedParameters(self, widget):
491        """ Returns list of selected (highlighted) parameters """
492        return [s.row() for s in widget.selectionModel().selectedRows()]
493
494    def setRowSelection(self, widget, status=QtCore.Qt.Unchecked):
495        """
496        Selected models are chosen for fitting
497        """
498        # Convert to proper indices and set requested enablement
499        for row in self.selectedParameters(widget):
500            widget.item(row, 0).setCheckState(status)
501
502    def deleteConstraint(self):#, row):
503        """
504        Delete all selected constraints.
505        """
506        # Removing rows from the table we're iterating over,
507        # so prepare a list of data first
508        constraints_to_delete = []
509        for row in self.selectedParameters(self.tblConstraints):
510            constraints_to_delete.append(self.tblConstraints.item(row, 0).data(0))
511        for constraint in constraints_to_delete:
512            moniker = constraint[:constraint.index(':')]
513            param = constraint[constraint.index(':')+1:constraint.index('=')].strip()
514            tab = self.available_tabs[moniker]
515            tab.deleteConstraintOnParameter(param)
516        # Constraints removed - refresh the table widget
517        self.initializeFitList()
518
519    def uneditableItem(self, data=""):
520        """
521        Returns an uneditable Table Widget Item
522        """
523        item = QtWidgets.QTableWidgetItem(data)
524        item.setFlags( QtCore.Qt.ItemIsSelectable |  QtCore.Qt.ItemIsEnabled )
525        return item
526
527    def updateFitLine(self, tab):
528        """
529        Update a single line of the table widget with tab info
530        """
531        fit_page = ObjectLibrary.getObject(tab)
532        model = fit_page.kernel_module
533        if model is None:
534            return
535        tab_name = tab
536        model_name = model.id
537        moniker = model.name
538        model_data = fit_page.data
539        model_filename = model_data.filename
540        self.available_tabs[moniker] = fit_page
541
542        # Update the model table widget
543        pos = self.tblTabList.rowCount()
544        self.tblTabList.insertRow(pos)
545        item = self.uneditableItem(tab_name)
546        item.setFlags(item.flags() ^ QtCore.Qt.ItemIsUserCheckable)
547        if tab_name in self.tabs_for_fitting:
548            state = QtCore.Qt.Checked if self.tabs_for_fitting[tab_name] else QtCore.Qt.Unchecked
549            item.setCheckState(state)
550        else:
551            item.setCheckState(QtCore.Qt.Checked)
552            self.tabs_for_fitting[tab_name] = True
553
554        # Disable signals so we don't get infinite call recursion
555        self.tblTabList.blockSignals(True)
556        self.tblTabList.setItem(pos, 0, item)
557        self.tblTabList.setItem(pos, 1, self.uneditableItem(model_name))
558        self.tblTabList.setItem(pos, 2, self.uneditableItem(model_filename))
559        # Moniker is editable, so no option change
560        item = QtWidgets.QTableWidgetItem(moniker)
561        self.tblTabList.setItem(pos, 3, item)
562        self.tblTabList.blockSignals(False)
563
564        # Check if any constraints present in tab
565        constraint_names = fit_page.getComplexConstraintsForModel()
566        constraints = fit_page.getConstraintObjectsForModel()
567        if not constraints: 
568            return
569        self.tblConstraints.setEnabled(True)
570        self.tblConstraints.blockSignals(True)
571        for constraint, constraint_name in zip(constraints, constraint_names):
572            # Create the text for widget item
573            label = moniker + ":"+ constraint_name[0] + " = " + constraint_name[1]
574            pos = self.tblConstraints.rowCount()
575            self.available_constraints[pos] = constraint
576
577            # Show the text in the constraint table
578            item = self.uneditableItem(label)
579            item.setFlags(item.flags() ^ QtCore.Qt.ItemIsUserCheckable)
580            item.setCheckState(QtCore.Qt.Checked)
581            self.tblConstraints.insertRow(pos)
582            self.tblConstraints.setItem(pos, 0, item)
583        self.tblConstraints.blockSignals(False)
584
585    def initializeFitList(self):
586        """
587        Fill the list of model/data sets for fitting/constraining
588        """
589        # look at the object library to find all fit tabs
590        # Show the content of the current "model"
591        objects = ObjectLibrary.listObjects()
592
593        # Tab dict
594        # moniker -> (kernel_module, data)
595        self.available_tabs = {}
596        # Constraint dict
597        # moniker -> [constraints]
598        self.available_constraints = {}
599
600        # Reset the table widgets
601        self.tblTabList.setRowCount(0)
602        self.tblConstraints.setRowCount(0)
603
604        # Fit disabled
605        self.cmdFit.setEnabled(False)
606
607        if not objects:
608            return
609
610        tabs = [tab for tab in ObjectLibrary.listObjects() if self.isTabImportable(tab)]
611        for tab in tabs:
612            self.updateFitLine(tab)
613            self.updateSignalsFromTab(tab)
614            # We have at least 1 fit page, allow fitting
615            self.cmdFit.setEnabled(True)
616
617    def validateMoniker(self, new_moniker=None):
618        """
619        Check new_moniker for correctness.
620        It must be non-empty.
621        It must not be the same as other monikers.
622        """
623        if not new_moniker:
624            return False
625
626        for existing_moniker in self.available_tabs:
627            if existing_moniker == new_moniker and existing_moniker != self.current_cell:
628                return False
629
630        return True
631
632    def getObjectByName(self, name):
633        """
634        Given name of the fit, returns associated fit object
635        """
636        for object_name in ObjectLibrary.listObjects():
637            object = ObjectLibrary.getObject(object_name)
638            if isinstance(object, FittingWidget):
639                try:
640                    if object.kernel_module.name == name:
641                        return object
642                except AttributeError:
643                    # Disregard atribute errors - empty fit widgets
644                    continue
645        return None
646
647    def showMultiConstraint(self):
648        """
649        Invoke the complex constraint editor
650        """
651        selected_rows = self.selectedParameters(self.tblTabList)
652        assert(len(selected_rows)==2)
653
654        tab_list = [ObjectLibrary.getObject(self.tblTabList.item(s, 0).data(0)) for s in selected_rows]
655        # Create and display the widget for param1 and param2
656        cc_widget = ComplexConstraint(self, tabs=tab_list)
657        if cc_widget.exec_() != QtWidgets.QDialog.Accepted:
658            return
659
660        constraint = Constraint()
661        model1, param1, operator, constraint_text = cc_widget.constraint()
662
663        constraint.func = constraint_text
664        constraint.param = param1
665        # Find the right tab
666        constrained_tab = self.getObjectByName(model1)
667        if constrained_tab is None:
668            return
669
670        # Find the constrained parameter row
671        constrained_row = constrained_tab.getRowFromName(param1)
672
673        # Update the tab
674        constrained_tab.addConstraintToRow(constraint, constrained_row)
Note: See TracBrowser for help on using the repository browser.