Ejemplo n.º 1
0
    def test_start_calibration_worker(self, task):
        instrument, cer = ("test_ins", "test_cer")
        old_pending = CalibrationInfo(sample_path=None, instrument=None)
        self.presenter.pending_calibration = old_pending
        expected_pending = CalibrationInfo(sample_path=cer,
                                           instrument=instrument)
        self.presenter.instrument = instrument

        self.presenter.start_calibration_worker(cer, False, None)

        self.check_calibration_equal(self.presenter.pending_calibration,
                                     expected_pending)
Ejemplo n.º 2
0
    def test_validate_while_searching(self, create_error):
        self.presenter.current_calibration = CalibrationInfo(
            sample_path="Fake/Path", instrument="ENGINX")
        self.view.is_searching.return_value = True

        self.assertEqual(False, self.presenter._validate())
        self.assertEqual(1, create_error.call_count)
Ejemplo n.º 3
0
 def setUp(self):
     self.test_dir = tempfile.mkdtemp()
     self.model = model.FocusModel()
     self.current_calibration = CalibrationInfo(
         vanadium_path="/mocked/out/anyway",
         sample_path="this_is_mocked_out_too",
         instrument="ENGINX")
Ejemplo n.º 4
0
    def __init__(self, model, view):
        self.model = model
        self.view = view
        self.worker = None
        self.calibration_notifier = self.CalibrationNotifier(self)

        self.current_calibration = CalibrationInfo()
        self.pending_calibration = CalibrationInfo()

        self.connect_view_signals()

        # Main Window State Variables
        self.instrument = "ENGINX"
        self.rb_num = None

        # Cropping Options
        self.cropping_widget = CroppingWidget(
            self.view, view=self.view.get_cropping_widget())
        self.show_cropping(False)
Ejemplo n.º 5
0
    def __init__(self, model, view):
        self.model = model
        self.view = view
        self.worker = None
        self.calibration_observer = self.CalibrationObserver(self)

        # Connect view signals to local methods.
        self.view.set_on_focus_clicked(self.on_focus_clicked)
        self.view.set_enable_controls_connection(self.set_focus_controls_enabled)
        self.view.set_on_check_cropping_state_changed(self.show_cropping)

        # Variables from other GUI tabs.
        self.current_calibration = CalibrationInfo()
        self.instrument = "ENGINX"
        self.rb_num = None

        # Cropping Options
        self.cropping_widget = CroppingWidget(self.view, view=self.view.get_cropping_widget())
        self.show_cropping(False)
Ejemplo n.º 6
0
    def test_validate_with_invalid_spectra(self, create_error, wsp_check):
        self.presenter.current_calibration = CalibrationInfo(vanadium_path="Fake/Path",
                                                             sample_path="Fake/Path",
                                                             instrument="ENGINX")
        self.view.is_searching.return_value = False
        wsp_check.return_value = True
        self.presenter.cropping_widget.is_valid.return_value = False

        self.presenter._validate()
        create_error.assert_called_with(self.presenter.view, "Check cropping values are valid.")
Ejemplo n.º 7
0
    def test_validate_with_invalid_calibration(self, create_error):
        self.presenter.current_calibration = CalibrationInfo(vanadium_path=None,
                                                             sample_path=None,
                                                             instrument=None)
        self.view.is_searching.return_value = False

        self.presenter._validate()
        create_error.assert_called_with(
            self.presenter.view,
            "Create or Load a calibration via the Calibration tab before focusing.")
Ejemplo n.º 8
0
    def test_set_current_calibration(self):
        self.presenter.calibration_notifier = MagicMock()
        pending = CalibrationInfo(sample_path="test/set/path/2",
                                  instrument="TEST_INS")
        pendcpy = CalibrationInfo(sample_path="test/set/path/2",
                                  instrument="TEST_INS")
        self.presenter.pending_calibration = pending
        current = CalibrationInfo(sample_path="old/cera", instrument="ENGINX")
        blank = CalibrationInfo()
        self.presenter.current_calibration = current

        self.presenter.set_current_calibration()

        self.check_calibration_equal(self.presenter.current_calibration,
                                     pendcpy)
        self.check_calibration_equal(self.presenter.pending_calibration, blank)
        self.assertEqual(
            self.presenter.calibration_notifier.notify_subscribers.call_count,
            1)
