Exemplo n.º 1
0
void QtActionWidget::onClick() {
	PyScopedGIL gil;
	PyQtGuiObject* control = getControl();
	if(!control) return;

	control->updateSubjectObject();
	if(control->subjectObject) {
		PyObject* ret = PyObject_CallFunction(control->subjectObject, NULL);
		if(!ret) {
			if(PyErr_Occurred()) PyErr_Print();			
		}
		Py_XDECREF(ret);
	}
	
	Py_DECREF(control);
}
Exemplo n.º 2
0
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);
	});
}