// Configured by cmake macro @CMAKE_CURRENT_LIST_FILENAME@ #include #include #ifdef __GNUC__ // Disable warnings related to Py_DECREF() macro // See http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html // Note: Ideally the incriminated functions and macros should be fixed upstream ... #pragma GCC diagnostic ignored "-Wold-style-cast" #endif //----------------------------------------------------------------------------- static PyMethodDef Py@TARGET@PythonQt_ClassMethods[] = { {NULL, NULL, 0, NULL}}; extern "C" { void init@TARGET@PythonQt(); } //----------------------------------------------------------------------------- void copyAttributes(PyObject* orig_module, PyObject* dest_module) { PyObject* keys = PyObject_Dir(orig_module); if (keys) { PyObject* key; PyObject* value; int nKeys = PyList_Size(keys); for (int i = 0; i < nKeys; ++i) { key = PyList_GetItem(keys, i); value = PyObject_GetAttr(orig_module, key); if (!value) { continue; } //printf("%s\n", PyString_AsString(key)); if (!PyObject_HasAttr(dest_module, key)) { PyObject_SetAttr(dest_module, key, value); } Py_DECREF((void*)value); } Py_DECREF(keys); } } //----------------------------------------------------------------------------- extern "C" {void PythonQt_init_@WRAPPING_NAMESPACE_UNDERSCORE@_@TARGET@(PyObject*); } //----------------------------------------------------------------------------- void init@TARGET@PythonQt() { static const char @TARGET@[] = "@TARGET@PythonQt"; PyObject *m; m = Py_InitModule((char*)@TARGET@, Py@TARGET@PythonQt_ClassMethods); PythonQt_init_@WRAPPING_NAMESPACE_UNDERSCORE@_@TARGET@(m); // Since invoking 'PythonQt_init_@WRAPPING_NAMESPACE_UNDERSCORE@_@TARGET@', will create // the module "PythonQt.@TARGET@". Let's copy its content into the current module. PythonQtObjectPtr currentModule = PyImport_ImportModule((char*)"PythonQt.@TARGET@"); copyAttributes(currentModule, m); }