From c61469466de42bbeee6da5adfd0231fc3642ee2d Mon Sep 17 00:00:00 2001 From: Tom Titcombe <t.j.titcombe@gmail.com> Date: Mon, 15 Apr 2019 16:01:34 +0100 Subject: [PATCH] Update view.add_runs_presenter save dir on defaultsave change Add unit test to check run tab presenter save dir change calls add runs presenter Update release notes re #25537 --- docs/source/release/v4.1.0/sans.rst | 1 + .../ui/sans_isis/sans_data_processor_gui.py | 4 ++-- scripts/SANS/sans/gui_logic/gui_common.py | 13 ++----------- .../sans/gui_logic/presenter/add_runs_presenter.py | 10 +++++++++- .../sans/gui_logic/presenter/run_tab_presenter.py | 4 ++++ scripts/SANS/sans/test_helper/mock_objects.py | 3 +++ .../test/SANS/gui_logic/run_tab_presenter_test.py | 14 ++++++++++++++ 7 files changed, 35 insertions(+), 14 deletions(-) diff --git a/docs/source/release/v4.1.0/sans.rst b/docs/source/release/v4.1.0/sans.rst index 92bf6169dda..5aa7202bcda 100644 --- a/docs/source/release/v4.1.0/sans.rst +++ b/docs/source/release/v4.1.0/sans.rst @@ -23,6 +23,7 @@ Improvements - **Load Batch File** opens to the directory of your last selected batch file. **Load User File** opens to the directory of your last selected user file. - Batch files created by exporting the runs table have the same order of keys as in the table. - Batch files no longer require an output name to load. When processing, an auto-generated name is used instead. +- When the main save directory is changed, the add runs save directory is also updated. Add runs save directory can be still changed independently of the main save directory. Bug Fixes ######### diff --git a/scripts/Interface/ui/sans_isis/sans_data_processor_gui.py b/scripts/Interface/ui/sans_isis/sans_data_processor_gui.py index 425049d3014..16b71f7ec9d 100644 --- a/scripts/Interface/ui/sans_isis/sans_data_processor_gui.py +++ b/scripts/Interface/ui/sans_isis/sans_data_processor_gui.py @@ -571,13 +571,13 @@ class SANSDataProcessorGui(QMainWindow, self.get_user_file_path) # Set full user file path for default loading - self.gui_properties_handler.update_default("user_file", self.get_user_file_path()) + self.gui_properties_handler.set_setting("user_file", self.get_user_file_path()) # Notify presenters self._call_settings_listeners(lambda listener: listener.on_user_file_load()) def on_user_file_load_failure(self): - self.gui_properties_handler.update_default("user_file", "") + self.gui_properties_handler.set_setting("user_file", "") self.user_file_line_edit.setText("") def set_out_default_user_file(self): diff --git a/scripts/SANS/sans/gui_logic/gui_common.py b/scripts/SANS/sans/gui_logic/gui_common.py index 88f3a5ac6c5..cf8d43b99fb 100644 --- a/scripts/SANS/sans/gui_logic/gui_common.py +++ b/scripts/SANS/sans/gui_logic/gui_common.py @@ -9,7 +9,6 @@ import os from qtpy.QtCore import QSettings from qtpy.QtWidgets import QFileDialog -from mantid.kernel import Logger from sans.common.enums import SANSInstrument, ISISReductionMode, DetectorType @@ -285,13 +284,6 @@ class SANSGuiPropertiesHandler(object): pass load_func(*args) - def update_default(self, gui_property, value): - if gui_property in self.keys: - self._set_setting(self.__generic_settings, gui_property, value) - else: - Logger("SANSPropertyHandler").information("Trying to set property {} for which a default property " - "does not exist".format(gui_property)) - @staticmethod def _load_default_file(line_edit_field, q_settings_group_key, q_settings_key): settings = QSettings() @@ -310,9 +302,8 @@ class SANSGuiPropertiesHandler(object): return default_property - @staticmethod - def _set_setting(q_settings_group_key, q_settings_key, value): + def set_setting(self, q_settings_key, value): settings = QSettings() - settings.beginGroup(q_settings_group_key) + settings.beginGroup(self.__generic_settings) settings.setValue(q_settings_key, value) settings.endGroup() diff --git a/scripts/SANS/sans/gui_logic/presenter/add_runs_presenter.py b/scripts/SANS/sans/gui_logic/presenter/add_runs_presenter.py index ca8d9697731..5cd27b8c63a 100644 --- a/scripts/SANS/sans/gui_logic/presenter/add_runs_presenter.py +++ b/scripts/SANS/sans/gui_logic/presenter/add_runs_presenter.py @@ -130,8 +130,16 @@ class AddRunsPagePresenter(object): def _handle_output_directory_changed(self): directory = self._view.display_save_directory_box("Save sum runs", self.save_directory) directory = os.path.join(directory, '') # Add an OS specific trailing slash if it doesn't already exist + self.handle_new_save_directory(directory) + + def handle_new_save_directory(self, directory): + """ + This method is called when a new save directory is selected on the add runs page, but is also called + in the run_tab_presenter when a new default save directory is selected through Manage Directories. + :param directory: A string. The new path to the save directory + """ self.set_output_directory(directory) - self.gui_properties_handler.update_default("add_runs_output_directory", directory) + self.gui_properties_handler.set_setting("add_runs_output_directory", directory) def _handle_sum(self): run_selection = self._run_selector_presenter.run_selection() diff --git a/scripts/SANS/sans/gui_logic/presenter/run_tab_presenter.py b/scripts/SANS/sans/gui_logic/presenter/run_tab_presenter.py index d1482b56ebb..1da1c49f78c 100644 --- a/scripts/SANS/sans/gui_logic/presenter/run_tab_presenter.py +++ b/scripts/SANS/sans/gui_logic/presenter/run_tab_presenter.py @@ -261,6 +261,10 @@ class RunTabPresenter(object): :return: """ self._view.set_out_file_directory(new_directory) + # Update add runs save location. We want distinct reduction save/add runs save locations, + # but the add runs directory change when the main directory is, to avoid users having to + # remember to update in two places. + self._view.add_runs_presenter.handle_new_save_directory(new_directory) # ------------------------------------------------------------------------------------------------------------------ # Table + Actions diff --git a/scripts/SANS/sans/test_helper/mock_objects.py b/scripts/SANS/sans/test_helper/mock_objects.py index 252ba0e687c..8c68032c624 100644 --- a/scripts/SANS/sans/test_helper/mock_objects.py +++ b/scripts/SANS/sans/test_helper/mock_objects.py @@ -118,6 +118,9 @@ def create_mock_view(user_file_path, batch_file_path=None, row_user_file_path="" # Mock objects used in the properties handler view.user_file_line_edit = mock.Mock() + # Mock the add runs presenter + view.add_runs_presenter = mock.Mock() + # --------------------- # Mocking properties # --------------------- diff --git a/scripts/test/SANS/gui_logic/run_tab_presenter_test.py b/scripts/test/SANS/gui_logic/run_tab_presenter_test.py index 1e0e98d76d6..07cba72f409 100644 --- a/scripts/test/SANS/gui_logic/run_tab_presenter_test.py +++ b/scripts/test/SANS/gui_logic/run_tab_presenter_test.py @@ -1014,6 +1014,20 @@ class RunTabPresenterTest(unittest.TestCase): args, _ = presenter._view.can_sas_checkbox.setEnabled.call_args_list[-1] self.assertTrue(args[0], "Can SAS checkbox should have been enabled, since we switched to 1D reduction mode.") + def test_that_updating_default_save_directory_also_updates_add_runs_save_directory(self): + """This test checks that add runs presenter's save directory update method is called + when the defaultsave directory is updated.""" + presenter = RunTabPresenter(SANSFacility.ISIS) + view = mock.MagicMock() + presenter.set_view(view) + + presenter._handle_output_directory_changed("a_new_directory") + calls = presenter._view.add_runs_presenter.handle_new_save_directory.call_args_list + self.assertEqual(len(calls), 1) + + args = calls[0][0] + self.assertEqual(args, ("a_new_directory",)) + @staticmethod def _clear_property_manager_data_service(): for element in PropertyManagerDataService.getObjectNames(): -- GitLab