コード例 #1
0
ファイル: test_element.py プロジェクト: franzlst/gaphas
    def test_minimal_se(self):
        """
        Test resizing of element by dragging it SE handle.
        """
        canvas = Canvas()
        box = Box()
        handles = box.handles()

        canvas.add(box)

        h_nw, h_ne, h_se, h_sw = handles
        assert h_nw is handles[NW]
        assert h_ne is handles[NE]
        assert h_sw is handles[SW]
        assert h_se is handles[SE]

        h_se.pos.x -= 20  # h.se.{x,y} == -10
        h_se.pos.y -= 20
        assert h_se.pos.x == h_se.pos.y == -10

        box.request_update()
        canvas.update()

        self.assertEqual(10, h_se.pos.x)  # h_se changed above, should be 10
        self.assertEqual(10, h_se.pos.y)

        self.assertEqual(10, h_ne.pos.x)
        self.assertEqual(10, h_sw.pos.y)
コード例 #2
0
ファイル: conftest.py プロジェクト: amolenaar/gaphas
    def __init__(self):
        self.canvas = Canvas()

        self.box1 = Box()
        self.canvas.add(self.box1)
        self.box1.matrix.translate(100, 50)
        self.box1.width = 40
        self.box1.height = 40
        self.box1.request_update()

        self.box2 = Box()
        self.canvas.add(self.box2)
        self.box2.matrix.translate(100, 150)
        self.box2.width = 50
        self.box2.height = 50
        self.box2.request_update()

        self.line = Line()
        self.head = self.line.handles()[0]
        self.tail = self.line.handles()[-1]
        self.tail.pos = 100, 100
        self.canvas.add(self.line)

        self.canvas.update_now()
        self.view = GtkView()
        self.view.canvas = self.canvas

        self.win = Gtk.Window()
        self.win.add(self.view)
        self.view.show()
        self.view.update()
        self.win.show()

        self.tool = ConnectHandleTool(self.view)
コード例 #3
0
def create_canvas(canvas, title):
    # Setup drawing window
    window = Gtk.Window()
    window.set_title(title)
    window.set_default_size(400, 400)

    view = GtkView()  #Gtk widget
    view.painter = DefaultPainter()
    view.canvas = canvas

    win_box = Gtk.Box(
        orientation=Gtk.Orientation.HORIZONTAL)  #added Gtk box to Gtk window
    window.add(win_box)
    win_box.pack_start(view, True, True, 0)  #added "view" widget to the box

    # Draw gaphas box
    b2 = Box(60, 60)
    b2.min_width = 40
    b2.min_height = 50
    b2.matrix.translate(170, 170)
    canvas.add(b2)

    # Draw gaphas line
    line = Line()
    line.matrix.translate(100, 60)
    canvas.add(line)
    line.handles()[1].pos = (30, 30)
    segment = Segment(line, canvas)
    segment.split_segment(0)

    window.show_all()
    window.connect("destroy", Gtk.main_quit)
コード例 #4
0
ファイル: test_view.py プロジェクト: pcakapratibha/gaphas
    def test_get_item_at_point(self):
        """
        Hover tool only reacts on motion-notify events
        """
        canvas = Canvas()
        view = GtkView(canvas)
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.add(view)
        window.show_all()

        box = Box()
        canvas.add(box)
        # No gtk main loop, so updates occur instantly
        assert not canvas.require_update()
        box.width = 50
        box.height = 50

        # Process pending (expose) events, which cause the canvas to be drawn.
        while gtk.events_pending():
            gtk.main_iteration()

        assert len(view._qtree._ids) == 1
        assert not view._qtree._bucket.bounds == (0, 0, 0, 0), view._qtree._bucket.bounds

        assert view.get_item_at_point((10, 10)) is box
        assert view.get_item_at_point((60, 10)) is None

        window.destroy()
