Added dynamic on-the-fly backdrop node renaming.
This commit is contained in:
parent
2e5fbad9be
commit
2ee93ca374
Binary file not shown.
@ -1,16 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from Qt import QtWidgets, QtGui
|
||||
from Qt import QtWidgets, QtGui, QtCore
|
||||
from OdenGraphQt import BaseNode
|
||||
from OdenGraphQt.constants import NodePropWidgetEnum
|
||||
from OdenGraphQt.qgraphics.node_backdrop import BackdropNodeItem
|
||||
|
||||
|
||||
class BackdropNode(BaseNode):
|
||||
"""
|
||||
Backdrop Node:
|
||||
- Allows grouping or annotating other nodes by resizing a large rectangle.
|
||||
- Provides a custom context menu for renaming and recoloring (via on_context_menu).
|
||||
- Title is set by double-clicking in the title area.
|
||||
"""
|
||||
|
||||
__identifier__ = 'bunny-lab.io.backdrop'
|
||||
@ -23,6 +22,9 @@ class BackdropNode(BaseNode):
|
||||
# Default color (teal).
|
||||
self.model.color = (5, 129, 138, 255)
|
||||
|
||||
# Set default title without prompting:
|
||||
self.set_name("Double-Click to Add Name to Backdrop")
|
||||
|
||||
# Multi-line text property for storing the backdrop text.
|
||||
self.create_property(
|
||||
'backdrop_text',
|
||||
@ -31,6 +33,24 @@ class BackdropNode(BaseNode):
|
||||
tab='Backdrop'
|
||||
)
|
||||
|
||||
# Override the view's double-click event to allow editing the title.
|
||||
original_double_click = self.view.mouseDoubleClickEvent
|
||||
|
||||
def new_double_click_event(event):
|
||||
# Assume the title is in the top 30 pixels of the node.
|
||||
if event.pos().y() < 30:
|
||||
new_title, ok = QtWidgets.QInputDialog.getText(
|
||||
None, "Edit Title", "Enter new backdrop title:", text=self.name()
|
||||
)
|
||||
if ok and new_title:
|
||||
self.set_name(new_title)
|
||||
self.view.update() # force immediate update of the node title
|
||||
else:
|
||||
if original_double_click:
|
||||
original_double_click(event)
|
||||
|
||||
self.view.mouseDoubleClickEvent = new_double_click_event
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Resizing / Geometry
|
||||
# --------------------------------------------------------------------------
|
||||
@ -139,38 +159,3 @@ class BackdropNode(BaseNode):
|
||||
|
||||
def outputs(self):
|
||||
return
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Custom Context Menu
|
||||
# --------------------------------------------------------------------------
|
||||
def on_context_menu(self, menu):
|
||||
"""
|
||||
Called manually by the node context menu callback in older NodeGraphQt versions.
|
||||
"""
|
||||
rename_action = menu.addAction("Set Title...")
|
||||
rename_action.triggered.connect(self._change_title)
|
||||
|
||||
color_action = menu.addAction("Set Color...")
|
||||
color_action.triggered.connect(self._change_color)
|
||||
|
||||
def _change_title(self):
|
||||
"""
|
||||
Prompt for a new backdrop title (header).
|
||||
"""
|
||||
new_title, ok = QtWidgets.QInputDialog.getText(
|
||||
None, "Backdrop Title", "Enter new backdrop title:"
|
||||
)
|
||||
if ok and new_title:
|
||||
self.set_name(new_title)
|
||||
|
||||
def _change_color(self):
|
||||
"""
|
||||
Prompt for a new backdrop color via QColorDialog.
|
||||
"""
|
||||
current_color = QtGui.QColor(*self.model.color)
|
||||
color = QtWidgets.QColorDialog.getColor(
|
||||
current_color, None, "Select Backdrop Color"
|
||||
)
|
||||
if color.isValid():
|
||||
self.model.color = (color.red(), color.green(), color.blue(), color.alpha())
|
||||
self.view.update()
|
||||
|
Loading…
x
Reference in New Issue
Block a user