Ejemplo n.º 9
0
    def test_worker_started_with_correct_params_custom_crop(self, worker, wsp_exists):
        self.presenter.current_calibration = CalibrationInfo(vanadium_path="Fake/Path",
                                                             sample_path="Fake/Path",
                                                             instrument="ENGINX")
        self.view.get_focus_filenames.return_value = "305738"
        self.presenter.cropping_widget.get_custom_spectra.return_value = "2-45"
        self.view.get_plot_output.return_value = True
        self.view.is_searching.return_value = False
        wsp_exists.return_value = True

        self.presenter.on_focus_clicked()
        worker.assert_called_with("305738", None, True, None, "2-45")
Ejemplo n.º 10
0
    def test_calibrate_clicked_load_valid_path(self, path, update):
        self.presenter.calibration_notifier = MagicMock()
        self.view.get_new_checked.return_value = False
        self.view.get_load_checked.return_value = True

        path.return_value = True
        instrument, van, cer = ("test_ins", "test_van", "test_cer")
        self.model.load_existing_gsas_parameters.return_value = instrument, van, cer
        current = CalibrationInfo(vanadium_path="old/value",
                                  sample_path="old/cera",
                                  instrument="ENGINX")
        new = CalibrationInfo(vanadium_path=van,
                              sample_path=cer,
                              instrument=instrument)
        self.presenter.current_calibration = current

        self.presenter.on_calibrate_clicked()

        self.assertEqual(update.call_count, 1)
        self.assertEqual(self.presenter.current_calibration.get_vanadium(),
                         new.get_vanadium())
        self.assertEqual(self.presenter.current_calibration.get_sample(),
                         new.get_sample())
        self.assertEqual(self.presenter.current_calibration.get_instrument(),
                         new.get_instrument())
        self.assertEqual(
            self.presenter.calibration_notifier.notify_subscribers.call_count,
            1)
Ejemplo n.º 11
0
    def test_calibrate_clicked_load_invalid_path(self, path, setting):
        self.presenter.calibration_notifier = MagicMock()
        self.view.get_new_checked.return_value = False
        self.view.get_load_checked.return_value = True
        path.return_value = False
        current = CalibrationInfo(sample_path="old/cera", instrument="ENGINX")
        self.presenter.current_calibration = current

        self.presenter.on_calibrate_clicked()

        self.assertEqual(self.presenter.current_calibration, current)
        self.assertEqual(
            self.presenter.calibration_notifier.notify_subscribers.call_count,
            0)
Ejemplo n.º 12
0
    def test_worker_started_with_correct_params_custom_crop(
            self, worker, setting):
        self.presenter.current_calibration = CalibrationInfo(
            sample_path="Fake/Path", instrument="ENGINX")
        self.view.get_focus_filenames.return_value = "305738"
        self.view.get_vanadium_filename.return_value = "307521"
        self.presenter.current_calibration.set_roi_info(None, None, "2-45")
        self.view.get_plot_output.return_value = True
        self.view.is_searching.return_value = False
        rp_dict_cropped = {'Cropped': 'Custom_spectra_grouping'}

        self.presenter.on_focus_clicked()
        worker.assert_called_with("305738", "307521", True, None,
                                  rp_dict_cropped)
        self.assertEqual(1, setting.call_count)
Ejemplo n.º 13
0
    def test_worker_started_with_correct_params(self, worker, setting):
        self.presenter.current_calibration = CalibrationInfo(
            sample_path="Fake/Path", instrument="ENGINX")
        self.view.get_focus_filenames.return_value = "305738"
        self.view.get_vanadium_filename.return_value = "307521"
        # testing south bank roi info is correctly propagated
        self.presenter.current_calibration.set_roi_info('2', None, None)
        self.view.get_plot_output.return_value = True
        self.view.is_searching.return_value = False

        self.presenter.on_focus_clicked()
        grp_dict_south = {'bank_2': 'SouthBank_grouping'}
        worker.assert_called_with("305738", "307521", True, None,
                                  grp_dict_south)
        self.assertEqual(1, setting.call_count)
Ejemplo n.º 14
0
    def __init__(self, model, view):
        self.model = model
        self.view = view
        self.worker = None
        self.calibration_observer = CalibrationObserver(self)

        # Observable Setup
        self.focus_run_notifier = GenericObservable()

        # Connect view signals to local methods.
        self.view.set_on_focus_clicked(self.on_focus_clicked)
        self.view.set_enable_controls_connection(
            self.set_focus_controls_enabled)

        # Variables from other GUI tabs.
        self.current_calibration = CalibrationInfo()
        self.instrument = "ENGINX"
        self.rb_num = None

        last_van_path = get_setting(output_settings.INTERFACES_SETTINGS_GROUP,
                                    output_settings.ENGINEERING_PREFIX,
                                    "last_vanadium_run")
        if last_van_path:
            self.view.set_van_file_text_with_search(last_van_path)
