Skip to content

Commit

Permalink
Refs #9204 - Make sure new settings object is cleared ...
Browse files Browse the repository at this point in the history
... whenever the singleton is reset.

Also, slight change so that we only ever load the instrument once on
interface startup.
  • Loading branch information
PeterParker committed May 7, 2014
1 parent d13dddd commit 26cf78a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
24 changes: 15 additions & 9 deletions Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 =";
Expand Down Expand Up @@ -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)";
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions Code/Mantid/scripts/SANS/ISISCommandInterface.py
Expand Up @@ -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):
"""
Expand Down
9 changes: 9 additions & 0 deletions Code/Mantid/scripts/SANS/isis_reducer.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 26cf78a

Please sign in to comment.