Ejemplo n.º 1
0
    def testUndoOnDeletedElement(self):
        b1 = Box()

        b2 = Box()
        line = Line()

        canvas = Canvas()
        canvas.add(b1)
        self.assertEqual(2, len(canvas.solver.constraints))

        canvas.add(b2)
        self.assertEqual(4, len(canvas.solver.constraints))

        canvas.add(line)

        sink = ConnectionSink(b1, b1.ports()[0])
        connector = Connector(line, line.handles()[0])
        connector.connect(sink)

        sink = ConnectionSink(b2, b2.ports()[0])
        connector = Connector(line, line.handles()[-1])
        connector.connect(sink)

        self.assertEqual(6, len(canvas.solver.constraints))
        self.assertEqual(2, len(list(canvas.get_connections(item=line))))

        del undo_list[:]

        # Here disconnect is not invoked!
        canvas.remove(b2)

        self.assertEqual(3, len(canvas.solver.constraints))
        self.assertEqual(1, len(list(canvas.get_connections(item=line))))

        cinfo = canvas.get_connection(line.handles()[0])
        self.assertEqual(b1, cinfo.connected)

        cinfo = canvas.get_connection(line.handles()[-1])
        self.assertEqual(None, cinfo)

        self.assertEqual([],
                         list(
                             canvas.solver.constraints_with_variable(
                                 line.handles()[-1].pos.x)))
        self.assertEqual([],
                         list(
                             canvas.solver.constraints_with_variable(
                                 line.handles()[-1].pos.y)))

        undo()

        self.assertEqual(6, len(canvas.solver.constraints))
        self.assertEqual(2, len(list(canvas.get_connections(item=line))))

        cinfo = canvas.get_connection(line.handles()[0])
        self.assertEqual(b1, cinfo.connected)

        cinfo = canvas.get_connection(line.handles()[-1])
        self.assertEqual(b2, cinfo.connected)
Ejemplo n.º 2
0
def test_undo_on_delete_element(revert_undo, undo_fixture):
    b1 = Box()
    b2 = Box()
    line = Line()

    canvas = Canvas()
    canvas.add(b1)
    assert 2 == len(canvas.solver.constraints)

    canvas.add(b2)
    assert 4 == len(canvas.solver.constraints)

    canvas.add(line)

    sink = ConnectionSink(b1, b1.ports()[0])
    connector = Connector(line, line.handles()[0])
    connector.connect(sink)

    sink = ConnectionSink(b2, b2.ports()[0])
    connector = Connector(line, line.handles()[-1])
    connector.connect(sink)

    assert 6 == len(canvas.solver.constraints)
    assert 2 == len(list(canvas.get_connections(item=line)))

    del undo_fixture[2][:]  # Clear undo_list

    # Here disconnect is not invoked!
    canvas.remove(b2)

    assert 3 == len(canvas.solver.constraints)
    assert 1 == len(list(canvas.get_connections(item=line)))

    cinfo = canvas.get_connection(line.handles()[0])
    assert b1 == cinfo.connected

    cinfo = canvas.get_connection(line.handles()[-1])
    assert cinfo is None

    assert [] == list(
        canvas.solver.constraints_with_variable(line.handles()[-1].pos.x))
    assert [] == list(
        canvas.solver.constraints_with_variable(line.handles()[-1].pos.y))

    undo_fixture[0]()  # Call undo

    assert 6 == len(canvas.solver.constraints)
    assert 2 == len(list(canvas.get_connections(item=line)))

    cinfo = canvas.get_connection(line.handles()[0])
    assert b1 == cinfo.connected

    cinfo = canvas.get_connection(line.handles()[-1])
    assert b2 == cinfo.connected
Ejemplo n.º 3
0
    def testUndoOnDeletedElement(self):
        b1 = Box()

        b2 = Box()
        line = Line()

        canvas = Canvas()
        canvas.add(b1)
        self.assertEquals(6, len(canvas.solver.constraints))

        canvas.add(b2)
        self.assertEquals(12, len(canvas.solver.constraints))

        canvas.add(line)

        sink = ConnectionSink(b1, b1.ports()[0])
        connector = Connector(line, line.handles()[0])
        connector.connect(sink)

        sink = ConnectionSink(b2, b2.ports()[0])
        connector = Connector(line, line.handles()[-1])
        connector.connect(sink)

        self.assertEquals(14, len(canvas.solver.constraints))
        self.assertEquals(2, len(list(canvas.get_connections(item=line))))

        del undo_list[:]

        # Here disconnect is not invoked!
        canvas.remove(b2)

        self.assertEquals(7, len(canvas.solver.constraints))
        self.assertEquals(1, len(list(canvas.get_connections(item=line))))

        cinfo = canvas.get_connection(line.handles()[0])
        self.assertEquals(b1, cinfo.connected)

        cinfo = canvas.get_connection(line.handles()[-1])
        self.assertEquals(None, cinfo)

        self.assertEquals([], list(canvas.solver.constraints_with_variable(line.handles()[-1].pos.x)))
        self.assertEquals([], list(canvas.solver.constraints_with_variable(line.handles()[-1].pos.y)))

        undo()

        self.assertEquals(14, len(canvas.solver.constraints))
        self.assertEquals(2, len(list(canvas.get_connections(item=line))))

        cinfo = canvas.get_connection(line.handles()[0])
        self.assertEquals(b1, cinfo.connected)

        cinfo = canvas.get_connection(line.handles()[-1])
        self.assertEquals(b2, cinfo.connected)
