Fixed Node Spawn Positioning Issues

This commit is contained in:
Nicole Rappe 2025-02-15 23:53:57 -07:00
parent 6bac303dea
commit 2e5fbad9be
4 changed files with 45 additions and 7 deletions

Binary file not shown.

38
Nodes/blueprint_node.py Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env python3
from OdenGraphQt import BaseNode
from Qt import QtCore
class BlueprintNode(BaseNode):
"""
A placeholder node used to preview placement before spawning
the real node. It has a distinct color and minimal UI.
"""
__identifier__ = 'bunny-lab.io.blueprint'
NODE_NAME = 'Blueprint Node'
def __init__(self):
super(BlueprintNode, self).__init__()
# Display a name so the user sees "Click to Place Node"
self.set_name("Click to Place Node")
# Give it a bluish color + white text, for visibility
self.set_color(60, 120, 220) # R, G, B
self.view.text_color = (255, 255, 255, 200)
self.view.border_color = (255, 255, 255, 180)
# Make it slightly transparent if desired (alpha=150)
self.view._bg_color = (60, 120, 220, 150)
# Remove any default inputs/outputs (make it minimal)
for port in self.input_ports() + self.output_ports():
self.model.delete_port(port.name(), port.port_type)
# Store the "actual node" we want to spawn
self.create_property("actual_node_type", "", widget_type=0)
def process_input(self):
"""
We do nothing here; it is purely a placeholder node.
"""
pass

View File

@ -21,13 +21,11 @@ def _patched_setSelectionArea(self, painterPath, second_arg, *args, **kwargs):
# Monkey-patch the setSelectionArea method.
QtWidgets.QGraphicsScene.setSelectionArea = _patched_setSelectionArea
# --- End of patch section ---
import sys
import pkgutil
import importlib
import inspect
from Qt import QtWidgets, QtCore
from Qt import QtWidgets, QtCore, QtGui
from OdenGraphQt import NodeGraph, BaseNode
def import_nodes_from_folder(package_name):
@ -47,12 +45,14 @@ def import_nodes_from_folder(package_name):
def make_node_command(graph, nt):
"""
Given a NodeGraph instance and a node type string nt, return a command
function that creates a node of that type.
function that creates a node of that type at the current mouse location.
"""
def command():
try:
node = graph.create_node(nt)
# (No need to force top-level if nodes are created as top-level by default.)
# Get the current cursor position in scene coordinates
pos = graph.cursor_pos()
# Create the node with the current cursor position.
node = graph.create_node(nt, pos=pos)
except Exception as e:
print(f"Error creating node of type {nt}: {e}")
return command