Skip to content

Commit

Permalink
Disable automatic algorithm execution on accept for scripts
Browse files Browse the repository at this point in the history
Also renamed MantidUI member function call to make its purpose clearer.
Refs #9756
  • Loading branch information
martyngigg committed Jun 30, 2014
1 parent 00c177b commit 4e8e959
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Code/Mantid/Framework/PythonInterface/mantid/simpleapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,9 @@ def make_str(value):

# finally run the configured dialog
import mantidplot
dialog = mantidplot.createPropertyInputDialog(algm_object.name(), presets, message, enabled_list, disabled_list)
if dialog == False:
raise RuntimeError('Dialog cancel pressed. Script execution halted.')
dialog_accepted = mantidplot.createScriptInputDialog(algm_object.name(), presets, message, enabled_list, disabled_list)
if not dialog_accepted:
raise RuntimeError('Algorithm input cancelled')

#----------------------------------------------------------------------------------------------------------------------

Expand All @@ -765,7 +765,7 @@ def algorithm_wrapper(*args, **kwargs):
kwargs[item] = ""

algm = _create_algorithm_object(algorithm, _version)
_set_properties_dialog(algm, *args, **kwargs)
_set_properties_dialog(algm, *args, **kwargs) # throws if input cancelled
algm.execute()
return algm

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidPlot/mantidplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,9 @@ def importTableWorkspace(name, visible=False):
"""
return new_proxy(proxies.MDIWindow,_qti.app.mantidUI.importTableWorkspace, name,False,visible)

def createPropertyInputDialog(alg_name, preset_values, optional_msg, enabled, disabled):
def createScriptInputDialog(alg_name, preset_values, optional_msg, enabled, disabled):
"""Raises a property input dialog for an algorithm"""
return threadsafe_call(_qti.app.mantidUI.createPropertyInputDialog, alg_name, preset_values, optional_msg, enabled, disabled)
return threadsafe_call(_qti.app.mantidUI.createScriptInputDialog, alg_name, preset_values, optional_msg, enabled, disabled)

#-----------------------------------------------------------------------------
#-------------------------- SliceViewer functions ----------------------------
Expand Down
7 changes: 4 additions & 3 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2132,8 +2132,9 @@ MantidMatrix* MantidUI::newMantidMatrix(const QString& wsName, int start, int en
return importMatrixWorkspace(wsName, false, false, start, end);
}

bool MantidUI::createPropertyInputDialog(const QString & alg_name, const QString & preset_values,
const QString & optional_msg, const QStringList & enabled, const QStringList & disabled)
bool MantidUI::createScriptInputDialog(const QString & alg_name, const QString & preset_values,
const QString & optional_msg, const QStringList & enabled,
const QStringList & disabled)
{
IAlgorithm_sptr alg = AlgorithmManager::Instance().newestInstanceOf(alg_name.toStdString());
if( !alg )
Expand All @@ -2157,7 +2158,7 @@ bool MantidUI::createPropertyInputDialog(const QString & alg_name, const QString
MantidQt::API::InterfaceManager interfaceManager;
MantidQt::API::AlgorithmDialog *dlg =
interfaceManager.createDialog(alg, m_appWindow->getScriptWindowHandle(),
true, presets, optional_msg, enabled, disabled);
true, presets, optional_msg, enabled, disabled);
return (dlg->exec() == QDialog::Accepted);
}

Expand Down
5 changes: 3 additions & 2 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ class MantidUI:public QObject
MantidMatrix* newMantidMatrix(const QString& name, int start=-1, int end=-1);

void setIsRunning(bool running);
bool createPropertyInputDialog(const QString & alg_name, const QString & preset_values,
const QString & optional_msg, const QStringList & enabled, const QStringList & disabled);
bool createScriptInputDialog(const QString & alg_name, const QString & preset_values,
const QString & optional_msg, const QStringList & enabled,
const QStringList & disabled);
/// Group selected workspaces
void groupWorkspaces();
/// UnGroup selected groupworkspace
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/qti.sip
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ public:
Table* importTableWorkspace(const QString&, bool = false, bool = false);

void setIsRunning(bool running);
bool createPropertyInputDialog(const QString &, const QString &, const QString&, const QStringList&, const QStringList&);
bool createScriptInputDialog(const QString &, const QString &, const QString&, const QStringList&, const QStringList&);

MantidQt::MantidWidgets::FitPropertyBrowser* fitFunctionBrowser();
private:
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/AlgorithmDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ protected slots:
void setPresetValues(const QHash<QString,QString> & presetValues);
/// Set whether this is intended for use from a script or not
void isForScript(bool forScript);
/// If true then execute the algorithm on acceptance
void executeOnAccept(bool on);
/// Set an optional message to be displayed at the top of the dialog
void setOptionalMessage(const QString & message);
/// Set comma-separated-list of enabled parameter names
Expand Down
12 changes: 11 additions & 1 deletion Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void AlgorithmDialog::initializeLayout()
this->setPropertyValues();
}

connect(this, SIGNAL(accepted()), this, SLOT(executeAlgorithmAsync()));
executeOnAccept(true);

m_isInitialized = true;
}
Expand Down Expand Up @@ -850,6 +850,16 @@ void AlgorithmDialog::isForScript(bool forScript)
m_forScript = forScript;
}

//------------------------------------------------------------------------------------------------
/**
* @param on If true the algorithm is executed when "ok" is pressed
*/
void AlgorithmDialog::executeOnAccept(bool on)
{
if(on) connect(this, SIGNAL(accepted()), this, SLOT(executeAlgorithmAsync()));
else disconnect(this, SIGNAL(accepted()), this, SLOT(executeAlgorithmAsync()));
}

//-------------------------------------------------------------------------------------------------
/** Set an optional message to be displayed at the top of the widget
* @param message :: The message string */
Expand Down
5 changes: 3 additions & 2 deletions Code/Mantid/MantidQt/API/src/InterfaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Mantid::Kernel::AbstractInstantiator<MantidHelpInterface> *InterfaceManager::m_h
* Return a specialized dialog for the given algorithm. If none exists then the default is returned
* @param alg :: A pointer to the algorithm
* @param parent :: An optional parent widget
* @param forScript :: A boolean indicating if this dialog is to be use for from a script or not
* @param forScript :: A boolean indicating if this dialog is to be use for from a script or not. If true disables the autoexecution of the dialog
* @param presetValues :: A hash of property names to preset values for the dialog
* @param optionalMsg :: An optional message string to be placed at the top of the dialog
* @param enabled :: These properties will be left enabled
Expand Down Expand Up @@ -84,7 +84,8 @@ InterfaceManager::createDialog(boost::shared_ptr<Mantid::API::IAlgorithm> alg, Q
// Setup the layout
dlg->initializeLayout();

return dlg;
if(forScript) dlg->executeOnAccept(false); //override default
return dlg;
}

/**
Expand Down

0 comments on commit 4e8e959

Please sign in to comment.