コード例 #5
0
ファイル: conftest.py プロジェクト: wglu2010/gaphas
    def __init__(self):
        self.canvas = Canvas()

        self.box1 = Box()
        self.canvas.add(self.box1)
        self.box1.matrix.translate(100, 50)
        self.box1.width = 40
        self.box1.height = 40
        self.box1.request_update()

        self.box2 = Box()
        self.canvas.add(self.box2)
        self.box2.matrix.translate(100, 150)
        self.box2.width = 50
        self.box2.height = 50
        self.box2.request_update()

        self.line = Line()
        self.head = self.line.handles()[0]
        self.tail = self.line.handles()[-1]
        self.tail.pos = 100, 100
        self.canvas.add(self.line)

        self.canvas.update_now()
        self.view = GtkView()
        self.view.canvas = self.canvas

        self.win = Gtk.Window()
        self.win.add(self.view)
        self.view.show()
        self.view.update()
        self.win.show()

        self.tool = ConnectHandleTool(self.view)
コード例 #6
0
    def test_minimal_se(self):
        """
        Test resizing of element by dragging it SE handle.
        """
        canvas = Canvas()
        box = Box()
        handles = box.handles()

        canvas.add(box)

        h_nw, h_ne, h_se, h_sw = handles
        assert h_nw is handles[NW]
        assert h_ne is handles[NE]
        assert h_sw is handles[SW]
        assert h_se is handles[SE]

        h_se.pos.x -= 20      # h.se.{x,y} == -10
        h_se.pos.y -= 20
        assert h_se.pos.x == h_se.pos.y == -10

        box.request_update()
        canvas.update()

        self.assertEquals(10, h_se.pos.x) # h_se changed above, should be 10
        self.assertEquals(10, h_se.pos.y)

        self.assertEquals(10, h_ne.pos.x)
        self.assertEquals(10, h_sw.pos.y)
コード例 #7
0
ファイル: test_view.py プロジェクト: franzlst/gaphas
    def test_get_item_at_point(self):
        """
        Hover tool only reacts on motion-notify events
        """
        canvas = Canvas()
        view = GtkView(canvas)
        window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
        window.add(view)
        window.show_all()

        box = Box()
        canvas.add(box)
        # No gtk main loop, so updates occur instantly
        assert not canvas.require_update()
        box.width = 50
        box.height = 50

        # Process pending (expose) events, which cause the canvas to be drawn.
        while Gtk.events_pending():
            Gtk.main_iteration()

        assert len(view._qtree._ids) == 1
        assert not view._qtree._bucket.bounds == (
            0, 0, 0, 0), view._qtree._bucket.bounds

        assert view.get_item_at_point((10, 10)) is box
        assert view.get_item_at_point((60, 10)) is None

        window.destroy()
コード例 #8
0
def test_reparent():
    c = Canvas()
    b1 = Box()
    b2 = Box()
    c.add(b1)
    c.add(b2, b1)
    c.reparent(b2, None)
コード例 #9
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"]
コード例 #10
0
def test_get_handle_at_point(view_fixture):
    box = Box()
    box.min_width = 20
    box.min_height = 30
    box.matrix.translate(20, 20)
    box.matrix.rotate(math.pi / 1.5)
    view_fixture.canvas.add(box)

    i, h = view_fixture.view.get_handle_at_point((20, 20))
    assert i is box
    assert h is box.handles()[0]
コード例 #11
0
ファイル: test_undo.py プロジェクト: jvorcak/gpylint
    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)
コード例 #12
0
ファイル: test_undo.py プロジェクト: amolenaar/gaphas
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
コード例 #13
0
ファイル: test_canvas.py プロジェクト: amolenaar/gaphas
def test_update_matrices():
    """Test updating of matrices"""
    c = Canvas()
    i = Box()
    ii = Box()
    c.add(i)
    c.add(ii, i)

    i.matrix = (1.0, 0.0, 0.0, 1.0, 5.0, 0.0)
    ii.matrix = (1.0, 0.0, 0.0, 1.0, 0.0, 8.0)

    updated = c.update_matrices([i])

    assert i._matrix_i2c == cairo.Matrix(1, 0, 0, 1, 5, 0)
    assert ii._matrix_i2c == cairo.Matrix(1, 0, 0, 1, 5, 8)