Ejemplo n.º 4
0
def test_undo_on_delete_element(revert_undo, undo_fixture):
    b1 = Box()
    b2 = Box()
    line = Line()

    canvas = Canvas()
    canvas.add(b1)
    assert 2 == len(canvas.solver.constraints)

    canvas.add(b2)
    assert 4 == len(canvas.solver.constraints)

    canvas.add(line)

    sink = ConnectionSink(b1, b1.ports()[0])
    connector = Connector(line, line.handles()[0])
    connector.connect(sink)

    sink = ConnectionSink(b2, b2.ports()[0])
    connector = Connector(line, line.handles()[-1])
    connector.connect(sink)

    assert 6 == len(canvas.solver.constraints)
    assert 2 == len(list(canvas.get_connections(item=line)))

    del undo_fixture[2][:]  # Clear undo_list

    # Here disconnect is not invoked!
    canvas.remove(b2)

    assert 3 == len(canvas.solver.constraints)
    assert 1 == len(list(canvas.get_connections(item=line)))

    cinfo = canvas.get_connection(line.handles()[0])
    assert b1 == cinfo.connected

    cinfo = canvas.get_connection(line.handles()[-1])
    assert cinfo is None

    assert [] == list(canvas.solver.constraints_with_variable(line.handles()[-1].pos.x))
    assert [] == list(canvas.solver.constraints_with_variable(line.handles()[-1].pos.y))

    undo_fixture[0]()  # Call undo

    assert 6 == len(canvas.solver.constraints)
    assert 2 == len(list(canvas.get_connections(item=line)))

    cinfo = canvas.get_connection(line.handles()[0])
    assert b1 == cinfo.connected

    cinfo = canvas.get_connection(line.handles()[-1])
    assert b2 == cinfo.connected
Ejemplo n.º 5
0
    def test_connect_item(self):
        b1 = Box()
        b2 = Box()
        l = Line()
        c = Canvas()
        c.add(b1)
        c.add(b2)
        c.add(l)

        c.connect_item(l, l.handles()[0], b1, b1.ports()[0])
        assert count(c.get_connections(handle=l.handles()[0])) == 1

        # Add the same
        self.assertRaises(ConnectionError, c.connect_item, l, l.handles()[0], b1, b1.ports()[0])
        assert count(c.get_connections(handle=l.handles()[0])) == 1
Ejemplo n.º 6
0
def test_connect_item():
    b1 = Box()
    b2 = Box()
    line = Line()
    c = Canvas()
    c.add(b1)
    c.add(b2)
    c.add(line)

    c.connect_item(line, line.handles()[0], b1, b1.ports()[0])
    assert count(c.get_connections(handle=line.handles()[0])) == 1

    # Add the same
    with pytest.raises(ConnectionError):
        c.connect_item(line, line.handles()[0], b1, b1.ports()[0])
    assert count(c.get_connections(handle=line.handles()[0])) == 1
Ejemplo n.º 7
0
def test_connect_item():
    b1 = Box()
    b2 = Box()
    line = Line()
    c = Canvas()
    c.add(b1)
    c.add(b2)
    c.add(line)

    c.connect_item(line, line.handles()[0], b1, b1.ports()[0])
    assert count(c.get_connections(handle=line.handles()[0])) == 1

    # Add the same
    with pytest.raises(ConnectionError):
        c.connect_item(line, line.handles()[0], b1, b1.ports()[0])
    assert count(c.get_connections(handle=line.handles()[0])) == 1
Ejemplo n.º 8
0
def test_disconnect_item_by_deleting_element():
    b1 = Box()
    b2 = Box()
    line = Line()
    c = Canvas()
    c.add(b1)
    c.add(b2)
    c.add(line)

    events = []

    def callback():
        events.append("called")

    c.connect_item(line,
                   line.handles()[0],
                   b1,
                   b1.ports()[0],
                   callback=callback)
    assert count(c.get_connections(handle=line.handles()[0])) == 1

    c.remove(b1)

    assert count(c.get_connections(handle=line.handles()[0])) == 0
    assert events == ["called"]
