Add "color" as an internal attribute

Setting this attribute allows the user to change the color
of a node, either by directly providing an SVG color name or an
hexadecimal color code, or by picking a color with the selector.
This commit is contained in:
Candice Bentéjac 2022-08-02 14:16:11 +02:00
parent 330382ab0c
commit 21d01acc9a
4 changed files with 98 additions and 1 deletions

View file

@ -532,6 +532,15 @@ class BaseNode(BaseObject):
return label
return self.nameToLabel(self._name)
def getColor(self):
"""
Returns:
str: the user-provided custom color of the node if it exists, empty string otherwise
"""
if self.hasInternalAttribute("color"):
return self.internalAttribute("color").value.strip()
return ""
@Slot(str, result=str)
def nameToLabel(self, name):
"""
@ -1088,6 +1097,7 @@ class BaseNode(BaseObject):
name = Property(str, getName, constant=True)
label = Property(str, getLabel, constant=True)
color = Property(str, getColor, constant=True)
nodeType = Property(str, nodeType.fget, constant=True)
documentation = Property(str, getDocumentation, constant=True)
positionChanged = Signal()