ソースを参照

Merge branch 'add-systemexit-exception-handler'

* add-systemexit-exception-handler:
  Add SystemExit python exception handler
Jean-Christophe Fillion-Robin 12 年 前
コミット
11a59a395d
共有3 個のファイルを変更した30 個の追加2 個の削除を含む
  1. 1 1
      CMakeExternals/PythonQt.cmake
  2. 18 1
      Libs/Scripting/Python/Core/ctkAbstractPythonManager.cpp
  3. 11 0
      Libs/Scripting/Python/Core/ctkAbstractPythonManager.h

+ 1 - 1
CMakeExternals/PythonQt.cmake

@@ -53,7 +53,7 @@ if(${add_project})
         message(FATAL_ERROR "error: Python is required to build ${PROJECT_NAME}")
       endif()
 
-      set(revision_tag a386dc60f71c15e67c611bc31b26cee756ed833a)
+      set(revision_tag 7132dba93064c2a02591b42305fecdd5d59702d3)
       if(${proj}_REVISION_TAG)
         set(revision_tag ${${proj}_REVISION_TAG})
       endif()

+ 18 - 1
Libs/Scripting/Python/Core/ctkAbstractPythonManager.cpp

@@ -143,7 +143,9 @@ void ctkAbstractPythonManager::initPythonQt(int flags)
   signal(SIGINT, SIG_DFL);
   #endif
 
-  PythonQtObjectPtr _mainContext = PythonQt::self()->getMainModule();
+  // Forward signal from PythonQt::self() to this instance of ctkAbstractPythonManager
+  this->connect(PythonQt::self(), SIGNAL(systemExitExceptionRaised(int)),
+                SIGNAL(systemExitExceptionRaised(int)));
 
   this->connect(PythonQt::self(), SIGNAL(pythonStdOut(QString)),
                 SLOT(printStdout(QString)));
@@ -161,6 +163,7 @@ void ctkAbstractPythonManager::initPythonQt(int flags)
     initCode << QString("sys.path.append('%1')").arg(QDir::fromNativeSeparators(path));
     }
 
+  PythonQtObjectPtr _mainContext = PythonQt::self()->getMainModule();
   _mainContext.evalScript(initCode.join("\n"));
 
   this->preInitialization();
@@ -227,6 +230,20 @@ void ctkAbstractPythonManager::registerCPPClassForPythonQt(const char* name)
 }
 
 //-----------------------------------------------------------------------------
+bool ctkAbstractPythonManager::systemExitExceptionHandlerEnabled()const
+{
+  Q_D(const ctkAbstractPythonManager);
+  return PythonQt::self()->systemExitExceptionHandlerEnabled();
+}
+
+//-----------------------------------------------------------------------------
+void ctkAbstractPythonManager::setSystemExitExceptionHandlerEnabled(bool value)
+{
+  Q_D(ctkAbstractPythonManager);
+  PythonQt::self()->setSystemExitExceptionHandlerEnabled(value);
+}
+
+//-----------------------------------------------------------------------------
 QVariant ctkAbstractPythonManager::executeString(const QString& code,
                                                  ctkAbstractPythonManager::ExecuteStringMode mode)
 {

+ 11 - 0
Libs/Scripting/Python/Core/ctkAbstractPythonManager.h

@@ -68,6 +68,12 @@ public:
   void registerClassForPythonQt(const QMetaObject* metaobject);
   void registerCPPClassForPythonQt(const char* name);
 
+  /// \sa PythonQt::systemExitExceptionHandlerEnabled
+  bool systemExitExceptionHandlerEnabled()const;
+
+  /// \sa PythonQt::setSystemExitExceptionHandlerEnabled
+  void setSystemExitExceptionHandlerEnabled(bool value);
+
   /// This enum maps to Py_eval_input, Py_file_input and Py_single_input
   /// \see http://docs.python.org/c-api/veryhigh.html#Py_eval_input
   /// \see http://docs.python.org/c-api/veryhigh.html#Py_file_input
@@ -126,6 +132,11 @@ Q_SIGNALS:
   /// \sa executeScripts
   void pythonInitialized();
 
+  //! emitted when both custom SystemExit exception handler is enabled and a SystemExit
+  //! exception is raised.
+  //! \sa setSystemExitExceptionHandlerEnabled(bool), PythonQt::systemExitExceptionRaised(int)
+  void systemExitExceptionRaised(int exitCode);
+
 protected Q_SLOTS:
   void printStderr(const QString&);
   void printStdout(const QString&);