Handles and Ports¶
To connect one item to another, you need something to connect, and something to connect to.
These roles are fulfilled by Handle
and Port
.
The Handle is an item you normally see on screen as a small square, eiter green or red. Although the actual shape depends on the Painter used.
Ports represent the receiving side. A port decides if it wants a connection with a handle. If it does, a constraint can be created and this constraint will be managed by a Connections instance. It is not uncommon to create special ports to suite your application’s behavior, whereas Handles are rarely subtyped.
Handle¶
- class gaphas.connector.Handle(pos: Tuple[float, float] = (0, 0), strength: int = 20, connectable: bool = False, movable: bool = True)[source]¶
Handles are used to support modifications of Items.
If the handle is connected to an item, the
connected_to
property should refer to the item. Adisconnect
handler should be provided that handles all disconnect behaviour (e.g. clean up constraints andconnected_to
).Note for those of you that use the Pickle module to persist a canvas: The property
disconnect
should contain a callable object (with __call__() method), so the pickle handler can also pickle that. Pickle is not capable of picklinginstancemethod
orfunction
objects.- property pos¶
The Handle’s position
- property connectable¶
Can this handle actually connectect to a port?
- property movable¶
Can this handle be moved by a mouse pointer?
- property visible¶
Is this handle visible to the user?
Port¶
The Port
class. There are two default implementations: LinePort
and PointPort
.
- class gaphas.connector.Port[source]¶
Port connectable part of an item.
The Item’s handle connects to a port.
- class gaphas.connector.LinePort(start: gaphas.position.Position, end: gaphas.position.Position)[source]¶
Port defined as a line between two handles.
- glue(pos: Tuple[SupportsFloat, SupportsFloat]) → Tuple[Tuple[float, float], float][source]¶
Get glue point on the port and distance to the port.
>>> p1, p2 = (0.0, 0.0), (100.0, 100.0) >>> port = LinePort(p1, p2) >>> port.glue((50, 50)) ((50.0, 50.0), 0.0) >>> port.glue((0, 10)) ((5.0, 5.0), 7.0710678118654755)
- class gaphas.connector.PointPort(point: gaphas.position.Position)[source]¶
Port defined as a point.