Re-fixed graph selection logic
This commit is contained in:
parent
2c2ea67775
commit
2d9d791237
67
borealis.py
67
borealis.py
@ -7,26 +7,53 @@ import pkgutil
|
|||||||
import importlib
|
import importlib
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
# Patch QGraphicsScene.setSelectionArea to handle selection arguments
|
# --- BEGIN MONKEY PATCH FOR PIPE COLOR (Optional) ---
|
||||||
|
# If you want custom pipe colors, uncomment this patch:
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
from OdenGraphQt.qgraphics.pipe import PipeItem
|
||||||
|
|
||||||
|
_orig_pipeitem_init = PipeItem.__init__
|
||||||
|
|
||||||
|
def _new_pipeitem_init(self, *args, **kwargs):
|
||||||
|
_orig_pipeitem_init(self, *args, **kwargs)
|
||||||
|
new_color = QtGui.QColor(29, 202, 151)
|
||||||
|
self._pen = QtGui.QPen(new_color, 2.0)
|
||||||
|
self._pen_dragging = QtGui.QPen(new_color, 2.0)
|
||||||
|
|
||||||
|
PipeItem.__init__ = _new_pipeitem_init
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
print("WARNING: Could not patch PipeItem color - OdenGraphQt.qgraphics.pipe not found.")
|
||||||
|
"""
|
||||||
|
# --- END MONKEY PATCH FOR PIPE COLOR ---
|
||||||
|
|
||||||
|
# --- BEGIN ROBUST PATCH FOR QGraphicsScene.setSelectionArea ---
|
||||||
_original_setSelectionArea = QtWidgets.QGraphicsScene.setSelectionArea
|
_original_setSelectionArea = QtWidgets.QGraphicsScene.setSelectionArea
|
||||||
|
|
||||||
def _patched_setSelectionArea(self, painterPath, second_arg, *args, **kwargs):
|
def _patched_setSelectionArea(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
A robust patch that handles various call signatures for QGraphicsScene.setSelectionArea().
|
||||||
|
We try calling the original method with whatever arguments are provided.
|
||||||
|
If a TypeError occurs, we assume it was missing some arguments and re-call with defaults.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
# Try calling the original method with the provided arguments.
|
# First, try the original call with the given arguments.
|
||||||
return _original_setSelectionArea(self, painterPath, second_arg, *args, **kwargs)
|
return _original_setSelectionArea(self, *args, **kwargs)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# If a TypeError is raised, assume the call was made with only a QPainterPath
|
# If a TypeError occurs, the caller likely used a minimal signature.
|
||||||
# and an ItemSelectionMode, and patch it by supplying defaults.
|
# We'll fallback to a known signature with default arguments.
|
||||||
# Default operation: ReplaceSelection, default transform: QTransform()
|
if not args:
|
||||||
return _original_setSelectionArea(
|
raise # If no args at all, we cannot fix it.
|
||||||
self,
|
|
||||||
painterPath,
|
painterPath = args[0] # QPainterPath
|
||||||
QtCore.Qt.ReplaceSelection,
|
selection_op = QtCore.Qt.ReplaceSelection
|
||||||
second_arg,
|
selection_mode = QtCore.Qt.IntersectsItemShape
|
||||||
QtGui.QTransform()
|
transform = QtGui.QTransform()
|
||||||
)
|
return _original_setSelectionArea(self, painterPath, selection_op, selection_mode, transform)
|
||||||
|
|
||||||
QtWidgets.QGraphicsScene.setSelectionArea = _patched_setSelectionArea
|
QtWidgets.QGraphicsScene.setSelectionArea = _patched_setSelectionArea
|
||||||
|
# --- END ROBUST PATCH FOR QGraphicsScene.setSelectionArea ---
|
||||||
|
|
||||||
from OdenGraphQt import NodeGraph, BaseNode
|
from OdenGraphQt import NodeGraph, BaseNode
|
||||||
|
|
||||||
@ -53,7 +80,7 @@ def make_node_command(graph, node_type_str):
|
|||||||
pos = graph.cursor_pos()
|
pos = graph.cursor_pos()
|
||||||
graph.create_node(node_type_str, pos=pos)
|
graph.create_node(node_type_str, pos=pos)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error creating node of type {}: {}".format(node_type_str, e))
|
print(f"Error creating node of type {node_type_str}: {e}")
|
||||||
return command
|
return command
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -71,10 +98,10 @@ if __name__ == "__main__":
|
|||||||
# Add context menu commands for dynamic node creation.
|
# Add context menu commands for dynamic node creation.
|
||||||
graph_context_menu = graph.get_context_menu("graph")
|
graph_context_menu = graph.get_context_menu("graph")
|
||||||
for node_class in custom_nodes:
|
for node_class in custom_nodes:
|
||||||
node_type = "{}.{}".format(node_class.__identifier__, node_class.__name__)
|
node_type = f"{node_class.__identifier__}.{node_class.__name__}"
|
||||||
node_name = node_class.NODE_NAME
|
node_name = node_class.NODE_NAME
|
||||||
graph_context_menu.add_command(
|
graph_context_menu.add_command(
|
||||||
"Add {}".format(node_name),
|
f"Add {node_name}",
|
||||||
make_node_command(graph, node_type)
|
make_node_command(graph, node_type)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -92,14 +119,12 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# Optionally, create a subtle gradient in the scene:
|
# Optionally, create a subtle gradient in the scene:
|
||||||
scene = graph.scene()
|
scene = graph.scene()
|
||||||
|
|
||||||
# A QLinearGradient that uses ObjectBoundingMode so it stretches to fill the scene.
|
|
||||||
gradient = QtGui.QLinearGradient(0, 0, 0, 1)
|
gradient = QtGui.QLinearGradient(0, 0, 0, 1)
|
||||||
gradient.setCoordinateMode(QtGui.QGradient.ObjectBoundingMode)
|
gradient.setCoordinateMode(QtGui.QGradient.ObjectBoundingMode)
|
||||||
gradient.setColorAt(0.0, QtGui.QColor(9, 44, 68)) # Very Top Gradient
|
gradient.setColorAt(0.0, QtGui.QColor(9, 44, 68)) # Very Top Gradient
|
||||||
gradient.setColorAt(0.3, QtGui.QColor(30, 30, 30)) # Middle Gradient
|
gradient.setColorAt(0.3, QtGui.QColor(30, 30, 30)) # Middle Gradient
|
||||||
gradient.setColorAt(0.7, QtGui.QColor(30, 30, 30)) # Middle Gradient
|
gradient.setColorAt(0.7, QtGui.QColor(30, 30, 30)) # Middle Gradient
|
||||||
gradient.setColorAt(1.0, QtGui.QColor(9, 44, 68)) # Very Bottom Gradient
|
gradient.setColorAt(1.0, QtGui.QColor(9, 44, 68)) # Very Bottom Gradient
|
||||||
scene.setBackgroundBrush(QtGui.QBrush(gradient))
|
scene.setBackgroundBrush(QtGui.QBrush(gradient))
|
||||||
|
|
||||||
# Resize and show the graph widget.
|
# Resize and show the graph widget.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user