schrodinger.ui.qt.widgetmixins.basicmixins module

class schrodinger.ui.qt.widgetmixins.basicmixins.InitMixin(*args, **kwargs)

Bases: object

A mixin that breaks up widget initialization into several discrete steps and provides some basic formatting boilerplate. Each of these steps is meant to be overridden during subclassing so that

  1. The initialization is organized

  2. Repetition when subclassing is minimized, because the five provided initialization methods can be overridden rather than all of __init__.

Expects to be inherited by a QtWidgets.QWidget.

To install a Qt Designer ui module on the widget, set the class variable ui_module to the *_ui module created by pyuic.

ui_module = None
__init__(*args, **kwargs)
initSetOptions()

Suggested subclass use: set instance variables, excluding layouts and subwidgets. Also use here to (optionally) apply the legacy stylesheet spacing settings (PANEL-19101).

initSetUp()

Creates widget from ui and stores it ui_widget.

Suggested subclass use: create and initialize subwidgets, and connect signals.

initLayOut()

Create a vertical layout for the widget (widget_layout) and populate it with two vertical sub-layouts: main_layout and bottom_layout.

If the user has specified the ui data member, insert the resultant ui_widget into main_layout.

If the widget already has a layout defined, this method will produce a warning (but not a traceback). main_layout and bottom_layout will be inserted into the existing widget layout, which will not be the same as widget_layout. It is therefore recommended that this mixin is used only with widgets that do not already have a layout.

Suggested subclass use: create, initialize, and populate layouts.

setWidgetLayout()

Set the widget layout

initSetDefaults()

Set widget to its default state. If the widget uses a model/mapper, it’s preferable to reset the widget state by resetting the model.

initFinalize()

Suggested subclass use: perform any remaining initialization.

class schrodinger.ui.qt.widgetmixins.basicmixins.ExecutionMixin(*args, **kwargs)

Bases: object

A mixin that facilitates the use of the run method, which provides a flexible means of opening the inheriting widget.

Expects to be inherited by a QtWidgets.QWidget.

self._return_value is provided as a way to give self.run(blocking=True) a return value.

Variables

SHOW_AS_WINDOW (bool) – Whether the widget is intended to be shown as a window (e.g. the widget is dialog-like). If you create a child widget using this class and unexpectedly see its contents inside the parent, set this to True.

SHOW_AS_WINDOW = False
__init__(*args, **kwargs)
run(blocking: bool = False, modal: bool = False, finished_callback: Callable = None) None | bool

Show this widget, while optionally blocking, making the widget window modal, and registering a callback for when the widget is closed again.

Parameters
  • blocking – if True, block progress in the calling method until the widget is closed again.

  • modal – if True, open this widget as window modal. Otherwise, open this widget as nonmodal.

  • finished_callback – an object that will be called with no arguments when this widget is closed.

Returns

None for non-blocking or boolean value indicating whether the widget was accepted or rejected for a blocking call.

setWindowFlagsForRun()
setWindowFlags(flags=None)
closeEvent(event)
setVisible(set_visible)
debug()
class schrodinger.ui.qt.widgetmixins.basicmixins.MessageBoxMixin

Bases: object

A mixin that facilitates the creation of several common types of message boxes as children of the inheriting class.

showMessageBox(*args, **kwargs)

Shows a popup message box. For parameter documentation see messagebox.MessageBox.

warning(*args, **kwargs)

Shows a popup warning message box. For parameter documentation see messagebox.MessageBox.

error(*args, **kwargs)

Shows a popup error message box. For parameter documentation see messagebox.MessageBox.

info(*args, **kwargs)

Shows a popup information message box. For parameter documentation see messagebox.MessageBox.

question(*args, **kwargs)

Shows a popup question message box. For parameter documentation see messagebox.QuestionMessageBox.

forgetMessageBoxResponse(key)

Forgets any previously saved response that was stored via a save_response_key.

Parameters

key – the key for the response to forget

class schrodinger.ui.qt.widgetmixins.basicmixins.BottomButtonMixin(*args, **kwargs)

Bases: object

Provides an interface for quickly adding buttons to the bottom of the widget. This includes standard buttons like OK, Cancel and Help, as well as custom buttons, specified with the appmethods.custom decorator.

Requires InitMixin. Works with ExecutionMixin, if present, such that value of self.accepted will be returned from self.run(blocking=True)

To add standard buttons other than “Help”, set self.std_btn_specs with keys from the BottomButtonMixin.StdBtn enum and values which are a tuple of (slot, text, tooltip).

slot: a function that will be called when the button is clicked. The slot provides custom functionality on top of the standard behavior of the button. Returning False will abort the default behavior. Use None for the slot if there is no custom behavior to implement.