Ejemplo n.º 15
0
    def test_calibrate_clicked_load_valid_path(self, path, setting):
        self.presenter.calibration_notifier = MagicMock()
        self.view.get_new_checked.return_value = False
        self.view.get_load_checked.return_value = True

        path.return_value = True
        instrument, cer, grp_ws, roi, banks = ("test_ins", "test_cer",
                                               "test_grpws", "test_roi",
                                               ['test'])
        self.model.load_existing_calibration_files.return_value = instrument, cer, grp_ws, roi, banks
        current = CalibrationInfo(sample_path="old/cera", instrument="ENGINX")
        new = CalibrationInfo(sample_path=cer, instrument=instrument)
        new.set_roi_info_load(banks, grp_ws, roi)
        self.presenter.current_calibration = current

        self.presenter.on_calibrate_clicked()

        self.assertEqual(self.presenter.current_calibration.get_sample(),
                         new.get_sample())
        self.assertEqual(self.presenter.current_calibration.get_instrument(),
                         new.get_instrument())
        self.assertEqual(
            self.presenter.calibration_notifier.notify_subscribers.call_count,
            1)
Ejemplo n.º 16
0
class FocusPresenter(object):
    def __init__(self, model, view):
        self.model = model
        self.view = view
        self.worker = None
        self.calibration_observer = self.CalibrationObserver(self)

        # Connect view signals to local methods.
        self.view.set_on_focus_clicked(self.on_focus_clicked)
        self.view.set_enable_controls_connection(self.set_focus_controls_enabled)
        self.view.set_on_check_cropping_state_changed(self.show_cropping)

        # Variables from other GUI tabs.
        self.current_calibration = CalibrationInfo()
        self.instrument = "ENGINX"
        self.rb_num = None

        # Cropping Options
        self.cropping_widget = CroppingWidget(self.view, view=self.view.get_cropping_widget())
        self.show_cropping(False)

    def on_focus_clicked(self):
        if not self._validate():
            return
        banks, spectrum_numbers = self._get_banks()
        focus_paths = self.view.get_focus_filenames()
        if self._number_of_files_warning(focus_paths):
            self.start_focus_worker(focus_paths, banks, self.view.get_plot_output(), self.rb_num, spectrum_numbers)

    def start_focus_worker(self, focus_paths, banks, plot_output, rb_num, spectrum_numbers=None):
        """
        Focus data in a separate thread to stop the main GUI from hanging.
        :param focus_paths: List of paths to the files containing the data to focus.
        :param banks: A list of banks that are to be focused.
        :param plot_output: True if the output should be plotted.
        :param rb_num: The RB Number from the main window (often an experiment id)
        :param spectrum_numbers: Optional parameter to crop to a specific list of spectrum numbers.
        """
        self.worker = AsyncTask(self.model.focus_run,
                                (focus_paths, banks, plot_output, self.instrument, rb_num, spectrum_numbers),
                                error_cb=self._on_worker_error,
                                finished_cb=self.emit_enable_button_signal)
        self.set_focus_controls_enabled(False)
        self.worker.start()

    def set_instrument_override(self, instrument):
        instrument = INSTRUMENT_DICT[instrument]
        self.view.set_instrument_override(instrument)
        self.instrument = instrument

    def set_rb_num(self, rb_num):
        self.rb_num = rb_num

    def _validate(self):
        """
        Ensure that the worker is ready to be started.
        :return: True if the worker can be started safely.
        """
        if self.view.is_searching():
            create_error_message(self.view, "Mantid is searching for data files. Please wait.")
            return False
        if not self.view.get_focus_valid():
            create_error_message(self.view, "Check run numbers/path is valid.")
            return False
        if not check_workspaces_exist() or not self.current_calibration.is_valid():
            create_error_message(
                self.view, "Create or Load a calibration via the Calibration tab before focusing.")
            return False
        if self.current_calibration.get_instrument() != self.instrument:
            create_error_message(
                self.view,
                "Please make sure the selected instrument matches instrument for the current calibration.\n"
                "The instrument for the current calibration is: " + self.current_calibration.get_instrument())
            return False
        if self.view.get_crop_checked() and not self.cropping_widget.is_valid():
            create_error_message(self.view, "Check cropping values are valid.")
            return False
        return True

    def _number_of_files_warning(self, paths):
        if len(paths) > 10:  # Just a guess on the warning for now. May change in future.
            response = QMessageBox.warning(
                self.view, 'Engineering Diffraction - Warning',
                'You are attempting to focus {} workspaces. This may take some time.\n\n Would you like to continue?'
                .format(len(paths)), QMessageBox.Ok | QMessageBox.Cancel)
            return response == QMessageBox.Ok
        else:
            return True

    def _on_worker_error(self, _):
        self.emit_enable_button_signal()

    def set_focus_controls_enabled(self, enabled):
        self.view.set_focus_button_enabled(enabled)
        self.view.set_plot_output_enabled(enabled)

    def _get_banks(self):
        if self.view.get_crop_checked():
            if self.cropping_widget.is_custom():
                return None, self.cropping_widget.get_custom_spectra()
            else:
                return [self.cropping_widget.get_bank()], None
        else:
            return ["1", "2"], None

    def emit_enable_button_signal(self):
        self.view.sig_enable_controls.emit(True)

    def update_calibration(self, calibration):
        """
        Update the current calibration following an call from a CalibrationNotifier
        :param calibration: The new current calibration.
        """
        self.current_calibration = calibration

    def show_cropping(self, visible):
        self.view.set_cropping_widget_visibility(visible)

    # -----------------------
    # Observers / Observables
    # -----------------------
    class CalibrationObserver(Observer):
        def __init__(self, outer):
            Observer.__init__(self)
            self.outer = outer

        def update(self, observable, calibration):
            self.outer.update_calibration(calibration)
