mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-29 18:27:23 +02:00
[core] Add support for lambda function in Attribute desc value
Allows to dynamically configure the default value of the Attribute in python.
This commit is contained in:
parent
05a93c28a2
commit
bbc56cfb31
2 changed files with 7 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
|||
import collections
|
||||
import re
|
||||
import weakref
|
||||
import types
|
||||
|
||||
from meshroom.common import BaseObject, Property, Variant, Signal, ListModel, DictModel, Slot
|
||||
from meshroom.core import desc, pyCompatibility, hashValue
|
||||
|
@ -189,7 +190,7 @@ class Attribute(BaseObject):
|
|||
if self.isLink:
|
||||
return self.getLinkParam().asLinkExpr()
|
||||
if self.isOutput:
|
||||
return self.desc.value
|
||||
return self.defaultValue()
|
||||
return self._value
|
||||
|
||||
def getValueStr(self):
|
||||
|
@ -201,6 +202,8 @@ class Attribute(BaseObject):
|
|||
return str(self.value)
|
||||
|
||||
def defaultValue(self):
|
||||
if isinstance(self.desc.value, types.FunctionType):
|
||||
return self.desc.value(self)
|
||||
return self.desc.value
|
||||
|
||||
def _isDefault(self):
|
||||
|
|
|
@ -583,8 +583,9 @@ class BaseNode(BaseObject):
|
|||
if not isinstance(attr.attributeDesc, desc.File):
|
||||
continue
|
||||
|
||||
attr.value = attr.attributeDesc.value.format(**self._cmdVars)
|
||||
attr._invalidationValue = attr.attributeDesc.value.format(**cmdVarsNoCache)
|
||||
defaultValue = attr.defaultValue()
|
||||
attr.value = defaultValue.format(**self._cmdVars)
|
||||
attr._invalidationValue = defaultValue.format(**cmdVarsNoCache)
|
||||
v = attr.getValueStr()
|
||||
|
||||
self._cmdVars[name] = '--{name} {value}'.format(name=name, value=v)
|
||||
|
|
Loading…
Add table
Reference in a new issue