service_ptr output_manager_v2::addCallback( std::function<void() > f ) { output_config_change_callback_impl * obj = new output_config_change_callback_impl(); obj->f = f; this->addCallback( obj ); service_ptr_t<output_manager_v2> selfRef ( this ); return fb2k::callOnRelease( [obj, selfRef] { selfRef->removeCallback( obj ); delete obj; } ); }
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); }); }