Esempio n. 1
0
    @abc.abstractmethod
    def group(self) -> None:
        """Perform grouping of items."""

    @abc.abstractmethod
    def ungroup(self) -> None:
        """Perform ungrouping of items."""


# Work around issue https://github.com/python/mypy/issues/3135 (Class decorators are not type checked)
# This definition, along with the the ignore below, seems to fix the behaviour for mypy at least.


# @multidispatch(object, object)
class NoGrouping(AbstractGroup):
    def can_contain(self) -> bool:
        return False

    def group(self) -> None:
        pass

    def ungroup(self) -> None:
        pass


Group: FunctionDispatcher[Type[AbstractGroup]] = multidispatch(
    object, object)(NoGrouping)

# Until we can deal with types (esp. typing.Any) we use this as a workaround:
Group.register(None, object)(NoGrouping)
Esempio n. 2
0
    ) -> None:
        pass

    def allow(self, handle: Handle, port: Port) -> bool:
        return False

    def connect(self, handle: Handle, port: Port) -> bool:
        return False

    def disconnect(self, handle: Handle) -> None:
        pass


# Work around issue https://github.com/python/mypy/issues/3135 (Class decorators are not type checked)
# This definition, along with the the ignore below, seems to fix the behaviour for mypy at least.
Connector: FunctionDispatcher[Type[ConnectorProtocol]] = multidispatch(
    object, object)(NoConnector)


class UnaryRelationshipConnect(BaseConnector):
    """
    Base class for relationship connections, such as associations,
    dependencies and implementations.

    Unary relationships are allowed to connect both ends to the same element

    This class introduces a new method: relationship() which is used to
    find an existing relationship in the model that does not yet exist
    on the canvas.
    """

    element: ElementPresentation[Element]
Esempio n. 3
0
        """
        raise NotImplementedError(f"No connector for {self.item} and {self.line_item}")

    def disconnect(self, handle: Handle) -> None:
        """
        The true disconnect. Disconnect a handle.connected_to from an
        element. This requires that the relationship is also removed at
        model level.
        """
        raise NotImplementedError(f"No connector for {self.item} and {self.line_item}")


# Work around issue https://github.com/python/mypy/issues/3135 (Class decorators are not type checked)
# This definition, along with the the ignore below, seems to fix the behaviour for mypy at least.
IConnect: FunctionDispatcher[Type[ConnectBase]] = multidispatch(object, object)(
    ConnectBase
)


class AbstractConnect(ConnectBase):
    """
    Connection adapter for Gaphor diagram items.

    Line item ``line`` connects with a handle to a connectable item ``element``.

    Attributes:

    - line: connecting item
    - element: connectable item

    The following methods are required to make this work: