Node editor

A node editor like the shader graph or Blender’s:
examples/dnd/node_editor.py.
python examples/dnd/node_editor.py-
Nodes are draggables on a canvas, moved by their title (
handle=Trueand apz.drag_handlearound the title). The canvas is a droppable that accepts"node", with a 10-pixel grid:title = pz.drag_handle(pz.container(ui.label(n["title"], weight="bold"), padding=(6, 10)))node = pz.draggable(body, key, type="node", handle=True, source="hide", lift=1.0, drop_animation=0)graph = pz.droppable(pz.stack([self.wires(), *nodes]), "graph", accepts="node", snap=10,on_drop=self.move_node) -
Outputs drag wires. An output port is a draggable with
preview="wire", typed by what it carries:pz.draggable(self.dot(kind), f"out/{node}/{name}", data=(node, name), type=f"port:{kind}",preview="wire", wire_color=TYPE_COLORS[kind]) -
Inputs take matching wires. An input accepts its own type, and
can_dropforbids wires from the same node:pz.droppable(self.dot(kind), f"in/{node}/{name}", accepts=f"port:{kind}",can_drop=lambda e, n=node: e.data[0] != n, on_drop=self.connect) -
Links are data.
connectstores the link (one per input) andwires()draws every link as a curve withpz.canvas, from the port positions.
Right-clicking an input unplugs it.