Beispiel #1
0
    def __init__(self):
        super(FatLine, self).__init__()
        self._handles.extend((Handle(), Handle()))

        h1, h2 = self._handles

        self._ports.append(LinePort(h1.pos, h2.pos))

        self.constraint(vertical=(h1.pos, h2.pos))
        self.constraint(above=(h1.pos, h2.pos), delta=20)
Beispiel #2
0
    def __init__(self):
        super(LifetimeItem, self).__init__()

        self.top = Handle(strength=STRONG - 1)
        self.bottom = Handle(strength=STRONG)

        self.top.movable = False
        self.top.visible = False

        self.port = LifetimePort(self.top.pos, self.bottom.pos)
        self.visible = False

        self._c_min_length = None # to be set by lifeline item
Beispiel #3
0
    def __init__(self, connections: Connections, **kwargs: object) -> None:
        super().__init__(**kwargs)
        self._connections = connections
        self._handles = [
            Handle(connectable=True),
            Handle((10, 10), connectable=True)
        ]
        self._ports: List[Port] = []
        self._update_ports()

        self._line_width = 2.0
        self._fuzziness = 0.0
        self._orthogonal_constraints: List[Constraint] = []
        self._horizontal = False
Beispiel #4
0
    def __init__(self):
        super(Line, self).__init__()
        self._handles = [
            Handle(connectable=True),
            Handle((10, 10), connectable=True)
        ]
        self._ports = []
        self._update_ports()

        self._line_width = 2
        self._fuzziness = 0
        self._orthogonal_constraints = []
        self._horizontal = False
        self._head_angle = self._tail_angle = 0
def test_line_guide(line, canvas):
    line.handles().append(Handle((20, 20), strength=WEAK))
    line.handles().append(Handle((30, 30), strength=WEAK))
    line.handles().append(Handle((40, 40), strength=WEAK))
    line.orthogonal = True
    canvas.update_now((line, ))

    guides = list(Guide(line).horizontal())
    assert 2 == len(guides)
    assert 10.0 == guides[0]
    assert 40.0 == guides[1]

    guides = list(Guide(line).vertical())
    assert 2 == len(guides)
    assert 10.0 == guides[0]
    assert 30.0 == guides[1]
Beispiel #6
0
    def __init__(self,
                 in_port,
                 name=None,
                 parent=None,
                 side=SnappedSide.RIGHT):
        self.handle = Handle(connectable=True)
        self.port = RectanglePointPort(self.handle.pos, self)
        self._is_in_port = in_port
        self._side = None
        self.direction = None
        self.side = side
        self._parent = ref(parent)
        self._view = None

        self.text_color = gui_config.gtk_colors['LABEL']
        self.fill_color = gui_config.gtk_colors['LABEL']

        self._incoming_handles = []
        self._outgoing_handles = []
        self._connected_connections = []
        self._tmp_incoming_connected = False
        self._tmp_outgoing_connected = False

        self._name = name

        self.label_print_inside = True

        self._port_image_cache = ImageCache()
        self._label_image_cache = ImageCache()
        self._last_label_size = self.port_side_size, self.port_side_size
        self._last_label_relative_pos = 0, 0
Beispiel #7
0
    def __init__(self, width=10, height=10):
        super(PortoBox, self).__init__(width, height)

        # disable default ports
        for p in self._ports:
            p.connectable = False

        nw = self._handles[NW]
        sw = self._handles[SW]
        ne = self._handles[NE]
        se = self._handles[SE]

        # handle for movable port
        self._hm = Handle(strength=WEAK)
        self._hm.pos = width, height / 2.0
        self._handles.append(self._hm)

        # movable port
        self._ports.append(PointPort(self._hm.pos))

        # keep movable port at right edge
        self.constraint(vertical=(self._hm.pos, ne.pos), delta=10)
        self.constraint(above=(ne.pos, self._hm.pos))
        self.constraint(above=(self._hm.pos, se.pos))

        # static point port
        self._sport = PointPort(Position((width / 2.0, height)))
        l = sw.pos, se.pos
        self.constraint(line=(self._sport.point, l))
        self._ports.append(self._sport)

        # line port
        self._lport = LinePort(nw.pos, se.pos)
        self._ports.append(self._lport)
