You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the recommended way, to allow only scriptable methods (annotated with Q_SCRIPTABLE) and scriptable properties (SCRIPTABLE attribute of a Q_PROPERTY)?
Should I filter the data when doing introspection (PythonQt::introspection) to prevent the user from selecting any other methods and properties or is it possible to filter out methods and properties when a QObject becomes visible / registered to the Python interpreter. What is the right place in the source code to touch if i would like to enable only scriptable methods and properties?
Ok, I have found the solution. The relevant file is PythonQtClassInfo and the relevant methods ar propertyList and memberList. I added tests for scriptable attributes and this worked:
QStringList PythonQtClassInfo::propertyList()
{
QStringList l;
if (_isQObject && _meta) {
int i;
int numProperties = _meta->propertyCount();
for (i = 0; i < numProperties; i++) {
QMetaProperty p = _meta->property(i);
if (!p.isScriptable()) {
l << QString(p.name());
}
}
}
QStringList members = memberList();
foreach(QString member, members) {
if (member.startsWith("py_get_")) {
l << member.mid(7);
}
}
return l;
}
QStringList PythonQtClassInfo::memberList()
{
decorator();
QStringList l;
QString h;
// normal slots of QObject (or wrapper QObject)if (_meta) {
int numMethods = _meta->methodCount();
bool skipQObj = !_isQObject;
for (int i = skipQObj?QObject::staticMetaObject.methodCount():0; i < numMethods; i++) {
QMetaMethod m = _meta->method(i);
if ((m.attributes() & QMetaMethod::Scriptable) &&
(((m.methodType() == QMetaMethod::Method || m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public)
|| m.methodType()==QMetaMethod::Signal))
{
l << PythonQtUtils::methodName(m);
}
}
}
Activity
githubuser0xFFFF commentedon Dec 2, 2021
Ok, I have found the solution. The relevant file is
PythonQtClassInfoand the relevant methods arpropertyListandmemberList. I added tests for scriptable attributes and this worked: