From 2b52357baffbb5e39e41db4682b132764a29d9fb Mon Sep 17 00:00:00 2001 From: Valerio Mariani <valerio.mariani@unibas.ch> Date: Wed, 22 Dec 2010 15:41:15 +0100 Subject: [PATCH] Added stop script command For debugging purposes --- modules/gui/pymod/export_gosty.cc | 1 + modules/gui/src/gosty_app.cc | 8 ++++++++ modules/gui/src/gosty_app.hh | 5 +++++ modules/gui/src/python_shell/python_interpreter.cc | 4 ++++ modules/gui/src/python_shell/python_interpreter.hh | 3 +++ scripts/init.py | 4 ++++ scripts/init_cl.py | 3 +++ 7 files changed, 28 insertions(+) diff --git a/modules/gui/pymod/export_gosty.cc b/modules/gui/pymod/export_gosty.cc index 152e22110..7bacc6373 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 0253e11aa..d6b6bfdd0 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 45e4080b1..2723ad846 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 3dea745a5..07f1e9674 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 ec6639bbb..940b520cf 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 eb112990c..4ca4cb7a0 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 fba11d8ad..b17320747 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): -- GitLab