Skip to content

Commit

Permalink
Correct Python error, general refactoring
Browse files Browse the repository at this point in the history
Refs #10368
  • Loading branch information
DanNixon committed Oct 16, 2014
1 parent deb3379 commit cac2596
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/API/src/PythonRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ QString PythonRunner::runPythonCode(const QString & code, bool no_output)
tmpstring.append(stream.readLine().trimmed() + "\n");
}
//FIXME: Ticket-9217 - Commented out for the moment to try and get working with clang
//if(g_log.is(Logger::Priority::PRIO_DEBUG)) g_log.debug() << "Raw output from execution:\n" << tmpstring.toAscii().data() << "\n";
if(g_log.is(Logger::Priority::PRIO_DEBUG)) g_log.debug() << "Raw output from execution:\n" << tmpstring.toAscii().data() << "\n";
return tmpstring;
}
/** This Python helper function converts a list of strings into one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace CustomInterfaces
{
namespace IDA
{
class ConvFit : public IDATab
class DLLExport ConvFit : public IDATab
{
Q_OBJECT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace CustomInterfaces
{
namespace IDA
{
class Elwin : public IDATab
class DLLExport Elwin : public IDATab
{
Q_OBJECT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ namespace IDA
/// Constructor
IDATab(QWidget * parent = 0);

/// Sets up the tab.
void setupTab();
/// Runs the tab.
void runTab();
/// Loads the tab's settings.
void loadTabSettings(const QSettings & settings);
/// Returns the URL of the Mantid Wiki webpage for the tab.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ namespace MantidQt
virtual void loadSettings(const QSettings& settings) = 0;

signals:
/// Send signal to parent window to execute python script
void executePythonScript(const QString& pyInput, bool output);
/// Send signal to parent window to show a message box to user
void showMessageBox(const QString& message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ namespace IDA
void openDirectoryDialog();
/// Opens the Mantid Wiki web page of the current tab.
void help();
/// Slot showing a message box to the user
void showMessageBox(const QString& message);

private:
/// UI form containing all Qt elements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ namespace CustomInterfaces
/// Function to run an algorithm on a seperate thread
void runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm);

QString runPythonCode(QString vode, bool no_output = false);

/// Parent QWidget (if applicable)
QWidget *m_parentWidget;

Expand Down Expand Up @@ -149,8 +151,8 @@ namespace CustomInterfaces
signals:
/// Send signal to parent window to show a message box to user
void showMessageBox(const QString& message);
/// Run a python script
void runAsPythonScript(const QString & code, bool no_output);
/// Send signal to parent window to execute python script
void executePythonScript(const QString& pyInput, bool output);

private:
/// Overidden by child class.
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/ApplyCorr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ namespace IDA

pyInput += "print abscorFeeder(sample, container, geom, useCor, corrections, Verbose=verbose, RebinCan=rebin_can, ScaleOrNotToScale=scale, factor=scaleFactor, Save=save, PlotResult=plotResult)\n";

QString pyOutput = m_pythonRunner.runPythonCode(pyInput).trimmed();
QString pyOutput = runPythonCode(pyInput).trimmed();

if(pyOutput.toStdString() != "None")
{
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/CalcCorr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ namespace IDA
"canFormula = " + canFormula + "\n"
"IndirectAbsCor.AbsRunFeeder(inputws, canws, geom, ncan, size, avar, density, beam, sampleFormula, canFormula, sigs, siga, plot_opt=plotOpt, save=save, verbose=verbose)\n";

m_pythonRunner.runPythonCode(pyInput, false).trimmed();
runPythonCode(pyInput).trimmed();
}

bool CalcCorr::validate()
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidQt/CustomInterfaces/src/ConvFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace IDA
"ftype = '" + ftype + "'\n"
"confitSeq(input, func, startx, endx, ftype, bg, temp, specMin, specMax, Verbose=verbose, Plot=plot, Save=save)\n";

QString pyOutput = m_pythonRunner.runPythonCode(pyInput, false);
QString pyOutput = runPythonCode(pyInput);
}

/**
Expand Down Expand Up @@ -776,7 +776,7 @@ namespace IDA
g_log.error("No fit type defined!");
}

QString outputNm = m_pythonRunner.runPythonCode(QString("from IndirectCommon import getWSprefix\nprint getWSprefix('") + m_cfInputWSName + QString("')\n"), false).trimmed();
QString outputNm = runPythonCode(QString("from IndirectCommon import getWSprefix\nprint getWSprefix('") + m_cfInputWSName + QString("')\n")).trimmed();
outputNm += QString("conv_") + ftype + bg + uiForm().confit_lePlotSpectrum->text();
std::string output = outputNm.toStdString();

Expand Down
3 changes: 1 addition & 2 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Elwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ namespace IDA
pyInput +=
"eq1_ws, eq2_ws = elwin(input, eRange, log_type=logType, Normalise=normalise, Save=save, Verbose=verbose, Plot=plot)\n";

QString pyOutput = m_pythonRunner.runPythonCode(pyInput, false).trimmed();

runPythonCode(pyInput).trimmed();
}

bool Elwin::validate()
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidQt/CustomInterfaces/src/FuryFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ namespace IDA
pyInput += "furyfitMult(input, func, ftype, startx, endx, spec_min=spec_min, spec_max=spec_max, intensities_constrained=constrain_intens, Save=save, Plot=plot, Verbose=verbose)\n";
}

QString pyOutput = m_pythonRunner.runPythonCode(pyInput, false);
QString pyOutput = runPythonCode(pyInput);
}

bool FuryFit::validate()
Expand Down Expand Up @@ -604,7 +604,7 @@ namespace IDA

QString pyInput = "from IndirectCommon import getWSprefix\nprint getWSprefix('%1')\n";
pyInput = pyInput.arg(m_ffInputWSName);
QString outputNm = m_pythonRunner.runPythonCode(pyInput, false).trimmed();
QString outputNm = runPythonCode(pyInput).trimmed();
outputNm += QString("fury_") + ftype + uiForm().furyfit_lePlotSpectrum->text();
std::string output = outputNm.toStdString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ namespace IDA
m_dblEdFac = new DoubleEditorFactory(this);
m_blnEdFac = new QtCheckBoxFactory(this);

// Set up all tabs.
// Set up all tabs
for(auto tab = m_tabs.begin(); tab != m_tabs.end(); ++tab)
{
tab->second->setupTab();
connect(tab->second, SIGNAL(executePythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
connect(tab->second, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
}

connect(m_uiForm.pbHelp, SIGNAL(clicked()), this, SLOT(help()));
connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(run()));
Expand Down Expand Up @@ -151,6 +155,18 @@ namespace IDA
QString url = m_tabs[currentTab]->tabHelpURL();
QDesktopServices::openUrl(QUrl(url));
}

/**
* Slot to wrap the protected showInformationBox method defined
* in UserSubWindow and provide access to composed tabs.
*
* @param message The message to display in the message box
*/
void IndirectDataAnalysis::showMessageBox(const QString& message)
{
showInformationBox(message);
}

} // namespace IDA
} // namespace CustomInterfaces
} // namespace MantidQt
17 changes: 15 additions & 2 deletions Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace CustomInterfaces
m_plots(), m_curves(), m_rangeSelectors(),
m_properties(),
m_dblManager(new QtDoublePropertyManager()), m_blnManager(new QtBoolPropertyManager()), m_grpManager(new QtGroupPropertyManager()),
m_dblEdFac(new DoubleEditorFactory())
m_dblEdFac(new DoubleEditorFactory()),
m_pythonRunner()
{
m_parentWidget = dynamic_cast<QWidget *>(parent);

Expand All @@ -35,7 +36,7 @@ namespace CustomInterfaces
m_valPosDbl->setBottom(tolerance);

connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(algorithmFinished(bool)));
connect(&m_pythonRunner, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
connect(&m_pythonRunner, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(executePythonScript(const QString&, bool)));
}

