From 26cf78aba778e4b2bd6eafaff6666850b3be57fb Mon Sep 17 00:00:00 2001 From: Peter Parker Date: Wed, 7 May 2014 14:00:04 +0100 Subject: [PATCH] Refs #9204 - Make sure new settings object is cleared ... ... whenever the singleton is reset. Also, slight change so that we only ever load the instrument once on interface startup. --- .../CustomInterfaces/src/SANSRunWindow.cpp | 24 ++++++++++++------- .../scripts/SANS/ISISCommandInterface.py | 7 ++++++ Code/Mantid/scripts/SANS/isis_reducer.py | 9 +++++++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp index 47d694ce95af..1e4462df5968 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp @@ -314,9 +314,9 @@ void SANSRunWindow::initLocalPython() } runPythonCode("import ISISCommandInterface as i\nimport copy"); runPythonCode("import isis_instrument\nimport isis_reduction_steps"); - handleInstrumentChange(); loadUserFile(); + handleInstrumentChange(); } /** Initialise some of the data and signal connections in the save box */ @@ -690,7 +690,7 @@ bool SANSRunWindow::loadUserFile() m_uiForm.mask_table->removeRow(i); } - QString pyCode = "i.ReductionSingleton.clean(isis_reducer.ISISReducer)"; + QString pyCode = "i.Clean()"; pyCode += "\ni.ReductionSingleton().set_instrument(isis_instrument."; pyCode += getInstrumentClass()+")"; pyCode += "\ni.ReductionSingleton().user_settings ="; @@ -2362,7 +2362,6 @@ void SANSRunWindow::handleReduceButtonClick(const QString & typeStr) } //Reset the objects by initialising a new reducer object - //py_code = "i._refresh_singleton()"; if (runMode == SingleMode) // TODO: test if it is really necessary to reload the file settings. { py_code = "\ni.ReductionSingleton.clean(isis_reducer.ISISReducer)"; @@ -2821,12 +2820,19 @@ void SANSRunWindow::handleInstrumentChange() //set up the required Python objects and delete what's out of date (perhaps everything is cleaned here) const QString instClass(getInstrumentClass()); - QString pyCode("if i.ReductionSingleton().get_instrument() != '"); - pyCode += m_uiForm.inst_opt->currentText()+"':"; - pyCode += "\n\ti.ReductionSingleton.clean(isis_reducer.ISISReducer)"; - pyCode += "\ni.ReductionSingleton().set_instrument(isis_instrument."; - pyCode += instClass+")"; - runReduceScriptFunction(pyCode); + + // Only set the instrument if it isn't alread set to what has been selected. + // This is useful on interface start up, where we have already loaded the user file + // and don't want to set the instrument twice. + const QString currentInstName = runPythonCode( + "print i.ReductionSingleton().get_instrument().name()").trimmed(); + if( currentInstName != m_uiForm.inst_opt->currentText() ) + { + QString pyCode("i.ReductionSingleton.clean(isis_reducer.ISISReducer)"); + pyCode += "\ni.ReductionSingleton().set_instrument(isis_instrument."; + pyCode += instClass+")"; + runReduceScriptFunction(pyCode); + } //now update the GUI fillDetectNames(m_uiForm.detbank_sel); diff --git a/Code/Mantid/scripts/SANS/ISISCommandInterface.py b/Code/Mantid/scripts/SANS/ISISCommandInterface.py index 98ed8e1c2220..ab56f4c78502 100644 --- a/Code/Mantid/scripts/SANS/ISISCommandInterface.py +++ b/Code/Mantid/scripts/SANS/ISISCommandInterface.py @@ -56,6 +56,13 @@ def issueWarning(msg): def _refresh_singleton(): ReductionSingleton.clean(isis_reducer.ISISReducer) ReductionSingleton().remove_settings() + +def Clean(): + """ + An exposed command to allow cleaning of the reducer, and any related + settings. + """ + _refresh_singleton() def UserPath(path): """ diff --git a/Code/Mantid/scripts/SANS/isis_reducer.py b/Code/Mantid/scripts/SANS/isis_reducer.py index a940b4499156..49fd596eb1fa 100644 --- a/Code/Mantid/scripts/SANS/isis_reducer.py +++ b/Code/Mantid/scripts/SANS/isis_reducer.py @@ -133,6 +133,12 @@ def __getitem__(self, key): def __setitem__(self, key, value): self._prop_man()[key] = value + def __len__(self): + return len(self._prop_man()) + + def clear(self): + PropertyManagerDataService.remove(SETTINGS_PROP_MAN_NAME) + return PropertyManagerPicklableWrapper() class Sample(object): @@ -435,8 +441,11 @@ def deep_copy(self): return copy.deepcopy(current_settings) def remove_settings(self): + logger.debug("Clearing reducer settings.") global current_settings current_settings = None + self.settings.clear() + assert len(self.settings) == 0 def cur_settings(self): """