Changeset 412e069e in sasview


Ignore:
Timestamp:
Nov 7, 2017 6:29:59 AM (6 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:
3e8dee3
Parents:
6280464
Message:

More Qt5 related fixes

Location:
src/sas/qtgui
Files:
20 edited

Legend:

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

    r6280464 r412e069e  
    5656 
    5757        # validator for coefficient 
    58         self.txtNumber.setValidator(QtGui.QDoubleValidator()) 
     58        self.txtNumber.setValidator(GuiUtils.DoubleValidator()) 
    5959 
    6060        self.layoutOutput = QtWidgets.QHBoxLayout() 
  • src/sas/qtgui/Calculators/GenericScatteringCalculator.py

    r6280464 r412e069e  
    611611            'options': QtWidgets.QFileDialog.DontUseNativeDialog} 
    612612        # Query user for filename. 
    613         filename = str(QtWidgets.QFileDialog.getSaveFileName(**kwargs)) 
     613        filename_tuple = QtWidgets.QFileDialog.getSaveFileName(**kwargs) 
     614        filename = name_tuple[0] 
    614615        if filename: 
    615616            try: 
    616                 if os.path.splitext(filename)[1].lower() == '.sld': 
    617                     sas_gen.SLDReader().write(filename, self.sld_data) 
    618                 else: 
    619                     sas_gen.SLDReader().write('.'.join((filename, 'sld')), 
    620                                               self.sld_data) 
     617                _, extension = os.path.splitext(filename) 
     618                if not extension: 
     619                    filename = '.'.join((filename, 'sld')) 
     620                sas_gen.SLDReader().write(filename, self.sld_data) 
    621621            except: 
    622622                raise 
  • src/sas/qtgui/Calculators/ResolutionCalculatorPanel.py

    r6280464 r412e069e  
    106106 
    107107        # double validator 
    108         self.txtSource2SampleDistance.setValidator(QtGui.QDoubleValidator()) 
    109         self.txtSample2DetectorDistance.setValidator(QtGui.QDoubleValidator()) 
    110         self.txtSampleOffset.setValidator(QtGui.QDoubleValidator()) 
     108        self.txtSource2SampleDistance.setValidator(GuiUtils.DoubleValidator()) 
     109        self.txtSample2DetectorDistance.setValidator(GuiUtils.DoubleValidator()) 
     110        self.txtSampleOffset.setValidator(GuiUtils.DoubleValidator()) 
    111111 
    112112        # call compute to calculate with default values 
  • src/sas/qtgui/MainWindow/DataExplorer.py

    r6280464 r412e069e  
    270270            'options'   : QtWidgets.QFileDialog.DontUseNativeDialog 
    271271        } 
    272         filename = str(QtWidgets.QFileDialog.getSaveFileName(**kwargs)) 
     272        name_tuple = QtWidgets.QFileDialog.getSaveFileName(**kwargs) 
     273        filename = name_tuple[0] 
    273274        if filename: 
     275            _, extension = os.path.splitext(filename) 
     276            if not extension: 
     277                filename = '.'.join((filename, 'json')) 
    274278            self.communicator.statusBarUpdateSignal.emit("Saving Project... %s\n" % os.path.basename(filename)) 
    275279            with open(filename, 'w') as outfile: 
     
    10841088        # TODO: fix this to resemble GuiUtils.updateModelItemWithPlot 
    10851089        # 
    1086         self.model.beginResetModel() 
    1087         current_tab_name = model_item.text()[:2] 
    1088         for current_index in range(self.theory_model.rowCount()): 
    1089             if current_tab_name in self.theory_model.item(current_index).text(): 
    1090                 self.theory_model.removeRow(current_index) 
    1091                 break 
    1092  
    1093         # Reset the view 
    1094         self.model.endResetModel() 
     1090        ##self.model.beginResetModel() 
     1091        ##current_tab_name = model_item.text()[:2] 
     1092        ##for current_index in range(self.theory_model.rowCount()): 
     1093            #if current_tab_name in self.theory_model.item(current_index).text(): 
     1094            #    return 
     1095        ##        self.theory_model.removeRow(current_index) 
     1096        ##        break 
     1097 
     1098        ### Reset the view 
     1099        ##self.model.endResetModel() 
    10951100 
    10961101        # Reset the view 
  • src/sas/qtgui/MainWindow/GuiManager.py

    r6280464 r412e069e  
    88from PyQt5.QtWidgets import * 
    99from PyQt5.QtGui import * 
    10 from PyQt5.QtCore import Qt, QLocale 
     10from PyQt5.QtCore import Qt, QLocale, QUrl 
    1111from PyQt5.QtWebKitWidgets import QWebView 
    1212 
     
    5555        self._workspace = parent 
    5656        self._parent = parent 
     57 
     58        # Decide on a locale 
     59        QLocale.setDefault(QLocale('en_US')) 
    5760 
    5861        # Add signal callbacks 
  • src/sas/qtgui/MainWindow/MainWindow.py

    r6280464 r412e069e  
    6161    # (unless you know what you're doing) 
    6262    import qt5reactor 
    63     # Using the Qt4 reactor wrapper from https://github.com/ghtdak/qtreactor 
     63    # Using the Qt5 reactor wrapper from https://github.com/ghtdak/qtreactor 
    6464    qt5reactor.install() 
    6565 
  • src/sas/qtgui/Perspectives/Fitting/FittingOptions.py

    r0849aec r412e069e  
    8888                validator.setBottom(0) 
    8989            elif f_type == float: 
    90                 validator = QtGui.QDoubleValidator() 
     90                validator = GuiUtils.DoubleValidator() 
    9191                validator.setBottom(0) 
    9292            else: 
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r6280464 r412e069e  
    1313from PyQt5 import QtWidgets 
    1414from PyQt5 import QtWebKitWidgets 
     15# Officially QtWebEngineWidgets are the way to display HTML in Qt5, 
     16# but this module isn't ported to PyQt5 yet... 
     17# let's wait. In the meantime no Help. 
     18#from PyQt5 import QtWebEngineWidgets 
    1519 
    1620from sasmodels import generate 
     
    5054DEFAULT_POLYDISP_FUNCTION = 'gaussian' 
    5155 
    52 USING_TWISTED = True 
     56#USING_TWISTED = True 
     57USING_TWISTED = False 
    5358 
    5459class ToolTippedItemModel(QtGui.QStandardItemModel): 
     
    463468        menu = QtWidgets.QMenu() 
    464469        label = QtWidgets.QLabel(msg) 
    465         action = QtGui.QWidgetAction(self) 
     470        action = QtWidgets.QWidgetAction(self) 
    466471        action.setDefaultWidget(label) 
    467472        menu.addAction(action) 
     
    472477        Respond to select Model from list event 
    473478        """ 
    474         model = str(self.cbModel.currentText()) 
     479        model = self.cbModel.currentText() 
    475480 
    476481        # empty combobox forced to be read 
     
    528533        Select Category from list 
    529534        """ 
    530         category = str(self.cbCategory.currentText()) 
     535        category = self.cbCategory.currentText() 
    531536        # Check if the user chose "Choose category entry" 
    532537        if category == CATEGORY_DEFAULT: 
     
    674679            helpfile = "mag_help.html" 
    675680        help_location = tree_location + helpfile 
     681 
     682        content = QtCore.QUrl(help_location) 
    676683        self.helpView.load(QtCore.QUrl(help_location)) 
    677684        self.helpView.show() 
     
    727734            fitter = Fit() 
    728735            data = GuiUtils.dataFromItem(fit_index) 
    729             fitter.set_model(model, fit_id, params_to_fit, data=data, 
     736            try: 
     737                fitter.set_model(model, fit_id, params_to_fit, data=data, 
    730738                             constraints=constraints) 
     739            except ValueError as ex: 
     740                logging.error("Setting model parameters failed with: %s" % ex) 
     741                return 
     742 
    731743            qmin, qmax, _ = self.logic.computeRangeFromData(data) 
    732744            fitter.set_data(data=data, id=fit_id, smearer=smearer, qmin=qmin, 
     
    15131525        residuals_plot.id = "Residual " + residuals_plot.id 
    15141526        self.createNewIndex(residuals_plot) 
    1515         self.communicate.plotUpdateSignal.emit([residuals_plot]) 
     1527        #self.communicate.plotUpdateSignal.emit([residuals_plot]) 
    15161528 
    15171529    def calcException(self, etype, value, tb): 
  • src/sas/qtgui/Perspectives/Fitting/OptionsWidget.py

    r0849aec r412e069e  
    88 
    99from sas.qtgui.Plotting.PlotterData import Data2D 
     10import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    1011 
    1112# Local UI 
     
    6667 
    6768        # Let only floats in the range edits 
    68         self.txtMinRange.setValidator(QtGui.QDoubleValidator()) 
    69         self.txtMaxRange.setValidator(QtGui.QDoubleValidator()) 
     69        self.txtMinRange.setValidator(GuiUtils.DoubleValidator()) 
     70        self.txtMaxRange.setValidator(GuiUtils.DoubleValidator()) 
    7071        # Let only ints in the number of points edit 
    7172        self.txtNpts.setValidator(QtGui.QIntValidator()) 
  • src/sas/qtgui/Perspectives/Fitting/SmearingWidget.py

    r0849aec r412e069e  
    88from sas.qtgui.Plotting.PlotterData import Data1D 
    99from sas.qtgui.Plotting.PlotterData import Data2D 
     10import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    1011 
    1112# Local UI 
     
    5152        self.parent = parent 
    5253        # Let only floats in the line edits 
    53         self.txtSmearDown.setValidator(QtGui.QDoubleValidator()) 
    54         self.txtSmearUp.setValidator(QtGui.QDoubleValidator()) 
     54        self.txtSmearDown.setValidator(GuiUtils.DoubleValidator()) 
     55        self.txtSmearUp.setValidator(GuiUtils.DoubleValidator()) 
    5556 
    5657        # Attach slots 
  • src/sas/qtgui/Perspectives/Fitting/ViewDelegate.py

    r6280464 r412e069e  
    44 
    55import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    6  
    7 class CommaLessValidator(QtGui.QDoubleValidator): 
    8     """ 
    9     Custom double validator which doesn't allow for commas to be used as decimal point 
    10     """ 
    11     pass 
    126 
    137class ModelViewDelegate(QtWidgets.QStyledItemDelegate): 
     
    8781        if index.column() == self.param_value: #only in the value column 
    8882            editor = QtWidgets.QLineEdit(widget) 
    89             validator = QtGui.QDoubleValidator() 
     83            validator = GuiUtils.DoubleValidator() 
    9084            editor.setValidator(validator) 
    9185            return editor 
     
    168162        elif index.column() in self.editableParameters(): 
    169163            self.editor = QtWidgets.QLineEdit(widget) 
    170             validator = QtGui.QDoubleValidator() 
     164            validator = GuiUtils.DoubleValidator() 
    171165            self.editor.setValidator(validator) 
    172166            return self.editor 
     
    246240        if index.column() in self.editableParameters(): 
    247241            editor = QtWidgets.QLineEdit(widget) 
    248             validator = QtGui.QDoubleValidator() 
     242            validator = GuiUtils.DoubleValidator() 
    249243            editor.setValidator(validator) 
    250244            return editor 
  • src/sas/qtgui/Plotting/BoxSum.py

    r6280464 r412e069e  
    55from PyQt5 import QtGui 
    66from PyQt5 import QtWidgets 
     7 
     8import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    79 
    810# Local UI 
     
    1719        assert isinstance(model, QtGui.QStandardItemModel) 
    1820 
    19         self.txtBoxHeight.setValidator(QtGui.QDoubleValidator()) 
    20         self.txtBoxWidth.setValidator(QtGui.QDoubleValidator()) 
    21         self.txtCenterX.setValidator(QtGui.QDoubleValidator()) 
    22         self.txtCenterY.setValidator(QtGui.QDoubleValidator()) 
     21        self.txtBoxHeight.setValidator(GuiUtils.DoubleValidator()) 
     22        self.txtBoxWidth.setValidator(GuiUtils.DoubleValidator()) 
     23        self.txtCenterX.setValidator(GuiUtils.DoubleValidator()) 
     24        self.txtCenterY.setValidator(GuiUtils.DoubleValidator()) 
    2325 
    2426        self.model = model 
  • src/sas/qtgui/Plotting/ColorMap.py

    r0849aec r412e069e  
    1313from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 
    1414from sas.qtgui.Plotting.PlotterData import Data2D 
    15 from sas.qtgui.Utilities.GuiUtils import formatNumber 
     15from sas.qtgui.Utilities.GuiUtils import formatNumber, DoubleValidator 
    1616from .rangeSlider import RangeSlider 
    1717 
     
    5151 
    5252        # Initialize validators on amplitude textboxes 
    53         validator_min = QtGui.QDoubleValidator(self.txtMinAmplitude) 
     53        validator_min = DoubleValidator(self.txtMinAmplitude) 
    5454        validator_min.setNotation(0) 
    5555        self.txtMinAmplitude.setValidator(validator_min) 
    56         validator_max = QtGui.QDoubleValidator(self.txtMaxAmplitude) 
     56        validator_max = DoubleValidator(self.txtMaxAmplitude) 
    5757        validator_max.setNotation(0) 
    5858        self.txtMaxAmplitude.setValidator(validator_max) 
  • src/sas/qtgui/Plotting/LinearFit.py

    r304d082 r412e069e  
    88from PyQt5 import QtWidgets 
    99 
    10 from sas.qtgui.Utilities.GuiUtils import formatNumber 
     10from sas.qtgui.Utilities.GuiUtils import formatNumber, DoubleValidator 
    1111 
    1212from sas.qtgui.Plotting import Fittings 
     
    4343        self.y_is_log = self.yLabel == "log10(y)" 
    4444 
    45         self.txtFitRangeMin.setValidator(QtGui.QDoubleValidator()) 
    46         self.txtFitRangeMax.setValidator(QtGui.QDoubleValidator()) 
     45        self.txtFitRangeMin.setValidator(DoubleValidator()) 
     46        self.txtFitRangeMax.setValidator(DoubleValidator()) 
    4747 
    4848        # Default values in the line edits 
     
    158158        y_model = self.model.run(xmin) 
    159159        tempx.append(xminView) 
    160         tempy.append(numpy.power(10, y_model) if self.y_is_log else y_model) 
     160        tempy.append(numpy.power(10.0, y_model) if self.y_is_log else y_model) 
    161161 
    162162        # load tempy with the maximum transformation 
    163163        y_model = self.model.run(xmax) 
    164164        tempx.append(xmaxView) 
    165         tempy.append(numpy.power(10, y_model) if self.y_is_log else y_model) 
     165        tempy.append(numpy.power(10.0, y_model) if self.y_is_log else y_model) 
    166166 
    167167        # Set the fit parameter display when  FitDialog is opened again 
     
    247247            return numpy.sqrt(numpy.sqrt(x)) 
    248248        elif self.xLabel == "log10(x)": 
    249             return numpy.power(10, x) 
     249            return numpy.power(10.0, x) 
    250250        elif self.xLabel == "ln(x)": 
    251251            return numpy.exp(x) 
    252252        elif self.xLabel == "log10(x^(4))": 
    253             return numpy.sqrt(numpy.sqrt(numpy.power(10, x))) 
     253            return numpy.sqrt(numpy.sqrt(numpy.power(10.0, x))) 
    254254        return x 
    255255 
  • src/sas/qtgui/Plotting/Plotter2D.py

    r6280464 r412e069e  
    33import pylab 
    44import functools 
     5import logging 
    56 
    67from PyQt5 import QtCore 
     
    126127        zmax_temp = self.zmax 
    127128        # self.scale predefined in the baseclass 
     129        # in numpy > 1.12 power(int, -int) raises ValueException 
     130        # "Integers to negative integer powers are not allowed." 
    128131        if self.scale == 'log_{10}': 
    129132            if self.zmin is not None: 
    130                 zmin_temp = numpy.power(10, self.zmin) 
     133                zmin_temp = numpy.power(10.0, self.zmin) 
    131134            if self.zmax is not None: 
    132                 zmax_temp = numpy.power(10, self.zmax) 
     135                zmax_temp = numpy.power(10.0, self.zmax) 
    133136        else: 
    134137            if self.zmin is not None: 
     
    289292        new_plot.is_data = True 
    290293        GuiUtils.updateModelItemWithPlot(self._item, new_plot, new_plot.id) 
     294 
    291295        self.manager.communicator.plotUpdateSignal.emit([new_plot]) 
    292296 
  • src/sas/qtgui/Plotting/SetGraphRange.py

    r0849aec r412e069e  
    55from PyQt5 import QtGui 
    66from PyQt5 import QtWidgets 
     7 
     8import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    79 
    810# Local UI 
     
    1820        assert(isinstance(y_range, tuple)) 
    1921 
    20         self.txtXmin.setValidator(QtGui.QDoubleValidator()) 
    21         self.txtXmax.setValidator(QtGui.QDoubleValidator()) 
    22         self.txtYmin.setValidator(QtGui.QDoubleValidator()) 
    23         self.txtYmax.setValidator(QtGui.QDoubleValidator()) 
     22        self.txtXmin.setValidator(GuiUtils.DoubleValidator()) 
     23        self.txtXmax.setValidator(GuiUtils.DoubleValidator()) 
     24        self.txtYmin.setValidator(GuiUtils.DoubleValidator()) 
     25        self.txtYmax.setValidator(GuiUtils.DoubleValidator()) 
    2426 
    2527        self.txtXmin.setText(str(x_range[0])) 
  • src/sas/qtgui/Plotting/SlicerModel.py

    r0849aec r412e069e  
    11from PyQt5 import QtGui 
     2from PyQt5 import QtCore 
    23 
    34import sas.qtgui.Utilities.GuiUtils as GuiUtils 
  • src/sas/qtgui/Plotting/SlicerParameters.py

    r0849aec r412e069e  
    88from PyQt5 import QtWidgets 
    99from PyQt5 import QtWebKitWidgets 
     10 
     11import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    1012 
    1113# Local UI 
     
    126128            super(PositiveDoubleEditor, self).__init__(parent) 
    127129            self.setAutoFillBackground(True) 
    128             validator = QtGui.QDoubleValidator() 
     130            validator = GuiUtils.DoubleValidator() 
    129131            # Don't use the scientific notation, cause 'e'. 
    130             validator.setNotation(QtGui.QDoubleValidator.StandardNotation) 
     132            validator.setNotation(GuiUtils.DoubleValidator.StandardNotation) 
    131133 
    132134            self.setValidator(validator) 
  • src/sas/qtgui/Plotting/Slicers/SectorSlicer.py

    r0849aec r412e069e  
    33""" 
    44import numpy 
     5import logging 
    56 
    67from .BaseInteractor import BaseInteractor 
     
    167168        new_plot.is_data = True 
    168169        GuiUtils.updateModelItemWithPlot(self._item, new_plot, new_plot.id) 
     170 
    169171        self.base.manager.communicator.plotUpdateSignal.emit([new_plot]) 
    170172 
  • src/sas/qtgui/Utilities/GuiUtils.py

    r6280464 r412e069e  
    584584    } 
    585585    # Query user for filename. 
    586     filename = QtWidgets.QFileDialog.getSaveFileName(**kwargs) 
     586    filename_tuple = QtWidgets.QFileDialog.getSaveFileName(**kwargs) 
     587    filename = filename_tuple[0] 
    587588 
    588589    # User cancelled. 
    589590    if not filename: 
    590591        return 
    591  
    592     filename = str(filename) 
    593592 
    594593    #Instantiate a loader 
     
    616615    } 
    617616    # Query user for filename. 
    618     filename = QtWidgets.QFileDialog.getSaveFileName(**kwargs) 
     617    filename_tuple = QtWidgets.QFileDialog.getSaveFileName(**kwargs) 
     618    filename = filename_tuple[0] 
    619619 
    620620    # User cancelled. 
    621621    if not filename: 
    622622        return 
    623     filename = str(filename) 
     623 
    624624    #Instantiate a loader 
    625625    loader = Loader() 
     
    825825    else: 
    826826        raise ValueError 
     827 
     828class DoubleValidator(QtGui.QDoubleValidator): 
     829    """ 
     830    Allow only dots as decimal separator 
     831    """ 
     832    def validate(self, input, pos): 
     833        """ 
     834        Return invalid for commas 
     835        """ 
     836        if (',' in input): 
     837            return (QtGui.QValidator.Invalid, input, pos) 
     838        return super(DoubleValidator, self).validate(input, pos) 
     839 
     840    def fixup(self, input): 
     841        """ 
     842        Correct (remove) potential preexisting content 
     843        """ 
     844        QtGui.QDoubleValidator.fixup(input) 
     845        input = input.replace(",", "") 
     846 
Note: See TracChangeset for help on using the changeset viewer.