Ejemplo n.º 9
0
    def test_connect_item(self):
        b1 = Box()
        b2 = Box()
        l = Line()
        c = Canvas()
        c.add(b1)
        c.add(b2)
        c.add(l)

        c.connect_item(l, l.handles()[0], b1, b1.ports()[0])
        assert count(c.get_connections(handle=l.handles()[0])) == 1

        # Add the same
        self.assertRaises(ConnectionError, c.connect_item, l,
                          l.handles()[0], b1,
                          b1.ports()[0])
        assert count(c.get_connections(handle=l.handles()[0])) == 1
Ejemplo n.º 10
0
def test_disconnect_item_with_constraint():
    b1 = Box()
    b2 = Box()
    line = Line()
    c = Canvas()
    c.add(b1)
    c.add(b2)
    c.add(line)

    cons = b1.ports()[0].constraint(c, line, line.handles()[0], b1)

    c.connect_item(line, line.handles()[0], b1, b1.ports()[0], constraint=cons)
    assert count(c.get_connections(handle=line.handles()[0])) == 1

    assert len(c.solver.constraints) == 13

    c.disconnect_item(line, line.handles()[0])
    assert count(c.get_connections(handle=line.handles()[0])) == 0

    assert len(c.solver.constraints) == 12
Ejemplo n.º 11
0
def test_remove_connected_item():
    """Test adding canvas constraint.

    """
    canvas = Canvas()

    from gaphas.aspect import Connector, ConnectionSink

    l1 = Line()
    canvas.add(l1)

    b1 = Box()
    canvas.add(b1)

    number_cons1 = len(canvas.solver.constraints)

    b2 = Box()
    canvas.add(b2)

    number_cons2 = len(canvas.solver.constraints)

    conn = Connector(l1, l1.handles()[0])
    sink = ConnectionSink(b1, b1.ports()[0])

    conn.connect(sink)

    assert canvas.get_connection(l1.handles()[0])

    conn = Connector(l1, l1.handles()[1])
    sink = ConnectionSink(b2, b2.ports()[0])

    conn.connect(sink)

    assert canvas.get_connection(l1.handles()[1])

    assert number_cons2 + 2 == len(canvas.solver.constraints)

    canvas.remove(b1)

    # Expecting a class + line connected at one end only
    assert number_cons1 + 1 == len(canvas.solver.constraints)
Ejemplo n.º 12
0
    def test_remove_connected_item(self):
        """Test adding canvas constraint"""
        canvas = Canvas()

        from gaphas.aspect import Connector, ConnectionSink

        l1 = Line()
        canvas.add(l1)


        b1 = Box()
        canvas.add(b1)

        number_cons1 = len(canvas.solver.constraints)

        b2 = Box()
        canvas.add(b2)

        number_cons2 = len(canvas.solver.constraints)

        conn = Connector(l1, l1.handles()[0])
        sink = ConnectionSink(b1, b1.ports()[0])

        conn.connect(sink)

        assert canvas.get_connection(l1.handles()[0])

        conn = Connector(l1, l1.handles()[1])
        sink = ConnectionSink(b2, b2.ports()[0])

        conn.connect(sink)

        assert canvas.get_connection(l1.handles()[1])


        self.assertEquals(number_cons2 + 2, len(canvas.solver.constraints))

        canvas.remove(b1)

        # Expecting a class + line connected at one end only
        self.assertEquals(number_cons1 + 1, len(canvas.solver.constraints))
Ejemplo n.º 13
0
    def test_disconnect_item_with_constraint(self):
        b1 = Box()
        b2 = Box()
        l = Line()
        c = Canvas()
        c.add(b1)
        c.add(b2)
        c.add(l)

        cons = b1.ports()[0].constraint(c, l, l.handles()[0], b1)

        c.connect_item(l, l.handles()[0], b1, b1.ports()[0], constraint=cons)
        assert count(c.get_connections(handle=l.handles()[0])) == 1

        ncons = len(c.solver.constraints)
        assert ncons == 5

        c.disconnect_item(l, l.handles()[0])
        assert count(c.get_connections(handle=l.handles()[0])) == 0

        assert len(c.solver.constraints) == 4
Ejemplo n.º 14
0
    def test_disconnect_item_with_constraint(self):
        b1 = Box()
        b2 = Box()
        l = Line()
        c = Canvas()
        c.add(b1)
        c.add(b2)
        c.add(l)

        cons = b1.ports()[0].constraint(c, l, l.handles()[0], b1)

        c.connect_item(l, l.handles()[0], b1, b1.ports()[0], constraint=cons)
        assert count(c.get_connections(handle=l.handles()[0])) == 1

        ncons = len(c.solver.constraints)
        assert ncons == 5

        c.disconnect_item(l, l.handles()[0])
        assert count(c.get_connections(handle=l.handles()[0])) == 0

        assert len(c.solver.constraints) == 4
