def _wrapper(self): global QAPP if not QAPP: setup_library_paths() QAPP = QApplication(['']) test_method(self) QAPP.closeAllWindows()
def setUpClass(cls): """Prepare for test execution. Ensure that a (single copy of) QApplication has been created """ global _QAPP if _QAPP is None: setup_library_paths() _QAPP = QApplication([cls.__name__])
def setUp(self): qapp = QApplication.instance() if qapp is None: setup_library_paths() cls._qapp = QApplication([cls.__name__]) else: self._qapp = qapp orig_setUp(self)
def open_in_window(widget_name, script): """ Displays a widget in a window. :param widget_name: A qualified name of a widget, ie mantidqt.mywidget.MyWidget :param script: A qualified name of a test function that can be run after the widget is created. The test function must have the signature: def test(widget): ... where argument widget is an instance of the tested widget. The test function can yield from time to time after which the widget can update itself. This will make the test non-blocking and changes can be viewed as the script runs. If the test yields an integer it is interpreted as the number of seconds to wait until the next step. """ raw_input( 'Please attach the Debugger now if required. Press any key to continue' ) setup_library_paths() app = QApplication([""]) w = create_widget(widget_name) w.setWindowTitle(widget_name) w.show() if script is not None: try: # If script is a generator script_iter allows non-blocking # test execution script_iter = iter(run_script(script, w)) pause_timer = QTimer() pause_timer.setSingleShot(True) def idle(): if not pause_timer.isActive(): try: # Run test script until the next 'yield' pause_sec = script_iter.next() if pause_sec is not None: # Start non-blocking pause in seconds pause_timer.start(int(pause_sec * 1000)) except StopIteration: pass except: traceback.print_exc() timer = QTimer() # Zero-timeout timer runs idle() between Qt events timer.timeout.connect(idle) timer.start() except: pass sys.exit(app.exec_())
def get_application(name=''): """ Initialise and return the global application object :param name: Optional application name :return: Global appliction object """ global _QAPP if _QAPP is None: setup_library_paths() _QAPP = QApplication([name]) return _QAPP
def open_in_window(widget_name, script): """ Displays a widget in a window. :param widget_name: A qualified name of a widget, ie mantidqt.mywidget.MyWidget :param script: A qualified name of a test function that can be run after the widget is created. The test function must have the signature: def test(widget): ... where argument widget is an instance of the tested widget. The test function can yield from time to time after which the widget can update itself. This will make the test non-blocking and changes can be viewed as the script runs. If the test yields an integer it is interpreted as the number of seconds to wait until the next step. """ raw_input('Please attach the Debugger now if required. Press any key to continue') setup_library_paths() app = QApplication([""]) w = create_widget(widget_name) w.setWindowTitle(widget_name) w.show() if script is not None: try: # If script is a generator script_iter allows non-blocking # test execution script_iter = iter(run_script(script, w)) pause_timer = QTimer() pause_timer.setSingleShot(True) def idle(): if not pause_timer.isActive(): try: # Run test script until the next 'yield' pause_sec = script_iter.next() if pause_sec is not None: # Start non-blocking pause in seconds pause_timer.start(int(pause_sec * 1000)) except StopIteration: pass except: traceback.print_exc() timer = QTimer() # Zero-timeout timer runs idle() between Qt events timer.timeout.connect(idle) timer.start() except: pass sys.exit(app.exec_())
def get_application(name=''): """ Initialise and return the global application object :param name: Optional application name :return: Global appliction object """ global _QAPP def exception_handler(exctype, value, tb): traceback.print_exception(exctype, value, tb) sys.exit(1) if _QAPP is None: setup_library_paths() _QAPP = QApplication([name]) sys.excepthook = exception_handler return _QAPP
def get_application(name=''): """ Initialise and return the global application object :param name: Optional application name :return: Global appliction object """ global _QAPP def exception_handler(exctype, value, tb): traceback.print_exception(exctype, value, tb) sys.exit(1) if _QAPP is None: setup_library_paths() _QAPP = QApplication([name]) if PYQT4: # Do not destroy C++ Qtcore objects on exit # Matches PyQt5 behaviour to avoid random segfaults # https://www.riverbankcomputing.com/static/Docs/PyQt5/pyqt4_differences.html#object-destruction-on-exit sip.setdestroyonexit(False) sys.excepthook = exception_handler return _QAPP
QPixmap) # noqa from qtpy.QtWidgets import (QApplication, QDesktopWidget, QFileDialog, QMainWindow, QSplashScreen) # noqa from mantidqt.algorithminputhistory import AlgorithmInputHistory # noqa from mantidqt.interfacemanager import InterfaceManager # noqa from mantidqt.widgets import manageuserdirectories # noqa from mantidqt.widgets.scriptrepository import ScriptRepositoryView # noqa from mantidqt.widgets.codeeditor.execution import PythonCodeExecution # noqa from mantidqt.utils.qt import (add_actions, create_action, plugins, widget_updates_disabled) # noqa from mantidqt.project.project import Project # noqa from mantidqt.usersubwindowfactory import UserSubWindowFactory # noqa from mantidqt.usersubwindow import UserSubWindow # noqa # Pre-application setup plugins.setup_library_paths() # Importing resources loads the data in. This must be imported before the # QApplication is created or paths to Qt's resources will not be set up correctly from workbench.app.resources import qCleanupResources # noqa from workbench.config import APPNAME, CONF, ORG_DOMAIN, ORGANIZATION # noqa from workbench.plotting.globalfiguremanager import GlobalFigureManager # noqa from workbench.utils.windowfinder import find_all_windows_that_are_savable # noqa from workbench.utils.workspacehistorygeneration import get_all_workspace_history_from_ads # noqa from workbench.projectrecovery.projectrecovery import ProjectRecovery # noqa from mantidqt.utils.asynchronous import BlockingAsyncTaskWithCallback # noqa from mantidqt.utils.qt.qappthreadcall import QAppThreadCall # noqa # ----------------------------------------------------------------------------- # Create the application instance early, set the application name for window
# ----------------------------------------------------------------------------- from workbench import requirements # noqa requirements.check_qt() # ----------------------------------------------------------------------------- # Qt # ----------------------------------------------------------------------------- from qtpy.QtCore import (QEventLoop, Qt, QTimer) # noqa from qtpy.QtGui import (QColor, QPixmap) # noqa from qtpy.QtWidgets import (QApplication, QDesktopWidget, QFileDialog, QMainWindow, QSplashScreen) # noqa from mantidqt.utils.qt import plugins, widget_updates_disabled # noqa # Pre-application setup plugins.setup_library_paths() # ----------------------------------------------------------------------------- # Create the application instance early, set the application name for window # titles and hold on to a reference to it. Required to be performed early so # that the splash screen can be displayed # ----------------------------------------------------------------------------- def qapplication(): """Either return a reference to an existing application instance or create a new one :return: A reference to the QApplication object """ app = QApplication.instance() if app is None: app = QApplication(['Mantid Workbench'])