Ejemplo n.º 17
0
class FocusPresenter(object):
    def __init__(self, model, view):
        self.model = model
        self.view = view
        self.worker = None
        self.calibration_observer = CalibrationObserver(self)

        # Observable Setup
        self.focus_run_notifier = GenericObservable()

        # Connect view signals to local methods.
        self.view.set_on_focus_clicked(self.on_focus_clicked)
        self.view.set_enable_controls_connection(
            self.set_focus_controls_enabled)

        # Variables from other GUI tabs.
        self.current_calibration = CalibrationInfo()
        self.instrument = "ENGINX"
        self.rb_num = None

        last_van_path = get_setting(output_settings.INTERFACES_SETTINGS_GROUP,
                                    output_settings.ENGINEERING_PREFIX,
                                    "last_vanadium_run")
        if last_van_path:
            self.view.set_van_file_text_with_search(last_van_path)

    def add_focus_subscriber(self, obs):
        self.focus_run_notifier.add_subscriber(obs)

    def on_focus_clicked(self):
        if not self._validate():
            return
        regions_dict = self.current_calibration.create_focus_roi_dictionary()
        focus_paths = self.view.get_focus_filenames()
        van_path = self.view.get_vanadium_filename()
        if self._number_of_files_warning(focus_paths):
            self.start_focus_worker(focus_paths, van_path,
                                    self.view.get_plot_output(), self.rb_num,
                                    regions_dict)
        van_run = self.view.get_vanadium_run()
        set_setting(output_settings.INTERFACES_SETTINGS_GROUP,
                    output_settings.ENGINEERING_PREFIX, "last_vanadium_run",
                    van_run)

    def start_focus_worker(self, focus_paths: list, van_path: str,
                           plot_output: bool, rb_num: str,
                           regions_dict: dict) -> None:
        """
        Focus data in a separate thread to stop the main GUI from hanging.
        :param focus_paths: List of paths to the files containing the data to focus.
        :param plot_output: True if the output should be plotted.
        :param rb_num: The RB Number from the main window (often an experiment id)
        :param regions_dict: Dictionary containing the regions to focus over, mapping region_name -> grouping_ws_name
        """
        self.worker = AsyncTask(self.model.focus_run,
                                (focus_paths, van_path, plot_output,
                                 self.instrument, rb_num, regions_dict),
                                error_cb=self._on_worker_error,
                                finished_cb=self._on_worker_success)
        self.set_focus_controls_enabled(False)
        self.worker.start()

    def _on_worker_success(self):
        self.emit_enable_button_signal()
        self.focus_run_notifier.notify_subscribers(
            self.model.get_last_focused_files())

    def set_instrument_override(self, instrument):
        instrument = INSTRUMENT_DICT[instrument]
        self.view.set_instrument_override(instrument)
        self.instrument = instrument

    def set_rb_num(self, rb_num):
        self.rb_num = rb_num

    def _validate(self):
        """
        Ensure that the worker is ready to be started.
        :return: True if the worker can be started safely.
        """
        if self.view.is_searching():
            create_error_message(
                self.view, "Mantid is searching for data files. Please wait.")
            return False
        if not self.view.get_focus_valid():
            create_error_message(self.view, "Check run numbers/path is valid.")
            return False
        if not self.view.get_vanadium_valid():
            create_error_message(self.view,
                                 "Check vanadium run number/path is valid.")
            return False
        if not self.current_calibration.is_valid():
            create_error_message(
                self.view,
                "Create or Load a calibration via the Calibration tab before focusing."
            )
            return False
        if self.current_calibration.get_instrument() != self.instrument:
            create_error_message(
                self.view,
                "Please make sure the selected instrument matches instrument for the current calibration.\n"
                "The instrument for the current calibration is: " +
                self.current_calibration.get_instrument())
            return False
        return True

    def _number_of_files_warning(self, paths):
        if len(
                paths
        ) > 10:  # Just a guess on the warning for now. May change in future.
            response = QMessageBox.warning(
                self.view, 'Engineering Diffraction - Warning',
                'You are attempting to focus {} workspaces. This may take some time.\n\n Would you like to continue?'
                .format(len(paths)), QMessageBox.Ok | QMessageBox.Cancel)
            return response == QMessageBox.Ok
        else:
            return True

    def _on_worker_error(self, error_info):
        logger.error(str(error_info))
        self.emit_enable_button_signal()

    def set_focus_controls_enabled(self, enabled):
        self.view.set_focus_button_enabled(enabled)
        self.view.set_plot_output_enabled(enabled)

    def emit_enable_button_signal(self):
        self.view.sig_enable_controls.emit(True)

    def update_calibration(self, calibration):
        """
        Update the current calibration following an call from a CalibrationNotifier
        :param calibration: The new current calibration.
        """
        self.current_calibration = calibration
        region_text = calibration.get_roi_text()
        self.view.set_region_display_text(region_text)
