Skip to content

Commit

Permalink
Allow CTK PythonQt python module to be imported outside of a Qt appli…
Browse files Browse the repository at this point in the history
…catio,

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',
  [...]
  • Loading branch information
jcfr committed Nov 7, 2014
1 parent 6093013 commit 8248925
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CMake/ctkMacroWrapPythonQtModuleInit.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <PythonQt.h>
#include <Python.h>

#include <QCoreApplication>

//-----------------------------------------------------------------------------
static PyMethodDef Py@TARGET_CONFIG@PythonQt_ClassMethods[] = {
{NULL, NULL, 0, NULL}};
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 8248925

Please sign in to comment.