Skip to content

Commit

Permalink
Refs #5421 Added support for showing a message box to user.
Browse files Browse the repository at this point in the history
Also properly documented the ResNorm code.
  • Loading branch information
Samuel Jackson committed Sep 13, 2013
1 parent 3009298 commit 6e76190
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace MantidQt
Q_OBJECT

public: //public constants and enums

/// Enumeration for the index of each tab
enum TabChoice
{
RES_NORM,
Expand All @@ -65,12 +67,19 @@ namespace MantidQt
virtual void initLayout();

private slots:
/// Run the appropriate action depending based on the selected tab
// Run the appropriate action depending based on the selected tab

/// Slot for clicking on the run button
void runClicked();
/// Slot for clicking on the hlep button
void helpClicked();
/// Slot for clicking on the manage directories button
void manageUserDirectories();
/// Slot showing a message box to the user
void showMessageBox(const QString& message);

private:
/// Map of tabs indexed by position on the window
std::map<unsigned int, IndirectBayesTab*> m_bayesTabs;

///Main interface window
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,19 @@ namespace MantidQt
IndirectBayesTab(QWidget * parent = 0);
~IndirectBayesTab();

/// Returns a URL for the wiki help page for this interface
QString tabHelpURL();

/// Base methods implemented in derived classes
virtual QString help() = 0;
virtual bool validate() = 0;
virtual void run() = 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);

protected:
/// Function to plot a workspace to the miniplot using a workspace name
Expand Down
30 changes: 29 additions & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ IndirectBayes::IndirectBayes(QWidget *parent) : UserSubWindow(parent)
m_bayesTabs.insert(std::make_pair(STRETCH, new Stretch(m_uiForm.indirectBayesTabs->widget(STRETCH))));
m_bayesTabs.insert(std::make_pair(JUMP_FIT, new JumpFit(m_uiForm.indirectBayesTabs->widget(JUMP_FIT))));

//Connect each tab to the python execution method
//Connect each tab to the actions available in this GUI
std::map<unsigned int, IndirectBayesTab*>::iterator iter;
for (iter = m_bayesTabs.begin(); iter != m_bayesTabs.end(); ++iter)
{
connect(iter->second, SIGNAL(executePythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
connect(iter->second, SIGNAL(showMessageBox(const QString&)), this, SIGNAL(showMessageBox(const QString&)));
}

//Connect statements for the buttons shared between all tabs on the Indirect Bayes interface
connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(runClicked()));
connect(m_uiForm.pbHelp, SIGNAL(clicked()), this, SLOT(helpClicked()));
connect(m_uiForm.pbManageDirs, SIGNAL(clicked()), this, SLOT(manageUserDirectories()));
Expand All @@ -42,6 +44,13 @@ void IndirectBayes::initLayout()
{
}

/**
* Slot to run the underlying algorithm code based on the currently selected
* tab.
*
* This method checks the tabs validate method is passing before calling
* the run method.
*/
void IndirectBayes::runClicked()
{
int tabIndex = m_uiForm.indirectBayesTabs->currentIndex();
Expand All @@ -52,20 +61,39 @@ void IndirectBayes::runClicked()
}
}

/**
* Slot to open a new browser window and navigate to the help page
* on the wiki for the currently selected tab.
*/
void IndirectBayes::helpClicked()
{
int tabIndex = m_uiForm.indirectBayesTabs->currentIndex();
QString url = m_bayesTabs[tabIndex]->tabHelpURL();
QDesktopServices::openUrl(QUrl(url));
}

/**
* Slot to show the manage user dicrectories dialog when the user clicks
* the button on the interface.
*/
void IndirectBayes::manageUserDirectories()
{
MantidQt::API::ManageUserDirectories *ad = new MantidQt::API::ManageUserDirectories(this);
ad->show();
ad->setFocus();
}

