Changeset a3c94b54 in sasview
- Timestamp:
- Jan 10, 2018 5:05:35 AM (7 years ago)
- 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:
- fca1f50
- Parents:
- 2109350
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
r2109350 ra3c94b54 466 466 self.options_widget.plot_signal.connect(self.onOptionsUpdate) 467 467 468 def modelName(self): 469 """ 470 Returns model name, by default M<tab#>, e.g. M1, M2 471 """ 472 return "M%i" % self.tab_id 473 474 def nameForFittedData(self, name): 475 """ 476 Generate name for the current fit 477 """ 478 if self.is2D: 479 name += "2d" 480 name = "%s [%s]" % (self.modelName(), name) 481 return name 482 468 483 def showModelContextMenu(self, position): 469 470 #rows = len([s.row() for s in self.lstParams.selectionModel().selectedRows()]) 484 """ 485 Show context specific menu in the parameter table. 486 When clicked on parameter(s): fitting/constraints options 487 When clicked on white space: model description 488 """ 471 489 rows = [s.row() for s in self.lstParams.selectionModel().selectedRows()] 472 490 menu = self.showModelDescription() if not rows else self.modelContextMenu(rows) … … 479 497 def modelContextMenu(self, rows): 480 498 """ 481 Create context menu for the given model499 Create context menu for the parameter selection 482 500 """ 483 501 menu = QtWidgets.QMenu() … … 486 504 param_string = "parameter " if num_rows==1 else "parameters " 487 505 to_string = "to its current value" if num_rows==1 else "to their current values" 506 has_constraints = any([self.rowHasConstraint(i) for i in rows]) 488 507 489 508 self.actionSelect = QtWidgets.QAction(self) … … 515 534 menu.addSeparator() 516 535 517 if self.rowHasConstraint(rows[0]):536 if has_constraints: 518 537 menu.addAction(self.actionRemoveConstraint) 538 #if num_rows == 1: 539 # menu.addAction(self.actionEditConstraint) 519 540 else: 520 541 menu.addAction(self.actionConstrain) 521 if num_rows == 2:522 menu.addAction(self.actionMutualMultiConstrain)542 if num_rows == 2: 543 menu.addAction(self.actionMutualMultiConstrain) 523 544 524 545 # Define the callbacks … … 553 574 item = QtGui.QStandardItem() 554 575 item.setData(constraint) 576 555 577 # Which row is the constrained parameter in? 556 557 578 row = self.rowFromName(constraint.param) 558 579 self._model_model.item(row, 1).setChild(0, item) 559 580 #self.constraintAddedSignal.emit([row]) 581 560 582 # Show visual hints for the constraint 561 583 font = QtGui.QFont() … … 564 586 self.modifyViewOnRow(row, font=font, brush=brush) 565 587 566 # Pass the constraint to the parser588 # Notify the user 567 589 self.communicate.statusBarUpdateSignal.emit('Constraints added') 568 590 569 591 def rowFromName(self, name): 570 592 """ 571 given parameter name get the row number in self._model_model593 Given parameter name get the row number in self._model_model 572 594 """ 573 595 for row in range(self._model_model.rowCount()): … … 600 622 Adds a constraint on a single parameter. 601 623 """ 624 min_col = self.lstParams.itemDelegate().param_min 625 max_col = self.lstParams.itemDelegate().param_max 602 626 for row in self.selectedParameters(): 603 627 param = self._model_model.item(row, 0).text() 604 628 value = self._model_model.item(row, 1).text() 605 min = self._model_model.item(row, 2).text()606 max = self._model_model.item(row, 3).text()629 min = self._model_model.item(row, min_col).text() 630 max = self._model_model.item(row, max_col).text() 607 631 # Create a Constraint object 608 632 constraint = Constraint(param=param, value=value, min=min, max=max) … … 612 636 self._model_model.item(row, 1).setChild(0, item) 613 637 # Set min/max to the value constrained 614 self._model_model.item(row, 2).setText(value)615 self._model_model.item(row, 3).setText(value)638 self._model_model.item(row, min_col).setText(value) 639 self._model_model.item(row, max_col).setText(value) 616 640 #self.constraintAddedSignal.emit([row]) 617 641 # Show visual hints for the constraint … … 627 651 Delete constraints from selected parameters. 628 652 """ 653 min_col = self.lstParams.itemDelegate().param_min 654 max_col = self.lstParams.itemDelegate().param_max 629 655 for row in self.selectedParameters(): 630 656 # Get the Constraint object from of the model item 631 657 item = self._model_model.item(row, 1) 658 if not item.hasChildren(): 659 continue 632 660 constraint = item.child(0).data() 661 if constraint is None: 662 continue 663 if not isinstance(constraint, Constraint): 664 continue 633 665 # Retrieve old values and put them on the model 634 666 if constraint.min is not None: 635 self._model_model.item(row, 2).setText(constraint.min)667 self._model_model.item(row, min_col).setText(constraint.min) 636 668 if constraint.max is not None: 637 self._model_model.item(row, 3).setText(constraint.max)669 self._model_model.item(row, max_col).setText(constraint.max) 638 670 # Remove constraint item 639 671 item.removeRow(0) … … 643 675 pass 644 676 677 def getConstraintForRow(self, row): 678 """ 679 For the given row, return its constraint, if any 680 """ 681 try: 682 item = self._model_model.item(row, 1) 683 return item.child(0).data() 684 except AttributeError: 685 # return none when no constraints 686 return None 687 645 688 def rowHasConstraint(self, row): 646 689 """ … … 652 695 def selectParameters(self): 653 696 """ 654 Selected parameter s arechosen for fitting697 Selected parameter is chosen for fitting 655 698 """ 656 699 status = QtCore.Qt.Checked … … 666 709 def selectedParameters(self): 667 710 """ Returns list of selected (highlighted) parameters """ 668 return [s.row() for s in self.lstParams.selectionModel().selectedRows() if self.isCheckable(s.row())] 711 return [s.row() for s in self.lstParams.selectionModel().selectedRows() 712 if self.isCheckable(s.row())] 669 713 670 714 def setParameterSelection(self, status=QtCore.Qt.Unchecked): … … 675 719 for row in self.selectedParameters(): 676 720 self._model_model.item(row, 0).setCheckState(status) 677 pass 721 pass # debugger hook 722 723 def getConstraintsForModel(self): 724 """ 725 Return a list of tuples. Each tuple contains constraints mapped as 726 ('constrained parameter', 'function to constrain') 727 e.g. [('sld','5*sld_solvent')] 728 """ 729 model_name = self.modelName() 730 self.kernel_module.name = model_name 731 param_number = self._model_model.rowCount() 732 params = [(self._model_model.item(s, 0).text(), 733 model_name+"."+self._model_model.item(s, 1).child(0).data().func) 734 for s in range(param_number) if self.rowHasConstraint(s)] 735 return params 678 736 679 737 def showModelDescription(self): … … 936 994 # These should be updating somehow? 937 995 fit_id = 0 938 constraints = []996 constraints = self.getConstraintsForModel() 939 997 smearer = None 940 998 page_id = [210] … … 1607 1665 if isChecked(row_index)] 1608 1666 1609 def nameForFittedData(self, name):1610 """1611 Generate name for the current fit1612 """1613 if self.is2D:1614 name += "2d"1615 name = "M%i [%s]" % (self.tab_id, name)1616 return name1617 1618 1667 def createNewIndex(self, fitted_data): 1619 1668 """ -
src/sas/qtgui/Perspectives/Fitting/MultiConstraint.py
r2109350 ra3c94b54 29 29 30 30 self.cmdOK.clicked.connect(self.accept) 31 self.cmdHelp.clicked.connect(self.onHelp) 31 32 self.cmdRevert.clicked.connect(self.revert) 32 33 self.txtConstraint.editingFinished.connect(self.validateFormula) … … 122 123 return True 123 124 125 def onHelp(self): 126 """ 127 Display related help section 128 """ 129 try: 130 location = GuiUtils.HELP_DIRECTORY_LOCATION + \ 131 "/user/sasgui/perspectives/fitting/fitting_help.html#simultaneous-fits-with-constraints" 132 133 self.manager._helpView.load(QtCore.QUrl(location)) 134 self.manager._helpView.show() 135 except AttributeError: 136 # No manager defined - testing and standalone runs 137 pass 124 138 125 139 -
src/sas/qtgui/Perspectives/Fitting/UI/MultiConstraintUI.ui
r2109350 ra3c94b54 4 4 <widget class="QDialog" name="MultiConstraintUI"> 5 5 <property name="windowModality"> 6 <enum>Qt:: WindowModal</enum>6 <enum>Qt::ApplicationModal</enum> 7 7 </property> 8 8 <property name="geometry"> … … 150 150 <property name="text"> 151 151 <string>OK</string> 152 </property> 153 </widget> 154 </item> 155 <item> 156 <widget class="QPushButton" name="cmdCancel"> 157 <property name="text"> 158 <string>Cancel</string> 159 </property> 160 </widget> 161 </item> 162 <item> 163 <widget class="QPushButton" name="cmdHelp"> 164 <property name="text"> 165 <string>Help</string> 152 166 </property> 153 167 </widget> … … 175 189 </hints> 176 190 </connection> 191 <connection> 192 <sender>cmdCancel</sender> 193 <signal>clicked()</signal> 194 <receiver>MultiConstraintUI</receiver> 195 <slot>reject()</slot> 196 <hints> 197 <hint type="sourcelabel"> 198 <x>187</x> 199 <y>121</y> 200 </hint> 201 <hint type="destinationlabel"> 202 <x>184</x> 203 <y>71</y> 204 </hint> 205 </hints> 206 </connection> 177 207 </connections> 178 208 </ui>
Note: See TracChangeset
for help on using the changeset viewer.