コード例 #14
0
    def test_update_matrices(self):
        """Test updating of matrices"""
        c = Canvas()
        i = Box()
        ii = Box()
        c.add(i)
        c.add(ii, i)

        i.matrix = (1.0, 0.0, 0.0, 1.0, 5.0, 0.0)
        ii.matrix = (1.0, 0.0, 0.0, 1.0, 0.0, 8.0)

        updated = c.update_matrices([i])

        self.assertEquals(i._matrix_i2c, cairo.Matrix(1, 0, 0, 1, 5, 0))
        self.assertEquals(ii._matrix_i2c, cairo.Matrix(1, 0, 0, 1, 5, 8))
コード例 #15
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
コード例 #16
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
コード例 #17
0
ファイル: test_canvas.py プロジェクト: amolenaar/gaphas
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
コード例 #18
0
ファイル: test_view.py プロジェクト: franzlst/gaphas
    def test_view_registration_2(self):
        """
        Test view registration and destroy when view is destroyed.
        """
        canvas = Canvas()
        view = GtkView(canvas)
        window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
        window.add(view)
        window.show_all()

        box = Box()
        canvas.add(box)

        assert hasattr(box, '_matrix_i2v')
        assert hasattr(box, '_matrix_v2i')

        assert box._matrix_i2v[view]
        assert box._matrix_v2i[view]

        assert len(canvas._registered_views) == 1
        assert view in canvas._registered_views

        window.destroy()

        assert len(canvas._registered_views) == 0

        assert view not in box._matrix_i2v
        assert view not in box._matrix_v2i
コード例 #19
0
    def __init__(self, canvas):
        Gtk.Window.__init__(self, title="Hello World")

        #connect the  button widget
        #connect to its clicked signal
        #add is as child to the top-level window
        #self.button = Gtk.Button(label="Click Here")
        #self.button.connect("clicked", self.on_button_clicked)

        self.label = Gtk.Label()

        self.view = GtkView()  #Gtk widget
        self.view.painter = DefaultPainter()

        self.view.canvas = canvas

        self.win_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        self.add(self.win_box)

        self.win_box.pack_start(self.label, True, True, 0)
        self.win_box.pack_start(self.view, True, True, 0)

        self.b2 = Box(60, 60)
        self.b2.min_width = 40
        self.b2.min_height = 50
        self.b2.matrix.translate(170, 170)
        canvas.add(self.b2)

        # Draw gaphas line
        self.line = Line()
        self.line.matrix.translate(100, 60)
        canvas.add(self.line)
        self.line.handles()[1].pos = (30, 30)
        self.segment = Segment(self.line, canvas)
        self.segment.split_segment(0)
コード例 #20
0
ファイル: test_view.py プロジェクト: franzlst/gaphas
    def test_item_removal(self):
        canvas = Canvas()
        view = GtkView(canvas)
        window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
        window.add(view)
        window.show_all()

        box = Box()
        canvas.add(box)
        # No gtk main loop, so updates occur instantly
        assert not canvas.require_update()

        # Process pending (expose) events, which cause the canvas to be drawn.
        while Gtk.events_pending():
            Gtk.main_iteration()

        assert len(canvas.get_all_items()) == len(view._qtree)

        view.focused_item = box
        canvas.remove(box)

        assert len(canvas.get_all_items()) == 0
        assert len(view._qtree) == 0

        window.destroy()
コード例 #21
0
ファイル: test_view.py プロジェクト: franzlst/gaphas
    def test_bounding_box_calculations(self):
        """
        A view created before and after the canvas is populated should contain
        the same data.
        """
        canvas = Canvas()

        window1 = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
        view1 = GtkView(canvas=canvas)
        window1.add(view1)
        view1.realize()
        window1.show_all()

        box = Box()
        box.matrix = (1.0, 0.0, 0.0, 1, 10, 10)
        canvas.add(box)

        line = Line()
        line.fyzzyness = 1
        line.handles()[1].pos = (30, 30)
        #line.split_segment(0, 3)
        line.matrix.translate(30, 60)
        canvas.add(line)

        window2 = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
        view2 = GtkView(canvas=canvas)
        window2.add(view2)
        window2.show_all()

        # Process pending (expose) events, which cause the canvas to be drawn.
        while Gtk.events_pending():
            Gtk.main_iteration()

        try:
            assert view2.get_item_bounding_box(box)
            assert view1.get_item_bounding_box(box)
            assert view1.get_item_bounding_box(
                box) == view2.get_item_bounding_box(
                    box), '%s != %s' % (view1.get_item_bounding_box(box),
                                        view2.get_item_bounding_box(box))
            assert view1.get_item_bounding_box(
                line) == view2.get_item_bounding_box(
                    line), '%s != %s' % (view1.get_item_bounding_box(line),
                                         view2.get_item_bounding_box(line))
        finally:
            window1.destroy()
            window2.destroy()
