Exemple #1
0
    def __init__(self, id=None, model=None):
        super().__init__(id, model)
        self.bar_width = 12

        ht, hb = Handle(), Handle()
        ht.connectable = True

        # TODO: need better interface for this!
        self._handles.append(ht)
        self._handles.append(hb)

        self.constraint(vertical=(ht.pos, hb.pos))

        r = self.bar_width / 2
        nw = Position((-r, 0), strength=WEAK)
        ne = Position((r, 0), strength=WEAK)
        se = Position((r, 0), strength=WEAK)
        sw = Position((-r, 0), strength=WEAK)

        self.constraint(horizontal=(sw, hb.pos))
        self.constraint(horizontal=(se, hb.pos))

        self._ports.append(LinePort(nw, sw))
        self._ports.append(LinePort(ne, se))

        self.shape = Box(style={"fill": "white"}, draw=draw_border)
 def test_set_xy(self):
     pos = Position((1,2))
     x = Variable()
     y = Variable()
     assert x is not pos.x
     assert y is not pos.y
     
     pos.set_x(x)
     pos.set_y(y)
     assert x is pos.x
     assert y is pos.y
Exemple #3
0
    def get_state_drawing_area(state):
        assert isinstance(state, StateView)
        border_width = state.border_width

        state_nw_pos_x = state.handles()[NW].pos.x + border_width
        state_nw_pos_y = state.handles()[NW].pos.y + border_width
        state_nw_pos = Position((state_nw_pos_x, state_nw_pos_y))
        state_se_pos_x = state.handles()[SE].pos.x - border_width
        state_se_pos_y = state.handles()[SE].pos.y - border_width
        state_se_pos = Position((state_se_pos_x, state_se_pos_y))

        return state_nw_pos, state_se_pos
Exemple #4
0
	def up1(self):
		''' this is a update method used to update variables before drawing them again'''

		self.wide = self.h[SE].pos.x - self.h[NW].pos.x
		self.height = self.h[SE].pos.y - self.h[NW].pos.y
		self.normx = self.wide*0.1
		self.normy = self.height*0.1
		if not (len(self.port_in)==0 and len(self.port_out)==0):
			for w in self._ports:
				if(w.get_portinstance().io == PORT_IN):
					w.point._set_pos(Position(((float(self.port_in[w.portinstance.name][0]) * self.normx),(float(self.port_in[w.portinstance.name][1]) * self.normy))))
				else:
					w.point._set_pos(Position(((float(self.port_out[w.portinstance.name][0]) * self.normx),(float(self.port_out[w.portinstance.name][1]) * self.normy))))
Exemple #5
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)
Exemple #6
0
 def __init__(self, blockinstance, portname, location, portlabel):
     super(BlockPort,
           self).__init__(Position(
               (float(location[0]), float(location[1]))))
     self.portinstance = blockinstance.ports[portname]
     self.portname = portname
     self.portlabel = portlabel
     self.location = location
Exemple #7
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")
Exemple #8
0
    def __init__(self, diagram, id=None):
        super().__init__(diagram, id=id)
        self._connections = diagram.connections

        self.bar_width = 12

        ht, hb = Handle(), Handle()
        ht.connectable = True

        self._handles = [ht, hb]
        self.watch_handle(ht)
        self.watch_handle(hb)

        self._connections.add_constraint(self, constraint(vertical=(ht.pos, hb.pos)))

        r = self.bar_width / 2
        nw = Position(-r, 0, strength=WEAK)
        ne = Position(r, 0, strength=WEAK)
        se = Position(r, 0, strength=WEAK)
        sw = Position(-r, 0, strength=WEAK)

        for c in (
            constraint(horizontal=(nw, ht.pos)),
            constraint(horizontal=(ne, ht.pos)),
            constraint(horizontal=(sw, hb.pos)),
            constraint(horizontal=(se, hb.pos)),
            constraint(vertical=(nw, ht.pos), delta=-r),
            constraint(vertical=(ne, ht.pos), delta=r),
            constraint(vertical=(sw, hb.pos), delta=-r),
            constraint(vertical=(se, hb.pos), delta=r),
        ):
            self._connections.add_constraint(self, c)

        self._ports = [LinePort(nw, sw), LinePort(ne, se)]

        self.shape = Box(
            style={"background-color": (1.0, 1.0, 1.0, 1.0)}, draw=draw_border
        )
Exemple #9
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()
Exemple #10
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()
Exemple #11
0
def test_set_xy():
    pos = Position((1, 2))
    x = Variable()
    y = Variable()
    assert x is not pos.x
    assert y is not pos.y

    pos.set_x(x)
    pos.set_y(y)
    assert x is pos.x
    assert y is pos.y
Exemple #12
0
def test_position(position):
    pos = Position(position)
    assert position[0] == pos.x
    assert position[1] == pos.y
Exemple #13
0
 def test_position(self):
     pos = Position((0, 0))
     self.assertEqual(0, pos.x)
     self.assertEqual(0, pos.y)
Exemple #14
0
 def test_position(self):
     pos = Position((1, 2))
     self.assertEqual(1, pos.x)
     self.assertEqual(2, pos.y)