Beispiel #8
0
    def load(self, name, value):
        if name == "matrix":
            self.matrix.set(*ast.literal_eval(value))
        elif name == "points":
            points = ast.literal_eval(value)
            for _ in range(len(points) - 2):
                h = Handle((0, 0))
                self._handles.insert(1, h)
            for i, p in enumerate(points):
                self.handles()[i].pos = p

            # Update connection ports of the line. Only handles are saved
            # in Gaphor file therefore ports need to be recreated after
            # handles information is loaded.
            self._update_ports()

        elif name == "orthogonal":
            self._load_orthogonal = ast.literal_eval(value)
        elif name == "horizontal":
            self.horizontal = ast.literal_eval(value)
        elif name in ("head_connection", "head-connection"):
            self._load_head_connection = value
        elif name in ("tail_connection", "tail-connection"):
            self._load_tail_connection = value
        else:
            super().load(name, value)
Beispiel #9
0
 def init_handles(self):
     self._handles = []
     for pt in self.pts:
         pt = self.renderise(pt)
         h = Handle(strength=VERY_STRONG)
         h.pos.x = pt[0]
         h.pos.y = pt[1]
         self._handles.append(h)
Beispiel #10
0
    def __init__(self):
        super().__init__()
        self._handles = [Handle(movable=False)]
        h = self._handles[0]
        h.visible = False
        self._ports.append(PointPort(h.pos))

        self.id: int
        self.colour_hovered = (0.8, 0.8, 1, 0.8)
        self.colour = (1, 0, 1, 0.8)
def test_line_handle_no_events_for_removed_handle(diagram, undo_manager, event_manager):
    with Transaction(event_manager):
        line = diagram.create(LinePresentation)

    # Note that inserting and removing handles is *not* transactional
    handle = Handle()
    line.insert_handle(1, handle)
    line.remove_handle(handle)

    new_pos = (30, 40)

    with Transaction(event_manager):
        handle.pos = new_pos

    assert tuple(handle.pos) == new_pos

    undo_manager.undo_transaction()

    assert handle.pos.tuple() == new_pos
Beispiel #12
0
def test_line_delete(diagram, undo_manager, event_manager):
    with Transaction(event_manager):
        line = LinePresentation(diagram)
        line.insert_handle(1, Handle((20, 20)))
        line.matrix.translate(10, 10)

    with Transaction(event_manager):
        line.unlink()

    undo_manager.undo_transaction()

    line = diagram.ownedPresentation[0]
    assert len(line.handles()) == 3
    assert line.handles()[1].pos.tuple() == (20, 20)
    assert line.matrix.tuple() == (1, 0, 0, 1, 10, 10)
Beispiel #13
0
 def load(self, name, value):
     if name == "horizontal":
         self.horizontal = ast.literal_eval(value)
     elif name == "matrix":
         self.matrix.set(*ast.literal_eval(value))
     elif name == "orthogonal":
         self._load_orthogonal = ast.literal_eval(value)
     elif name == "points":
         points = ast.literal_eval(value)
         for _ in range(len(points) - 2):
             h = Handle((0, 0))
             self._handles.insert(1, h)
         for i, p in enumerate(points):
             self.handles()[i].pos = p
         self._update_ports()
Beispiel #14
0
        def do_split(segment, count):
            handles = item.handles()
            p0 = handles[segment].pos
            p1 = handles[segment + 1].pos
            dx, dy = p1.x - p0.x, p1.y - p0.y
            new_h = Handle((p0.x + dx / count, p0.y + dy / count), strength=WEAK)
            item.insert_handle(segment + 1, new_h)

            p0 = LinePort(p0, new_h.pos)
            p1 = LinePort(new_h.pos, p1)
            item.remove_port(item.ports()[segment])
            item.insert_port(segment, p0)
            item.insert_port(segment + 1, p1)

            if count > 2:
                do_split(segment + 1, count - 1)