コード例 #22
0
ファイル: test_view.py プロジェクト: franzlst/gaphas
    def test_get_handle_at_point(self):
        canvas = Canvas()
        view = GtkView(canvas)
        window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
        window.add(view)
        window.show_all()

        box = Box()
        box.min_width = 20
        box.min_height = 30
        box.matrix.translate(20, 20)
        box.matrix.rotate(old_div(math.pi, 1.5))
        canvas.add(box)

        i, h = view.get_handle_at_point((20, 20))
        assert i is box
        assert h is box.handles()[0]
コード例 #23
0
ファイル: test_view.py プロジェクト: pcakapratibha/gaphas
    def test_get_handle_at_point(self):
        canvas = Canvas()
        view = GtkView(canvas)
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.add(view)
        window.show_all()

        box = Box()
        box.min_width = 20
        box.min_height = 30
        box.matrix.translate(20, 20)
        box.matrix.rotate(math.pi/1.5)
        canvas.add(box)

        i, h = view.get_handle_at_point((20, 20))
        assert i is box
        assert h is box.handles()[0]
コード例 #24
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
コード例 #25
0
def test_placement(diagram, page, element_factory):
    box = Box()
    diagram.canvas.add(box)
    diagram.canvas.update_now()
    page.view.request_update([box])

    diagram.create(CommentItem, subject=element_factory.create(Comment))
    assert len(element_factory.lselect()) == 2
コード例 #26
0
ファイル: simple-box.py プロジェクト: x64Eddie/gaphas
def create_canvas(canvas, title):
    # Setup drawing window
    view = GtkView()
    view.painter = DefaultPainter()
    view.canvas = canvas
    window = Gtk.Window()
    window.set_title(title)
    window.set_default_size(400, 400)
    win_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
    window.add(win_box)
    win_box.pack_start(view, True, True, 0)

    # Draw first gaphas box
    b1 = Box(60, 60)
    b1.matrix = (1.0, 0.0, 0.0, 1, 10, 10)
    canvas.add(b1)

    # Draw second gaphas box
    b2 = Box(60, 60)
    b2.min_width = 40
    b2.min_height = 50
    b2.matrix.translate(170, 170)
    canvas.add(b2)

    # Draw gaphas line
    line = Line()
    line.matrix.translate(100, 60)
    canvas.add(line)
    line.handles()[1].pos = (30, 30)

    window.show_all()
    window.connect("destroy", Gtk.main_quit)
コード例 #27
0
    def test_placement(self):
        box = Box()
        self.diagram.canvas.add(box)
        self.diagram.canvas.update_now()
        self.page.view.request_update([box])

        self.diagram.create(CommentItem,
                            subject=self.element_factory.create(UML.Comment))
        assert len(self.element_factory.lselect()) == 2
コード例 #28
0
    def test_creation_with_size(self):
        """
        Test if initial size holds when added to a canvas.
        """
        canvas = Canvas()
        box = Box(150, 153)

        assert box.width == 150, box.width
        assert box.height == 153, box.height
        assert box.handles()[SE].pos.x == 150, box.handles()[SE].pos.x
        assert box.handles()[SE].pos.y == 153, box.handles()[SE].pos.y

        canvas.add(box)

        assert box.width == 150, box.width
        assert box.height == 153, box.height
        assert box.handles()[SE].pos.x == 150, box.handles()[SE].pos.x
        assert box.handles()[SE].pos.y == 153, box.handles()[SE].pos.y
コード例 #29
0
    def test_get_handle_at_point_at_pi_div_2(self):
        canvas = Canvas()
        view = GtkView(canvas)
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.add(view)
        window.show_all()

        box = Box()
        box.min_width = 20
        box.min_height = 30
        box.matrix.translate(20, 20)
        box.matrix.rotate(math.pi / 2)
        canvas.add(box)

        p = canvas.get_matrix_i2c(box).transform_point(0, 20)
        p = canvas.get_matrix_c2i(box).transform_point(20, 20)
        i, h = view.get_handle_at_point((20, 20))
        assert i is box
        assert h is box.handles()[0]
