schrodinger.utils.qt_utils module¶
Utility classes and functions for use with Qt objects (such as QObjects). Note that contrary to schrodinger.ui.qt.utils, these utilities do not rely on QtGui or QtWidgets. This allows these utilities to be used on headless servers which shouldn’t import QtGui or QtWidgets.
-
class
schrodinger.utils.qt_utils.
suppress_signals
(*args)¶ Bases:
object
A context manager to prevent signals from being emitted from the specified widget(s). All widgets to be suppressed should be passed as arguments.
-
__init__
(*args)¶ Initialize self. See help(type(self)) for accurate signature.
-
-
exception
schrodinger.utils.qt_utils.
SignalTimeoutException
¶ Bases:
RuntimeError
-
__init__
¶ Initialize self. See help(type(self)) for accurate signature.
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
schrodinger.utils.qt_utils.
wait_for_signal
(signal, timeout=None)¶ Uses an event loop to wait until a signal is emitted. If the signal is not emitted within a specified timeout duration, a SignalTimeoutException is raised.
Parameters: - signal – the signal to wait for
- timeout (float) – number of seconds to wait for the signal before timing out
Returns: the args emitted with the signal, if any. If there is only one arg emitted, it will be returned directly. If there are more, they will be return as a tuple.
-
schrodinger.utils.qt_utils.
call_func_and_wait_for_signal
(func, signal, timeout=None)¶ Calls the specified function and then waits for the signal. The function is called in such a way that the signal is guaranteed to be caught, even if the signal is emitted before the function returns.
Parameters: func – the function to call See wait_for_signal for additional parameter documentation.
-
class
schrodinger.utils.qt_utils.
ABCMetaQObject
(name, bases, attrs)¶ Bases:
abc.ABCMeta
,sip.wrappertype
Metaclass to allow a derived object to be a QObject and an abc.
Usage:
- class MyClass(QtCore.QObject, metaclass=ABCMetaQObject):
- …
-
__init__
(name, bases, attrs)¶ Initialize self. See help(type(self)) for accurate signature.
-
mro
() → list¶ return a type’s method resolution order
-
register
(subclass)¶ Register a virtual subclass of an ABC.
Returns the subclass, to allow usage as a class decorator.
-
schrodinger.utils.qt_utils.
get_signals
(source)¶ Utility method for iterating through the signals on a QObject.
Parameters: - source (
QtCore.QObject
or instance thereof) – Any object or class with signals - filter (tuple of strings) – Any signals to ignore
Return type: list of tuples
Returns: A list of (name, signal) tuples
- source (
-
class
schrodinger.utils.qt_utils.
SignalAndSlot
(signal, slot)¶ Bases:
object
A composite object to manage a single signal/slot pair. Usage:
class ClassName(QtWidgets.QWidget): fooChangedSignal = QtCore.pyqtSignal() def __init__(self, parent=None): super(ClassName, self).__init__(parent) self.fooChanged = qt_utils.SignalAndSlot(self.fooChangedSignal, self.fooChangedSlot) def fooChangedSlot(self): pass
-
__init__
(signal, slot)¶ Create an object that acts as both a signal and a slot
Parameters: - signal (
PyQt5.QtCore.pyqtSignal
) – The signal object - slot (function) – The slot object
- signal (
-
emit
(*args, **kwargs)¶
-
connect
(*args, **kwargs)¶
-
disconnect
(*args, **kwargs)¶
-
-
schrodinger.utils.qt_utils.
add_enums_as_attributes
(enum_)¶ A class decorator that takes in an enum and aliases its members on the decorated class. For example:
Shape = enum.Enum('Shape', 'SQUARE TRIANGLE CIRCLE') @qt_utils.add_enums_as_attributes(Shape) class Foo: pass assert Foo.SQUARE is Shape.SQUARE assert Foo.TRIANGLE is Shape.TRIANGLE assert Foo.CIRCLE is Shape.CIRCLE