本文整理汇总了Python中gaphas.canvas.Canvas类的典型用法代码示例。如果您正苦于以下问题:Python Canvas类的具体用法?Python Canvas怎么用?Python Canvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Canvas类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SegmentFixture
class SegmentFixture(object):
def __init__(self):
self.canvas = Canvas()
self.line = Line()
self.canvas.add(self.line)
self.view = View(self.canvas)
self.item = Item()
示例2: 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)
示例3: 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
示例4: 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())
示例5: test_view_registration_2
def test_view_registration_2(self):
"""
Test view registration and destroy when view is destroyed.
"""
canvas = Canvas()
view = GtkView(canvas)
window = gtk.Window(gtk.WINDOW_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 not box._matrix_i2v.has_key(view)
assert not box._matrix_v2i.has_key(view)
示例6: test_minimal_se
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: test_get_item_at_point
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()
示例8: SegmentHandlesTest
class SegmentHandlesTest(unittest.TestCase):
def setUp(self):
self.canvas = Canvas()
self.line = Line()
self.canvas.add(self.line)
self.view = View(self.canvas)
def testHandleFinder(self):
finder = HandleFinder(self.line, self.view)
assert type(finder) is SegmentHandleFinder, type(finder)
示例9: test_item_removal
def test_item_removal(self):
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()
# 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()
示例10: __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)
示例11: test_get_handle_at_point
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]
示例12: test_reparent
def test_reparent(self):
c = Canvas()
b1 = Box()
b2 = Box()
c.add(b1)
c.add(b2, b1)
c.reparent(b2, None)
示例13: test_creation_with_size
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
示例14: test_orthogonal_line_split_segment
def test_orthogonal_line_split_segment(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)
assert len(line.handles()) == 3
del undo_list[:]
line.split_segment(0)
assert len(canvas.solver._constraints) == 3
assert len(line.handles()) == 4
undo()
assert len(canvas.solver._constraints) == 2
assert len(line.handles()) == 3
assert canvas.solver._constraints == after_ortho
line.split_segment(0)
assert len(canvas.solver._constraints) == 3
assert len(line.handles()) == 4
after_split = set(canvas.solver._constraints)
del undo_list[:]
line.merge_segment(0)
assert len(canvas.solver._constraints) == 2
assert len(line.handles()) == 3
undo()
assert len(canvas.solver._constraints) == 3
assert len(line.handles()) == 4
assert canvas.solver._constraints == after_split
示例15: 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