[core] add GroupAttribute.childAttribute method

* easier access to child attributes
* callable from QML
This commit is contained in:
Yann Lanthony 2019-03-01 17:22:57 +01:00
parent 9b2338488b
commit 1a22fc8ae8

View file

@ -4,7 +4,7 @@ import collections
import re import re
import weakref import weakref
from meshroom.common import BaseObject, Property, Variant, Signal, ListModel, DictModel from meshroom.common import BaseObject, Property, Variant, Signal, ListModel, DictModel, Slot
from meshroom.core import desc, pyCompatibility, hashValue from meshroom.core import desc, pyCompatibility, hashValue
@ -371,6 +371,22 @@ class GroupAttribute(Attribute):
for key, value in exportedValue.items(): for key, value in exportedValue.items():
self._value.get(key).value = value self._value.get(key).value = value
@Slot(str, result=Attribute)
def childAttribute(self, key):
"""
Get child attribute by name or None if none was found.
Args:
key (str): the name of the child attribute
Returns:
Attribute: the child attribute or None
"""
try:
return self._value.get(key)
except KeyError:
return None
def uid(self, uidIndex): def uid(self, uidIndex):
uids = [] uids = []
for k, v in self._value.items(): for k, v in self._value.items():