//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -275,5 +276,17 @@ namespace CustomInterfaces
}
}

/**
* Run Python code and return anything printed to stdout.
*
* @param code Python code the execute
* @param no_output Enable to ignore any output
* @returns What was printed to stdout
*/
QString IndirectTab::runPythonCode(QString code, bool no_output)
{
return m_pythonRunner.runPythonCode(code, no_output);
}

} // namespace CustomInterfaces
} // namespace Mantid
4 changes: 2 additions & 2 deletions Code/Mantid/MantidQt/CustomInterfaces/src/MSDFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace IDA
pyInput +=
"msdfit(input, startX, endX, spec_min=specMin, spec_max=specMax, Save=save, Verbose=verbose, Plot=plot)\n";

QString pyOutput = m_pythonRunner.runPythonCode(pyInput, false).trimmed();
runPythonCode(pyInput).trimmed();
}

void MSDFit::singleFit()
Expand All @@ -103,7 +103,7 @@ namespace IDA
"output = msdfit(input, startX, endX, spec_min=specMin, spec_max=specMax, Save=False, Verbose=verbose, Plot=False)\n"
"print output \n";

QString pyOutput = m_pythonRunner.runPythonCode(pyInput, false).trimmed();
QString pyOutput = runPythonCode(pyInput).trimmed();
plotFit(pyOutput);
}

Expand Down

0 comments on commit cac2596

Please sign in to comment.