sas.qtgui.Utilities package

Submodules

sas.qtgui.Utilities.AddMultEditor module

sas.qtgui.Utilities.CategoryInstaller module

Class for making sure all category stuff is installed and works fine.

Copyright (c) Institut Laue-Langevin 2012

@author kieranrcampbell@gmail.com @modified by NIST/MD sasview team

class sas.qtgui.Utilities.CategoryInstaller.CategoryInstaller[source]

Bases: object

Class for making sure all category stuff is installed

Note - class is entirely static!

__dict__ = mappingproxy({'__module__': 'sas.qtgui.Utilities.CategoryInstaller', '__doc__': '\n    Class for making sure all category stuff is installed\n\n    Note - class is entirely static!\n    ', '__init__': <function CategoryInstaller.__init__>, '_get_home_dir': <staticmethod(<function CategoryInstaller._get_home_dir>)>, '_regenerate_model_dict': <staticmethod(<function CategoryInstaller._regenerate_model_dict>)>, '_regenerate_master_dict': <staticmethod(<function CategoryInstaller._regenerate_master_dict>)>, 'get_user_file': <staticmethod(<function CategoryInstaller.get_user_file>)>, 'get_default_file': <staticmethod(<function CategoryInstaller.get_default_file>)>, 'check_install': <staticmethod(<function CategoryInstaller.check_install>)>, '__dict__': <attribute '__dict__' of 'CategoryInstaller' objects>, '__weakref__': <attribute '__weakref__' of 'CategoryInstaller' objects>, '__annotations__': {}})
__doc__ = '\n    Class for making sure all category stuff is installed\n\n    Note - class is entirely static!\n    '
__init__()[source]

initialization

__module__ = 'sas.qtgui.Utilities.CategoryInstaller'
__weakref__

list of weak references to the object

static _get_home_dir()[source]

returns the users sasview config dir

static _regenerate_master_dict(by_model_dict, model_enabled_dict)[source]

regenerates master_category_dict from by_model_dict and model_enabled_dict returns the master category dictionary

static _regenerate_model_dict(master_category_dict)[source]

regenerates self.by_model_dict which has each model name as the key and the list of categories belonging to that model along with the enabled mapping returns tuplet (by_model_dict, model_enabled_dict)

static check_install(homedir=None, model_list=None)[source]

the main method of this class makes sure categories.json exists and if not compile it and install :param homefile: Override the default home directory :param model_list: List of model names except customized models

static get_default_file()[source]
static get_user_file()[source]

returns the user data file, eg .sasview/categories.json.json

sas.qtgui.Utilities.CodeEditor module

class sas.qtgui.Utilities.CodeEditor.QCodeEditor(parent=None)[source]

Bases: QPlainTextEdit

__annotations__ = {}
__doc__ = None
__init__(parent=None)[source]
__module__ = 'sas.qtgui.Utilities.CodeEditor'
highlightCurrentLine()[source]
lineNumberAreaPaintEvent(event)[source]
lineNumberAreaWidth()[source]
resizeEvent(self, e: QResizeEvent | None)[source]
updateLineNumberArea(rect, dy)[source]
updateLineNumberAreaWidth()[source]
class sas.qtgui.Utilities.CodeEditor.QLineNumberArea(editor)[source]

Bases: QWidget

__annotations__ = {}
__doc__ = None
__init__(editor)[source]
__module__ = 'sas.qtgui.Utilities.CodeEditor'
paintEvent(self, a0: QPaintEvent | None)[source]
sizeHint(self) QSize[source]

sas.qtgui.Utilities.ConnectionProxy module

class sas.qtgui.Utilities.ConnectionProxy.ConnectionProxy(url, timeout)[source]

Bases: object