Beispiel #15
0
def test_line_horizontal_property(diagram, undo_manager, event_manager):
    with Transaction(event_manager):
        line = LinePresentation(diagram)
        line.insert_handle(0, Handle())

    with Transaction(event_manager):
        line.horizontal = True

    assert line.horizontal

    undo_manager.undo_transaction()

    assert not line.horizontal

    undo_manager.redo_transaction()

    assert line.horizontal
Beispiel #16
0
    def __init__(self, id=None, model=None):
        super().__init__(id, model)

        h1 = Handle(connectable=True)
        self._handles.append(h1)

        d = self.dimensions()
        top_left = Position((d.x, d.y))
        top_right = Position((d.x1, d.y))
        bottom_right = Position((d.x1, d.y1))
        bottom_left = Position((d.x, d.y1))
        self._ports.append(LinePort(top_left, top_right))
        self._ports.append(LinePort(top_right, bottom_right))
        self._ports.append(LinePort(bottom_right, bottom_left))
        self._ports.append(LinePort(bottom_left, top_left))

        self._last_connected_side = None
        self.watch("subject[NamedElement].name")
Beispiel #17
0
 def load(self, name, value):
     if name == "matrix":
         self.matrix.set(*ast.literal_eval(value))
     elif name == "points":
         points = ast.literal_eval(value)
         for _ in range(len(points) - 2):
             h = Handle((0, 0))
             self._handles.insert(1, h)
             self.watch_handle(h)
         for i, p in enumerate(points):
             self.handles()[i].pos = p
         self._update_ports()
     elif name in ("head_connection", "head-connection"):
         self._load_head_connection = value
     elif name in ("tail_connection", "tail-connection"):
         self._load_tail_connection = value
     else:
         super().load(name, value)
Beispiel #18
0
    def __init__(self, diagram, id=None):
        super().__init__(diagram, id)
        self._connections = diagram.connections

        h1 = Handle(connectable=True)
        self._handles = [h1]
        self.watch_handle(h1)

        d = self.dimensions()
        top_left = Position(d.x, d.y)
        top_right = Position(d.x1, d.y)
        bottom_right = Position(d.x1, d.y1)
        bottom_left = Position(d.x, d.y1)
        self._ports = [
            LinePort(top_left, top_right),
            LinePort(top_right, bottom_right),
            LinePort(bottom_right, bottom_left),
            LinePort(bottom_left, top_left),
        ]

        self._last_connected_side = None
        self.watch("subject[NamedElement].name")
        self.update_shapes()
Beispiel #19
0
    def __init__(self, connections, id=None, model=None):
        super().__init__(id=id, model=model)
        self._matrix = Matrix()
        self._matrix_i2c = Matrix()
        self._connections = connections

        h1 = Handle(connectable=True)
        self._handles = [h1]

        d = self.dimensions()
        top_left = Position(d.x, d.y)
        top_right = Position(d.x1, d.y)
        bottom_right = Position(d.x1, d.y1)
        bottom_left = Position(d.x, d.y1)
        self._ports = [
            LinePort(top_left, top_right),
            LinePort(top_right, bottom_right),
            LinePort(bottom_right, bottom_left),
            LinePort(bottom_left, top_left),
        ]

        self._last_connected_side = None
        self.watch("subject[NamedElement].name")
        self.update_shapes()
Beispiel #20
0
def test_handle_x_y():
    h = Handle()
    assert 0.0 == h.pos.x
    assert 0.0 == h.pos.y
Beispiel #21
0
 def __init__(self):
     super(Circle, self).__init__()
     self._handles.extend((Handle(), Handle()))
Beispiel #22
0
 def __init__(self):
     super().__init__()
     self._handles = [Handle(), Handle()]
     h1, h2 = self._handles
     h1.movable = False
Beispiel #23
0
 def _create_handle(self, pos, strength=WEAK):
     return Handle(pos, strength=strength)
 def __init__(self):
     super().__init__()
     self._handles = (Handle(connectable=True),
                      Handle((10, 10), connectable=True))
     self._line_width = 2
Beispiel #25
0
 def test_handle_x_y(self):
     h = Handle()
     self.assertEqual(0.0, h.x)
     self.assertEqual(0.0, h.y)