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.

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

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
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