Exemple #1
0
    def on_save_state(self):
        UsageService.registerFeatureUsage(
            FeatureType.Feature,
            ["ISIS SANS", "Settings Diagnostics - Save JSON"], False)
        # Get the save location
        save_location = self._view.get_save_location()
        # Check if it exists
        path_dir = os.path.dirname(save_location)
        if not path_dir:
            self.gui_logger.warning(
                "The provided save location for the SANS state does not seem to exist. "
                "Please provide a validate path")
            return

        file_name, _ = os.path.splitext(save_location)
        full_file_path = file_name + JSON_SUFFIX

        row_index = self._view.get_current_row()
        state = self.get_state(row_index)
        Serializer.save_file(state, full_file_path)
        self.gui_logger.information(
            "The state for row {} has been saved to: {} ".format(
                row_index, full_file_path))

        # Update the file name in the UI
        self._view.set_save_location(full_file_path)
Exemple #2
0
    def __init__(self, parent=None):
        super(BeamCentre, self).__init__(parent)
        self.setupUi(self)
        self._setup_log_widget()
        self.instrument = None

        # Hook up signal and slots
        self.connect_signals()
        self._beam_centre_tab_listeners = []

        # Attach validators
        self._attach_validators()

        # This feature is currently broken and not strictly needed so I am hiding this part of the GUI.
        self.Q_limits.hide()
        self.Q_from.hide()
        self.q_min_line_edit.hide()
        self.q_max_line_edit.hide()
        self.Q_to.hide()

        # At the moment we only track how many times this is opened, if it's popular
        # we can track individual feature usage at a later date
        UsageService.registerFeatureUsage(FeatureType.Feature,
                                          ["ISIS SANS", "Beam Centre Tab"],
                                          False)
    def __init__(self, parent_widget=None):
        super(QtWidgets.QDialog, self).__init__(parent=parent_widget)
        self.subscribers = []
        self.setup_view()

        UsageService.registerFeatureUsage(FeatureType.Feature,
                                          ["ISIS SANS", "Save Other Tab"],
                                          False)
Exemple #4
0
    def test_exception_logged(self, mock_logger, mock_CrashReportPage):
        UsageService.setEnabled(True)

        widget = MockQWidget()

        exception_logger(widget, ValueError, None, None)

        self.assertEqual(1, mock_logger.error.call_count)
        mock_CrashReportPage.assert_called_once_with(
            show_continue_terminate=True)
        # 'user selects' continue working by default
        self.assertEqual(0, widget.close.call_count)
Exemple #5
0
    def test_exception_logged_no_UsageService(self, mock_logger,
                                              mock_WorkbenchErrorMessageBox):
        UsageService.setEnabled(False)

        widget = MockQWidget()
        mock_errorbox = MockQWidget()
        mock_WorkbenchErrorMessageBox.return_value = mock_errorbox

        exception_logger(widget, ValueError, None, None)

        self.assertEqual(1, mock_logger.error.call_count)
        self.assertEqual(1, mock_WorkbenchErrorMessageBox.call_count)
        mock_errorbox.exec_.assert_called_once_with()
