1// qcoreapplication.sip generated by MetaSIP 2// 3// This file is part of the QtCore Python extension module. 4// 5// Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com> 6// 7// This file is part of PyQt5. 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 22 23%ModuleCode 24#include <qcoreapplication.h> 25%End 26 27class QCoreApplication : QObject 28{ 29%TypeHeaderCode 30#include <qcoreapplication.h> 31%End 32 33public: 34 QCoreApplication(SIP_PYLIST argv /TypeHint="List[str]"/) /PostHook=__pyQtQAppHook__/ [(int &argc, char **argv)]; 35%MethodCode 36 // The Python interface is a list of argument strings that is modified. 37 38 int argc; 39 char **argv; 40 41 // Convert the list. 42 if ((argv = pyqt5_from_argv_list(a0, argc)) == NULL) 43 sipIsErr = 1; 44 else 45 { 46 // Create it now the arguments are right. 47 static int nargc; 48 nargc = argc; 49 50 Py_BEGIN_ALLOW_THREADS 51 sipCpp = new sipQCoreApplication(nargc, argv); 52 Py_END_ALLOW_THREADS 53 54 // Now modify the original list. 55 pyqt5_update_argv_list(a0, argc, argv); 56 } 57%End 58 59 virtual ~QCoreApplication() /ReleaseGIL/; 60%MethodCode 61 pyqt5_cleanup_qobjects(); 62%End 63 64 static void setOrganizationDomain(const QString &orgDomain); 65 static QString organizationDomain(); 66 static void setOrganizationName(const QString &orgName); 67 static QString organizationName(); 68 static void setApplicationName(const QString &application); 69 static QString applicationName(); 70 static QStringList arguments(); 71 static QCoreApplication *instance(); 72 static int exec() /PostHook=__pyQtPostEventLoopHook__,PreHook=__pyQtPreEventLoopHook__,PyName=exec_,ReleaseGIL/; 73%If (Py_v3) 74 static int exec() /PostHook=__pyQtPostEventLoopHook__,PreHook=__pyQtPreEventLoopHook__,ReleaseGIL/; 75%End 76 static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::ProcessEventsFlag::AllEvents) /ReleaseGIL/; 77 static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime) /ReleaseGIL/; 78 static void exit(int returnCode = 0); 79 static bool sendEvent(QObject *receiver, QEvent *event) /ReleaseGIL/; 80 static void postEvent(QObject *receiver, QEvent *event /Transfer/, int priority = Qt::EventPriority::NormalEventPriority); 81 static void sendPostedEvents(QObject *receiver = 0, int eventType = 0) /ReleaseGIL/; 82 static void removePostedEvents(QObject *receiver, int eventType = 0); 83 static bool hasPendingEvents(); 84 virtual bool notify(QObject *, QEvent *) /ReleaseGIL/; 85 static bool startingUp(); 86 static bool closingDown(); 87 static QString applicationDirPath(); 88 static QString applicationFilePath(); 89 static void setLibraryPaths(const QStringList &); 90 static QStringList libraryPaths(); 91 static void addLibraryPath(const QString &); 92 static void removeLibraryPath(const QString &); 93 static bool installTranslator(QTranslator *messageFile); 94 static bool removeTranslator(QTranslator *messageFile); 95 static QString translate(const char *context, const char *sourceText /Encoding="UTF-8"/, const char *disambiguation = 0, int n = -1); 96 static void flush() /ReleaseGIL/; 97 static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true); 98 static bool testAttribute(Qt::ApplicationAttribute attribute); 99 100public slots: 101 static void quit(); 102 103signals: 104 void aboutToQuit(); 105 106protected: 107 virtual bool event(QEvent *); 108 109public: 110 static void setApplicationVersion(const QString &version); 111 static QString applicationVersion(); 112 static qint64 applicationPid(); 113 static QAbstractEventDispatcher *eventDispatcher(); 114 static void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher /Transfer/); 115 static bool isQuitLockEnabled(); 116 static void setQuitLockEnabled(bool enabled); 117 void installNativeEventFilter(QAbstractNativeEventFilter *filterObj); 118 void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj); 119%If (Qt_5_3_0 -) 120 static void setSetuidAllowed(bool allow); 121%End 122%If (Qt_5_3_0 -) 123 static bool isSetuidAllowed(); 124%End 125 SIP_PYOBJECT __enter__(); 126%MethodCode 127 // Just return a reference to self. 128 sipRes = sipSelf; 129 Py_INCREF(sipRes); 130%End 131 132 void __exit__(SIP_PYOBJECT type, SIP_PYOBJECT value, SIP_PYOBJECT traceback); 133%MethodCode 134 // Make sure the QCoreApplication is destroyed. 135 delete sipCpp; 136%End 137}; 138 139void qAddPostRoutine(SIP_PYCALLABLE); 140%MethodCode 141 // Add it to the list of post routines if it already exists. 142 if (qtcore_PostRoutines != NULL) 143 { 144 // See if there is an empty slot. 145 bool app = true; 146 147 for (Py_ssize_t i = 0; i < PyList_Size(qtcore_PostRoutines); ++i) 148 if (PyList_GetItem(qtcore_PostRoutines, i) == Py_None) 149 { 150 Py_INCREF(a0); 151 PyList_SetItem(qtcore_PostRoutines, i, a0); 152 153 app = false; 154 155 break; 156 } 157 158 if (app && PyList_Append(qtcore_PostRoutines, a0) < 0) 159 sipIsErr = 1; 160 } 161 else if ((qtcore_PostRoutines = PyList_New(1)) != NULL) 162 { 163 Py_INCREF(a0); 164 PyList_SetItem(qtcore_PostRoutines, 0, a0); 165 166 qAddPostRoutine(qtcore_CallPostRoutines); 167 } 168 else 169 { 170 sipIsErr = 1; 171 } 172%End 173 174void qRemovePostRoutine(SIP_PYCALLABLE); 175%MethodCode 176 // Remove it from the list of post routines if it exists. 177 if (qtcore_PostRoutines != NULL) 178 for (Py_ssize_t i = 0; i < PyList_Size(qtcore_PostRoutines); ++i) 179 if (PyList_GetItem(qtcore_PostRoutines, i) == a0) 180 { 181 Py_INCREF(Py_None); 182 PyList_SetItem(qtcore_PostRoutines, i, Py_None); 183 184 break; 185 } 186%End 187 188%If (Qt_5_1_0 -) 189void qAddPreRoutine(SIP_PYCALLABLE routine /TypeHint="Callable[[], None]"/); 190%MethodCode 191 // Add it to the list of pre routines if it already exists. 192 if (qtcore_PreRoutines != NULL) 193 { 194 if (PyList_Append(qtcore_PreRoutines, a0) < 0) 195 sipIsErr = 1; 196 } 197 else if ((qtcore_PreRoutines = PyList_New(1)) != NULL) 198 { 199 Py_INCREF(a0); 200 PyList_SetItem(qtcore_PreRoutines, 0, a0); 201 202 qAddPreRoutine(qtcore_CallPreRoutines); 203 } 204 else 205 { 206 sipIsErr = 1; 207 } 208%End 209 210%End 211// Module code needed by qAddPreRoutine, qAddPostRoutine() and qRemovePostRoutine(). 212%ModuleCode 213#if QT_VERSION >= 0x050100 214// The list of Python pre routines. 215static PyObject *qtcore_PreRoutines = NULL; 216 217// Call all of the registered Python pre routines. 218static void qtcore_CallPreRoutines() 219{ 220 for (Py_ssize_t i = 0; i < PyList_Size(qtcore_PreRoutines); ++i) 221 { 222 PyObject *pr = PyList_GetItem(qtcore_PreRoutines, i); 223 224 if (pr != Py_None) 225 { 226 PyObject *res = PyObject_CallObject(pr, NULL); 227 228 Py_XDECREF(res); 229 } 230 } 231} 232#endif 233 234 235// The list of Python post routines. 236static PyObject *qtcore_PostRoutines = NULL; 237 238// Call all of the registered Python post routines. 239static void qtcore_CallPostRoutines() 240{ 241 for (Py_ssize_t i = 0; i < PyList_Size(qtcore_PostRoutines); ++i) 242 { 243 PyObject *pr = PyList_GetItem(qtcore_PostRoutines, i); 244 245 if (pr != Py_None) 246 { 247 PyObject *res = PyObject_CallObject(pr, NULL); 248 249 Py_XDECREF(res); 250 } 251 } 252} 253%End 254void pyqtRemoveInputHook(); 255%MethodCode 256 // Clear the Python input hook installed when the module was initialised. 257 PyOS_InputHook = 0; 258%End 259 260void pyqtRestoreInputHook(); 261%MethodCode 262 // Restore the input hook. 263 PyOS_InputHook = qtcore_input_hook; 264%End 265 266%ModuleCode 267#include <QCoreApplication> 268#include <QThread> 269 270#if defined(Q_OS_WIN) 271#include <conio.h> 272#include <QTimer> 273#else 274#include <QSocketNotifier> 275#endif 276 277// This is the input hook that will process events while the interpreter is 278// waiting for interactive input. 279extern "C" {static int qtcore_input_hook();} 280 281static int qtcore_input_hook() 282{ 283 QCoreApplication *app = QCoreApplication::instance(); 284 285 if (app && app->thread() == QThread::currentThread()) 286 { 287#if defined(Q_OS_WIN) 288 QTimer timer; 289 QObject::connect(&timer, SIGNAL(timeout()), app, SLOT(quit())); 290 291 while (!_kbhit()) 292 { 293 // The delay is based on feedback from users. 294 timer.start(35); 295 QCoreApplication::exec(); 296 timer.stop(); 297 } 298 299 QObject::disconnect(&timer, SIGNAL(timeout()), app, SLOT(quit())); 300#else 301 QSocketNotifier notifier(0, QSocketNotifier::Read, 0); 302 QObject::connect(¬ifier, SIGNAL(activated(int)), app, SLOT(quit())); 303 QCoreApplication::exec(); 304 QObject::disconnect(¬ifier, SIGNAL(activated(int)), app, SLOT(quit())); 305#endif 306 } 307 308 return 0; 309} 310%End 311 312%PostInitialisationCode 313// Process events from the input hook. 314PyOS_InputHook = qtcore_input_hook; 315%End 316 317%ExportedTypeHintCode 318# Support for QDate, QDateTime and QTime. 319import datetime 320 321# Convenient type aliases. 322PYQT_SIGNAL = typing.Union[QtCore.pyqtSignal, QtCore.pyqtBoundSignal] 323PYQT_SLOT = typing.Union[typing.Callable[..., None], QtCore.pyqtBoundSignal] 324%End 325 326%TypeHintCode 327# Support for QDate, QDateTime and QTime. 328import datetime 329 330 331# Support for new-style signals and slots. 332class pyqtSignal: 333 334 signatures = ... # type: typing.Tuple[str, ...] 335 336 def __init__(self, *types: typing.Any, name: str = ...) -> None: ... 337 338 @typing.overload 339 def __get__(self, instance: None, owner: typing.Type['QObject']) -> 'pyqtSignal': ... 340 341 @typing.overload 342 def __get__(self, instance: 'QObject', owner: typing.Type['QObject']) -> 'pyqtBoundSignal': ... 343 344 345 346class pyqtBoundSignal: 347 348 signal = ... # type: str 349 350 def __getitem__(self, key: object) -> 'pyqtBoundSignal': ... 351 352 def connect(self, slot: 'PYQT_SLOT') -> 'QMetaObject.Connection': ... 353 354 @typing.overload 355 def disconnect(self) -> None: ... 356 357 @typing.overload 358 def disconnect(self, slot: typing.Union['PYQT_SLOT', 'QMetaObject.Connection']) -> None: ... 359 360 def emit(self, *args: typing.Any) -> None: ... 361 362 363# Convenient type aliases. 364PYQT_SIGNAL = typing.Union[pyqtSignal, pyqtBoundSignal] 365PYQT_SLOT = typing.Union[typing.Callable[..., None], pyqtBoundSignal] 366%End 367