mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-07-20 01:57:16 +02:00
[core] Add reference to attribute's instance type in descriptions
This commit is contained in:
parent
eb60ad0389
commit
17e8e3e315
2 changed files with 33 additions and 11 deletions
|
@ -25,17 +25,7 @@ def attributeFactory(description, value, isOutput, node, root=None, parent=None)
|
||||||
root: (optional) parent Attribute (must be ListAttribute or GroupAttribute)
|
root: (optional) parent Attribute (must be ListAttribute or GroupAttribute)
|
||||||
parent (BaseObject): (optional) the parent BaseObject if any
|
parent (BaseObject): (optional) the parent BaseObject if any
|
||||||
"""
|
"""
|
||||||
if isinstance(description, desc.GroupAttribute):
|
attr = description.instanceType(node, description, isOutput, root, parent)
|
||||||
cls = GroupAttribute
|
|
||||||
elif isinstance(description, desc.ListAttribute):
|
|
||||||
cls = ListAttribute
|
|
||||||
elif isinstance(description, desc.ChoiceParam):
|
|
||||||
cls = ChoiceParam
|
|
||||||
elif isinstance(description, desc.PushButtonParam):
|
|
||||||
cls = PushButtonParam
|
|
||||||
else:
|
|
||||||
cls = Attribute
|
|
||||||
attr = cls(node, description, isOutput, root, parent)
|
|
||||||
if value is not None:
|
if value is not None:
|
||||||
attr._set_value(value, emitSignals=False)
|
attr._set_value(value, emitSignals=False)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -58,6 +58,12 @@ class Attribute(BaseObject):
|
||||||
visible = Property(bool, lambda self: self._visible, constant=True)
|
visible = Property(bool, lambda self: self._visible, constant=True)
|
||||||
type = Property(str, lambda self: self.__class__.__name__, constant=True)
|
type = Property(str, lambda self: self.__class__.__name__, constant=True)
|
||||||
|
|
||||||
|
def getInstanceType(self):
|
||||||
|
""" Return the correct Attribute instance corresponding to the description. """
|
||||||
|
# Import within the method to prevent cyclic dependencies
|
||||||
|
from meshroom.core.attribute import Attribute
|
||||||
|
return Attribute
|
||||||
|
|
||||||
def validateValue(self, value):
|
def validateValue(self, value):
|
||||||
""" Return validated/conformed 'value'. Need to be implemented in derived classes.
|
""" Return validated/conformed 'value'. Need to be implemented in derived classes.
|
||||||
|
|
||||||
|
@ -88,6 +94,10 @@ class Attribute(BaseObject):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# instanceType
|
||||||
|
# Attribute instance corresponding to the description
|
||||||
|
instanceType = Property(Variant, lambda self: self.getInstanceType(), constant=True)
|
||||||
|
|
||||||
|
|
||||||
class ListAttribute(Attribute):
|
class ListAttribute(Attribute):
|
||||||
""" A list of Attributes """
|
""" A list of Attributes """
|
||||||
|
@ -103,6 +113,11 @@ class ListAttribute(Attribute):
|
||||||
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)
|
joinChar = Property(str, lambda self: self._joinChar, constant=True)
|
||||||
|
|
||||||
|
def getInstanceType(self):
|
||||||
|
# Import within the method to prevent cyclic dependencies
|
||||||
|
from meshroom.core.attribute import ListAttribute
|
||||||
|
return ListAttribute
|
||||||
|
|
||||||
def validateValue(self, value):
|
def validateValue(self, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
return value
|
return value
|
||||||
|
@ -144,6 +159,11 @@ class GroupAttribute(Attribute):
|
||||||
|
|
||||||
groupDesc = Property(Variant, lambda self: self._groupDesc, constant=True)
|
groupDesc = Property(Variant, lambda self: self._groupDesc, constant=True)
|
||||||
|
|
||||||
|
def getInstanceType(self):
|
||||||
|
# Import within the method to prevent cyclic dependencies
|
||||||
|
from meshroom.core.attribute import GroupAttribute
|
||||||
|
return GroupAttribute
|
||||||
|
|
||||||
def validateValue(self, value):
|
def validateValue(self, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
return value
|
return value
|
||||||
|
@ -336,11 +356,18 @@ class PushButtonParam(Param):
|
||||||
super(PushButtonParam, self).__init__(name=name, label=label, description=description, value=None, uid=uid, group=group, advanced=advanced, semantic=semantic, enabled=enabled, visible=visible)
|
super(PushButtonParam, self).__init__(name=name, label=label, description=description, value=None, uid=uid, group=group, advanced=advanced, semantic=semantic, enabled=enabled, visible=visible)
|
||||||
self._valueType = None
|
self._valueType = None
|
||||||
|
|
||||||
|
def getInstanceType(self):
|
||||||
|
# Import within the method to prevent cyclic dependencies
|
||||||
|
from meshroom.core.attribute import PushButtonParam
|
||||||
|
return PushButtonParam
|
||||||
|
|
||||||
def validateValue(self, value):
|
def validateValue(self, value):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def checkValueTypes(self):
|
def checkValueTypes(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ChoiceParam(Param):
|
class ChoiceParam(Param):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
@ -362,6 +389,11 @@ class ChoiceParam(Param):
|
||||||
else:
|
else:
|
||||||
self._valueType = type(self._value)
|
self._valueType = type(self._value)
|
||||||
|
|
||||||
|
def getInstanceType(self):
|
||||||
|
# Import within the method to prevent cyclic dependencies
|
||||||
|
from meshroom.core.attribute import ChoiceParam
|
||||||
|
return ChoiceParam
|
||||||
|
|
||||||
def conformValue(self, value):
|
def conformValue(self, value):
|
||||||
""" Conform 'value' to the correct type and check for its validity """
|
""" Conform 'value' to the correct type and check for its validity """
|
||||||
# We do not check that the value is in the list of values.
|
# We do not check that the value is in the list of values.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue