Changeset 2add354 in sasview for src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
- Timestamp:
- May 9, 2017 1:38:40 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:
- f7f5796
- Parents:
- 31e4bb8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
r02ddfb4 r2add354 12 12 from PyQt4 import QtGui 13 13 from PyQt4 import QtCore 14 from PyQt4 import QtWebKit 14 15 15 16 from sasmodels import generate … … 32 33 from SmearingWidget import SmearingWidget 33 34 from OptionsWidget import OptionsWidget 35 from FitPage import FitPage 34 36 35 37 TAB_MAGNETISM = 4 … … 73 75 self.log_points = False 74 76 self.weighting = 0 77 self.chi2 = None 75 78 76 79 # Data for chosen model … … 132 135 """ 133 136 self.lstParams.setStyleSheet(stylesheet) 137 self.lstParams.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) 138 self.lstParams.customContextMenuRequested.connect(self.showModelDescription) 134 139 135 140 # Poly model displayed in poly list … … 163 168 self.initializeControls() 164 169 170 # Display HTML content 171 self.helpView = QtWebKit.QWebView() 172 165 173 self._index = None 166 174 if data is not None: 167 175 self.data = data 176 177 def close(self): 178 """ 179 Remember to kill off things on exit 180 """ 181 self.helpView.close() 182 del self.helpView 168 183 169 184 @property … … 197 212 self.lblFilename.setText(self.logic.data.filename) 198 213 self.updateQRange() 199 self.cmdFit.setEnabled(True)200 214 # Switch off Data2D control 201 215 self.chk2DView.setEnabled(False) … … 285 299 self.cmdFit.clicked.connect(self.onFit) 286 300 self.cmdPlot.clicked.connect(self.onPlot) 301 self.cmdHelp.clicked.connect(self.onHelp) 287 302 288 303 # Respond to change in parameters from the UI … … 294 309 # Signals from separate tabs asking for replot 295 310 self.options_widget.plot_signal.connect(self.onOptionsUpdate) 311 312 def showModelDescription(self, position): 313 """ 314 Shows a window with model description, when right clicked in the treeview 315 """ 316 msg = 'Model description:\n' 317 info = "Info" 318 if self.kernel_module is not None: 319 if str(self.kernel_module.description).rstrip().lstrip() == '': 320 msg += "Sorry, no information is available for this model." 321 else: 322 msg += self.kernel_module.description + '\n' 323 else: 324 msg += "You must select a model to get information on this" 325 326 menu = QtGui.QMenu() 327 label = QtGui.QLabel(msg) 328 action = QtGui.QWidgetAction(self) 329 action.setDefaultWidget(label) 330 menu.addAction(action) 331 menu.exec_(self.lstParams.viewport().mapToGlobal(position)) 296 332 297 333 def onSelectModel(self): … … 321 357 # Create default datasets if no data passed 322 358 self.createDefaultDataset() 359 360 #state = self.currentState() 323 361 324 362 def onSelectStructureFactor(self): … … 403 441 pass # debug anchor 404 442 443 def onHelp(self): 444 """ 445 Show the "Fitting" section of help 446 """ 447 tree_location = self.parent.HELP_DIRECTORY_LOCATION +\ 448 "/user/sasgui/perspectives/fitting/fitting_help.html" 449 self.helpView.load(QtCore.QUrl(tree_location)) 450 self.helpView.show() 451 405 452 def onFit(self): 406 453 """ … … 438 485 fitter.set_model(model, fit_id, params_to_fit, data=data, 439 486 constraints=constraints) 487 440 488 fitter.set_data(data=data, id=fit_id, smearer=smearer, qmin=qmin, 441 489 qmax=qmax) … … 501 549 self.communicate.statusBarUpdateSignal.emit(msg) 502 550 503 fitness= res.fitness551 self.chi2 = res.fitness 504 552 param_list = res.param_list 505 553 param_values = res.pvec … … 516 564 517 565 # Read only value - we can get away by just printing it here 518 chi2_repr = GuiUtils.formatNumber( fitness, high=True)566 chi2_repr = GuiUtils.formatNumber(self.chi2, high=True) 519 567 self.lblChi2Value.setText(chi2_repr) 520 568 … … 586 634 # Regardless of previous state, this should now be `plot show` functionality only 587 635 self.cmdPlot.setText("Show Plot") 588 self.recalculatePlotData()589 636 self.showPlot() 590 637 … … 685 732 checked_list = ['background', '0.001', '-inf', 'inf', '1/cm'] 686 733 FittingUtilities.addCheckedListToModel(model, checked_list) 734 last_row = model.rowCount()-1 735 model.item(last_row, 0).setEditable(False) 736 model.item(last_row, 4).setEditable(False) 687 737 688 738 def addScaleToModel(self, model): … … 693 743 checked_list = ['scale', '1.0', '0.0', 'inf', ''] 694 744 FittingUtilities.addCheckedListToModel(model, checked_list) 745 last_row = model.rowCount()-1 746 model.item(last_row, 0).setEditable(False) 747 model.item(last_row, 4).setEditable(False) 695 748 696 749 def addWeightingToData(self, data): … … 781 834 if model_column == 0: 782 835 self.checkboxSelected(item) 836 self.cmdFit.setEnabled(self.parameters_to_fit != [] and self.logic.data_is_loaded) 783 837 return 784 838 … … 787 841 788 842 # Extract changed value. Assumes proper validation by QValidator/Delegate 789 value = float(item.text()) 843 # TODO: disable model update for uneditable cells/columns 844 try: 845 value = float(item.text()) 846 except ValueError: 847 # Unparsable field 848 return 790 849 parameter_name = str(self._model_model.data(name_index).toPyObject()) # sld, background etc. 791 850 property_name = str(self._model_model.headerData(1, model_column).toPyObject()) # Value, min, max, etc. … … 944 1003 self.createNewIndex(fitted_data) 945 1004 # Calculate difference between return_data and logic.data 946 chi2 = FittingUtilities.calculateChi2(fitted_data, self.logic.data)1005 self.chi2 = FittingUtilities.calculateChi2(fitted_data, self.logic.data) 947 1006 # Update the control 948 chi2_repr = "---" if chi2 is None else GuiUtils.formatNumber(chi2, high=True)1007 chi2_repr = "---" if self.chi2 is None else GuiUtils.formatNumber(self.chi2, high=True) 949 1008 self.lblChi2Value.setText(chi2_repr) 950 1009
Note: See TracChangeset
for help on using the changeset viewer.