-----------------------------------------------------------------------------
| 656 | |
| 657 | //----------------------------------------------------------------------------- |
| 658 | PyObject* ctkAbstractPythonManager::pythonModule(const QString& module) |
| 659 | { |
| 660 | PyObject* dict = PyImport_GetModuleDict(); |
| 661 | PyObject* object = 0; |
| 662 | PyObject* prevObject = 0; |
| 663 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) |
| 664 | QStringList moduleList = module.split(".", Qt::KeepEmptyParts); |
| 665 | #else |
| 666 | QStringList moduleList = module.split(".", QString::KeepEmptyParts); |
| 667 | #endif |
| 668 | if (!dict) |
| 669 | { |
| 670 | return object; |
| 671 | } |
| 672 | foreach(const QString& module, moduleList) |
| 673 | { |
| 674 | object = PyDict_GetItemString(dict, module.toLatin1().data()); |
| 675 | if (prevObject) |
| 676 | { |
| 677 | Py_DECREF(prevObject); |
| 678 | } |
| 679 | if (!object) |
| 680 | { |
| 681 | break; |
| 682 | } |
| 683 | Py_INCREF(object); // This is required, otherwise python destroys object. |
| 684 | if (PyObject_HasAttrString(object, "__dict__")) |
| 685 | { |
| 686 | dict = PyObject_GetAttrString(object, "__dict__"); |
| 687 | }\ |
| 688 | prevObject = object; |
| 689 | } |
| 690 | return object; |
| 691 | } |
| 692 | |
| 693 | //----------------------------------------------------------------------------- |
| 694 | void ctkAbstractPythonManager::addObjectToPythonMain(const QString& name, QObject* obj) |
no outgoing calls