Skip to content

Commit

Permalink
Slightly cleaner MantidPlot startup if Python dies. Refs #4399
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Apr 17, 2012
1 parent 89b812c commit d3a6b20
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
23 changes: 13 additions & 10 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4843,7 +4843,7 @@ bool ApplicationWindow::setScriptingLanguage(const QString &lang)

if( m_bad_script_envs.contains(lang) )
{
QMessageBox::information(this, "MantidPlot", QString("Previous initialization of ") + lang + QString(" failed, cannot retry."));
this->writeErrorToLogWindow("Previous initialization of " + lang + " failed, cannot retry.");
return false;
}

Expand All @@ -4870,7 +4870,7 @@ bool ApplicationWindow::setScriptingLanguage(const QString &lang)
{
delete newEnv;
m_bad_script_envs.insert(lang);
QMessageBox::information(this, "MantidPlot", QString("Failed to initialize ") + lang);
QMessageBox::information(this, "MantidPlot", QString("Failed to initialize ") + lang + ". Please contact support.");
return false;
}
}
Expand Down Expand Up @@ -4898,7 +4898,7 @@ bool ApplicationWindow::setScriptingLanguage(const QString &lang)
void ApplicationWindow::showScriptingLangDialog()
{
// If a script is currently active, don't let a new one be selected
if( scriptingEnv()->isRunning() )
if( scriptingWindow->isExecuting() )
{
QMessageBox msg_box;
msg_box.setText("Cannot change scripting language, a script is still running.");
Expand Down Expand Up @@ -9504,17 +9504,14 @@ void ApplicationWindow::dragMoveEvent( QDragMoveEvent* e )

void ApplicationWindow::closeEvent( QCloseEvent* ce )
{

// Mantid changes here

// don't ask the closing sub-windows: the answer will be ignored
MDIWindowList windows = getAllWindows();
foreach(MdiSubWindow* w,windows)
{
w->confirmClose(false);
}

if( scriptingEnv()->isRunning() )
if(scriptingWindow && scriptingWindow->isExecuting())
{
if( QMessageBox::question(this, tr("MantidPlot"), "A script is still running, abort and quit application?", tr("Yes"), tr("No")) == 0 )
{
Expand Down Expand Up @@ -16473,12 +16470,18 @@ void ApplicationWindow::executeScriptFile(const QString & filename, const Script
bool ApplicationWindow::runPythonScript(const QString & code, const bool async,
bool quiet, bool redirect)
{
if( code.isEmpty() || scriptingEnv()->isRunning() ) return false;
if( code.isEmpty() ) return false;

if( m_iface_script == NULL )
{
setScriptingLanguage("Python");
m_iface_script = scriptingEnv()->newScript("<Interface>", NULL, Script::NonInteractive);
if( setScriptingLanguage("Python") )
{
m_iface_script = scriptingEnv()->newScript("<Interface>", NULL, Script::NonInteractive);
}
else
{
return false;
}

}
if( !quiet )
Expand Down
7 changes: 1 addition & 6 deletions Code/Mantid/MantidPlot/src/PythonScripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ Script *PythonScripting::newScript(const QString &name, QObject * context,
return new PythonScript(const_cast<PythonScripting*>(this), name, interact, context);
}

bool PythonScripting::isRunning() const
{
return (m_is_running );
}

/**
* Create a code lexer for Python. Ownership of the created object is transferred to the caller.
*/
Expand Down Expand Up @@ -378,7 +373,7 @@ const QStringList PythonScripting::fileExtensions() const

void PythonScripting::refreshAlgorithms(bool force)
{
if( (force || !isRunning()) && refresh_allowed==1)
if(force || refresh_allowed==1)
{
PyRun_SimpleString("mtd._refreshPyAlgorithms()");
}
Expand Down
2 changes: 0 additions & 2 deletions Code/Mantid/MantidPlot/src/PythonScripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class PythonScripting: public ScriptingEnv
static ScriptingEnv *constructor(ApplicationWindow *parent);
/// Destructor
~PythonScripting();
// Is a Python already executing a script
virtual bool isRunning() const;
/// Write text to std out
void write(const QString &text) { emit print(text); }
/// 'Fake' method needed for IPython import
Expand Down
11 changes: 6 additions & 5 deletions Code/Mantid/MantidPlot/src/ScriptingEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ class ScriptingEnv : public QObject
/// Is the environment initialized
bool isInitialized() const { return d_initialized; }
/// Query if any code is currently being executed
virtual bool isRunning() const { return m_is_running; }
/// Set that a script is being executed
void setIsRunning(bool running) { m_is_running = running; }
//bool isRunning() const { return m_is_running; }

/// Create a script object that is responsible for executing actual code
virtual Script *newScript(const QString &name, QObject * context, const Script::InteractionType interact) const = 0;
Expand Down Expand Up @@ -125,19 +123,22 @@ public slots:
virtual bool start() { return true; }
/// Override to perform shutdown code
virtual void shutdown() {}
/// Set that a script is being executed
void setIsRunning(bool running) { m_is_running = running; }


/// whether the interpreter has been successfully initialized
bool d_initialized;
/// the context in which we are running
ApplicationWindow *d_parent;
/// Whether a script is running
bool m_is_running;

private:
/// Private default constructor
ScriptingEnv();

private:
/// Whether a script is running
bool m_is_running;
int d_refcount;
QString m_languageName;
};
Expand Down
1 change: 0 additions & 1 deletion Code/Mantid/MantidPlot/src/muParserScripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class muParserScripting: public ScriptingEnv
muParserScripting(ApplicationWindow *parent) : ScriptingEnv(parent, langName) { d_initialized=true; }
static ScriptingEnv *constructor(ApplicationWindow *parent) { return new muParserScripting(parent); }

bool isRunning() const { return true; }
Script *newScript(const QString &name, QObject * context, const Script::InteractionType) const
{
return new muParserScript(const_cast<muParserScripting*>(this), name, context);
Expand Down

0 comments on commit d3a6b20

Please sign in to comment.