Socket shapes
Socket shapes decide how a socket is painted and where it can be clicked. See the socket shapes guide for usage.
nodeeditor.node_socket_shapes ¶
A module containing the Socket Shape system.
A socket shape decides two things: how a :class:~nodeeditor.node_socket.Socket
is painted, and which area of it counts as a hit. Four presets ship with the
library (circle, square, triangle, chevron) and applications
can register their own.
Shapes are named per socket type by the owning node (see
:meth:~nodeeditor.node_node.Node.getSocketShapeName), so they are declared in
code and never written to the graph file.
SocketShapeContext ¶
Everything a shape needs while it paints itself.
SocketShape ¶
Base class for socket shapes.
Subclasses describe their outline as a list of points normalized against the socket radius, and get the hit-test path and the painting for free.
points ¶
The outline as normalized points, in units of the socket radius.
:return: list of (x, y) pairs
path ¶
The outline as a path, centered on the item origin.
:param radius: the socket's radius in scene units
:param direction: +1 for output sockets, -1 for input sockets
:return: the outline path
draw ¶
Paint the shape.
:param painter: the QPainter to draw into
:param ctx: the :class:SocketShapeContext for this paint
CircleShape ¶
Bases: SocketShape
The classic socket: a filled circle.
path ¶
The circle as a path, centered on the item origin.
:param radius: the socket's radius in scene units :param direction: ignored, a circle looks the same on both sides :return: the outline path
SquareShape ¶
Bases: SocketShape
A square socket.
The half side is 0.85 * radius, which reads as the same weight as the
circle next to it.
points ¶
The square's four corners, in units of the socket radius.
:return: list of (x, y) pairs
TriangleShape ¶
Bases: SocketShape
A triangular socket.
The tip points away from the node: right on an output socket, left on an input socket.
points ¶
The triangle's three corners, in units of the socket radius.
The tip points right, so the outline mirrors on input sockets.
:return: list of (x, y) pairs
ChevronShape ¶
Bases: SocketShape
A chevron socket: the concave hexagon, pointing right.
The shape never mirrors, on either side of a node. A chevron on an input socket aims its tip into the node, so the two sides of a graph read as one left-to-right flow: in, processed, out.
points ¶
The chevron's six corners, in units of the socket radius.
:return: list of (x, y) pairs
CallbackShape ¶
Bases: SocketShape
Wraps a plain fn(painter, ctx) callback as a shape.
A callback only knows how to draw, not what its outline is, so the hit area falls back to the circle.
path ¶
The circle used as the hit area of a callback shape.
:param radius: the socket's radius in scene units :param direction: ignored, the fallback outline is always a circle :return: the outline path
draw ¶
Paint the shape by handing the paint over to the wrapped callback.
:param painter: the QPainter to draw into
:param ctx: the :class:SocketShapeContext for this paint
register_socket_shape ¶
Register a socket shape under name.
shape may be a :class:SocketShape instance, a :class:SocketShape
subclass, or a plain callable fn(painter, ctx). Registering an existing
name replaces the old shape.
:param name: the name nodes use to select this shape :param shape: the shape, its class, or a drawing callback :return: the registered shape
get_socket_shape ¶
The shape registered under name.
Unknown names fall back to the circle rather than raising, so a typo in a node's shape map cannot break a graph.
:param name: the registered shape name :return: the shape to draw with