mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-28 17:57:16 +02:00
[ui] Graph: Updating the way how color gets set on the selected nodes
Coloring the nodes now uses setAttribute command instead of relying on refrences to Nodes within the graph.
This commit is contained in:
parent
418bd638ad
commit
233bbb76c8
4 changed files with 11 additions and 65 deletions
|
@ -556,15 +556,6 @@ class BaseNode(BaseObject):
|
|||
return self.internalAttribute("color").value.strip()
|
||||
return ""
|
||||
|
||||
def setColor(self, color: str):
|
||||
""" Sets the color of the Node.
|
||||
|
||||
Args:
|
||||
color (str): The hex of the color to set on the node.
|
||||
"""
|
||||
if self.hasInternalAttribute("color"):
|
||||
self.internalAttribute("color").value = color
|
||||
|
||||
def getInvalidationMessage(self):
|
||||
"""
|
||||
Returns:
|
||||
|
@ -976,7 +967,7 @@ class BaseNode(BaseObject):
|
|||
if attr.value is None:
|
||||
# Discard dynamic values depending on the graph processing.
|
||||
return
|
||||
|
||||
|
||||
if self.graph and self.graph.isLoading:
|
||||
# Do not trigger attribute callbacks during the graph loading.
|
||||
return
|
||||
|
@ -1365,7 +1356,7 @@ class BaseNode(BaseObject):
|
|||
False otherwise.
|
||||
"""
|
||||
for attr in self._attributes:
|
||||
if attr.enabled and attr.isOutput and (attr.desc.semantic == "sequence" or
|
||||
if attr.enabled and attr.isOutput and (attr.desc.semantic == "sequence" or
|
||||
attr.desc.semantic == "imageList"):
|
||||
return True
|
||||
return False
|
||||
|
@ -1395,7 +1386,7 @@ class BaseNode(BaseObject):
|
|||
internalAttributes = Property(BaseObject, getInternalAttributes, constant=True)
|
||||
internalAttributesChanged = Signal()
|
||||
label = Property(str, getLabel, notify=internalAttributesChanged)
|
||||
color = Property(str, getColor, setColor, notify=internalAttributesChanged)
|
||||
color = Property(str, getColor, notify=internalAttributesChanged)
|
||||
invalidation = Property(str, getInvalidationMessage, notify=internalAttributesChanged)
|
||||
comment = Property(str, getComment, notify=internalAttributesChanged)
|
||||
internalFolderChanged = Signal()
|
||||
|
@ -1918,7 +1909,7 @@ def nodeFactory(nodeDict, name=None, template=False, uidConflict=False):
|
|||
# do not perform that check for internal attributes because there is no point in
|
||||
# raising compatibility issues if their number differs: in that case, it is only useful
|
||||
# if some internal attributes do not exist or are invalid
|
||||
if not template and (sorted([attr.name for attr in nodeDesc.inputs
|
||||
if not template and (sorted([attr.name for attr in nodeDesc.inputs
|
||||
if not isinstance(attr, desc.PushButtonParam)]) != sorted(inputs.keys()) or
|
||||
sorted([attr.name for attr in nodeDesc.outputs if not attr.isDynamicValue]) !=
|
||||
sorted(outputs.keys())):
|
||||
|
|
|
@ -205,54 +205,6 @@ class DuplicateNodesCommand(GraphCommand):
|
|||
self.graph.removeNode(duplicate)
|
||||
|
||||
|
||||
class UpdateNodeColorCommand(GraphCommand):
|
||||
""" Command representing the work for Coloring nodes in the Graph.
|
||||
"""
|
||||
|
||||
def __init__(self, graph, nodes, color, parent=None):
|
||||
""" Command Constructor.
|
||||
|
||||
Args:
|
||||
graph (meshroom.core.Graph): Current Graph instance.
|
||||
nodes (list<Node>): Array of nodes.
|
||||
color (str): Hex code for the color.
|
||||
|
||||
Keyword Args:
|
||||
parent (QObject): Parent QObject instance.
|
||||
"""
|
||||
super(UpdateNodeColorCommand, self).__init__(graph, parent)
|
||||
self._nodes = nodes
|
||||
self._color = color
|
||||
|
||||
# Existing colors
|
||||
# Map <Node: str>
|
||||
# Holds the existing color of the node which can be applied on the node back in case of an undo
|
||||
self._colorMap = {}
|
||||
|
||||
self.setText("Update Selected Node Color")
|
||||
|
||||
def redoImpl(self) -> bool:
|
||||
""" Redo implementation.
|
||||
"""
|
||||
for node in self._nodes:
|
||||
# Update the existing color for the node in the map
|
||||
self._colorMap[node] = node.color
|
||||
|
||||
# Now update the color of the node with the provided one
|
||||
node.color = self._color
|
||||
|
||||
return True
|
||||
|
||||
def undoImpl(self):
|
||||
""" Undo Implementation.
|
||||
"""
|
||||
with GraphModification(self.graph):
|
||||
# Revert the color for the nodes
|
||||
for node in self._nodes:
|
||||
# Get the color which was saved for the node
|
||||
node.color = self._colorMap.get(node)
|
||||
|
||||
|
||||
class PasteNodesCommand(GraphCommand):
|
||||
"""
|
||||
Handle node pasting in a Graph.
|
||||
|
|
|
@ -953,15 +953,18 @@ class UIGraph(QObject):
|
|||
self.selectNodes(self._graph.dfsOnDiscover(startNodes=[node], reverse=True, dependenciesOnly=True)[0])
|
||||
|
||||
@Slot(str)
|
||||
def updateNodeColor(self, color):
|
||||
def setSelectedNodesColor(self, color: str):
|
||||
""" Sets the Provided color on the selected Nodes.
|
||||
|
||||
Args:
|
||||
color (str): Hex code of the color to be set on the nodes.
|
||||
"""
|
||||
# Update the color attribute of the nodes which are currently selected
|
||||
with self.groupedGraphModification("Update Color for Select Nodes"):
|
||||
self.push(commands.UpdateNodeColorCommand(self._graph, list(self._selectedNodes), color))
|
||||
with self.groupedGraphModification("Set Nodes Color"):
|
||||
# For each of the selected nodes -> Check if the node has a color -> Apply the color if it has
|
||||
for node in self._selectedNodes:
|
||||
if node.hasInternalAttribute("color"):
|
||||
self.setAttribute(node.internalAttribute("color"), color)
|
||||
|
||||
@Slot(QObject, QObject)
|
||||
def boxSelect(self, selection, draggable):
|
||||
|
|
|
@ -1065,7 +1065,7 @@ Item {
|
|||
|
||||
// When a Color is selected
|
||||
onColorSelected: (color)=> {
|
||||
uigraph.updateNodeColor(color)
|
||||
uigraph.setSelectedNodesColor(color)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue