1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- // Configured by cmake macro @CMAKE_CURRENT_LIST_FILE@
- #include <PythonQt.h>
- #include <Python.h>
- //-----------------------------------------------------------------------------
- static PyMethodDef Py@TARGET_CONFIG@PythonQt_ClassMethods[] = {
- {NULL, NULL, 0, NULL}};
- //-----------------------------------------------------------------------------
- extern "C" { void Q_DECL_EXPORT init@TARGET_CONFIG@PythonQt(); }
- #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
- #cmakedefine HAS_DECORATOR
- namespace {
- //-----------------------------------------------------------------------------
- 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);
- }
- }
- } // end of anonymous namespace
- //-----------------------------------------------------------------------------
- #if PY_MAJOR_VERSION >= 3
- static struct PyModuleDef moduledef = {
- PyModuleDef_HEAD_INIT,
- "@TARGET_CONFIG@PythonQt", /* m_name */
- "The @TARGET_CONFIG@PythonQt module", /* m_doc */
- -1, /* m_size */
- Py@TARGET_CONFIG@PythonQt_ClassMethods, /* m_methods */
- NULL, /* m_reload */
- NULL, /* m_traverse */
- NULL, /* m_clear */
- NULL, /* m_free */
- };
- #endif
- //-----------------------------------------------------------------------------
- void init@TARGET_CONFIG@PythonQt()
- {
- static const char modulename[] = "@TARGET_CONFIG@PythonQt";
- PyObject *m;
- #if PY_MAJOR_VERSION >= 3
- m = PyModule_Create(&moduledef);
- #else
- m = Py_InitModule((char*)modulename, Py@TARGET_CONFIG@PythonQt_ClassMethods);
- #endif
- extern void PythonQt_init_@WRAPPING_NAMESPACE_UNDERSCORE@_@TARGET_CONFIG@(PyObject*);
- PythonQt_init_@WRAPPING_NAMESPACE_UNDERSCORE@_@TARGET_CONFIG@(m);
- #ifdef HAS_DECORATOR
- extern void init@TARGET_CONFIG@PythonQtDecorators();
- init@TARGET_CONFIG@PythonQtDecorators();
- #endif
- // Since invoking 'PythonQt_init_@WRAPPING_NAMESPACE_UNDERSCORE@_@TARGET_CONFIG@', will create
- // the module "PythonQt.@TARGET_CONFIG@". Let's copy its content into the current module.
- PythonQtObjectPtr currentModule = PyImport_ImportModule((char*)"PythonQt.@TARGET_CONFIG@");
- if(currentModule.isNull())
- {
- PyErr_SetString(PyExc_ImportError, (char*)"Failed to import PythonQt.@TARGET_CONFIG@");
- return;
- }
- copyAttributes(currentModule, m);
- }
|