Skip to content

Commit 8248925

Browse files
committed
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', [...]
1 parent 6093013 commit 8248925

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

CMake/ctkMacroWrapPythonQtModuleInit.cpp.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <PythonQt.h>
44
#include <Python.h>
55

6+
#include <QCoreApplication>
7+
68
//-----------------------------------------------------------------------------
79
static PyMethodDef Py@TARGET_CONFIG@PythonQt_ClassMethods[] = {
810
{NULL, NULL, 0, NULL}};
@@ -52,6 +54,12 @@ void copyAttributes(PyObject* orig_module, PyObject* dest_module)
5254
//-----------------------------------------------------------------------------
5355
void init@TARGET_CONFIG@PythonQt()
5456
{
57+
58+
if (!QCoreApplication::instance())
59+
{
60+
PythonQt::init(PythonQt::PythonAlreadyInitialized);
61+
}
62+
5563
static const char modulename[] = "@TARGET_CONFIG@PythonQt";
5664
PyObject *m;
5765

0 commit comments

Comments
 (0)