コード例 #30
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']
コード例 #31
0
ファイル: test_canvas.py プロジェクト: amolenaar/gaphas
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"]
コード例 #32
0
    def test_line_projection(self):
        """Test projection with line's handle on element's side"""
        line = Line()
        line.matrix.translate(15, 50)
        h1, h2 = line.handles()
        h1.x, h1.y = 0, 0
        h2.x, h2.y = 20, 20

        box = Box()
        box.matrix.translate(10, 10)
        box.width = 40
        box.height = 20
        h_nw, h_ne, h_se, h_sw = box.handles()

        canvas = Canvas()
        canvas.add(line)
        canvas.add(box)

        # move line's second handle on box side
        h2.x, h2.y = 5, -20
コード例 #33
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']
コード例 #34
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
コード例 #35
0
    def test_line_projection(self):
        """Test projection with line's handle on element's side"""
        line = Line()
        line.matrix.translate(15, 50)
        h1, h2 = line.handles()
        h1.x, h1.y = 0, 0
        h2.x, h2.y = 20, 20

        box = Box()
        box.matrix.translate(10, 10)
        box.width = 40
        box.height = 20
        h_nw, h_ne, h_se, h_sw = box.handles()

        canvas = Canvas()
        canvas.add(line)
        canvas.add(box)

        # move line's second handle on box side
        h2.x, h2.y = 5, -20
コード例 #36
0
def create_canvas():
    canvas = Canvas()
    box = Box()
    canvas.add(box)
    box.matrix.translate(100, 50)
    box.matrix.rotate(50)
    box2 = Box()
    canvas.add(box2, parent=box)

    line = Line()
    line.handles()[0].visible = False
    line.handles()[0].connected_to = box
    line.handles()[0].disconnect = my_disconnect()
    line.handles()[0].connection_data = 1

    canvas.add(line)

    canvas.update()

    return canvas
コード例 #37
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))
コード例 #38
0
ファイル: conftest.py プロジェクト: amolenaar/gaphas
class SimpleCanvas(object):
    """Creates a test canvas object.

    Adds a view, canvas, and handle connection tool to a test
    case. Two boxes and a line are added to the canvas as well.
    """

    def __init__(self):
        self.canvas = Canvas()

        self.box1 = Box()
        self.canvas.add(self.box1)
        self.box1.matrix.translate(100, 50)
        self.box1.width = 40
        self.box1.height = 40
        self.box1.request_update()

        self.box2 = Box()
        self.canvas.add(self.box2)
        self.box2.matrix.translate(100, 150)
        self.box2.width = 50
        self.box2.height = 50
        self.box2.request_update()

        self.line = Line()
        self.head = self.line.handles()[0]
        self.tail = self.line.handles()[-1]
        self.tail.pos = 100, 100
        self.canvas.add(self.line)

        self.canvas.update_now()
        self.view = GtkView()
        self.view.canvas = self.canvas

        self.win = Gtk.Window()
        self.win.add(self.view)
        self.view.show()
        self.view.update()
        self.win.show()

        self.tool = ConnectHandleTool(self.view)
コード例 #39
0
ファイル: test_view.py プロジェクト: pcakapratibha/gaphas
    def test_bounding_box_calculations(self):
        """
        A view created before and after the canvas is populated should contain
        the same data.
        """
        canvas = Canvas()

        window1 = gtk.Window(gtk.WINDOW_TOPLEVEL)
        view1 = GtkView(canvas=canvas)
        window1.add(view1)
        view1.realize()
        window1.show_all()

        box = Box()
        box.matrix = (1.0, 0.0, 0.0, 1, 10,10)
        canvas.add(box)

        line = Line()
        line.fyzzyness = 1
        line.handles()[1].pos = (30, 30)
        #line.split_segment(0, 3)
        line.matrix.translate(30, 60)
        canvas.add(line)

        window2 = gtk.Window(gtk.WINDOW_TOPLEVEL)
        view2 = GtkView(canvas=canvas)
        window2.add(view2)
        window2.show_all()

        # Process pending (expose) events, which cause the canvas to be drawn.
        while gtk.events_pending():
            gtk.main_iteration()

        try: 
            assert view2.get_item_bounding_box(box)
            assert view1.get_item_bounding_box(box)
            assert view1.get_item_bounding_box(box) == view2.get_item_bounding_box(box), '%s != %s' % (view1.get_item_bounding_box(box), view2.get_item_bounding_box(box))
            assert view1.get_item_bounding_box(line) == view2.get_item_bounding_box(line), '%s != %s' % (view1.get_item_bounding_box(line), view2.get_item_bounding_box(line))
        finally:
            window1.destroy()
            window2.destroy()
