From e4f7a7ce94628d646bbf8a3feca48ca2ed5c11de Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Fri, 7 Nov 2014 07:21:01 -0500 Subject: [PATCH] Allow CTK PythonQt python module to be imported outside of a Qt applicatio, On Linux, I was able to import the ctk module doing the following: $ cd /path/to/CTK-build/CTK-build/bin $ PYTHONPATH=./Python/ python >> import ctk >> import pprint as pp >> pp.pprint(dir(ctk)) ['QAbstractButton', 'QAbstractItemModel', [...] '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'ctkActionsWidget', 'ctkAddRemoveComboBox', 'ctkAxesWidget', 'ctkBasePopupWidget', 'ctkButtonGroup', 'ctkCallback', 'ctkCheckBox', 'ctkCheckBoxPixmaps', 'ctkCheckableComboBox', 'ctkCheckablePushButton', 'ctkCollapsibleButton', 'ctkCollapsibleGroupBox', 'ctkColorDialog', 'ctkColorPickerButton', 'ctkComboBox', 'ctkCommandLineParser', 'ctkCompleter', 'ctkConsole', [...] --- CMake/ctkMacroWrapPythonQtModuleInit.cpp.in | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMake/ctkMacroWrapPythonQtModuleInit.cpp.in b/CMake/ctkMacroWrapPythonQtModuleInit.cpp.in index c74b6665cd..8f2bc84cb1 100644 --- a/CMake/ctkMacroWrapPythonQtModuleInit.cpp.in +++ b/CMake/ctkMacroWrapPythonQtModuleInit.cpp.in @@ -3,6 +3,8 @@ #include #include +#include + //----------------------------------------------------------------------------- static PyMethodDef Py@TARGET_CONFIG@PythonQt_ClassMethods[] = { {NULL, NULL, 0, NULL}}; @@ -52,6 +54,12 @@ void copyAttributes(PyObject* orig_module, PyObject* dest_module) //----------------------------------------------------------------------------- void init@TARGET_CONFIG@PythonQt() { + + if (!QCoreApplication::instance()) + { + PythonQt::init(PythonQt::PythonAlreadyInitialized); + } + static const char modulename[] = "@TARGET_CONFIG@PythonQt"; PyObject *m;