/**
* 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 showMessageBox(const QString& message)
{
showInformationBox(const QString & message);
}

IndirectBayes::~IndirectBayes()
{
}
45 changes: 37 additions & 8 deletions Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,49 @@ namespace MantidQt
{
}

/**
* Method to build a URL to the appropriate page on the wiki for this tab.
*
* @return The URL to the wiki page
*/
QString IndirectBayesTab::tabHelpURL()
{
return "http://www.mantidproject.org/IndirectBayes:" + help();
}

/**
* Emits a signal to run a python script using the method in the parent
* UserSubWindow
*
* @param pyInput :: A string of python code to execute
*/
void IndirectBayesTab::runPythonScript(const QString& pyInput)
{
emit executePythonScript(pyInput, false);
}

/**
* Plot a workspace to the miniplot given a workspace name and
* a specturm index.
*
* This method uses the analysis data service to retrieve the workspace.
*
* @param workspace :: The name of the workspace
* @param index :: The spectrum index of the workspace
*/
void IndirectBayesTab::plotMiniPlot(const QString& workspace, size_t index)
{
auto ws = Mantid::API::AnalysisDataService::Instance().retrieveWS<const Mantid::API::MatrixWorkspace>(workspace.toStdString());
plotMiniPlot(ws, index);
}

/**
* Plot a workspace to the miniplot given a workspace pointer and
* a specturm index.
*
* @param workspace :: Pointer to the workspace
* @param index :: The spectrum index of the workspace
*/
void IndirectBayesTab::plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex)
{
using Mantid::MantidVec;
Expand All @@ -52,17 +79,19 @@ namespace MantidQt
size_t nhist = workspace->getNumberHistograms();
if ( wsIndex >= nhist )
{
//showInformationBox("Error: Workspace index out of range.");
emit showMessageBox("Error: Workspace index out of range.");
}

auto dataX = workspace->readX(wsIndex);
auto dataY = workspace->readY(wsIndex);
else
{
auto dataX = workspace->readX(wsIndex);
auto dataY = workspace->readY(wsIndex);

m_curve = new QwtPlotCurve();
m_curve->setData(&dataX[0], &dataY[0], static_cast<int>(workspace->blocksize()));
m_curve->attach(m_plot);
m_curve = new QwtPlotCurve();
m_curve->setData(&dataX[0], &dataY[0], static_cast<int>(workspace->blocksize()));
m_curve->attach(m_plot);

m_plot->replot();
m_plot->replot();
}
}
}
} // namespace MantidQt
15 changes: 15 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/src/ResNorm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace MantidQt
m_plot->setAxisFont(QwtPlot::yLeft, parent->font());
}

/**
* Validate the form to check we can run the program
*/
bool ResNorm::validate()
{
//check we have files/workspaces available to run with
Expand All @@ -43,6 +46,10 @@ namespace MantidQt
return true;
}

/**
* Collect the settings on the GUI and build a python
* script that runs ResNorm
*/
void ResNorm::run()
{
QString verbose("False");
Expand All @@ -52,16 +59,19 @@ namespace MantidQt
QString pyInput =
"from IndirectBayes import ResNormRun\n";

// get the file names
QString VanName = m_uiForm.dsVanadium->getCurrentDataName();
QString ResName = m_uiForm.dsResolution->getCurrentDataName();

//get the parameters for ResNomr
QString EMin = m_properties["EMin"]->valueText();
QString EMax = m_properties["EMax"]->valueText();

QString ERange = "[" + EMin + "," + EMax + "]";

QString nBin = m_properties["VanBinning"]->valueText();

//get output options
if(m_uiForm.ckVerbose->isChecked()){ verbose = "True"; }
if(m_uiForm.ckPlot->isChecked()){ plot = "True"; }
if(m_uiForm.ckSave->isChecked()){ save ="True"; }
Expand All @@ -72,6 +82,11 @@ namespace MantidQt
runPythonScript(pyInput);
}

/**
* Plots the loaded file to the miniplot
*
* @param filename :: The name of the workspace to plot
*/
void ResNorm::handleVanadiumInputReady(const QString& filename)
{
plotMiniPlot(filename, 0);
Expand Down

0 comments on commit 6e76190

Please sign in to comment.