PyObject * py_guiQt_main(PyObject* self) { (void)self; // This is called from Python and replaces the main() control. // It might make sense to assert that we are the main thread. // However, there is no good cross-platform way to do this (afaik). // We could use Python... For now, we just hope that Qt behaves sane. // Anyway, on the Python side, we should have called this // in the main thread. int ret = 0; { PyScopedGIUnlock giunlock; QtApp::prepareInit(); // Keep it static. Noone should access it when we return // from here, but I like to be safe anyway. static QtApp app; setupMenu(); if(!app.openMainWindow()) { PyScopedGIL gil; PyErr_SetString(PyExc_SystemError, "guiQt.main: failed to create main window"); return NULL; } { PyScopedGIL gil; PyObject* initRet = handleModuleCommand("main", "handleApplicationInit", NULL); if(!initRet) { PyErr_SetString(PyExc_SystemError, "guiQt.main: main.handleApplicationInit() error"); return NULL; } Py_DECREF(initRet); } // Enter the Qt main event loop. ret = app.exec(); // Note that it depends on the Qt backend whether we return here or not. } PyErr_SetObject(PyExc_SystemExit, PyInt_FromLong(ret)); return NULL; }
int drv_app(int drvid, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6, void* a7, void* a8, void* a9) { handle_head* head = (handle_head*)a0; QtApp *self = (QtApp*)head->native; switch (drvid) { case APP_INIT: { drvNewObj(a0,new QtApp); break; } case APP_CLOSE: { drvDelObj(a0,self); break; } case APP_EXEC: { drvSetInt(a1,self->exec()); break; } case APP_EXIT: { self->exit(drvGetInt(a1)); break; } case APP_SETFONT: { self->setFont(drvGetFont(a1)); break; } case APP_FONT: { drvSetFont(a1,self->font()); break; } case APP_CLOSEALLWINDOWS: { self->closeAllWindows(); break; } case APP_ONREMOVEITEM: { self->pfnDeleteObj = a1; break; } default: return 0; } return 1; }