当前位置: 首页>>代码示例>>Python>>正文


Python item.Line类代码示例

本文整理汇总了Python中gaphas.item.Line的典型用法代码示例。如果您正苦于以下问题:Python Line类的具体用法?Python Line怎么用?Python Line使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Line类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_orthogonal_line_undo

def test_orthogonal_line_undo(revert_undo, undo_fixture):
    """Test orthogonal line undo.

    """
    canvas = Canvas()
    line = Line()
    canvas.add(line)

    segment = Segment(line, None)
    segment.split_segment(0)

    # Start with no orthogonal constraints
    assert len(canvas.solver._constraints) == 0

    line.orthogonal = True

    # Check orthogonal constraints
    assert 2 == len(canvas.solver._constraints)
    assert 3 == len(line.handles())

    undo_fixture[0]()  # Call undo

    assert not line.orthogonal
    assert 0 == len(canvas.solver._constraints)
    assert 2 == len(line.handles())
开发者ID:amolenaar,项目名称:gaphas,代码行数:25,代码来源:test_line.py

示例2: test_constraints_after_merge

    def test_constraints_after_merge(self):
        """Test if constraints are recreated after line merge
        """

        # connect line2 to self.line
        line2 = Line()
        self.canvas.add(line2)
        head = line2.handles()[0]

        #conn = Connector(line2, head)
        #sink = conn.glue((25, 25))
        #assert sink is not None

        #conn.connect(sink)

        self.tool.connect(line2, head, (25, 25))
        cinfo = self.canvas.get_connection(head)
        self.assertEquals(self.line, cinfo.connected)

        segment = Segment(self.line, self.view)
        segment.split_segment(0)
        assert len(self.line.handles()) == 3
        c1 = cinfo.constraint

        segment.merge_segment(0)
        assert len(self.line.handles()) == 2

        h1, h2 = self.line.handles()
        # connection shall be reconstrained between 1st and 2nd handle
        cinfo = self.canvas.get_connection(head)
        self.assertEquals(cinfo.constraint._line[0]._point, h1.pos)
        self.assertEquals(cinfo.constraint._line[1]._point, h2.pos)
        self.assertFalse(c1 == cinfo.constraint)
开发者ID:jvorcak,项目名称:gpylint,代码行数:33,代码来源:test_segment.py

示例3: test_orthogonal_horizontal_undo

def test_orthogonal_horizontal_undo(revert_undo, undo_fixture):
    """Test orthogonal line constraints bug (#107).

    """
    canvas = Canvas()
    line = Line()
    canvas.add(line)
    assert not line.horizontal
    assert len(canvas.solver._constraints) == 0

    segment = Segment(line, None)
    segment.split_segment(0)

    line.orthogonal = True

    assert 2 == len(canvas.solver._constraints)

    del undo_fixture[2][:]  # Clear undo_list
    line.horizontal = True

    assert 2 == len(canvas.solver._constraints)

    undo_fixture[0]()  # Call undo

    assert not line.horizontal
    assert 2 == len(canvas.solver._constraints)

    line.horizontal = True

    assert line.horizontal
    assert 2 == len(canvas.solver._constraints)
开发者ID:amolenaar,项目名称:gaphas,代码行数:31,代码来源:test_line.py

示例4: test_orthogonal_horizontal_undo

    def test_orthogonal_horizontal_undo(self):
        canvas = Canvas()
        line = Line()
        canvas.add(line)

        assert len(canvas.solver._constraints) == 0

        line.orthogonal = True

        assert len(canvas.solver._constraints) == 2
        after_ortho = set(canvas.solver._constraints)

        del undo_list[:]
        line.horizontal = True

        assert len(canvas.solver._constraints) == 2

        undo()

        assert not line.horizontal
        assert len(canvas.solver._constraints) == 2, canvas.solver._constraints

        line.horizontal = True

        assert line.horizontal
        assert len(canvas.solver._constraints) == 2, canvas.solver._constraints
开发者ID:hugoruscitti,项目名称:examplelab,代码行数:26,代码来源:test_line.py

示例5: create_canvas

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)
开发者ID:amolenaar,项目名称:gaphas,代码行数:32,代码来源:simple-box.py

示例6: test_segment

 def test_segment(self):
     """
     """
     view = self.view
     line = Line()
     self.canvas.add(line)
     segment = Segment(line, self.view)
     self.assertEquals(2, len(line.handles()))
     segment.split((5, 5))
     self.assertEquals(3, len(line.handles()))
开发者ID:jvorcak,项目名称:gpylint,代码行数:10,代码来源:test_segment.py

示例7: test_connect_item

    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
开发者ID:adrianboguszewski,项目名称:gaphas,代码行数:15,代码来源:test_canvas.py

示例8: __init__

    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)
开发者ID:amolenaar,项目名称:gaphas,代码行数:34,代码来源:conftest.py

示例9: test_connect_item

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
开发者ID:amolenaar,项目名称:gaphas,代码行数:16,代码来源:test_canvas.py

示例10: testUndoOnDeletedElement

    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)
开发者ID:jvorcak,项目名称:gpylint,代码行数:53,代码来源:test_undo.py

示例11: test_disconnect_item_with_callback

    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']
开发者ID:adrianboguszewski,项目名称:gaphas,代码行数:19,代码来源:test_canvas.py

示例12: test_undo_on_delete_element

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
开发者ID:amolenaar,项目名称:gaphas,代码行数:52,代码来源:test_undo.py

示例13: test_constraints_after_split

    def test_constraints_after_split(self):
        """Test if constraints are recreated after line split
        """

        # connect line2 to self.line
        line2 = Line()
        self.canvas.add(line2)
        head = line2.handles()[0]
        self.tool.connect(line2, head, (25, 25))
        cinfo = self.canvas.get_connection(head)
        self.assertEquals(self.line, cinfo.connected)

        Segment(self.line, self.view).split_segment(0)
        assert len(self.line.handles()) == 3
        h1, h2, h3 = self.line.handles()

        cinfo = self.canvas.get_connection(head)
        # connection shall be reconstrained between 1st and 2nd handle
        self.assertEquals(h1.pos, cinfo.constraint._line[0]._point)
        self.assertEquals(h2.pos, cinfo.constraint._line[1]._point)
开发者ID:jvorcak,项目名称:gpylint,代码行数:20,代码来源:test_segment.py

示例14: test_disconnect_item_with_callback

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"]
开发者ID:amolenaar,项目名称:gaphas,代码行数:20,代码来源:test_canvas.py

示例15: test_line_projection

    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
开发者ID:adrianboguszewski,项目名称:gaphas,代码行数:20,代码来源:test_canvas.py


注:本文中的gaphas.item.Line类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。