コード例 #40
0
def test_line_projection():
    """Test projection with line's handle on element's side.

    """
    line = Line()
    line.matrix.translate(15, 50)
    h1, h2 = line.handles()
    h1.pos = (0, 0)
    h2.pos = (20, 20)

    box = Box()
    box.matrix.translate(10, 10)
    box.width = 40
    box.height = 20

    canvas = Canvas()
    canvas.add(line)
    canvas.add(box)

    # move line's second handle on box side
    h2.pos = (5, -20)
コード例 #41
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
コード例 #42
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
コード例 #43
0
ファイル: conftest.py プロジェクト: wglu2010/gaphas
class SimpleCanvas:
    """Creates a test canvas object.

    Adds a view, canvas, and handle connection tool to a test
    case. Two boxes and a line are added to the canvas as well.
    """
    def __init__(self):
        self.canvas = Canvas()

        self.box1 = Box()
        self.canvas.add(self.box1)
        self.box1.matrix.translate(100, 50)
        self.box1.width = 40
        self.box1.height = 40
        self.box1.request_update()

        self.box2 = Box()
        self.canvas.add(self.box2)
        self.box2.matrix.translate(100, 150)
        self.box2.width = 50
        self.box2.height = 50
        self.box2.request_update()

        self.line = Line()
        self.head = self.line.handles()[0]
        self.tail = self.line.handles()[-1]
        self.tail.pos = 100, 100
        self.canvas.add(self.line)

        self.canvas.update_now()
        self.view = GtkView()
        self.view.canvas = self.canvas

        self.win = Gtk.Window()
        self.win.add(self.view)
        self.view.show()
        self.view.update()
        self.win.show()

        self.tool = ConnectHandleTool(self.view)
コード例 #44
0
ファイル: test_undo.py プロジェクト: franzlst/gaphas
    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)
コード例 #45
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)
コード例 #46
0
ファイル: test_canvas.py プロジェクト: amolenaar/gaphas
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)
コード例 #47
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))
コード例 #48
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))
コード例 #49
0
 def test_placement(self):
     tab = self.tab
     diagram = self.diagram
     from gaphas import Element
     from gaphas.examples import Box
     box = Box()
     diagram.canvas.add(box)
     diagram.canvas.update_now()
     tab.view.request_update([box])
     
     from gaphor.diagram.comment import CommentItem
     comment = self.diagram.create(CommentItem, subject=self.element_factory.create(uml2.Comment))
     self.assertEquals(len(self.element_factory.lselect()), 2)
コード例 #50
0
ファイル: test_element.py プロジェクト: franzlst/gaphas
    def test_resize_se(self):
        """
        Test resizing of element by dragging it SE handle.
        """
        canvas = Canvas()
        box = Box()
        handles = box.handles()

        canvas.add(box)

        h_nw, h_ne, h_se, h_sw = handles
        assert h_nw is handles[NW]
        assert h_ne is handles[NE]
        assert h_sw is handles[SW]
        assert h_se is handles[SE]

        # to see how many solver was called:
        # GAPHAS_TEST_COUNT=3 nosetests -s --with-prof --profile-restrict=gaphas gaphas/tests/test_element.py | grep -e '\<solve\>' -e dirty

        count = getenv('GAPHAS_TEST_COUNT')
        if count:
            count = int(count)
        else:
            count = 1

        for i in range(count):
            h_se.pos.x += 100  # h.se.{x,y} = 10, now
            h_se.pos.y += 100
            box.request_update()
            canvas.update()

        self.assertEqual(
            110 * count,
            h_se.pos.x)  # h_se changed above, should remain the same
        self.assertEqual(110 * count, float(h_se.pos.y))

        self.assertEqual(110 * count, float(h_ne.pos.x))
        self.assertEqual(110 * count, float(h_sw.pos.y))
