Пример #1
0
 def test_should_show_on_startup_invalid_facility(self, MockConfigService):
     MockConfigService.getFacility.side_effect = RuntimeError("Invalid Facility name")
     self.assertTrue(AboutPresenter.should_show_on_startup(),
                     "If the facilty is invalid then should_show_on_startup should always be true")
     MockConfigService.getString.assert_has_calls([call(AboutPresenter.FACILITY),
                                                   call(AboutPresenter.INSTRUMENT)])
     MockConfigService.getFacility.assert_has_calls([call("FACILITY1")])
Пример #2
0
 def test_should_show_on_startup_no_facility(self, MockConfigService):
     MockConfigService.getString.return_value = ""
     self.assertTrue(
         AboutPresenter.should_show_on_startup(),
         "If the facilty is not set then should_show_on_startup should always be true"
     )
     MockConfigService.getString.assert_has_calls(
         [call(AboutPresenter.FACILITY),
          call(AboutPresenter.INSTRUMENT)])
Пример #3
0
 def test_should_show_on_startup_do_not_show_same_version(self, MockConfigService):
     version_str = "the same every time"
     with patch(self.QSETTINGS_CLASSPATH, return_value=FakeQSettings(version_str)):
         with patch(self.RELEASE_NOTES_URL_CLASSPATH, return_value=version_str):
             self.assertFalse(AboutPresenter.should_show_on_startup(),
                              "If do not show is in Qsettings then should_show_on_startup should always be False"
                              + "for the same version")
     MockConfigService.getString.assert_has_calls([call(AboutPresenter.FACILITY),
                                                   call(AboutPresenter.INSTRUMENT)])
     MockConfigService.getFacility.assert_has_calls([call("FACILITY1")])
     MockConfigService.getInstrument.assert_has_calls([call("FACILITY1")])
Пример #4
0
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()

    # 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!
    return app.exec_()
Пример #5
0
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)