schrodinger.utils.qapplication 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.utils.qapplication.ApplicationMode¶
alias of
schrodinger.utils.qapplication.RunMode
- exception schrodinger.utils.qapplication.CantCreateQApplicationError(msg='', *args, **kwargs)[source]¶
Bases:
RuntimeError
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- schrodinger.utils.qapplication.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.utils.qapplication.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
isFalse
.
- Raises
CantCreateQApplicationError – if use_qtcore_app is False and importing QtWidgets fails (e.g. due to missing graphics libraries)
- Returns
the application
- Return type
QApplication or None
- schrodinger.utils.qapplication.is_core_application()[source]¶
Return whether the application instance is a QtCore application (as opposed to a QtWidgets application).
- Returns
Whether there is a QtCore application or None if there’s no application
- Return type
bool or NoneType
- schrodinger.utils.qapplication.get_app_mode()[source]¶
Returns the current application mode, which is a member of the ApplicationMode enum.
- schrodinger.utils.qapplication.in_canvas()[source]¶
Checks whether we are currently running from within canvas
- schrodinger.utils.qapplication.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.utils.qapplication.run_application(main_callable, use_qtcore_app=True)[source]¶
This function is the same as start_application with two important differences:
Creates a QCoreApplication by default
- 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.