__dict__ = mappingproxy({'__module__': 'sas.qtgui.Utilities.ConnectionProxy', '__init__': <function ConnectionProxy.__init__>, '_get_addresses_of_proxy_pac': <function ConnectionProxy._get_addresses_of_proxy_pac>, '_parse_proxy_pac': <function ConnectionProxy._parse_proxy_pac>, '_set_proxy': <function ConnectionProxy._set_proxy>, 'connect': <function ConnectionProxy.connect>, '__dict__': <attribute '__dict__' of 'ConnectionProxy' objects>, '__weakref__': <attribute '__weakref__' of 'ConnectionProxy' objects>, '__doc__': None, '__annotations__': {}})
__doc__ = None
__init__(url, timeout)[source]
__module__ = 'sas.qtgui.Utilities.ConnectionProxy'
__weakref__

list of weak references to the object

_get_addresses_of_proxy_pac()[source]

Return a list of possible auto proxy .pac files being used, based on the system registry (win32) or system preferences (OSX). @return: list of urls

_parse_proxy_pac(pac_urls_list)[source]

For every pac file url in pac_urls_list, it tryes to connect. If the connection is successful parses the file in search for http proxies. @param pac_urls_list: List with urls for the pac files @return: list with all found http proxies

_set_proxy(proxy_dic=None)[source]

