示例#1
0
def test_allow(commentline, comment):
    aspect = Connector(commentline, commentline.handles()[0])
    assert aspect.item is commentline
    assert aspect.handle is commentline.handles()[0]

    sink = ConnectionSink(comment, comment.ports()[0])
    assert aspect.allow(sink)
示例#2
0
    def test_allow(self):
        aspect = Connector(self.commentline, self.commentline.handles()[0])
        assert aspect.item is self.commentline
        assert aspect.handle is self.commentline.handles()[0]

        sink = ConnectionSink(self.comment, self.comment.ports()[0])
        assert aspect.allow(sink)
示例#3
0
    def test_allow(self):
        aspect = Connector(self.commentline, self.commentline.handles()[0])
        assert aspect.item is self.commentline
        assert aspect.handle is self.commentline.handles()[0]

        sink = ConnectionSink(self.comment, self.comment.ports()[0])
        assert aspect.allow(sink)
示例#4
0
    def glue(self, pos, distance=None):
        """
        Glue to an item near a specific point.

        Returns a ConnectionSink or None.
        """
        item = self.item
        handle = self.handle
        view = self.view

        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
        state_l = view.get_state_at_point(pos, distance=distance)
        state_v = state_l
        if state_v is not None and not state_v.model.state.is_root_state:
            return ConnectionSink(state_v, None)
        return None