コード例 #51
0
    def test_resize_se(self):
        """
        Test resizing of element by dragging it SE handle.
        """
        canvas = Canvas()
        box = Box()
        handles = box.handles()

        canvas.add(box)

        h_nw, h_ne, h_se, h_sw = handles
        assert h_nw is handles[NW]
        assert h_ne is handles[NE]
        assert h_sw is handles[SW]
        assert h_se is handles[SE]

        # to see how many solver was called:
        # GAPHAS_TEST_COUNT=3 nosetests -s --with-prof --profile-restrict=gaphas gaphas/tests/test_element.py | grep -e '\<solve\>' -e dirty

        count = getenv('GAPHAS_TEST_COUNT')
        if count:
            count = int(count)
        else:
            count = 1

        for i in range(count):
            h_se.pos.x += 100      # h.se.{x,y} = 10, now
            h_se.pos.y += 100
            box.request_update()
            canvas.update()

        self.assertEquals(110 * count, h_se.pos.x) # h_se changed above, should remain the same
        self.assertEquals(110 * count, float(h_se.pos.y))

        self.assertEquals(110 * count, float(h_ne.pos.x))
        self.assertEquals(110 * count, float(h_sw.pos.y))
コード例 #52
0
ファイル: demo.py プロジェクト: kubaraczkowski/gaphas
def create_canvas(c=None):
    if not c:
        c = Canvas()
    b=MyBox()
    b.min_width = 20
    b.min_height = 30
    print 'box', b
    b.matrix=(1.0, 0.0, 0.0, 1, 20,20)
    b.width = b.height = 40
    c.add(b)

    bb=Box()
    print 'box', bb
    bb.matrix=(1.0, 0.0, 0.0, 1, 10,10)
    c.add(bb, parent=b)

    fl = FatLine()
    fl.height = 50
    fl.matrix.translate(100, 100)
    c.add(fl)

    circle = Circle()
    h1, h2 = circle.handles()
    circle.radius = 20
    circle.matrix.translate(50, 100)
    c.add(circle)

    # AJM: extra boxes:
    bb = Box()
    print 'box', bb
    bb.matrix.rotate(math.pi/4.)
    c.add(bb, parent=b)
#    for i in xrange(10):
#        bb=Box()
#        print 'box', bb
#        bb.matrix.rotate(math.pi/4.0 * i / 10.0)
#        c.add(bb, parent=b)

    b = PortoBox(60, 60)
    b.min_width = 40
    b.min_height = 50
    b.matrix.translate(55, 55)
    c.add(b)

    t = UnderlineText()
    t.matrix.translate(70,30)
    c.add(t)

    t = MyText('Single line')
    t.matrix.translate(70,70)
    c.add(t)

    l = MyLine()
    c.add(l)
    l.handles()[1].pos = (30, 30)
    segment = Segment(l, view=None)
    segment.split_segment(0, 3)
    l.matrix.translate(30, 60)
    l.orthogonal = True

    off_y = 0
    for align_x in (-1, 0, 1):
        for align_y in (-1, 0, 1):
            t=MyText('Aligned text %d/%d' % (align_x, align_y),
                     align_x=align_x, align_y=align_y)
            t.matrix.translate(120, 200 + off_y)
            off_y += 30
            c.add(t)

    t=MyText('Multiple\nlines', multiline = True)
    t.matrix.translate(70,100)
    c.add(t)

    return c
コード例 #53
0
ファイル: test_element.py プロジェクト: amolenaar/gaphas
 def __init__(self):
     self.canvas = Canvas()
     self.box = Box()
     self.handles = self.box.handles()
コード例 #54
0
ファイル: test_element.py プロジェクト: amolenaar/gaphas
class CanvasBox(object):
    def __init__(self):
        self.canvas = Canvas()
        self.box = Box()
        self.handles = self.box.handles()