mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-06-12 15:52:07 +02:00
[core] ListAttribute and GroupAttribute can now be exported on command line
* ListAttribute, GroupAttribute: can now be exported on command line with customizable join character. * ChoiceParam with non exclusive values are exported on command line as before but using the new getValueStr()
This commit is contained in:
parent
7ceea28174
commit
ad84d20eb5
2 changed files with 19 additions and 6 deletions
|
@ -34,15 +34,17 @@ class Attribute(BaseObject):
|
||||||
|
|
||||||
class ListAttribute(Attribute):
|
class ListAttribute(Attribute):
|
||||||
""" A list of Attributes """
|
""" A list of Attributes """
|
||||||
def __init__(self, elementDesc, name, label, description, group='allParams'):
|
def __init__(self, elementDesc, name, label, description, group='allParams', joinChar=' '):
|
||||||
"""
|
"""
|
||||||
:param elementDesc: the Attribute description of elements to store in that list
|
:param elementDesc: the Attribute description of elements to store in that list
|
||||||
"""
|
"""
|
||||||
self._elementDesc = elementDesc
|
self._elementDesc = elementDesc
|
||||||
|
self._joinChar = joinChar
|
||||||
super(ListAttribute, self).__init__(name=name, label=label, description=description, value=None, uid=(), group=group)
|
super(ListAttribute, self).__init__(name=name, label=label, description=description, value=None, uid=(), group=group)
|
||||||
|
|
||||||
elementDesc = Property(Attribute, lambda self: self._elementDesc, constant=True)
|
elementDesc = Property(Attribute, lambda self: self._elementDesc, constant=True)
|
||||||
uid = Property(Variant, lambda self: self.elementDesc.uid, constant=True)
|
uid = Property(Variant, lambda self: self.elementDesc.uid, constant=True)
|
||||||
|
joinChar = Property(str, lambda self: self._joinChar, constant=True)
|
||||||
|
|
||||||
def validateValue(self, value):
|
def validateValue(self, value):
|
||||||
if not (isinstance(value, collections.Iterable) and isinstance(value, basestring)):
|
if not (isinstance(value, collections.Iterable) and isinstance(value, basestring)):
|
||||||
|
@ -52,11 +54,12 @@ class ListAttribute(Attribute):
|
||||||
|
|
||||||
class GroupAttribute(Attribute):
|
class GroupAttribute(Attribute):
|
||||||
""" A macro Attribute composed of several Attributes """
|
""" A macro Attribute composed of several Attributes """
|
||||||
def __init__(self, groupDesc, name, label, description, group='allParams'):
|
def __init__(self, groupDesc, name, label, description, group='allParams', joinChar=' '):
|
||||||
"""
|
"""
|
||||||
:param groupDesc: the description of the Attributes composing this group
|
:param groupDesc: the description of the Attributes composing this group
|
||||||
"""
|
"""
|
||||||
self._groupDesc = groupDesc
|
self._groupDesc = groupDesc
|
||||||
|
self._joinChar = joinChar
|
||||||
super(GroupAttribute, self).__init__(name=name, label=label, description=description, value=None, uid=(), group=group)
|
super(GroupAttribute, self).__init__(name=name, label=label, description=description, value=None, uid=(), group=group)
|
||||||
|
|
||||||
groupDesc = Property(Variant, lambda self: self._groupDesc, constant=True)
|
groupDesc = Property(Variant, lambda self: self._groupDesc, constant=True)
|
||||||
|
@ -73,6 +76,7 @@ class GroupAttribute(Attribute):
|
||||||
return allUids
|
return allUids
|
||||||
|
|
||||||
uid = Property(Variant, retrieveChildrenUids, constant=True)
|
uid = Property(Variant, retrieveChildrenUids, constant=True)
|
||||||
|
joinChar = Property(str, lambda self: self._joinChar, constant=True)
|
||||||
|
|
||||||
|
|
||||||
class Param(Attribute):
|
class Param(Attribute):
|
||||||
|
|
|
@ -245,6 +245,12 @@ class Attribute(BaseObject):
|
||||||
return self.desc.value
|
return self.desc.value
|
||||||
return self._value
|
return self._value
|
||||||
|
|
||||||
|
def getValueStr(self):
|
||||||
|
if isinstance(self.attributeDesc, desc.ChoiceParam) and not self.attributeDesc.exclusive:
|
||||||
|
assert(isinstance(self.value, collections.Sequence) and not isinstance(self.value, basestring))
|
||||||
|
return self.attributeDesc.joinChar.join(self.value)
|
||||||
|
return str(self.value)
|
||||||
|
|
||||||
def isDefault(self):
|
def isDefault(self):
|
||||||
return self._value == self.desc.value
|
return self._value == self.desc.value
|
||||||
|
|
||||||
|
@ -334,6 +340,9 @@ class ListAttribute(Attribute):
|
||||||
else:
|
else:
|
||||||
return [attr.getPrimitiveValue(exportDefault=exportDefault) for attr in self._value if not attr.isDefault()]
|
return [attr.getPrimitiveValue(exportDefault=exportDefault) for attr in self._value if not attr.isDefault()]
|
||||||
|
|
||||||
|
def getValueStr(self):
|
||||||
|
return self.attributeDesc.joinChar.join([v.getValueStr() for v in self._value])
|
||||||
|
|
||||||
# Override value property setter
|
# Override value property setter
|
||||||
value = Property(Variant, Attribute._get_value, _set_value, notify=Attribute.valueChanged)
|
value = Property(Variant, Attribute._get_value, _set_value, notify=Attribute.valueChanged)
|
||||||
|
|
||||||
|
@ -388,6 +397,9 @@ class GroupAttribute(Attribute):
|
||||||
else:
|
else:
|
||||||
return {name: attr.getPrimitiveValue(exportDefault=exportDefault) for name, attr in self._value.items() if not attr.isDefault()}
|
return {name: attr.getPrimitiveValue(exportDefault=exportDefault) for name, attr in self._value.items() if not attr.isDefault()}
|
||||||
|
|
||||||
|
def getValueStr(self):
|
||||||
|
return self.attributeDesc.joinChar.join([v.getValueStr() for v in self._value.objects.values()])
|
||||||
|
|
||||||
# Override value property
|
# Override value property
|
||||||
value = Property(Variant, Attribute._get_value, _set_value, notify=Attribute.valueChanged)
|
value = Property(Variant, Attribute._get_value, _set_value, notify=Attribute.valueChanged)
|
||||||
|
|
||||||
|
@ -782,10 +794,7 @@ class Node(BaseObject):
|
||||||
for name, attr in self._attributes.objects.items():
|
for name, attr in self._attributes.objects.items():
|
||||||
if attr.isOutput:
|
if attr.isOutput:
|
||||||
continue # skip outputs
|
continue # skip outputs
|
||||||
v = attr.value
|
v = attr.getValueStr()
|
||||||
if isinstance(attr.attributeDesc, desc.ChoiceParam) and not attr.attributeDesc.exclusive:
|
|
||||||
assert(isinstance(v, collections.Sequence) and not isinstance(v, basestring))
|
|
||||||
v = attr.attributeDesc.joinChar.join(v)
|
|
||||||
|
|
||||||
cmdVars[name] = '--{name} {value}'.format(name=name, value=v)
|
cmdVars[name] = '--{name} {value}'.format(name=name, value=v)
|
||||||
cmdVars[name + 'Value'] = str(v)
|
cmdVars[name + 'Value'] = str(v)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue