def start_workbench(app): """Given an application instance create the MainWindow, show it and start the main event loop """ # The ordering here is very delicate. Test thoroughly when # changing anything! main_window = MainWindow() # Load matplotlib as early as possible and set our defaults # Setup our custom backend and monkey patch in custom current figure manager main_window.set_splash('Preloading matplotlib') from workbench.plotting.config import initialize_matplotlib # noqa initialize_matplotlib() # Setup widget layouts etc. mantid cannot be imported before this # or the log messages don't get through main_window.setup() # start mantid main_window.set_splash('Preloading mantid') importlib.import_module('mantid') main_window.show() if main_window.splash: main_window.splash.hide() # lift-off! return app.exec_()
def start_workbench(app, command_line_options): """Given an application instance create the MainWindow, show it and start the main event loop """ # The ordering here is very delicate. Test thoroughly when # changing anything! main_window = MainWindow() # decorates the excepthook callback with the reference to the main window # this is used in case the user wants to terminate the workbench from the error window shown sys.excepthook = partial(exception_logger, main_window) # Load matplotlib as early as possible and set our defaults # Setup our custom backend and monkey patch in custom current figure manager main_window.set_splash('Preloading matplotlib') from workbench.plotting.config import initialize_matplotlib # noqa initialize_matplotlib() # Setup widget layouts etc. mantid.simple cannot be used before this # or the log messages don't get through to the widget main_window.setup() # start mantid main_window.set_splash('Initializing mantid framework') FrameworkManagerImpl.Instance() main_window.post_mantid_init() if main_window.splash: main_window.splash.hide() if command_line_options.script is not None: main_window.editor.open_file_in_new_tab(command_line_options.script) editor_task = None if command_line_options.execute: # if the quit flag is not specified, this task reference will be # GC'ed, and the task will be finished alongside the GUI startup editor_task = main_window.editor.execute_current_async() if command_line_options.quit: # wait for the code interpreter thread to finish executing the script editor_task.join() main_window.close() # for task exit code descriptions see the classes AsyncTask and TaskExitCode return int(editor_task.exit_code) if editor_task else 0 main_window.show() main_window.setWindowIcon(QIcon(':/images/MantidIcon.ico')) # Project Recovey on startup main_window.project_recovery.repair_checkpoints() if main_window.project_recovery.check_for_recover_checkpoint(): main_window.project_recovery.attempt_recovery() else: main_window.project_recovery.start_recovery_thread() # lift-off! return app.exec_()
def start_workbench(app, command_line_options): """Given an application instance create the MainWindow, show it and start the main event loop """ # The ordering here is very delicate. Test thoroughly when # changing anything! main_window = MainWindow() # Load matplotlib as early as possible and set our defaults # Setup our custom backend and monkey patch in custom current figure manager main_window.set_splash('Preloading matplotlib') from workbench.plotting.config import initialize_matplotlib # noqa initialize_matplotlib() # Setup widget layouts etc. mantid.simple cannot be used before this # or the log messages don't get through to the widget main_window.setup() # start mantid main_window.set_splash('Initializing mantid framework') FrameworkManagerImpl.Instance() main_window.post_mantid_init() main_window.show() main_window.setWindowIcon(QIcon(':/images/MantidIcon.ico')) if main_window.splash: main_window.splash.hide() if command_line_options.script is not None: main_window.editor.open_file_in_new_tab(command_line_options.script) if command_line_options.execute: main_window.editor.execute_current( ) # TODO use the result as an exit code if command_line_options.quit: main_window.close() return 0 # lift-off! return app.exec_()
def start_workbench(app, command_line_options): """Given an application instance create the MainWindow, show it and start the main event loop """ # The ordering here is very delicate. Test thoroughly when # changing anything! main_window = MainWindow() # Load matplotlib as early as possible and set our defaults # Setup our custom backend and monkey patch in custom current figure manager main_window.set_splash('Preloading matplotlib') from workbench.plotting.config import initialize_matplotlib # noqa initialize_matplotlib() # Setup widget layouts etc. mantid.simple cannot be used before this # or the log messages don't get through to the widget main_window.setup() # start mantid main_window.set_splash('Initializing mantid framework') FrameworkManagerImpl.Instance() main_window.post_mantid_init() main_window.show() main_window.setWindowIcon(QIcon(':/images/MantidIcon.ico')) if main_window.splash: main_window.splash.hide() if command_line_options.script is not None: main_window.editor.open_file_in_new_tab(command_line_options.script) if command_line_options.execute: main_window.editor.execute_current() # TODO use the result as an exit code if command_line_options.quit: main_window.close() return 0 # lift-off! return app.exec_()
def create_and_launch_workbench(app, command_line_options): """Given an application instance create the MainWindow, show it and start the main event loop """ exit_value = 0 try: # MainWindow needs to be imported locally to ensure the matplotlib # backend is not imported too early. from workbench.app.mainwindow import MainWindow # The ordering here is very delicate. Test thoroughly when # changing anything! main_window = MainWindow() # Set the mainwindow as the parent for additional QMainWindow instances from workbench.config import set_additional_windows_parent set_additional_windows_parent(main_window) # decorates the excepthook callback with the reference to the main window # this is used in case the user wants to terminate the workbench from the error window shown sys.excepthook = partial(exception_logger, main_window) # Load matplotlib as early as possible and set our defaults # Setup our custom backend and monkey patch in custom current figure manager main_window.set_splash('Preloading matplotlib') from workbench.plotting.config import initialize_matplotlib # noqa initialize_matplotlib() # Setup widget layouts etc. mantid.simple cannot be used before this # or the log messages don't get through to the widget main_window.setup() # start mantid main_window.set_splash('Initializing mantid framework') FrameworkManagerImpl.Instance() main_window.post_mantid_init() if main_window.splash: main_window.splash.hide() if command_line_options.script is not None: main_window.editor.open_file_in_new_tab( command_line_options.script) editor_task = None if command_line_options.execute: # if the quit flag is not specified, this task reference will be # GC'ed, and the task will be finished alongside the GUI startup editor_task = main_window.editor.execute_current_async() if command_line_options.quit: # wait for the code interpreter thread to finish executing the script editor_task.join() main_window.close() # for task exit code descriptions see the classes AsyncTask and TaskExitCode return int(editor_task.exit_code) if editor_task else 0 main_window.show() main_window.setWindowIcon(QIcon(':/images/MantidIcon.ico')) # Project Recovery on startup main_window.project_recovery.repair_checkpoints() if main_window.project_recovery.check_for_recover_checkpoint(): main_window.project_recovery.attempt_recovery() else: main_window.project_recovery.start_recovery_thread() if not (command_line_options.execute or command_line_options.quit): if AboutPresenter.should_show_on_startup(): AboutPresenter(main_window).show() # lift-off! exit_value = app.exec_() except BaseException: # We count this as a crash import traceback # This is type of thing we want to capture and have reports # about. Prints to stderr as we can't really count on anything # else traceback.print_exc(file=ORIGINAL_STDERR) try: print_file_path = os.path.join(ConfigService.getAppDataDirectory(), STACKTRACE_FILE) with open(print_file_path, 'w') as print_file: traceback.print_exc(file=print_file) except OSError: pass exit_value = -1 finally: ORIGINAL_SYS_EXIT(exit_value)