Ejemplo n.º 18
0
class CalibrationPresenter(object):
    def __init__(self, model, view):
        self.model = model
        self.view = view
        self.worker = None
        self.calibration_notifier = self.CalibrationNotifier(self)

        self.current_calibration = CalibrationInfo()
        self.pending_calibration = CalibrationInfo()

        self.connect_view_signals()

        # Main Window State Variables
        self.instrument = "ENGINX"
        self.rb_num = None

        # Cropping Options
        self.cropping_widget = CroppingWidget(
            self.view, view=self.view.get_cropping_widget())
        self.show_cropping(False)

    def connect_view_signals(self):
        self.view.set_on_calibrate_clicked(self.on_calibrate_clicked)
        self.view.set_enable_controls_connection(
            self.set_calibrate_controls_enabled)
        self.view.set_update_fields_connection(self.set_field_values)
        self.view.set_on_radio_new_toggled(self.set_create_new_enabled)
        self.view.set_on_radio_existing_toggled(self.set_load_existing_enabled)
        self.view.set_on_check_cropping_state_changed(self.show_cropping)

    def on_calibrate_clicked(self):
        plot_output = self.view.get_plot_output()
        if self.view.get_new_checked() and self._validate():
            vanadium_file = self.view.get_vanadium_filename()
            sample_file = self.view.get_sample_filename()
            if self.view.get_crop_checked():
                self.start_cropped_calibration_worker(vanadium_file,
                                                      sample_file, plot_output,
                                                      self.rb_num)
            else:
                self.start_calibration_worker(vanadium_file, sample_file,
                                              plot_output, self.rb_num)
        elif self.view.get_load_checked():
            if not self.validate_path():
                return
            filename = self.view.get_path_filename()
            instrument, vanadium_file, sample_file = self.model.load_existing_gsas_parameters(
                filename)
            self.pending_calibration.set_calibration(vanadium_file,
                                                     sample_file, instrument)
            self.set_current_calibration()

    def start_calibration_worker(self,
                                 vanadium_path,
                                 sample_path,
                                 plot_output,
                                 rb_num,
                                 bank=None,
                                 spectrum_numbers=None):
        """
        Calibrate the data in a separate thread so as to not freeze the GUI.
        :param vanadium_path: Path to vanadium data file.
        :param sample_path: Path to sample data file.
        :param plot_output: Whether to plot the output.
        :param rb_num: The current RB number set in the GUI.
        :param bank: Optional parameter to crop by bank.
        :param spectrum_numbers: Optional parameter to crop by spectrum number.
        """
        self.worker = AsyncTask(self.model.create_new_calibration,
                                (vanadium_path, sample_path), {
                                    "plot_output": plot_output,
                                    "instrument": self.instrument,
                                    "rb_num": rb_num,
                                    "bank": bank,
                                    "spectrum_numbers": spectrum_numbers
                                },
                                error_cb=self._on_error,
                                success_cb=self._on_success)
        self.pending_calibration.set_calibration(vanadium_path, sample_path,
                                                 self.instrument)
        self.set_calibrate_controls_enabled(False)
        self.worker.start()

    def start_cropped_calibration_worker(self, vanadium_path, sample_path,
                                         plot_output, rb_num):
        if self.cropping_widget.is_custom():
            spec_nums = self.cropping_widget.get_custom_spectra()
            self.start_calibration_worker(vanadium_path,
                                          sample_path,
                                          plot_output,
                                          rb_num,
                                          spectrum_numbers=spec_nums)
        else:
            bank = self.cropping_widget.get_bank()
            self.start_calibration_worker(vanadium_path,
                                          sample_path,
                                          plot_output,
                                          rb_num,
                                          bank=bank)

    def set_current_calibration(self, success_info=None):
        if success_info:
            logger.information("Thread executed in " +
                               str(success_info.elapsed_time) + " seconds.")
        self.current_calibration = deepcopy(self.pending_calibration)
        self.calibration_notifier.notify_subscribers(self.current_calibration)
        self.emit_update_fields_signal()
        self.pending_calibration.clear()

    def set_field_values(self):
        self.view.set_sample_text(self.current_calibration.get_sample())
        self.view.set_vanadium_text(self.current_calibration.get_vanadium())

    def set_instrument_override(self, instrument):
        instrument = INSTRUMENT_DICT[instrument]
        self.view.set_instrument_override(instrument)
        self.instrument = instrument

    def set_rb_num(self, rb_num):
        self.rb_num = rb_num

    def _validate(self):
        # Do nothing if run numbers are invalid or view is searching.
        if self.view.is_searching():
            create_error_message(
                self.view, "Mantid is searching for data files. Please wait.")
            return False
        if not self.validate_run_numbers():
            create_error_message(self.view, "Check run numbers/path is valid.")
            return False
        if self.view.get_crop_checked(
        ) and not self.cropping_widget.is_valid():
            create_error_message(self.view, "Check cropping values are valid.")
            return False
        return True

    def validate_run_numbers(self):
        return self.view.get_sample_valid() and self.view.get_vanadium_valid()

    def validate_path(self):
        return self.view.get_path_valid()

    def emit_enable_button_signal(self):
        self.view.sig_enable_controls.emit(True)

    def emit_update_fields_signal(self):
        self.view.sig_update_fields.emit()

    def set_calibrate_controls_enabled(self, enabled):
        self.view.set_calibrate_button_enabled(enabled)
        self.view.set_check_plot_output_enabled(enabled)

    def _on_error(self, _):
        self.emit_enable_button_signal()

    def _on_success(self, success_info):
        self.set_current_calibration(success_info)
        self.emit_enable_button_signal()

    def set_create_new_enabled(self, enabled):
        self.view.set_vanadium_enabled(enabled)
        self.view.set_sample_enabled(enabled)
        if enabled:
            self.set_calibrate_button_text("Calibrate")
            self.view.set_check_plot_output_enabled(True)
            self.view.set_check_cropping_enabled(True)
            self.find_files()

    def set_load_existing_enabled(self, enabled):
        self.view.set_path_enabled(enabled)
        if enabled:
            self.set_calibrate_button_text("Load")
            self.view.set_check_plot_output_enabled(False)
            self.view.set_check_cropping_enabled(False)
            self.view.set_check_cropping_checked(False)

    def set_calibrate_button_text(self, text):
        self.view.set_calibrate_button_text(text)

    def find_files(self):
        self.view.find_sample_files()
        self.view.find_vanadium_files()

    def show_cropping(self, show):
        self.view.set_cropping_widget_visibility(show)

    # -----------------------
    # Observers / Observables
    # -----------------------
    class CalibrationNotifier(Observable):
        def __init__(self, outer):
            Observable.__init__(self)
            self.outer = outer

        def notify_subscribers(self, *args, **kwargs):
            Observable.notify_subscribers(self, *args)