mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-29 18:27:23 +02:00
Example of custom attribute inheriting existing classes
This commit is contained in:
parent
eb60ad0389
commit
4702906925
4 changed files with 74 additions and 2 deletions
|
@ -25,7 +25,11 @@ 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):
|
|
||||||
|
if description.attrType:
|
||||||
|
cls = description.attrType
|
||||||
|
|
||||||
|
elif isinstance(description, desc.GroupAttribute):
|
||||||
cls = GroupAttribute
|
cls = GroupAttribute
|
||||||
elif isinstance(description, desc.ListAttribute):
|
elif isinstance(description, desc.ListAttribute):
|
||||||
cls = ListAttribute
|
cls = ListAttribute
|
||||||
|
@ -35,6 +39,7 @@ def attributeFactory(description, value, isOutput, node, root=None, parent=None)
|
||||||
cls = PushButtonParam
|
cls = PushButtonParam
|
||||||
else:
|
else:
|
||||||
cls = Attribute
|
cls = Attribute
|
||||||
|
|
||||||
attr = cls(node, description, isOutput, root, parent)
|
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)
|
||||||
|
@ -417,7 +422,6 @@ class Attribute(BaseObject):
|
||||||
# Emit if the enable status has changed
|
# Emit if the enable status has changed
|
||||||
self.setEnabled(self.getEnabled())
|
self.setEnabled(self.getEnabled())
|
||||||
|
|
||||||
|
|
||||||
name = Property(str, getName, constant=True)
|
name = Property(str, getName, constant=True)
|
||||||
fullName = Property(str, getFullName, constant=True)
|
fullName = Property(str, getFullName, constant=True)
|
||||||
fullNameToNode = Property(str, getFullNameToNode, constant=True)
|
fullNameToNode = Property(str, getFullNameToNode, constant=True)
|
||||||
|
|
24
meshroom/core/custom.py
Normal file
24
meshroom/core/custom.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
from meshroom.common import BaseObject, Property, Variant, VariantList, JSValue
|
||||||
|
from meshroom.core import attribute, desc
|
||||||
|
|
||||||
|
|
||||||
|
class JobAttribute(attribute.ChoiceParam):
|
||||||
|
def __init__(self, node, attributeDesc, isOutput, root=None, parent=None):
|
||||||
|
super(JobAttribute, self).__init__(node, attributeDesc, isOutput, root, parent)
|
||||||
|
print("Constructor for JobParam")
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
print("Updating in JobParam, about to replace list of available params")
|
||||||
|
newValues = ["c", "d", "e", "f"]
|
||||||
|
self.setValues(newValues)
|
||||||
|
|
||||||
|
|
||||||
|
class JobParam(desc.ChoiceParam):
|
||||||
|
def __init__(self, name, label, description, value, values, exclusive, uid, group='allParams', joinChar=' ', advanced=False, semantic='',
|
||||||
|
enabled=True, validValue=True, errorMessage="", visible=True):
|
||||||
|
assert values
|
||||||
|
super(JobParam, self).__init__(name=name, label=label, description=description, value=value, values=values, exclusive=exclusive, uid=uid, group=group, joinChar=joinChar, advanced=advanced, semantic=semantic, enabled=enabled, validValue=validValue, errorMessage=errorMessage, visible=visible)
|
||||||
|
|
||||||
|
self._attrType = JobAttribute
|
||||||
|
|
||||||
|
type = Property(str, lambda self: self.__class__.__base__.__name__, constant=True)
|
|
@ -35,6 +35,8 @@ class Attribute(BaseObject):
|
||||||
self._isDynamicValue = (self._value is None)
|
self._isDynamicValue = (self._value is None)
|
||||||
self._valueType = None
|
self._valueType = None
|
||||||
|
|
||||||
|
self._attrType = None
|
||||||
|
|
||||||
name = Property(str, lambda self: self._name, constant=True)
|
name = Property(str, lambda self: self._name, constant=True)
|
||||||
label = Property(str, lambda self: self._label, constant=True)
|
label = Property(str, lambda self: self._label, constant=True)
|
||||||
description = Property(str, lambda self: self._description, constant=True)
|
description = Property(str, lambda self: self._description, constant=True)
|
||||||
|
@ -58,6 +60,8 @@ 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)
|
||||||
|
|
||||||
|
attrType = Property(Variant, lambda self: self._attrType, constant=True)
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
@ -405,6 +409,7 @@ class ChoiceParam(Param):
|
||||||
joinChar = Property(str, lambda self: self._joinChar, constant=True)
|
joinChar = Property(str, lambda self: self._joinChar, constant=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class StringParam(Param):
|
class StringParam(Param):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
|
39
meshroom/nodes/test/TestAttributeType.py
Normal file
39
meshroom/nodes/test/TestAttributeType.py
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
""" Input node that creates custom attributes inheriting from existing ones.
|
||||||
|
"""
|
||||||
|
__version__ = "1.0"
|
||||||
|
|
||||||
|
# Meshroom
|
||||||
|
from meshroom.core import desc, custom
|
||||||
|
|
||||||
|
class TestAttributeType(desc.InputNode):
|
||||||
|
documentation = """ Test node to access the frame that is currently selected in the gallery from a node. """
|
||||||
|
category = 'Test/Bidule'
|
||||||
|
|
||||||
|
# Inputs to the node
|
||||||
|
inputs = [
|
||||||
|
custom.JobParam(
|
||||||
|
name="jobParam",
|
||||||
|
label="Test Job Param",
|
||||||
|
description="Random choice param with a hard-coded default list that will be updated dynamically\n"
|
||||||
|
"with a global update function defined at the attribute level.",
|
||||||
|
value="a",
|
||||||
|
values=["a", "b"],
|
||||||
|
exclusive=True,
|
||||||
|
uid=[0],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
# Output which the node provides
|
||||||
|
outputs = [
|
||||||
|
desc.File(
|
||||||
|
name="fullPath",
|
||||||
|
label="Current Frame Full Path",
|
||||||
|
description="Full path of the frame that is currently selected in the gallery.",
|
||||||
|
value="",
|
||||||
|
uid=[],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
def onJobParamChanged(self, node):
|
||||||
|
print("On JobParamChanged")
|
||||||
|
node.jobParam.update()
|
Loading…
Add table
Reference in a new issue