Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
from gaphas.guide import GuidedItemInMotion
from gaphor.core import inject, Transaction, transactional
from gaphor.diagram.interfaces import IEditor, IConnect, IGroup
from gaphor.diagram.diagramline import DiagramLine
from gaphor.diagram.elementitem import ElementItem
# cursor to indicate grouping
IN_CURSOR = gtk.gdk.Cursor(gtk.gdk.DIAMOND_CROSS)
# cursor to indicate ungrouping
OUT_CURSOR = gtk.gdk.Cursor(gtk.gdk.SIZING)
@Connector.when_type(DiagramLine)
class DiagramItemConnector(Connector.default):
"""
Handle Tool (acts on item handles) that uses the IConnect protocol
to connect items to one-another.
It also adds handles to lines when a line is grabbed on the middle of
a line segment (points are drawn by the LineSegmentPainter).
"""
def allow(self, sink):
adapter = component.queryMultiAdapter((sink.item, self.item), IConnect)
return adapter and adapter.allow(self.handle, sink.port)
@transactional
def connect(self, sink):
from gaphor.core import Transaction, transactional
from gaphor.diagram.connectors import IConnect
from gaphor.diagram.grouping import Group
from gaphor.diagram.inlineeditors import InlineEditor
from gaphor.diagram.presentation import ElementPresentation, LinePresentation
# cursor to indicate grouping
IN_CURSOR_TYPE = Gdk.CursorType.DIAMOND_CROSS
# cursor to indicate ungrouping
OUT_CURSOR_TYPE = Gdk.CursorType.CROSSHAIR
log = logging.getLogger(__name__)
@Connector.register(LinePresentation)
class DiagramItemConnector(ItemConnector):
"""
Handle Tool (acts on item handles) that uses the IConnect protocol
to connect items to one-another.
It also adds handles to lines when a line is grabbed on the middle of
a line segment (points are drawn by the LineSegmentPainter).
"""
def allow(self, sink):
adapter = IConnect(sink.item, self.item)
return adapter and adapter.allow(self.handle, sink.port)
@transactional
def connect(self, 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)
def _postload_connect(self, handle, item):
"""
Postload connect method.
"""
from gaphas.aspect import Connector
connector = Connector(self, handle)
sink = self._get_sink(handle, item)
connector.connect(sink)
def postload_connect(handle, item):
connector = gaphas.aspect.Connector(self, handle)
sink = get_sink(handle, item)
connector.connect(sink)