Beispiel #1
0
void QtBaseWidget::resizeEvent(QResizeEvent* ev) {
	if(handleResize) return; // avoid infinite recursion
	handleResize = true;
	
	QWidget::resizeEvent(ev);
	
	PyScopedGIL gil;
	PyQtGuiObject* control = getControl();
	if(control) control->layout();
	Py_XDECREF(control);
	
	handleResize = false;
}
Beispiel #2
0
bool QtApp::openWindow(const std::string& name) {
    assert(QThread::currentThread() == qApp->thread());

    PyScopedGIL gil;

    PyObject* rootObj = handleModuleCommand("gui", "RootObjs.__getitem__", "(s)", name.c_str());
    if(!rootObj) return false; // Python errs already handled in handleModuleCommand

    PyQtGuiObject* control = NULL;
    control = (PyQtGuiObject*) PyObject_GetAttrString(rootObj, "guiObj");
    if(!control) {
        if(PyErr_Occurred()) PyErr_Print();
        Py_DECREF(rootObj);
        return false;
    }

    if((PyObject*) control == Py_None) Py_CLEAR(control);
    if(control) {
        if(PyType_IsSubtype(Py_TYPE(control), &QtGuiObject_Type)) {
            QtBaseWidget::ScopedRef win(control->widget);
            if(win) {
                win->show();
                return true;
            }
            // continue with existing control but create new window
        }
        else {
            printf("Qt open window: existing rootObj.guiObj is of wrong type\n");
            // reset and continue with new control creation
            Py_CLEAR(control);
        }
    }

    if(!control) {
        control = (PyQtGuiObject*) PyObject_CallFunction((PyObject*) &QtGuiObject_Type, NULL);
        if(!control) {
            if(PyErr_Occurred()) PyErr_Print();
            Py_DECREF(rootObj);
            return false;
        }

        assert(control->root == NULL);
        control->root = control;
        Py_XINCREF(control->root);
        assert(control->subjectObject == NULL);
        control->subjectObject = PyObject_GetAttrString(rootObj, "obj");
        if(!control->subjectObject) {
            if(PyErr_Occurred()) PyErr_Print();
            Py_DECREF(rootObj);
            Py_DECREF(control);
            return false;
        }
    }

    if(PyObject_SetAttrString(rootObj, "guiObj", (PyObject*) control) < 0) {
        if(PyErr_Occurred()) PyErr_Print();
        Py_DECREF(rootObj);
        Py_DECREF(control);
        return false;
    }

    // check subjectObject
    {
        PyObject* subjectObject = PyObject_GetAttrString(rootObj, "obj");
        if(!subjectObject) {
            if(PyErr_Occurred()) PyErr_Print();
            // continue, maybe it doesn't matter
        }
        else {
            if(subjectObject != control->subjectObject) {
                printf("Qt open window: got new subject object\n");
                // strange, but just overtake and continue
                Py_CLEAR(control->subjectObject);
                control->subjectObject = subjectObject;
                subjectObject = NULL;
            }
        }
        Py_XDECREF(subjectObject);
    }

    QtBaseWidget* win = new QtBaseWidget(control);
    win->setAttribute(Qt::WA_DeleteOnClose);

    // set title
    {
        PyObject* title = PyObject_GetAttrString(rootObj, "title");
        std::string titleStr;
        if(!title || !pyStr(title, titleStr)) {
            if(PyErr_Occurred()) PyErr_Print();
            win->setWindowTitle(QString::fromStdString(name));
        }
        else {
            win->setWindowTitle(QString::fromStdString(titleStr));
        }
        Py_XDECREF(title);
    }

    Vec size = control->setupChilds();
    win->setMinimumSize(size.x, size.y);

    // ...

    win->show();
    control->layout();

    Py_DECREF(rootObj);
    Py_DECREF(control);
    return true;
}