Exemple #6
0
 def on_vertical_clicked(self):
     UsageService.registerFeatureUsage(
         FeatureType.Feature, ["ISIS SANS", "Diagnostics - Vertical"],
         False)
     self._view.disable_integrals()
     input_file = self._view.run_input
     period = self._view.period
     state_model_with_view_update = self._parent_presenter.update_model_from_view(
     )
     state = self._model.create_state(state_model_with_view_update,
                                      input_file, period, self._facility)
     mask = self._view.vertical_mask
     range = self._view.vertical_range
     detector = get_detector_from_gui_selection(self._view.detector)
     self._worker.run_integral(range, mask, IntegralEnum.Vertical, detector,
                               state)
    def __init__(self):
        super(SettingsDiagnosticTab, self).__init__()
        self.setupUi(self)

        # Hook up signal and slots
        self.connect_signals()
        self._settings_diagnostic_listeners = []

        # Excluded settings entries
        self.excluded = ["state_module", "state_name"]

        # Q Settings
        self.__generic_settings = GENERIC_SETTINGS
        self.__save_location_path_key = "save_state_location"

        UsageService.registerFeatureUsage(
            FeatureType.Feature, ["ISIS SANS", "Settings Diagnostics Tab"],
            False)
    def on_run_clicked(self):
        UsageService.registerFeatureUsage(
            FeatureType.Feature, ["ISIS SANS", "Beam Centre Finder - Run"],
            False)
        # Get the state information for the first row.
        state = self._parent_presenter.get_state_for_row(0)

        if not state:
            self._logger.information(
                "You can only calculate the beam centre if a user file has been loaded and there"
                "valid sample scatter entry has been provided in the selected row."
            )
            return

        # Disable the button
        self._view.set_run_button_to_processing()
        self._update_beam_model_from_view()

        # Run the task
        state_copy = copy.copy(state)
        self._worker.find_beam_centre(
            state_copy, self._beam_centre_model.pack_beam_centre_settings())
Exemple #9
0
def get_workspace_history_list(workspace):
    """
    Return a list of commands that will recover the state of a workspace.
    """
    alg_name = "GeneratePythonScript"
    alg = AlgorithmManager.createUnmanaged(alg_name, 1)
    alg.setChild(True)
    alg.setLogging(False)
    alg.initialize()
    alg.setProperty("InputWorkspace", workspace)
    alg.setProperty("IgnoreTheseAlgs", ALGS_TO_IGNORE)
    alg.setProperty("IgnoreTheseAlgProperties", ALG_PROPERTIES_TO_IGNORE)
    alg.setPropertyValue("StartTimestamp", UsageService.getStartTime().toISO8601String())
    alg.setProperty("AppendTimestamp", True)
    alg.setProperty("AppendExecCount", True)
    alg.execute()
    history = alg.getPropertyValue("ScriptText")
    return history.split('\n')[6:]  # trim the header and import
Exemple #10
0
def exception_logger(main_window, exc_type, exc_value, exc_traceback):
    """
    Captures ALL EXCEPTIONS.
    Prevents the Workbench from crashing silently, instead it logs the error on ERROR level.

    :param main_window: A reference to the main window, that will be used to close it in case of the user
                        choosing to terminate the execution.
    :param exc_type: The type of the exception
    :param exc_value: Value of the exception, typically contains the error message.
    :param exc_traceback: Stack trace of the exception.
    """
    logger.error("".join(traceback.format_exception(exc_type, exc_value, exc_traceback)))

    if UsageService.isEnabled():
        page = CrashReportPage(show_continue_terminate=True)
        presenter = ErrorReporterPresenter(page, '', 'workbench', traceback.format_exception(exc_type, exc_value, exc_traceback))
        presenter.show_view_blocking()
        if not page.continue_working:
            main_window.close()
    else:
        # show the exception message without the traceback
        WorkbenchErrorMessageBox(main_window, "".join(traceback.format_exception_only(exc_type, exc_value))).exec_()
Exemple #11
0
def exception_logger(main_window, exc_type, exc_value, exc_traceback):
    """
    Captures ALL EXCEPTIONS.
    Prevents the Workbench from crashing silently, instead it logs the error on ERROR level.

    :param main_window: A reference to the main window, that will be used to close it in case of the user
                        choosing to terminate the execution.
    :param exc_type: The type of the exception
    :param exc_value: Value of the exception, typically contains the error message.
    :param exc_traceback: Stack trace of the exception.
    """
    logger.error("".join(traceback.format_exception(exc_type, exc_value, exc_traceback)))

    if UsageService.isEnabled():
        page = CrashReportPage(show_continue_terminate=True)
        presenter = ErrorReporterPresenter(page, '', 'workbench')
        presenter.show_view_blocking()
        if not page.continue_working:
            main_window.close()
    else:
        # show the exception message without the traceback
        WorkbenchErrorMessageBox(main_window, "".join(traceback.format_exception_only(exc_type, exc_value))).exec_()
Exemple #12
0
 def tearDownClass(cls):
     UsageService.setEnabled(False)