Changeset b0c5e8c in sasview for src/sas/qtgui/Perspectives/Fitting
- Timestamp:
- Jun 15, 2017 8:24:49 AM (8 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:
- 72f4834
- Parents:
- 144ec831
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingOptions.py
r2d0e0c1 rb0c5e8c 2 2 import sys 3 3 import os 4 import types 5 4 6 from PyQt4 import QtCore 5 7 from PyQt4 import QtGui … … 8 10 from sas.qtgui.UI import images_rc 9 11 from sas.qtgui.UI import main_resources_rc 10 #from bumps.fitters import FITTERS, FIT_AVAILABLE_IDS, FIT_ACTIVE_IDS, FIT_DEFAULT_ID 12 import sas.qtgui.Utilities.GuiUtils as GuiUtils 13 11 14 from bumps import fitters 12 15 import bumps.options … … 31 34 settings = [('steps', 1000), ('starts', 1), ('radius', 0.15), ('xtol', 1e-6), ('ftol', 1e-8)] 32 35 """ 33 fit_option_changed = QtCore.pyqtSignal(str , dict)36 fit_option_changed = QtCore.pyqtSignal(str) 34 37 35 38 def __init__(self, parent=None, config=None): … … 49 52 # Handle the Apply button click 50 53 self.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked.connect(self.onApply) 54 # handle the Help button click 55 self.buttonBox.button(QtGui.QDialogButtonBox.Help).clicked.connect(self.onHelp) 51 56 52 57 # Handle the combo box changes … … 57 62 default_index = self.cbAlgorithm.findText(default_name) 58 63 self.cbAlgorithm.setCurrentIndex(default_index) 64 65 # Assign appropriate validators 66 self.assignValidators() 67 59 68 self.current_fitter_id = fitters.FIT_DEFAULT_ID 60 69 61 # Fill in options for all active fitters 62 #[self.updateWidgetFromBumps(fitter_id) for fitter_id in fitters.FIT_ACTIVE_IDS] 70 # Display HTML content 71 self.helpView = QtWebKit.QWebView() 72 73 def assignValidators(self): 74 """ 75 Use options.FIT_FIELDS to assert which line edit gets what validator 76 """ 77 for option in bumps.options.FIT_FIELDS.iterkeys(): 78 (f_name, f_type) = bumps.options.FIT_FIELDS[option] 79 validator = None 80 if type(f_type) == types.FunctionType: 81 validator = QtGui.QIntValidator() 82 elif f_type == types.FloatType: 83 validator = QtGui.QDoubleValidator() 84 else: 85 continue 86 for fitter_id in fitters.FIT_ACTIVE_IDS: 87 line_edit = self.widgetFromOption(str(option), current_fitter=str(fitter_id)) 88 if hasattr(line_edit, 'setValidator') and validator is not None: 89 line_edit.setValidator(validator) 63 90 64 91 def onAlgorithmChange(self, index): … … 75 102 # Convert the name into widget instance 76 103 widget_to_activate = eval(widget_name) 104 index_for_this_id = self.stackedWidget.indexOf(widget_to_activate) 77 105 78 106 # Select the requested widget 79 self.stackedWidget.setCurrentIndex( self.stackedWidget.indexOf(widget_to_activate))107 self.stackedWidget.setCurrentIndex(index_for_this_id) 80 108 81 109 self.updateWidgetFromBumps(self.current_fitter_id) 82 110 111 self.assignValidators() 112 83 113 def onApply(self): 84 114 """ 85 Update the fitter object in perspective115 Update the fitter object 86 116 """ 87 self.fit_option_changed.emit(self.cbAlgorithm.currentText(), {}) 117 # Notify the perspective, so the window title is updated 118 self.fit_option_changed.emit(self.cbAlgorithm.currentText()) 88 119 89 # or just do it locally 90 for option in self.config.values[self.current_fitter_id].iterkeys(): 120 def bumpsUpdate(option): 121 """ 122 Utility method for bumps state update 123 """ 91 124 widget = self.widgetFromOption(option) 92 new_value = "" 93 if isinstance(widget, QtGui.QComboBox): 94 new_value = widget.currentText() 95 else: 96 new_value = float(widget.text()) 125 new_value = widget.currentText() if isinstance(widget, QtGui.QComboBox) \ 126 else float(widget.text()) 97 127 self.config.values[self.current_fitter_id][option] = new_value 98 128 99 def widgetFromOption(self, option_id): 129 # Update the BUMPS singleton 130 [bumpsUpdate(o) for o in self.config.values[self.current_fitter_id].iterkeys()] 131 132 def onHelp(self): 133 """ 134 Show the "Fitting options" section of help 135 """ 136 tree_location = GuiUtils.HELP_DIRECTORY_LOCATION + "/user/sasgui/perspectives/fitting/" 137 138 # Actual file anchor will depend on the combo box index 139 # Note that we can be clusmy here, since bad current_fitter_id 140 # will just make the page displayed from the top 141 helpfile = "optimizer.html#fit-" + self.current_fitter_id 142 help_location = tree_location + helpfile 143 self.helpView.load(QtCore.QUrl(help_location)) 144 self.helpView.show() 145 146 def widgetFromOption(self, option_id, current_fitter=None): 100 147 """ 101 148 returns widget's element linked to the given option_id 102 149 """ 103 return eval('self.' + option_id + '_' + self.current_fitter_id) 150 if current_fitter is None: 151 current_fitter = self.current_fitter_id 152 if option_id not in bumps.options.FIT_FIELDS.keys(): return None 153 option = option_id + '_' + current_fitter 154 if not hasattr(self, option): return None 155 return eval('self.' + option) 104 156 105 157 def getResults(self): … … 127 179 128 180 pass 129 130 def updateBumpsOptions(self, optimizer_id):131 """132 Given the ID of the optimizer, gather widget's values133 and update the bumps options134 """135 pass136 -
src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py
r2d0e0c1 rb0c5e8c 159 159 self.addFit(data) 160 160 161 def onFittingOptionsChange(self, fit_engine , fit_options):161 def onFittingOptionsChange(self, fit_engine): 162 162 """ 163 React to the fitting algorithm change by modifying window title 163 164 """ 164 165 fitter = [f.id for f in options.FITTERS if f.name == str(fit_engine)][0] 165 166 166 # set the optimizer 167 167 self.fit_options.selected_id = str(fitter) 168 # set the options169 #170 168 # Update the title 171 169 self.updateWindowTitle() -
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
r144ec831 rb0c5e8c 522 522 Show the "Fitting" section of help 523 523 """ 524 tree_location = self.parent.HELP_DIRECTORY_LOCATION + "/user/sasgui/perspectives/fitting/"524 tree_location = GuiUtils.HELP_DIRECTORY_LOCATION + "/user/sasgui/perspectives/fitting/" 525 525 526 526 # Actual file will depend on the current tab -
src/sas/qtgui/Perspectives/Fitting/UI/FittingOptionsUI.ui
r2d0e0c1 rb0c5e8c 7 7 <x>0</x> 8 8 <y>0</y> 9 <width> 503</width>10 <height> 672</height>9 <width>440</width> 10 <height>538</height> 11 11 </rect> 12 12 </property> … … 27 27 <item row="0" column="0"> 28 28 <widget class="QComboBox" name="cbAlgorithm"> 29 <property name="sizePolicy"> 30 <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> 31 <horstretch>0</horstretch> 32 <verstretch>0</verstretch> 33 </sizepolicy> 34 </property> 29 35 <property name="sizeAdjustPolicy"> 30 36 <enum>QComboBox::AdjustToContents</enum>
Note: See TracChangeset
for help on using the changeset viewer.