diff --git a/modules/gui/pymod/export_gosty.cc b/modules/gui/pymod/export_gosty.cc index 152e221104cc55fef419a7d0b881045ef1e4291b..7bacc63732d7c2b25aa9141d71ebd44e6d16f70c 100644 --- a/modules/gui/pymod/export_gosty.cc +++ b/modules/gui/pymod/export_gosty.cc @@ -79,6 +79,7 @@ void export_Gosty() .def("Instance", &GostyApp::Instance, return_value_policy<reference_existing_object>()).staticmethod("Instance") .def("SetAppTitle", &GostyApp::SetAppTitle) + .def("StopScript",&GostyApp::StopScript) .def("GetPyShell", &GostyApp::GetPyShell, return_value_policy<reference_existing_object>()) .add_property("py_shell", make_function(&GostyApp::GetPyShell, diff --git a/modules/gui/src/gosty_app.cc b/modules/gui/src/gosty_app.cc index 0253e11aa65878390940168d3e1e5caef94c4173..d6b6bfdd0d4cb3ca4de74b7175a12da2a5b15072 100644 --- a/modules/gui/src/gosty_app.cc +++ b/modules/gui/src/gosty_app.cc @@ -25,6 +25,7 @@ #include <ost/gui/tools/tool_options_win.hh> #include <ost/gui/perspective.hh> #include <ost/gui/main_area.hh> +#include <ost/gui/python_shell/python_interpreter.hh> #include <QApplication> @@ -118,6 +119,13 @@ PythonShell* GostyApp::GetPyShell() return py_shell_; } + +void GostyApp::StopScript() +{ + PythonInterpreter::Instance().StopScript(); +} + + GLWin* GostyApp::GetGLWin() { if (gl_win_==NULL) { diff --git a/modules/gui/src/gosty_app.hh b/modules/gui/src/gosty_app.hh index 45e4080b1bd5acb21c0b86694e6fb10329592c05..2723ad8460ebcc373f367f27ea603e80d6c62893 100644 --- a/modules/gui/src/gosty_app.hh +++ b/modules/gui/src/gosty_app.hh @@ -105,6 +105,11 @@ public: /// All subsequent calls will return the same MessageWidget instance. MessageWidget* GetMessageWidget(); + /// \brief stop script execution + /// + /// Stops the execution of the script. + void StopScript(); + #if OST_IMG_ENABLED /// \brief create new DataViewer /// diff --git a/modules/gui/src/python_shell/python_interpreter.cc b/modules/gui/src/python_shell/python_interpreter.cc index 3dea745a5cdc9265fed41ffe9abbdb8aed624856..07f1e9674da648643b32d99586c9f8cf2a5d429d 100644 --- a/modules/gui/src/python_shell/python_interpreter.cc +++ b/modules/gui/src/python_shell/python_interpreter.cc @@ -83,6 +83,10 @@ void PythonInterpreter::Start() emit WakeWorker(); } +void PythonInterpreter::StopScript() +{ + PyErr_SetInterrupt(); +} unsigned int PythonInterpreter::RunScript(const QString& fname) diff --git a/modules/gui/src/python_shell/python_interpreter.hh b/modules/gui/src/python_shell/python_interpreter.hh index ec6639bbb8d10342b657afc43eda2096dea9c67a..940b520cffb32f1c8f37e90de83636b2e9c78e9f 100644 --- a/modules/gui/src/python_shell/python_interpreter.hh +++ b/modules/gui/src/python_shell/python_interpreter.hh @@ -82,6 +82,9 @@ public: /// /// \sa Stop void Start(); + /// \brief stop script execution + void StopScript(); + public slots: diff --git a/scripts/init.py b/scripts/init.py index eb112990c73e1f2716119236fc7def6e50dd7c9c..4ca4cb7a0a0e5fdc16735b22274b632fffc92be3 100644 --- a/scripts/init.py +++ b/scripts/init.py @@ -138,6 +138,10 @@ def _SplitIDSel(name): return name[:pos], name[pos+1:-1] return name, '' +def stop(): + gui.GostyApp.Instance().StopScript() + + loading_list=[] script_argv=[] images=[] diff --git a/scripts/init_cl.py b/scripts/init_cl.py index fba11d8adb9fa5a6f6b9baca7905b9de55c028e5..b173207477f1620c5ea7c60c617210223ba5ea75 100644 --- a/scripts/init_cl.py +++ b/scripts/init_cl.py @@ -10,6 +10,9 @@ def show_help(option, opt, value, parser): def interactive_flag(option, opt, value, parser): pass +def stop(): + sys.exit(0) + usage = 'usage: ost [ost options] [script to execute] [script parameters]' class OstOptionParser(optparse.OptionParser): def __init__(self, **kwargs):