void QtActionWidget::updateTitle() { PyScopedGIL gil; PyQtGuiObject* control = getControl(); if(!control) return; if(control->attr) { PyObject* attrName = PyObject_GetAttrString(control->attr, "name"); if(!attrName) { if(PyErr_Occurred()) PyErr_Print(); return; } std::string name; if(!pyStr(attrName, name)) { if(PyErr_Occurred()) PyErr_Print(); } else { buttonWidget->setText(QString::fromStdString(name)); } Py_DECREF(attrName); } Py_DECREF(control); }
PyObject* py_guiQt_buildControl(PyObject* self, PyObject* args, PyObject* kws) { (void)self; PyObject* userAttr = NULL; PyQtGuiObject* parent = NULL; static const char *kwlist[] = {"userAttr", "parent", NULL}; if(!PyArg_ParseTupleAndKeywords( args, kws, "OO:buildControl", (char**)kwlist, &userAttr, &parent)) return NULL; if(!PyType_IsSubtype(Py_TYPE(parent), &QtGuiObject_Type)) { PyErr_Format(PyExc_ValueError, "guiQt.buildControl: parent must be a QtGuiObject"); return NULL; } if(parent->root == NULL) { PyErr_Format(PyExc_ValueError, "guiQt.buildControl: parent.root is NULL"); return NULL; } if(parent->subjectObject == NULL) { PyErr_Format(PyExc_ValueError, "guiQt.buildControl: parent.subjectObject is NULL"); return NULL; } std::string controlType; { PyObject* typeClass = PyObject_CallMethod(userAttr, (char*)"getTypeClass", NULL); if(!typeClass) return NULL; PyObject* typeClassName = PyObject_GetAttrString(typeClass, "__name__"); if(!typeClassName) { Py_DECREF(typeClass); return NULL; } if(!pyStr(typeClassName, controlType)) { Py_DECREF(typeClass); Py_DECREF(typeClassName); return NULL; } PyObject* traitsMod = getModule("Traits"); // borrowed if(!traitsMod) { PyErr_Format(PyExc_ValueError, "guiQt.buildControl: Traits module not found"); Py_DECREF(typeClass); Py_DECREF(typeClassName); return NULL; } PyObject* traitsClass = PyObject_GetAttrString(traitsMod, controlType.c_str()); if(!traitsClass) { PyErr_Format(PyExc_ValueError, "guiQt.buildControl: Traits.%s not found", controlType.c_str()); Py_DECREF(typeClass); Py_DECREF(typeClassName); return NULL; } if(traitsClass != typeClass) { PyErr_Format(PyExc_ValueError, "guiQt.buildControl: Traits.%s is different class", controlType.c_str()); Py_DECREF(typeClass); Py_DECREF(typeClassName); Py_DECREF(traitsClass); return NULL; } Py_DECREF(typeClass); Py_DECREF(typeClassName); Py_DECREF(traitsClass); } ControlBuilderFunc builderFunc = getControlBuilder(controlType); if(!builderFunc) { // The current layouting engine + setupChilds() will be messed up if this fails. // So just provide some dummy fallback. printf("guiQt.buildControl: %s-widget not implemented yet, using Object-widget as fallback\n", controlType.c_str()); builderFunc = getControlBuilder("Object"); assert(builderFunc); } PyQtGuiObject* control = (PyQtGuiObject*) PyObject_CallFunction((PyObject*) &QtGuiObject_Type, NULL); if(!control) return NULL; assert(control->root == NULL); control->root = parent->root; Py_XINCREF(control->root); assert(control->parent == NULL); control->parent = parent; Py_XINCREF(control->parent); assert(control->attr == NULL); control->attr = userAttr; Py_XINCREF(control->attr); assert(control->subjectObject == NULL); control->subjectObject = PyObject_CallMethod(userAttr, (char*)"__get__", (char*)"(O)", parent->subjectObject); if(control->subjectObject == NULL) { Py_DECREF(control); return NULL; } { PyScopedGIUnlock gunlock; execInMainThread_sync([&]() { bool res = builderFunc(control); if(!res) // XXX: handle somehow? ... printf("guiQt.buildControl: warning, returned error\n"); }); } // forward control return (PyObject*) control; }
void QtOneLineTextWidget::updateContent() { PyQtGuiObject* control = NULL; std::string s = "???"; { PyScopedGIL gil; control = getControl(); if(!control) return; control->updateSubjectObject(); { PyObject* labelContent = getTextObj(); if(!labelContent && PyErr_Occurred()) PyErr_Print(); if(labelContent) { if(!pyStr(labelContent, s)) { if(PyErr_Occurred()) PyErr_Print(); } } } } WeakRef selfRefCopy(*this); // Note: We had this async before. But I think other code wants to know the actual size // and we only get it after we set the text. execInMainThread_sync([=]() { PyScopedGIL gil; ScopedRef selfRef(selfRefCopy.scoped()); if(selfRef) { auto self = dynamic_cast<QtOneLineTextWidget*>(selfRef.get()); assert(self); assert(self->lineEditWidget); self->lineEditWidget->setText(QString::fromStdString(s)); PyScopedGIL gil; /* NSColor* color = backgroundColor(control); if(color) { [self setDrawsBackground:YES]; [self setBackgroundColor:color]; } */ //[self setTextColor:foregroundColor(control)]; bool autosizeWidth = attrChain_bool_default(control->attr, "autosizeWidth", false); if(autosizeWidth) { QFontMetrics metrics(self->lineEditWidget->fontMetrics()); int w = metrics.boundingRect(self->lineEditWidget->text()).width(); w += 5; // TODO: margin size? self->resize(w, self->height()); PyObject* res = PyObject_CallMethod((PyObject*) control, (char*)"layoutLine", NULL); if(!res && PyErr_Occurred()) PyErr_Print(); Py_XDECREF(res); } } Py_DECREF(control); }); }
void IntraFunctor::addIntraStiffnesses(const shared_ptr<Particle>&, const shared_ptr<Node>&, Vector3r& ktrans, Vector3r& krot) const{ LOG_WARN("IntraFunctor::addIntraStiffnesses: not overridden for "+pyStr()+", internal stiffness ignored for timestep computation."); }
void NodeData::setDataOnNode(Node&){ throw std::runtime_error(pyStr()+" does not reimplement NodeData::setDataOnNode."); }
const char* NodeData::getterName() const { throw std::runtime_error(pyStr()+" does not reimplement NodeData::getterName."); }
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; }