Sets connection proxy. if proxy_dic is None get’s teh proxy from the system. To disable autodetected proxy pass an empty dictionary: {} @param proxy_dic: format: {‘http’: ‘http://www.example.com:3128/’}

connect()[source]

Performs the request and gets a response from self.url @return: response object from urllib2.urlopen

sas.qtgui.Utilities.CustomDir module

sas.qtgui.Utilities.CustomDir._find_customconf_dir()[source]

Find path of the config directory. The plugin directory is located in the user’s home directory.

sas.qtgui.Utilities.CustomDir._find_usersasview_dir()[source]

Find and return user/.sasview dir

sas.qtgui.Utilities.CustomDir.setup_conf_dir(path)[source]

Setup the custom config dir and cat file

sas.qtgui.Utilities.FileConverter module

sas.qtgui.Utilities.FrameSelect module

FrameSelect class describes behaviour of the FrameSelect dialog

class sas.qtgui.Utilities.FrameSelect.FrameSelect(parent=None, frames=1, isBSL=True)[source]

Bases: QDialog, Ui_FrameSelect

Class to describe the behaviour of the Frame Selector widget

__annotations__ = {}
__doc__ = '\n    Class to describe the behaviour of the Frame Selector widget\n    '
__init__(parent=None, frames=1, isBSL=True)[source]
__module__ = 'sas.qtgui.Utilities.FrameSelect'
addSlots()[source]

Describe behaviour of OK and Cancel buttons

addState()[source]

Minor bookkeeping

addText()[source]

Initialize view

getFrames()[source]

Accessor for state values

onFirstChanged()[source]

Manage view-model sync

onIncrementChanged()[source]

Manage view-model sync

onLastChanged()[source]

Manage view-model sync

updateDisplay()[source]

manage model-view sync

sas.qtgui.Utilities.GenericReader module

Thread handler used to load data

class sas.qtgui.Utilities.GenericReader.GenReader(path, loader, completefn=None, updatefn=None, yieldtime=0.01, worktime=0.01)[source]

Bases: CalcThread

Load a sld data given a filename

__annotations__ = {}
__doc__ = '\n    Load a sld data given a filename\n    '
__init__(path, loader, completefn=None, updatefn=None, yieldtime=0.01, worktime=0.01)[source]

Prepare the calculator

__module__ = 'sas.qtgui.Utilities.GenericReader'
compute()[source]

Read some data

isquit()[source]

@raise KeyboardInterrupt: when the thread is interrupted

sas.qtgui.Utilities.GridPanel module

sas.qtgui.Utilities.GuiUtils module

sas.qtgui.Utilities.IPythonWidget module

sas.qtgui.Utilities.ImageViewer module

sas.qtgui.Utilities.LocalConfig module

Application settings

sas.qtgui.Utilities.LocalConfig.printEVT(message)[source]

Post a debug message to console/file

sas.qtgui.Utilities.ModelEditor module

sas.qtgui.Utilities.ObjectLibrary module

sas.qtgui.Utilities.ObjectLibrary.addObject(obj_name, obj)[source]
sas.qtgui.Utilities.ObjectLibrary.deleteObjectByName(obj_name)[source]
sas.qtgui.Utilities.ObjectLibrary.deleteObjectByRef(obj)[source]
sas.qtgui.Utilities.ObjectLibrary.getObject(obj_name)[source]
sas.qtgui.Utilities.ObjectLibrary.listObjects()[source]

sas.qtgui.Utilities.PlotView module

class sas.qtgui.Utilities.PlotView.EmbeddedPylab(canvas)[source]

Bases: object

Define a ‘with’ context manager that lets you use pylab commands to plot on an embedded canvas. This is useful for wrapping existing scripts in a GUI, and benefits from being more familiar than the underlying object oriented interface.

As a convenience, the pylab module is returned on entry.

Example

The following example shows how to use the WxAgg backend in a wx panel:

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as Toolbar
from matplotlib.figure import Figure

class PlotPanel(wx.Panel):
    def __init__(self, *args, **kw):
        wx.Panel.__init__(self, *args, **kw)

        figure = Figure(figsize=(1,1), dpi=72)
        canvas = FigureCanvas(self, wx.ID_ANY, figure)
        self.pylab_interface = EmbeddedPylab(canvas)

        # Instantiate the matplotlib navigation toolbar and explicitly show it.
        mpl_toolbar = Toolbar(canvas)
        mpl_toolbar.Realize()

        # Create a vertical box sizer to manage the widgets in the main panel.
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(canvas, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, border=0)
        sizer.Add(mpl_toolbar, 0, wx.EXPAND|wx.ALL, border=0)

        # Associate the sizer with its container.
        self.SetSizer(sizer)
        sizer.Fit(self)

    def plot(self, *args, **kw):
        with self.pylab_interface as pylab:
            pylab.clf()
            pylab.plot(*args, **kw)

Similar patterns should work for the other backends. Check the source code in matplotlib.backend_bases.* for examples showing how to use matplotlib with other GUI toolkits.

__dict__ = mappingproxy({'__module__': 'sas.qtgui.Utilities.PlotView', '__doc__': "\n    Define a 'with' context manager that lets you use pylab commands to\n    plot on an embedded canvas.  This is useful for wrapping existing\n    scripts in a GUI, and benefits from being more familiar than the\n    underlying object oriented interface.\n\n    As a convenience, the pylab module is returned on entry.\n\n    *Example*\n\n    The following example shows how to use the WxAgg backend in a wx panel::\n\n        from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas\n        from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as Toolbar\n        from matplotlib.figure import Figure\n\n        class PlotPanel(wx.Panel):\n            def __init__(self, *args, **kw):\n                wx.Panel.__init__(self, *args, **kw)\n\n                figure = Figure(figsize=(1,1), dpi=72)\n                canvas = FigureCanvas(self, wx.ID_ANY, figure)\n                self.pylab_interface = EmbeddedPylab(canvas)\n\n                # Instantiate the matplotlib navigation toolbar and explicitly show it.\n                mpl_toolbar = Toolbar(canvas)\n                mpl_toolbar.Realize()\n\n                # Create a vertical box sizer to manage the widgets in the main panel.\n                sizer = wx.BoxSizer(wx.VERTICAL)\n                sizer.Add(canvas, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, border=0)\n                sizer.Add(mpl_toolbar, 0, wx.EXPAND|wx.ALL, border=0)\n\n                # Associate the sizer with its container.\n                self.SetSizer(sizer)\n                sizer.Fit(self)\n\n            def plot(self, *args, **kw):\n                with self.pylab_interface as pylab:\n                    pylab.clf()\n                    pylab.plot(*args, **kw)\n\n    Similar patterns should work for the other backends.  Check the source code\n    in matplotlib.backend_bases.* for examples showing how to use matplotlib\n    with other GUI toolkits.\n    ", '__init__': <function EmbeddedPylab.__init__>, '__enter__': <function EmbeddedPylab.__enter__>, '__exit__': <function EmbeddedPylab.__exit__>, '__dict__': <attribute '__dict__' of 'EmbeddedPylab' objects>, '__weakref__': <attribute '__weakref__' of 'EmbeddedPylab' objects>, '__annotations__': {}})
__doc__ = "\n    Define a 'with' context manager that lets you use pylab commands to\n    plot on an embedded canvas.  This is useful for wrapping existing\n    scripts in a GUI, and benefits from being more familiar than the\n    underlying object oriented interface.\n\n    As a convenience, the pylab module is returned on entry.\n\n    *Example*\n\n    The following example shows how to use the WxAgg backend in a wx panel::\n\n        from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas\n        from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as Toolbar\n        from matplotlib.figure import Figure\n\n        class PlotPanel(wx.Panel):\n            def __init__(self, *args, **kw):\n                wx.Panel.__init__(self, *args, **kw)\n\n                figure = Figure(figsize=(1,1), dpi=72)\n                canvas = FigureCanvas(self, wx.ID_ANY, figure)\n                self.pylab_interface = EmbeddedPylab(canvas)\n\n                # Instantiate the matplotlib navigation toolbar and explicitly show it.\n                mpl_toolbar = Toolbar(canvas)\n                mpl_toolbar.Realize()\n\n                # Create a vertical box sizer to manage the widgets in the main panel.\n                sizer = wx.BoxSizer(wx.VERTICAL)\n                sizer.Add(canvas, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, border=0)\n                sizer.Add(mpl_toolbar, 0, wx.EXPAND|wx.ALL, border=0)\n\n                # Associate the sizer with its container.\n                self.SetSizer(sizer)\n                sizer.Fit(self)\n\n            def plot(self, *args, **kw):\n                with self.pylab_interface as pylab:\n                    pylab.clf()\n                    pylab.plot(*args, **kw)\n\n    Similar patterns should work for the other backends.  Check the source code\n    in matplotlib.backend_bases.* for examples showing how to use matplotlib\n    with other GUI toolkits.\n    "
__enter__()[source]
__exit__(*args, **kw)[source]
__init__(canvas)[source]
__module__ = 'sas.qtgui.Utilities.PlotView'
__weakref__

list of weak references to the object

class sas.qtgui.Utilities.PlotView.PlotView(*args, **kw)[source]

Bases: QWidget, _PlotViewShared

__annotations__ = {}
__doc__ = None
__init__(*args, **kw)[source]
__module__ = 'sas.qtgui.Utilities.PlotView'
_is_shown()[source]
class sas.qtgui.Utilities.PlotView._PlotViewShared[source]

Bases: object

__annotations__ = {}
__dict__ = mappingproxy({'__module__': 'sas.qtgui.Utilities.PlotView', 'title': 'Plot', 'default_size': (600, 400), 'pylab_interface': None, 'plot_state': None, 'model': None, '_calculating': False, '_need_plot': False, '_need_newmodel': False, 'set_model': <function _PlotViewShared.set_model>, 'update_model': <function _PlotViewShared.update_model>, 'update_parameters': <function _PlotViewShared.update_parameters>, '_show': <function _PlotViewShared._show>, '_redraw': <function _PlotViewShared._redraw>, 'get_state': <function _PlotViewShared.get_state>, 'set_state': <function _PlotViewShared.set_state>, 'menu': <function _PlotViewShared.menu>, 'newmodel': <function _PlotViewShared.newmodel>, 'plot': <function _PlotViewShared.plot>, '__dict__': <attribute '__dict__' of '_PlotViewShared' objects>, '__weakref__': <attribute '__weakref__' of '_PlotViewShared' objects>, '__doc__': None, '__annotations__': {'pylab_interface': 'EmbeddedPylab'}})
__doc__ = None
__module__ = 'sas.qtgui.Utilities.PlotView'
__weakref__

list of weak references to the object

_calculating = False
_need_newmodel = False
_need_plot = False
_redraw(newmodel=False)[source]
_show()[source]
default_size = (600, 400)
get_state()[source]
menu()[source]

Return a model specific menu

model = None
newmodel(model=None)[source]

New or updated model structure. Do any sort or precalculation you need. plot will be called separately when you are done.

For long calculations, periodically perform wx.YieldIfNeeded() and then if self.cancel_calculation is True, return from the plot.

plot()[source]

Plot to the current figure. If model has a plot method, just use that.

For long calculations, periodically perform wx.YieldIfNeeded() and then if self.cancel_calculation is True, return from the plot.

plot_state = None
pylab_interface: EmbeddedPylab = None
set_model(model)[source]
set_state(state)[source]
title = 'Plot'
update_model(model)[source]
update_parameters(model)[source]

sas.qtgui.Utilities.PluginDefinition module

sas.qtgui.Utilities.PluginManager module

sas.qtgui.Utilities.PythonSyntax module

class sas.qtgui.Utilities.PythonSyntax.PythonHighlighter(document, is_python=True)[source]

Bases: QSyntaxHighlighter

Syntax highlighter for the Python language.

__annotations__ = {}
__doc__ = 'Syntax highlighter for the Python language.\n    '
__init__(document, is_python=True)[source]
__module__ = 'sas.qtgui.Utilities.PythonSyntax'
braces = ['\\{', '\\}', '\\(', '\\)', '\\[', '\\]']
c_keywords = ['auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto', 'if', 'int', 'long', 'register', 'return', 'short', 'signed', 'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while']
highlightBlock(text)[source]

Apply syntax highlighting to the given block of text.

match_multiline(text, delimiter, in_state, style)[source]

Do highlighting of multi-line strings. delimiter should be a QRegExp for triple-single-quotes or triple-double-quotes, and in_state should be a unique integer to represent the corresponding state changes when inside those strings. Returns True if we’re still inside a multi-line string when this function is finished.

operators = ['=', '==', '!=', '<', '<=', '>', '>=', '\\+', '-', '\\*', '/', '//', '\\%', '\\*\\*', '\\+=', '-=', '\\*=', '/=', '\\%=', '\\^', '\\|', '\\&', '\\~', '>>', '<<']
python_keywords = ['and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'yield', 'None', 'True', 'False']
sas.qtgui.Utilities.PythonSyntax.format(color, style='')[source]

Return a QTextCharFormat with the given attributes.

sas.qtgui.Utilities.ReportDialog module

sas.qtgui.Utilities.ResultPanel module

FitPanel class contains fields allowing to fit models and data

class sas.qtgui.Utilities.ResultPanel.ResultPanel(parent, manager=None, *args, **kwargs)[source]

Bases: QTabWidget

FitPanel class contains fields allowing to fit models and data

Note:

For Fit to be performed the user should check at least one parameter on fit Panel window.

__annotations__ = {}
__doc__ = '\n    FitPanel class contains fields allowing to fit  models and  data\n\n    :note: For Fit to be performed the user should check at least one parameter\n        on fit Panel window.\n\n    '
__init__(parent, manager=None, *args, **kwargs)[source]
__module__ = 'sas.qtgui.Utilities.ResultPanel'
clearAnyData()[source]

Clear any previous results and reset window to its base state.

closeEvent(event)[source]

Overwrite QDialog close method to allow for custom widget close

onDataDeleted(data)[source]

Check if the data set is shown in the window and close tabs as needed.

onPlotResults(results, optimizer='Unknown')[source]
updateBumps()[source]

Monkeypatching bumps plot viewer to allow Qt

windowClosedSignal

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

window_name = 'Result panel'

sas.qtgui.Utilities.SasviewLogger module

class sas.qtgui.Utilities.SasviewLogger.QtHandler[source]

Bases: QObject, Handler

Version of logging handler “emitting” the message to custom stdout()

__annotations__ = {}
__doc__ = '\n    Version of logging handler "emitting" the message to custom stdout()\n    '
__init__()[source]
__module__ = 'sas.qtgui.Utilities.SasviewLogger'
emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

messageWritten

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

sas.qtgui.Utilities.SasviewLogger.setup_qt_logging()[source]

sas.qtgui.Utilities.TabbedModelEditor module

Module contents