Changeset b0c5e8c in sasview


Ignore:
Timestamp:
Jun 15, 2017 6:24:49 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
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
Message:

Unit tests for fitting options dialog SASVIEW-514

Location:
src/sas/qtgui
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Calculators/DensityPanel.py

    rcd2cc745 rb0c5e8c  
    88from sas.qtgui.Utilities.GuiUtils import FormulaValidator 
    99from sas.qtgui.UI import main_resources_rc 
     10from sas.qtgui.Utilities.GuiUtils import HELP_DIRECTORY_LOCATION 
    1011 
    1112# Local UI 
     
    148149    def displayHelp(self): 
    149150        try: 
    150             location = self.manager.HELP_DIRECTORY_LOCATION + \ 
     151            location = HELP_DIRECTORY_LOCATION + \ 
    151152                "/user/sasgui/perspectives/calculator/density_calculator_help.html" 
    152153 
  • src/sas/qtgui/Calculators/GenericScatteringCalculator.py

    rdc5ef15 rb0c5e8c  
    378378        """ 
    379379        try: 
    380             location = self.manager.HELP_DIRECTORY_LOCATION + \ 
     380            location = GuiUtils.HELP_DIRECTORY_LOCATION + \ 
    381381                       "/user/sasgui/perspectives/calculator/sas_calculator_help.html" 
    382382            self.manager._helpView.load(QtCore.QUrl(location)) 
  • src/sas/qtgui/Calculators/KiessigPanel.py

    rcd2cc745 rb0c5e8c  
    44from sas.qtgui.UI import main_resources_rc 
    55from UI.KiessigPanel import Ui_KiessigPanel 
     6import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    67 
    78# sas-global 
     
    3738        """ 
    3839        try: 
    39             location = self.manager.HELP_DIRECTORY_LOCATION + \ 
     40            location = GuiUtils.HELP_DIRECTORY_LOCATION + \ 
    4041                "/user/sasgui/perspectives/calculator/kiessig_calculator_help.html" 
    4142 
  • src/sas/qtgui/Calculators/SldPanel.py

    rcd2cc745 rb0c5e8c  
    77from periodictable.nsf import neutron_scattering 
    88 
    9 from sas.qtgui.Utilities.GuiUtils import FormulaValidator 
     9import sas.qtgui.Utilities.GuiUtils as GuiUtils 
     10 
    1011from sas.qtgui.UI import main_resources_rc 
    1112 
     
    125126 
    126127        # set validators 
    127         self.ui.editMolecularFormula.setValidator(FormulaValidator(self.ui.editMolecularFormula)) 
     128        self.ui.editMolecularFormula.setValidator(GuiUtils.FormulaValidator(self.ui.editMolecularFormula)) 
    128129 
    129130        rx = QtCore.QRegExp("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") 
     
    216217    def displayHelp(self): 
    217218        try: 
    218             location = self.manager.HELP_DIRECTORY_LOCATION + \ 
     219            location = GuiUtils.HELP_DIRECTORY_LOCATION + \ 
    219220                "/user/sasgui/perspectives/calculator/sld_calculator_help.html" 
    220221            self.manager._helpView.load(QtCore.QUrl(location)) 
  • src/sas/qtgui/Calculators/SlitSizeCalculator.py

    rcd2cc745 rb0c5e8c  
    99 
    1010from sas.qtgui.UI import main_resources_rc 
     11import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    1112 
    1213from UI.SlitSizeCalculator import Ui_SlitSizeCalculator 
     
    4546        """ 
    4647        try: 
    47             location = self._parent.HELP_DIRECTORY_LOCATION + \ 
     48            location = GuiUtils.HELP_DIRECTORY_LOCATION + \ 
    4849                "/user/sasgui/perspectives/calculator/slit_calculator_help.html" 
    4950 
  • src/sas/qtgui/MainWindow/DataExplorer.py

    rdc5ef15 rb0c5e8c  
    138138        Show the "Loading data" section of help 
    139139        """ 
    140         tree_location = self.parent.HELP_DIRECTORY_LOCATION +\ 
     140        tree_location = GuiUtils.HELP_DIRECTORY_LOCATION +\ 
    141141            "/user/sasgui/guiframe/data_explorer_help.html" 
    142142        self._helpView.load(QtCore.QUrl(tree_location)) 
  • src/sas/qtgui/MainWindow/GuiManager.py

    r2d0e0c1 rb0c5e8c  
    4545    Main SasView window functionality 
    4646    """ 
    47     ## TODO: CHANGE FOR SHIPPED PATH IN RELEASE 
    48     HELP_DIRECTORY_LOCATION = "docs/sphinx-docs/build/html" 
    49  
    5047    def __init__(self, parent=None): 
    5148        """ 
     
    9996        self._helpView = QtWebKit.QWebView() 
    10097        # Needs URL like path, so no path.join() here 
    101         self._helpLocation = self.HELP_DIRECTORY_LOCATION + "/index.html" 
     98        self._helpLocation = GuiUtils.HELP_DIRECTORY_LOCATION + "/index.html" 
    10299 
    103100        # Current tutorial location 
    104         self._tutorialLocation = os.path.abspath(os.path.join(self.HELP_DIRECTORY_LOCATION, 
     101        self._tutorialLocation = os.path.abspath(os.path.join(GuiUtils.HELP_DIRECTORY_LOCATION, 
    105102                                              "_downloads", 
    106103                                              "Tutorial.pdf")) 
  • src/sas/qtgui/Perspectives/Fitting/FittingOptions.py

    r2d0e0c1 rb0c5e8c  
    22import sys 
    33import os 
     4import types 
     5 
    46from PyQt4 import QtCore 
    57from PyQt4 import QtGui 
     
    810from sas.qtgui.UI import images_rc 
    911from sas.qtgui.UI import main_resources_rc 
    10 #from bumps.fitters import FITTERS, FIT_AVAILABLE_IDS, FIT_ACTIVE_IDS, FIT_DEFAULT_ID 
     12import sas.qtgui.Utilities.GuiUtils as GuiUtils 
     13 
    1114from bumps import fitters 
    1215import bumps.options 
     
    3134        settings = [('steps', 1000), ('starts', 1), ('radius', 0.15), ('xtol', 1e-6), ('ftol', 1e-8)] 
    3235    """ 
    33     fit_option_changed = QtCore.pyqtSignal(str, dict) 
     36    fit_option_changed = QtCore.pyqtSignal(str) 
    3437 
    3538    def __init__(self, parent=None, config=None): 
     
    4952        # Handle the Apply button click 
    5053        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) 
    5156 
    5257        # Handle the combo box changes 
     
    5762        default_index = self.cbAlgorithm.findText(default_name) 
    5863        self.cbAlgorithm.setCurrentIndex(default_index) 
     64 
     65        # Assign appropriate validators 
     66        self.assignValidators() 
     67 
    5968        self.current_fitter_id = fitters.FIT_DEFAULT_ID 
    6069 
    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) 
    6390 
    6491    def onAlgorithmChange(self, index): 
     
    75102        # Convert the name into widget instance 
    76103        widget_to_activate = eval(widget_name) 
     104        index_for_this_id = self.stackedWidget.indexOf(widget_to_activate) 
    77105 
    78106        # Select the requested widget 
    79         self.stackedWidget.setCurrentIndex(self.stackedWidget.indexOf(widget_to_activate)) 
     107        self.stackedWidget.setCurrentIndex(index_for_this_id) 
    80108 
    81109        self.updateWidgetFromBumps(self.current_fitter_id) 
    82110 
     111        self.assignValidators() 
     112 
    83113    def onApply(self): 
    84114        """ 
    85         Update the fitter object in perspective 
     115        Update the fitter object 
    86116        """ 
    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()) 
    88119 
    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            """ 
    91124            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()) 
    97127            self.config.values[self.current_fitter_id][option] = new_value 
    98128 
    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): 
    100147        """ 
    101148        returns widget's element linked to the given option_id 
    102149        """ 
    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) 
    104156 
    105157    def getResults(self): 
     
    127179 
    128180        pass 
    129  
    130     def updateBumpsOptions(self, optimizer_id): 
    131         """ 
    132         Given the ID of the optimizer, gather widget's values 
    133         and update the bumps options 
    134         """ 
    135         pass 
    136  
  • src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py

    r2d0e0c1 rb0c5e8c  
    159159                self.addFit(data) 
    160160 
    161     def onFittingOptionsChange(self, fit_engine, fit_options): 
     161    def onFittingOptionsChange(self, fit_engine): 
    162162        """ 
     163        React to the fitting algorithm change by modifying window title 
    163164        """ 
    164165        fitter = [f.id for f in options.FITTERS if f.name == str(fit_engine)][0] 
    165  
    166166        # set the optimizer 
    167167        self.fit_options.selected_id = str(fitter) 
    168         # set the options 
    169         # 
    170168        # Update the title 
    171169        self.updateWindowTitle() 
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r144ec831 rb0c5e8c  
    522522        Show the "Fitting" section of help 
    523523        """ 
    524         tree_location = self.parent.HELP_DIRECTORY_LOCATION + "/user/sasgui/perspectives/fitting/" 
     524        tree_location = GuiUtils.HELP_DIRECTORY_LOCATION + "/user/sasgui/perspectives/fitting/" 
    525525 
    526526        # Actual file will depend on the current tab 
  • src/sas/qtgui/Perspectives/Fitting/UI/FittingOptionsUI.ui

    r2d0e0c1 rb0c5e8c  
    77    <x>0</x> 
    88    <y>0</y> 
    9     <width>503</width> 
    10     <height>672</height> 
     9    <width>440</width> 
     10    <height>538</height> 
    1111   </rect> 
    1212  </property> 
     
    2727      <item row="0" column="0"> 
    2828       <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> 
    2935        <property name="sizeAdjustPolicy"> 
    3036         <enum>QComboBox::AdjustToContents</enum> 
  • src/sas/qtgui/Perspectives/Invariant/InvariantPerspective.py

    rdc5ef15 rb0c5e8c  
    368368        """ 
    369369        """ 
    370         _TreeLocation = self._manager.HELP_DIRECTORY_LOCATION + \ 
     370        _TreeLocation = GuiUtils.HELP_DIRECTORY_LOCATION + \ 
    371371            "/user/sasgui/perspectives/invariant/invariant_help.html" 
    372372        self._helpView.load(QtCore.QUrl(_TreeLocation)) 
  • src/sas/qtgui/Utilities/GuiUtils.py

    rdc5ef15 rb0c5e8c  
    9494PATH_APP = get_app_dir() 
    9595DATAPATH = PATH_APP 
     96 
     97## TODO: CHANGE FOR SHIPPED PATH IN RELEASE 
     98HELP_DIRECTORY_LOCATION = "docs/sphinx-docs/build/html" 
    9699 
    97100# GUI always starts from the App folder 
Note: See TracChangeset for help on using the changeset viewer.