Ejemplo n.º 15
0
    def test_disconnect_item_with_constraint_by_deleting_element(self):
        b1 = Box()
        b2 = Box()
        l = Line()
        c = Canvas()
        c.add(b1)
        c.add(b2)
        c.add(l)

        cons = b1.ports()[0].constraint(c, l, l.handles()[0], b1)

        c.connect_item(l, l.handles()[0], b1, b1.ports()[0], constraint=cons)
        assert count(c.get_connections(handle=l.handles()[0])) == 1

        ncons = len(c.solver.constraints)
        assert ncons == 5

        c.remove(b1)

        assert count(c.get_connections(handle=l.handles()[0])) == 0

        self.assertEquals(2, len(c.solver.constraints))
Ejemplo n.º 16
0
def test_disconnect_item_with_constraint_by_deleting_element():
    b1 = Box()
    b2 = Box()
    line = Line()
    c = Canvas()
    c.add(b1)
    c.add(b2)
    c.add(line)

    cons = b1.ports()[0].constraint(c, line, line.handles()[0], b1)

    c.connect_item(line, line.handles()[0], b1, b1.ports()[0], constraint=cons)
    assert count(c.get_connections(handle=line.handles()[0])) == 1

    ncons = len(c.solver.constraints)
    assert ncons == 5

    c.remove(b1)

    assert count(c.get_connections(handle=line.handles()[0])) == 0

    assert 2 == len(c.solver.constraints)
Ejemplo n.º 17
0
    def test_disconnect_item_with_constraint_by_deleting_element(self):
        b1 = Box()
        b2 = Box()
        l = Line()
        c = Canvas()
        c.add(b1)
        c.add(b2)
        c.add(l)

        cons = b1.ports()[0].constraint(c, l, l.handles()[0], b1)

        c.connect_item(l, l.handles()[0], b1, b1.ports()[0], constraint=cons)
        assert count(c.get_connections(handle=l.handles()[0])) == 1

        ncons = len(c.solver.constraints)
        assert ncons == 5

        c.remove(b1)

        assert count(c.get_connections(handle=l.handles()[0])) == 0

        self.assertEquals(2, len(c.solver.constraints))
Ejemplo n.º 18
0
def test_disconnect_item_with_constraint_by_deleting_element():
    b1 = Box()
    b2 = Box()
    line = Line()
    c = Canvas()
    c.add(b1)
    c.add(b2)
    c.add(line)

    cons = b1.ports()[0].constraint(c, line, line.handles()[0], b1)

    c.connect_item(line, line.handles()[0], b1, b1.ports()[0], constraint=cons)
    assert count(c.get_connections(handle=line.handles()[0])) == 1

    ncons = len(c.solver.constraints)
    assert ncons == 13

    c.remove(b1)

    assert count(c.get_connections(handle=line.handles()[0])) == 0

    assert 6 == len(c.solver.constraints)
Ejemplo n.º 19
0
    def test_disconnect_item_with_callback(self):
        b1 = Box()
        b2 = Box()
        l = Line()
        c = Canvas()
        c.add(b1)
        c.add(b2)
        c.add(l)

        events = []
        def callback():
            events.append('called')

        c.connect_item(l, l.handles()[0], b1, b1.ports()[0], callback=callback)
        assert count(c.get_connections(handle=l.handles()[0])) == 1

        c.disconnect_item(l, l.handles()[0])
        assert count(c.get_connections(handle=l.handles()[0])) == 0
        assert events == ['called']
Ejemplo n.º 20
0
def test_disconnect_item_with_callback():
    b1 = Box()
    b2 = Box()
    line = Line()
    c = Canvas()
    c.add(b1)
    c.add(b2)
    c.add(line)

    events = []

    def callback():
        events.append("called")

    c.connect_item(line, line.handles()[0], b1, b1.ports()[0], callback=callback)
    assert count(c.get_connections(handle=line.handles()[0])) == 1

    c.disconnect_item(line, line.handles()[0])
    assert count(c.get_connections(handle=line.handles()[0])) == 0
    assert events == ["called"]
Ejemplo n.º 21
0
    def test_disconnect_item_with_callback(self):
        b1 = Box()
        b2 = Box()
        l = Line()
        c = Canvas()
        c.add(b1)
        c.add(b2)
        c.add(l)

        events = []

        def callback():
            events.append('called')

        c.connect_item(l, l.handles()[0], b1, b1.ports()[0], callback=callback)
        assert count(c.get_connections(handle=l.handles()[0])) == 1

        c.disconnect_item(l, l.handles()[0])
        assert count(c.get_connections(handle=l.handles()[0])) == 0
        assert events == ['called']