schrodinger.ui.qt.appframework2.application module

Functions for managing the global QApplication instance.

Typical usage:

if __name__ == ‘__main__’:

af2.start_application(MyPanel.panel)

(Note that the start_application function is available from the af2 namespace)

schrodinger.ui.qt.appframework2.application.ApplicationMode

alias of schrodinger.ui.qt.appframework2.application.RunMode

schrodinger.ui.qt.appframework2.application.require_application(func=None, create=False, use_qtcore_app=False)[source]

Use this decorator on functions that require a QApplication to run. When the decorated function is called, this will check whether a QApplication exists. If it does not, a RuntimeError will be raised unless create=True, which will cause a QApplication to be created.

Parameters
  • func – the function to decorate

  • create (bool) – whether to create a QApplication if one does not exist

  • use_qtcore_app (bool) – Whether to create the application using the QtCore module instead of the QtWidgets module.

schrodinger.ui.qt.appframework2.application.get_application(create=True, use_qtcore_app=False)[source]

Gets the global QApplication instance. By default, creates one if none exists.

Parameters
  • create (bool) – Whether to create a new application if none exists.

  • use_qtcore_app – Whether to create the application using the QtCore module instead of the QtWidgets module. Has no effect if create is False.

Returns

the application

Return type

QApplication or None

schrodinger.ui.qt.appframework2.application.get_app_mode()[source]

Returns the current application mode, which is a member of the ApplicationMode enum.

schrodinger.ui.qt.appframework2.application.in_canvas()[source]

Checks whether we are currently running from within canvas

schrodinger.ui.qt.appframework2.application.start_application(main_callable, use_qtcore_app=False)[source]

Begins the application’s event loop using the exec_ method. The main callable is called via timer from within the event loop. This function is meant to be used when running in standalone scripts as follows:

if __name__ == ‘__main__’:

application.start_application(main)

Using this function to launch standalone scripts/panels more closely mimics the way Python is run under Maestro. For example, a panel may be presented with MyPanel.show() without having to call application.exec_().

This is generally intended for use with GUI scripts.

Parameters
  • main_callable (callable) – the function/method to be run in the event loop, commonly a module level main function or MyPanelClass.panel

  • use_qtcore_app (bool) – Whether to create the application using the QtCore module instead of the QtWidgets module. Set to True for scripts that are non-GUI and/or need to run on machines that have no display.

schrodinger.ui.qt.appframework2.application.run_application(main_callable, use_qtcore_app=True)[source]

This function is the same as start_application with two important differences:

  1. Creates a QCoreApplication by default

  2. Quits the application as soon as the main_callable function returns

    and does a system exit with that return value

This is generally intended for use by non-GUI, commandline scripts.

schrodinger.ui.qt.appframework2.application.process_events(flags=None)[source]

Calls processEvents on the main event loop. Requires a QApplication.

Parameters

flags – passed to processEvents. See QApplication.processEvents for documentation

Raises

RuntimeError – if there is no QApplication

schrodinger.ui.qt.appframework2.application.quit_application()[source]

Quits the application.