-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[ui] Graph Editor Update: Quick Node Coloring with the Color Selector Tool #2604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
58a9b74
d77b7a3
418bd63
233bbb7
225f4dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -556,6 +556,15 @@ def getColor(self): | |
| 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: | ||
|
|
@@ -967,7 +976,7 @@ def _onAttributeChanged(self, attr: Attribute): | |
| 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 | ||
|
|
@@ -1356,7 +1365,7 @@ def hasSequenceOutputAttribute(self): | |
| 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 | ||
|
|
@@ -1386,7 +1395,7 @@ def has3DOutputAttribute(self): | |
| internalAttributes = Property(BaseObject, getInternalAttributes, constant=True) | ||
| internalAttributesChanged = Signal() | ||
| label = Property(str, getLabel, notify=internalAttributesChanged) | ||
| color = Property(str, getColor, notify=internalAttributesChanged) | ||
| color = Property(str, getColor, setColor, notify=internalAttributesChanged) | ||
|
||
| invalidation = Property(str, getInvalidationMessage, notify=internalAttributesChanged) | ||
| comment = Property(str, getComment, notify=internalAttributesChanged) | ||
| internalFolderChanged = Signal() | ||
|
|
@@ -1909,7 +1918,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())): | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -952,6 +952,17 @@ def selectFollowing(self, node): | |||||
| """ Select all the nodes the depend on 'node'. """ | ||||||
| self.selectNodes(self._graph.dfsOnDiscover(startNodes=[node], reverse=True, dependenciesOnly=True)[0]) | ||||||
|
|
||||||
| @Slot(str) | ||||||
| def updateNodeColor(self, color): | ||||||
|
||||||
| def updateNodeColor(self, color): | |
| def setSelectedNodesColor(self, color: str): |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the command name that appears in the undo stack:
| with self.groupedGraphModification("Update Color for Select Nodes"): | |
| with self.groupedGraphModification("Set Nodes Color"): |
I think we could go with removing the notion of "selected" in those, as selection operations are not undoable - therefore, undoing "Set Selected Nodes Color" is a bit ambiguous if the selection has changed in between.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, makes sense, I probably did not notice this while working on the previous comments. Thanks for the suggestion.
yann-lty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import QtQuick | ||
| import QtQuick.Controls | ||
|
|
||
| import Utils 1.0 | ||
| import MaterialIcons 2.2 | ||
|
|
||
| /** | ||
| * ColorSelector is a color picker based on a set of predefined colors. | ||
| * It takes the form of a ToolButton that pops-up its palette when pressed. | ||
| */ | ||
| MaterialToolButton { | ||
| id: root | ||
|
|
||
| text: MaterialIcons.palette | ||
|
|
||
| // Internal property holding when the popup remains visible and when is it toggled off | ||
| property var isVisible: false | ||
|
|
||
| property var colors: [ | ||
yann-lty marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "#FF6600", | ||
| "#FFAD7D", | ||
| "#FFF82F", | ||
| "#FFFB8B", | ||
| "#BDFF07", | ||
| "#E8FF97", | ||
| "#0BFFCA", | ||
| "#8EFFF7", | ||
| "#1158FF", | ||
| "#77A7FF", | ||
| "#9318FF", | ||
| "#EAACFF", | ||
| "#B61518", | ||
| "#FF989A", | ||
| ] | ||
|
|
||
| // When a color gets selected/choosen | ||
| signal colorSelected(var color) | ||
|
|
||
| // Toggles the visibility of the popup | ||
| onPressed: toggle() | ||
|
|
||
| function toggle() { | ||
| /* | ||
| * Toggles the visibility of the color palette. | ||
| */ | ||
| if (!isVisible) { | ||
| palettePopup.open() | ||
| isVisible = true | ||
| } | ||
| else { | ||
| palettePopup.close() | ||
| isVisible = false | ||
| } | ||
| } | ||
|
|
||
| // Popup for the color palette | ||
| Popup { | ||
| id: palettePopup | ||
|
|
||
| // The popup will not get closed unless explicitly closed | ||
| closePolicy: Popup.NoAutoClose | ||
|
|
||
| // Bounds | ||
| padding: 4 | ||
| width: (root.height * 4) + (padding * 4) | ||
|
|
||
| // center the current color | ||
| y: -height | ||
| x: -width + root.width + padding | ||
|
|
||
| // Layout of the Colors | ||
| Grid { | ||
| // Allow only 4 columns and all the colors can be adjusted in row multiples of 4 | ||
| columns: 4 | ||
|
|
||
| spacing: 2 | ||
| anchors.centerIn: parent | ||
|
|
||
| // Default -- Reset Colour button | ||
| ToolButton { | ||
| id: defaultButton | ||
| padding: 0 | ||
| width: root.height | ||
| height: root.height | ||
|
|
||
| // Emit no color so the graph sets None as the color of the Node | ||
| onClicked: { | ||
| root.colorSelected("") | ||
| } | ||
|
|
||
| background: Rectangle { | ||
| color: "#FFFFFF" | ||
| // display border of current/selected item | ||
| border.width: defaultButton.hovered ? 1 : 0 | ||
| border.color: "#000000" | ||
|
|
||
| // Another Rectangle | ||
| Rectangle { | ||
| color: "#FF0000" | ||
| width: parent.width + 8 | ||
| height: 2 | ||
| anchors.centerIn: parent | ||
| rotation: 135 // Diagonally creating a Red line from bottom left to top right | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Colors palette | ||
| Repeater { | ||
| model: root.colors | ||
| // display each color as a ToolButton with a custom background | ||
| delegate: ToolButton { | ||
| padding: 0 | ||
| width: root.height | ||
| height: root.height | ||
|
|
||
| // Emit the model data as the color to update | ||
| onClicked: { | ||
| colorSelected(modelData) | ||
| } | ||
|
|
||
| // Model color as the background of the button | ||
| background: Rectangle { | ||
| color: modelData | ||
| // display border of current/selected item | ||
| border.width: hovered ? 1 : 0 | ||
| border.color: "#000000" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,8 @@ Item { | |
| Keys.onPressed: function(event) { | ||
| if (event.key === Qt.Key_F) { | ||
| fit() | ||
| } else if (event.key === Qt.Key_C) { | ||
|
||
| colorSelector.toggle() | ||
| } else if (event.key === Qt.Key_Delete) { | ||
| if (event.modifiers === Qt.AltModifier) { | ||
| uigraph.removeNodesFrom(uigraph.selectedNodes) | ||
|
|
@@ -1048,6 +1050,24 @@ Item { | |
| } | ||
| } | ||
| } | ||
|
|
||
| // Separator | ||
| Rectangle { | ||
| Layout.fillHeight: true | ||
| Layout.margins: 2 | ||
| implicitWidth: 1 | ||
| color: activePalette.window | ||
| } | ||
|
|
||
| ColorSelector { | ||
| id: colorSelector | ||
| Layout.minimumWidth: colorSelector.width | ||
|
|
||
| // When a Color is selected | ||
| onColorSelected: (color)=> { | ||
| uigraph.updateNodeColor(color) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With regards to what this PR is addressing, adding the setter for this property is not needed.