Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
TODO: figure out if part of this functionality can be provided by
the storage code.
"""
from gaphas.aspect import ConnectionSink
hpos = self.canvas.get_matrix_i2i(self, item).transform_point(*handle.pos)
port = None
dist = 10e6
for p in item.ports():
pos, d = p.glue(hpos)
if not port or d < dist:
port = p
dist = d
return ConnectionSink(item, port)
def get_sink(handle, item):
assert self.canvas
hpos = self.canvas.get_matrix_i2i(self, item).transform_point(*handle.pos)
port = None
dist = 10e6
for p in item.ports():
pos, d = p.glue(hpos)
if not port or d < dist:
port = p
dist = d
return gaphas.aspect.ConnectionSink(item, port)
def connect(self, line, handle, item, port=None):
"""
Connect line's handle to an item.
If port is not provided, then first port is used.
"""
canvas = line.canvas
if port is None and len(item.ports()) > 0:
port = item.ports()[0]
sink = ConnectionSink(item, port)
connector = Connector(line, handle)
connector.connect(sink)
def connect(self, line, handle, item, port=None):
"""
Connect line's handle to an item.
If port is not provided, then first port is used.
"""
canvas = line.canvas
if port is None and len(item.ports()) > 0:
port = item.ports()[0]
sink = ConnectionSink(item, port)
connector = Connector(line, handle)
connector.connect(sink)
if distance is None:
distance = self.GLUE_DISTANCE
if not handle.connectable:
return None
state_v, port, glue_pos = view.get_port_at_point(pos, distance=distance, exclude=(item,),
exclude_port_fun=self._exclude_port)
# check if item and found item can be connected on closest port
if port is not None:
assert state_v is not None
connector = Connector(self.item, self.handle)
sink = ConnectionSink(state_v, port)
if connector.allow(sink):
# transform coordinates from view space to the item space and
# update position of item's handle
v2i = view.get_matrix_v2i(item).transform_point
handle.pos = v2i(*glue_pos)
return sink
return None