qjsengine.sip 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // qjsengine.sip generated by MetaSIP
  2. //
  3. // This file is part of the QtQml Python extension module.
  4. //
  5. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  6. //
  7. // This file is part of PyQt6.
  8. //
  9. // This file may be used under the terms of the GNU General Public License
  10. // version 3.0 as published by the Free Software Foundation and appearing in
  11. // the file LICENSE included in the packaging of this file. Please review the
  12. // following information to ensure the GNU General Public License version 3.0
  13. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  14. //
  15. // If you do not wish to use this file under the terms of the GPL version 3.0
  16. // then you may purchase a commercial license. For more information contact
  17. // info@riverbankcomputing.com.
  18. //
  19. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. %ModuleCode
  22. #include <qjsengine.h>
  23. %End
  24. class QJSEngine : public QObject
  25. {
  26. %TypeHeaderCode
  27. #include <qjsengine.h>
  28. %End
  29. %ConvertToSubClassCode
  30. static struct class_graph {
  31. const char *name;
  32. sipTypeDef **type;
  33. int yes, no;
  34. } graph[] = {
  35. {sipName_QJSEngine, &sipType_QJSEngine, 9, 1},
  36. {sipName_QQmlComponent, &sipType_QQmlComponent, -1, 2},
  37. {sipName_QQmlContext, &sipType_QQmlContext, -1, 3},
  38. {sipName_QQmlEngineExtensionPlugin, &sipType_QQmlEngineExtensionPlugin, -1, 4},
  39. {sipName_QQmlExpression, &sipType_QQmlExpression, -1, 5},
  40. {sipName_QQmlExtensionPlugin, &sipType_QQmlExtensionPlugin, -1, 6},
  41. {sipName_QQmlFileSelector, &sipType_QQmlFileSelector, -1, 7},
  42. {sipName_QQmlImageProviderBase, &sipType_QQmlImageProviderBase, -1, 8},
  43. {sipName_QQmlPropertyMap, &sipType_QQmlPropertyMap, -1, -1},
  44. {sipName_QQmlEngine, &sipType_QQmlEngine, 10, -1},
  45. {sipName_QQmlApplicationEngine, &sipType_QQmlApplicationEngine, -1, -1},
  46. };
  47. int i = 0;
  48. sipType = NULL;
  49. do
  50. {
  51. struct class_graph *cg = &graph[i];
  52. if (cg->name != NULL && sipCpp->inherits(cg->name))
  53. {
  54. sipType = *cg->type;
  55. i = cg->yes;
  56. }
  57. else
  58. i = cg->no;
  59. }
  60. while (i >= 0);
  61. %End
  62. public:
  63. QJSEngine();
  64. explicit QJSEngine(QObject *parent /TransferThis/);
  65. virtual ~QJSEngine();
  66. QJSValue globalObject() const;
  67. QJSValue evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1, SIP_PYLIST exceptionStackTrace /AllowNone,TypeHint="List[str]"/ = 0) /ReleaseGIL/;
  68. %MethodCode
  69. QStringList *st;
  70. st = (a3 ? new QStringList() : SIP_NULLPTR);
  71. Py_BEGIN_ALLOW_THREADS
  72. sipRes = new QJSValue(sipCpp->evaluate(*a0, *a1, a2, st));
  73. Py_END_ALLOW_THREADS
  74. if (st)
  75. {
  76. for (qsizetype i = 0; i < st->size(); ++i)
  77. {
  78. QString *s = new QString(st->at(i));
  79. PyObject *s_obj = sipConvertFromNewType(s, sipType_QString, SIP_NULLPTR);
  80. if (s_obj)
  81. {
  82. if (PyList_Append(a3, s_obj) < 0)
  83. {
  84. Py_DECREF(s_obj);
  85. sipIsErr = 1;
  86. break;
  87. }
  88. Py_DECREF(s_obj);
  89. }
  90. else
  91. {
  92. delete s;
  93. sipIsErr = 1;
  94. break;
  95. }
  96. }
  97. if (sipIsErr)
  98. {
  99. delete sipRes;
  100. sipRes = SIP_NULLPTR;
  101. }
  102. delete st;
  103. }
  104. %End
  105. QJSValue newObject();
  106. QJSValue newArray(uint length = 0);
  107. QJSValue newQObject(QObject *object /Transfer/);
  108. void collectGarbage();
  109. enum Extension /BaseType=Flag/
  110. {
  111. TranslationExtension,
  112. ConsoleExtension,
  113. GarbageCollectionExtension,
  114. AllExtensions,
  115. };
  116. typedef QFlags<QJSEngine::Extension> Extensions;
  117. void installExtensions(QJSEngine::Extensions extensions, const QJSValue &object = QJSValue());
  118. QJSValue newQMetaObject(const QMetaObject *metaObject);
  119. QJSValue importModule(const QString &fileName);
  120. QJSValue newErrorObject(QJSValue::ErrorType errorType, const QString &message = QString());
  121. void throwError(const QString &message);
  122. %If (Qt_6_1_0 -)
  123. void throwError(const QJSValue &error);
  124. %End
  125. void throwError(QJSValue::ErrorType errorType, const QString &message = QString());
  126. void setInterrupted(bool interrupted);
  127. bool isInterrupted() const;
  128. QString uiLanguage() const;
  129. void setUiLanguage(const QString &language);
  130. enum ObjectOwnership
  131. {
  132. CppOwnership,
  133. JavaScriptOwnership,
  134. };
  135. static void setObjectOwnership(QObject * /GetWrapper/, QJSEngine::ObjectOwnership);
  136. %MethodCode
  137. QJSEngine::ObjectOwnership old = QJSEngine::objectOwnership(a0);
  138. QJSEngine::setObjectOwnership(a0, a1);
  139. if (old != a1 && !a0->parent())
  140. {
  141. if (old == QJSEngine::CppOwnership)
  142. sipTransferTo(a0Wrapper, Py_None);
  143. else
  144. sipTransferBack(a0Wrapper);
  145. }
  146. %End
  147. static QJSEngine::ObjectOwnership objectOwnership(QObject *);
  148. %If (Qt_6_1_0 -)
  149. bool hasError() const;
  150. %End
  151. %If (Qt_6_1_0 -)
  152. QJSValue catchError();
  153. %End
  154. signals:
  155. void uiLanguageChanged();
  156. public:
  157. %If (Qt_6_2_0 -)
  158. bool registerModule(const QString &moduleName, const QJSValue &value);
  159. %End
  160. %If (Qt_6_2_0 -)
  161. QJSValue newSymbol(const QString &name);
  162. %End
  163. %If (Qt_6_5_0 -)
  164. QJSValue toScriptValue(const QVariant &value);
  165. %End
  166. %If (Qt_6_5_0 -)
  167. QJSManagedValue toManagedValue(const QVariant &value);
  168. %End
  169. %If (Qt_6_5_0 -)
  170. QJSPrimitiveValue toPrimitiveValue(const QVariant &value);
  171. %End
  172. };
  173. QJSEngine *qjsEngine(const QObject *);
  174. %ModuleHeaderCode
  175. #include "qpyqml_api.h"
  176. %End
  177. %PostInitialisationCode
  178. qpyqml_post_init(sipModuleDict);
  179. %End