MCPcopy Create free account
hub / github.com/TeXworks/texworks / setAttribute

Method setAttribute

plugins-src/TWPythonPlugin/PythonScript.cpp:297–333  ·  view source on GitHub ↗

static*/

Source from the content-addressed store, hash-verified

295
296/*static*/
297int PythonScript::setAttribute(PyObject * o, PyObject * attr_name, PyObject * v)
298{
299 QString propName;
300 QMetaProperty prop;
301
302 // Get the QObject* we operate on
303 if (!PyObject_TypeCheck(o, &pyQObjectType)) {
304 PyErr_SetString(PyExc_TypeError, qPrintable(tr("setattr: not a valid TW object")));
305 return -1;
306 }
307 if (!IS_ENCAPSULATED_C_POINTER(((pyQObject*)o)->_TWcontext)) {
308 PyErr_SetString(PyExc_TypeError, qPrintable(tr("setattr: not a valid TW object")));
309 return -1;
310 }
311 QObject * obj = (QObject*)GET_ENCAPSULATED_C_POINTER((PyObject*)(((pyQObject*)o)->_TWcontext));
312
313 // Get the parameters
314 if (!asQString(attr_name, propName)) {
315 PyErr_SetString(PyExc_TypeError, qPrintable(tr("setattr: invalid property name")));
316 return -1;
317 }
318
319 switch (doSetProperty(obj, propName, PythonScript::PythonToVariant(v))) {
320 case Property_DoesNotExist:
321 PyErr_Format(PyExc_AttributeError, qPrintable(tr("setattr: object doesn't have property %s")), qPrintable(propName));
322 return -1;
323 case Property_NotWritable:
324 PyErr_Format(PyExc_AttributeError, qPrintable(tr("setattr: property %s is not writable")), qPrintable(propName));
325 return -1;
326 case Property_OK:
327 return 0;
328 default:
329 break;
330 }
331 // we should never reach this point
332 return -1;
333}
334
335/*static*/
336PyObject * PythonScript::callMethod(PyObject * o, PyObject * pyArgs, PyObject * kw)

Callers 1

FullscreenManagerMethod · 0.80

Calls

no outgoing calls

Tested by 1

FullscreenManagerMethod · 0.64