Changeset 21e71f1 in sasview for src/sas/qtgui/Perspectives/Fitting/ConstraintWidget.py
- Timestamp:
- Nov 21, 2018 6:39:24 AM (5 years ago)
- 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:
- f2e199e
- Parents:
- 44c15fc (diff), fb39f28 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/ConstraintWidget.py
rc4c4957 r21e71f1 23 23 Constraints Dialog to select the desired parameter/model constraints. 24 24 """ 25 fitCompleteSignal = QtCore.pyqtSignal(tuple) 26 batchCompleteSignal = QtCore.pyqtSignal(tuple) 27 fitFailedSignal = QtCore.pyqtSignal(tuple) 25 28 26 29 def __init__(self, parent=None): … … 32 35 # To keep with previous SasView values, use 300 as the start offset 33 36 self.page_id = 301 37 self.tab_id = self.page_id 34 38 35 39 # Are we chain fitting? … … 60 64 Set up various widget states 61 65 """ 66 # disable special cases until properly defined 67 self.label.setVisible(False) 68 self.cbCases.setVisible(False) 69 62 70 labels = ['FitPage', 'Model', 'Data', 'Mnemonic'] 63 71 # tab widget - headers … … 79 87 self.tblConstraints.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch) 80 88 self.tblConstraints.setEnabled(False) 89 header = self.tblConstraints.horizontalHeaderItem(0) 90 header.setToolTip("Double click a row below to edit the constraint.") 81 91 82 92 self.tblConstraints.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) … … 93 103 self.cmdFit.clicked.connect(self.onFit) 94 104 self.cmdHelp.clicked.connect(self.onHelp) 105 self.cmdAdd.clicked.connect(self.showMultiConstraint) 95 106 self.chkChain.toggled.connect(self.onChainFit) 96 107 … … 100 111 self.tblConstraints.cellChanged.connect(self.onConstraintChange) 101 112 113 # Internal signals 114 self.fitCompleteSignal.connect(self.fitComplete) 115 self.batchCompleteSignal.connect(self.batchComplete) 116 self.fitFailedSignal.connect(self.fitFailed) 117 102 118 # External signals 103 119 self.parent.tabsModifiedSignal.connect(self.initializeFitList) … … 156 172 fitter = Fit() 157 173 fitter.fitter_id = self.page_id 158 159 # Notify the parent about fitting started160 self.parent.fittingStartedSignal.emit(tabs_to_fit)161 174 162 175 # prepare fitting problems for each tab … … 168 181 try: 169 182 for tab in tabs_to_fit: 183 if not self.isTabImportable(tab): continue 170 184 tab_object = ObjectLibrary.getObject(tab) 171 185 if tab_object is None: … … 177 191 except ValueError: 178 192 # No parameters selected in one of the tabs 179 no_params_msg = "Fitting can 193 no_params_msg = "Fitting cannot be performed.\n" +\ 180 194 "Not all tabs chosen for fitting have parameters selected for fitting." 181 195 QtWidgets.QMessageBox.warning(self, … … 200 214 batch_inputs = {} 201 215 batch_outputs = {} 216 217 # Notify the parent about fitting started 218 self.parent.fittingStartedSignal.emit(tabs_to_fit) 202 219 203 220 # new fit thread object … … 223 240 224 241 #disable the Fit button 242 self.cmdFit.setStyleSheet('QPushButton {color: red;}') 225 243 self.cmdFit.setText('Running...') 226 244 self.parent.communicate.statusBarUpdateSignal.emit('Fitting started...') … … 292 310 """ 293 311 item = self.tblConstraints.item(row, column) 294 if column == 0: 295 # Update the tabs for fitting list 296 constraint = self.available_constraints[row] 297 constraint.active = (item.checkState() == QtCore.Qt.Checked) 312 if column != 0: return 313 # Update the tabs for fitting list 314 constraint = self.available_constraints[row] 315 constraint.active = (item.checkState() == QtCore.Qt.Checked) 316 # Update the constraint formula 317 constraint = self.available_constraints[row] 318 function = item.text() 319 # remove anything left of '=' to get the constraint 320 function = function[function.index('=')+1:] 321 # No check on function here - trust the user (R) 322 if function != constraint.func: 323 # This becomes rather difficult to validate now. 324 # Turn off validation for Edit Constraint 325 constraint.func = function 326 constraint.validate = False 298 327 299 328 def onTabCellEntered(self, row, column): … … 308 337 def onFitComplete(self, result): 309 338 """ 339 Send the fit complete signal to main thread 340 """ 341 self.fitCompleteSignal.emit(result) 342 343 def fitComplete(self, result): 344 """ 310 345 Respond to the successful fit complete signal 311 346 """ 312 347 #re-enable the Fit button 348 self.cmdFit.setStyleSheet('QPushButton {color: black;}') 313 349 self.cmdFit.setText("Fit") 314 350 self.cmdFit.setEnabled(True) … … 347 383 def onBatchFitComplete(self, result): 348 384 """ 385 Send the fit complete signal to main thread 386 """ 387 self.batchCompleteSignal.emit(result) 388 389 def batchComplete(self, result): 390 """ 349 391 Respond to the successful batch fit complete signal 350 392 """ 351 393 #re-enable the Fit button 394 self.cmdFit.setStyleSheet('QPushButton {color: black;}') 352 395 self.cmdFit.setText("Fit") 353 396 self.cmdFit.setEnabled(True) … … 375 418 def onFitFailed(self, reason): 376 419 """ 420 Send the fit failed signal to main thread 421 """ 422 self.fitFailedSignal.emit(result) 423 424 def fitFailed(self, reason): 425 """ 377 426 Respond to fitting failure. 378 427 """ 379 428 #re-enable the Fit button 429 self.cmdFit.setStyleSheet('QPushButton {color: black;}') 380 430 self.cmdFit.setText("Fit") 381 431 self.cmdFit.setEnabled(True) … … 386 436 msg = "Fitting failed: %s s.\n" % reason 387 437 self.parent.communicate.statusBarUpdateSignal.emit(msg) 388 438 389 439 def isTabImportable(self, tab): 390 440 """ … … 599 649 # Show the text in the constraint table 600 650 item = self.uneditableItem(label) 651 item = QtWidgets.QTableWidgetItem(label) 601 652 item.setFlags(item.flags() ^ QtCore.Qt.ItemIsUserCheckable) 602 653 item.setCheckState(QtCore.Qt.Checked) … … 667 718 return None 668 719 720 def onAcceptConstraint(self, con_tuple): 721 """ 722 Receive constraint tuple from the ComplexConstraint dialog and adds contraint 723 """ 724 #"M1, M2, M3" etc 725 model_name, constraint = con_tuple 726 constrained_tab = self.getObjectByName(model_name) 727 if constrained_tab is None: 728 return 729 730 # Find the constrained parameter row 731 constrained_row = constrained_tab.getRowFromName(constraint.param) 732 733 # Update the tab 734 constrained_tab.addConstraintToRow(constraint, constrained_row) 735 736 # Select this parameter for adjusting/fitting 737 constrained_tab.selectCheckbox(constrained_row) 738 739 669 740 def showMultiConstraint(self): 670 741 """ … … 672 743 """ 673 744 selected_rows = self.selectedParameters(self.tblTabList) 674 assert(len(selected_rows)==2) 745 if len(selected_rows)!=2: 746 msg = "Please select two fit pages from the Source Choice table." 747 msgbox = QtWidgets.QMessageBox(self.parent) 748 msgbox.setIcon(QtWidgets.QMessageBox.Warning) 749 msgbox.setText(msg) 750 msgbox.setWindowTitle("2 fit page constraints") 751 retval = msgbox.exec_() 752 return 675 753 676 754 tab_list = [ObjectLibrary.getObject(self.tblTabList.item(s, 0).data(0)) for s in selected_rows] 677 755 # Create and display the widget for param1 and param2 678 756 cc_widget = ComplexConstraint(self, tabs=tab_list) 757 cc_widget.constraintReadySignal.connect(self.onAcceptConstraint) 758 679 759 if cc_widget.exec_() != QtWidgets.QDialog.Accepted: 680 760 return 681 761 682 constraint = Constraint() 683 model1, param1, operator, constraint_text = cc_widget.constraint() 684 685 constraint.func = constraint_text 686 # param1 is the parameter we're constraining 687 constraint.param = param1 688 689 # Find the right tab 690 constrained_tab = self.getObjectByName(model1) 691 if constrained_tab is None: 692 return 693 694 # Find the constrained parameter row 695 constrained_row = constrained_tab.getRowFromName(param1) 696 697 # Update the tab 698 constrained_tab.addConstraintToRow(constraint, constrained_row) 762 def getFitPage(self): 763 """ 764 Retrieves the state of this page 765 """ 766 param_list = [] 767 768 param_list.append(['is_constraint', 'True']) 769 param_list.append(['data_id', "cs_tab"+str(self.page_id)]) 770 param_list.append(['current_type', self.currentType]) 771 param_list.append(['is_chain_fitting', str(self.is_chain_fitting)]) 772 param_list.append(['special_case', self.cbCases.currentText()]) 773 774 return param_list 775 776 def getFitModel(self): 777 """ 778 Retrieves current model 779 """ 780 model_list = [] 781 782 checked_models = {} 783 for row in range(self.tblTabList.rowCount()): 784 model_name = self.tblTabList.item(row,1).data(0) 785 active = self.tblTabList.item(row,0).checkState()# == QtCore.Qt.Checked 786 checked_models[model_name] = str(active) 787 788 checked_constraints = {} 789 for row in range(self.tblConstraints.rowCount()): 790 model_name = self.tblConstraints.item(row,0).data(0) 791 active = self.tblConstraints.item(row,0).checkState()# == QtCore.Qt.Checked 792 checked_constraints[model_name] = str(active) 793 794 model_list.append(['checked_models', checked_models]) 795 model_list.append(['checked_constraints', checked_constraints]) 796 return model_list 797 798 def createPageForParameters(self, parameters=None): 799 """ 800 Update the page with passed parameter values 801 """ 802 # checked models 803 if not 'checked_models' in parameters: 804 return 805 models = parameters['checked_models'][0] 806 for model, check_state in models.items(): 807 for row in range(self.tblTabList.rowCount()): 808 model_name = self.tblTabList.item(row,1).data(0) 809 if model_name != model: 810 continue 811 # check/uncheck item 812 self.tblTabList.item(row,0).setCheckState(int(check_state)) 813 814 if not 'checked_constraints' in parameters: 815 return 816 # checked constraints 817 models = parameters['checked_constraints'][0] 818 for model, check_state in models.items(): 819 for row in range(self.tblConstraints.rowCount()): 820 model_name = self.tblConstraints.item(row,0).data(0) 821 if model_name != model: 822 continue 823 # check/uncheck item 824 self.tblConstraints.item(row,0).setCheckState(int(check_state)) 825 826 # fit/batch radio 827 isBatch = parameters['current_type'][0] == 'BatchPage' 828 if isBatch: 829 self.btnBatch.toggle() 830 831 # chain 832 is_chain = parameters['is_chain_fitting'][0] == 'True' 833 if isBatch: 834 self.chkChain.setChecked(is_chain)
Note: See TracChangeset
for help on using the changeset viewer.