Changeset 8b480d27 in sasview for src/sas/qtgui/Utilities


Ignore:
Timestamp:
Mar 21, 2018 6:24:36 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:
8ac3551
Parents:
3b3b40b
Message:

Code cleanup and minor fixes

Location:
src/sas/qtgui/Utilities
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Utilities/GridPanel.py

    r3b3b40b r8b480d27  
    44import webbrowser 
    55 
    6 from PyQt5 import QtCore, QtGui, QtWidgets 
     6from PyQt5 import QtCore, QtWidgets 
    77 
    88import sas.qtgui.Utilities.GuiUtils as GuiUtils 
     
    9191        return 
    9292 
    93     def onHelp(self): 
     93    @classmethod 
     94    def onHelp(cls): 
    9495        """ 
    9596        Open a local url in the default browser 
     
    119120                return 
    120121 
    121     def dataFromTable(self, table): 
     122    @classmethod 
     123    def dataFromTable(cls, table): 
    122124        """ 
    123125        Creates a dictionary {<parameter>:[list of values]} from the parameter table 
     
    125127        assert(isinstance(table, QtWidgets.QTableWidget)) 
    126128        params = {} 
    127         #return {"sld_solvent":[1.2, 2.0, 0.0], "scale":[1.0, 2.0, 3.0]} 
    128129        for column in range(table.columnCount()): 
    129             #pass 
    130130            value = [table.item(row, column).data(0) for row in range(table.rowCount())] 
    131131            key = table.horizontalHeaderItem(column).data(0) 
     
    144144            t = time.localtime(time.time()) 
    145145            time_str = time.strftime("%b %d %H:%M of %Y", t) 
    146             details = "File Generated by SasView "  
     146            details = "File Generated by SasView " 
    147147            details += "on %s.\n" % time_str 
    148148            self.writeBatchToFile(data=data, tmpfile=tmpfile, details=details) 
     
    247247        self.tblParams.resizeColumnsToContents() 
    248248 
    249     def writeBatchToFile(self, data, tmpfile, details=""): 
     249    @classmethod 
     250    def writeBatchToFile(cls, data, tmpfile, details=""): 
    250251        """ 
    251252        Helper to write result from batch into cvs file 
  • src/sas/qtgui/Utilities/ModelEditor.py

    r3b3b40b r8b480d27  
    1 # global 
    2 import sys 
    3 import os 
    4 import types 
    5 import webbrowser 
    6  
    71from PyQt5 import QtCore 
    8 from PyQt5 import QtGui 
    92from PyQt5 import QtWidgets 
    103 
    11 import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    124from sas.qtgui.Utilities.PythonSyntax import PythonHighlighter 
    135 
     
    4941        if self.txtEditor.toPlainText() != "": 
    5042            self.modelModified.emit() 
    51         pass 
    5243 
    5344    def getModel(self): 
  • src/sas/qtgui/Utilities/PluginDefinition.py

    r3b3b40b r8b480d27  
    1 # global 
    2 import sys 
    3 import os 
    4 import logging  
    5  
    61from PyQt5 import QtCore 
    72from PyQt5 import QtGui 
     
    6964        txt_validator = QtGui.QRegExpValidator(rx) 
    7065        self.txtName.setValidator(txt_validator) 
    71         self.highlight = PythonHighlighter(self.txtFunction.document())         
     66        self.highlight = PythonHighlighter(self.txtFunction.document()) 
    7267 
    7368    def initializeModel(self): 
  • src/sas/qtgui/Utilities/PluginManager.py

    r3b3b40b r8b480d27  
    11# global 
    2 import sys 
    32import os 
    4 import logging  
    53from shutil import copyfile 
    64 
    7 from PyQt5 import QtCore 
    8 from PyQt5 import QtGui 
    95from PyQt5 import QtWidgets 
    106 
  • src/sas/qtgui/Utilities/PythonSyntax.py

    • Property mode changed from 100755 to 100644
    r3b3b40b r8b480d27  
    1 import sys 
    2  
    31from PyQt5.QtCore import QRegExp 
    42from PyQt5.QtGui import QColor, QTextCharFormat, QFont, QSyntaxHighlighter 
     
    175173 
    176174if __name__ == '__main__': 
    177     import sys 
    178  
    179175    from PyQt5 import QtWidgets 
    180176 
  • src/sas/qtgui/Utilities/TabbedModelEditor.py

    r3b3b40b r8b480d27  
    22import sys 
    33import os 
    4 import types 
    54import datetime 
    65import numpy as np 
    7 import webbrowser 
    86import logging 
    97 
    10 from PyQt5 import QtCore 
    11 from PyQt5 import QtGui 
    128from PyQt5 import QtWidgets 
    139 
     
    1713from sas.qtgui.Utilities.PluginDefinition import PluginDefinition 
    1814from sas.qtgui.Utilities.ModelEditor import ModelEditor 
    19 import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    2015 
    2116class TabbedModelEditor(QtWidgets.QDialog, Ui_TabbedModelEditor): 
     
    314309        return self.tabWidget.currentWidget().getModel() 
    315310 
    316     def writeFile(self, fname, model_str=""): 
     311    @classmethod 
     312    def writeFile(cls, fname, model_str=""): 
    317313        """ 
    318314        Write model content to file "fname" 
     
    342338        model_text += 'parameters = [ \n' 
    343339        model_text += '#   ["name", "units", default, [lower, upper], "type", "description"],\n' 
    344         for pname, pvalue, desc in self.getParamHelper(param_str): 
    345             param_names.append(pname) 
    346             model_text += "    ['%s', '', %s, [-inf, inf], '', '%s'],\n" % (pname, pvalue, desc) 
    347         for pname, pvalue, desc in self.getParamHelper(pd_param_str): 
    348             param_names.append(pname) 
    349             pd_params.append(pname) 
    350             model_text += "    ['%s', '', %s, [-inf, inf], 'volume', '%s'],\n" % (pname, pvalue, desc) 
     340        if param_str: 
     341            for pname, pvalue, desc in self.getParamHelper(param_str): 
     342                param_names.append(pname) 
     343                model_text += "    ['%s', '', %s, [-inf, inf], '', '%s'],\n" % (pname, pvalue, desc) 
     344        if pd_param_str: 
     345            for pname, pvalue, desc in self.getParamHelper(pd_param_str): 
     346                param_names.append(pname) 
     347                pd_params.append(pname) 
     348                model_text += "    ['%s', '', %s, [-inf, inf], 'volume', '%s'],\n" % (pname, pvalue, desc) 
    351349        model_text += '    ]\n' 
    352350 
     
    381379        return model_text 
    382380 
    383     def checkModel(self, path): 
     381    @classmethod 
     382    def checkModel(cls, path): 
    384383        """ 
    385384        Check that the model save in file 'path' can run. 
     
    390389        model = Model() 
    391390        q =  np.array([0.01, 0.1]) 
    392         Iq = model.evalDistribution(q) 
     391        _ = model.evalDistribution(q) 
    393392        qx, qy =  np.array([0.01, 0.01]), np.array([0.1, 0.1]) 
    394         Iqxy = model.evalDistribution([qx, qy]) 
     393        _ = model.evalDistribution([qx, qy]) 
    395394 
    396395        # check the model's unit tests run 
     
    400399        return result 
    401400 
    402     def getParamHelper(self, param_str): 
     401    @classmethod 
     402    def getParamHelper(cls, param_str): 
    403403        """ 
    404404        yield a sequence of name, value pairs for the parameters in param_str 
     
    414414                if name: 
    415415                    yield [v.strip() for v in (name, value, desc)] 
    416          
    417     def strFromParamDict(self, param_dict): 
     416 
     417    @classmethod 
     418    def strFromParamDict(cls, param_dict): 
    418419        """ 
    419420        Creates string from parameter dictionary 
     
    423424        """ 
    424425        param_str = "" 
    425         for row, params in param_dict.items(): 
     426        for _, params in param_dict.items(): 
    426427            if not params[0]: continue 
    427428            value = 1 
     
    500501 
    501502if __name__ == '__main__': 
    502     import sys 
    503503    app = QtWidgets.QApplication(sys.argv) 
    504504    sheet = TabbedModelEditor() 
    505505    sheet.show() 
    506     sys.exit(app.exec_()) 
     506    app.exec_() 
    507507     
Note: See TracChangeset for help on using the changeset viewer.