text: customized button text to override the standard text (“OK”, “Cancel”, etc.)

tooltip: tooltip text

All parts of the spec are optional, and the tuple can be any length up to 3. As a convenience, in lieu of a tuple of length 1, the slot itself can be directly supplied as the spec. Examples:

self.std_btn_specs = {self.StdBtn.Ok : (self.onOkClicked, 'Run'),
                      self.StdBtn.Cancel : self.onCancelClicked,
                      self.StdBtn.Reset : None}

To get the help button to appear, just set self.help_topic to the appropriate string. No button spec is required for the help button.

To add custom buttons, decorate the intended slot with:

@appmethods.custom('Custom button text', order=1, tooltip=None)
def mySlot(self):
    ...

The order and tooltip arguments are optional. Custom buttons will be arranged from left to right according to the order value.

class StdBtn(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: enum.IntEnum

Ok = 0
Cancel = 1
Reset = 2
Help = 3
class BtnPos(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: enum.IntEnum

Left = 0
Middle = 1
Right = 2
__init__(*args, **kwargs)
initSetUp()
initLayOut()
property accepted
show()

Override the show method to clear and previous value of self.accepted

closeEvent(event)

Ensures proper handling of OK, Cancel, and [X] button clicks

class schrodinger.ui.qt.widgetmixins.basicmixins.SchrodingerStyleMixin

Bases: object

Mixin to (optionally) apply the spacing styles extracted from the global Schrodinger style sheet (PANEL-19101). While this is enabled by default to preserve the traditional panel appearance, new panels can disable this by assigning APPLY_LEGACY_STYLESHEET = False.

Meant to be inherited by a class that also inherits InitMixin and QtWidgets.QWidget.

Variables
  • APPLY_LEGACY_STYLESHEET (bool) – whether to apply the legacy stylesheet to this widget. While PanelX is under development, the default value can be set to False by setting an environment variable OMIT_LEGACY_STYLESHEET to true.

  • APPLY_PANELX_STYLESHEET – whether to apply the PanelX stylehseet to this widget.

APPLY_LEGACY_STYLESHEET = True
APPLY_PANELX_STYLESHEET = False
initSetOptions()
setStyleSheet(stylesheet)
class schrodinger.ui.qt.widgetmixins.basicmixins.BaseMixinCollection(*args, **kwargs)

Bases: schrodinger.ui.qt.widgetmixins.basicmixins.SchrodingerStyleMixin, schrodinger.ui.qt.widgetmixins.basicmixins.BottomButtonMixin, schrodinger.ui.qt.widgetmixins.basicmixins.InitMixin, schrodinger.ui.qt.widgetmixins.basicmixins.ExecutionMixin, schrodinger.ui.qt.widgetmixins.basicmixins.MessageBoxMixin, schrodinger.ui.qt.appframework2.validation.ValidationMixin

A mixin that combines other widget mixins for convenience. See individual mixin classes for full documentation: InitMixin, ExecutionMixin, MessageBoxMixin, validation.ValidationMixin

class schrodinger.ui.qt.widgetmixins.basicmixins.DockableMixinCollection(*args, **kwargs)

Bases: schrodinger.ui.qt.widgetmixins.basicmixins.BaseMixinCollection

A mixin collection for dockable widgets.

SHOW_AS_WINDOW = False
setWidgetLayout()

Set the widget layout. A QDockWidget’s layout does not allow nested layouts so we create a container widget to hold the widget layout.

setWindowFlagsForRun()

Don’t set any window flags for run

class schrodinger.ui.qt.widgetmixins.basicmixins.StatusBarMixin

Bases: object

A mixin that adds a status bar and repositions the help button to be on the status bar. Requires InitMixin and BottomButtonMixin.

initSetUp()
initLayOut()
setErrorStatusMessage(message)
clearStatusMessage()
schrodinger.ui.qt.widgetmixins.basicmixins.setup_panel_ui(panel)

Installs a ui module onto the specified panel.

  • If the panel subclasses a Ui_Form, the class itself will setup the ui_widget.

  • If the panel has a “ui” value set that is a Ui_Form instance, that will be used to populate the ui_widget.

  • If the panel has a “ui” value set that is a ui module containing Ui_Form, the Ui_Form will be instantiated and used to populate the ui_widget.

Parameters

panel (PanelMixin) – the panel to setup ui on

Raises

TypeError – if the panel has a “ui” value set that is neither a Ui_Form instance nor a ui module

schrodinger.ui.qt.widgetmixins.basicmixins.is_dockable(window)
schrodinger.ui.qt.widgetmixins.basicmixins.is_docked(window)