本文整理汇总了Python中gaphas.examples.Box类的典型用法代码示例。如果您正苦于以下问题:Python Box类的具体用法?Python Box怎么用?Python Box使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Box类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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)
示例2: 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)
示例3: __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)
示例4: 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()
示例5: 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)
示例6: 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
示例7: test_update_matrices
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)
示例8: test_update_matrices
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))
示例9: 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
示例10: 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
示例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_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
示例13: 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']
示例14: 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
示例15: 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"]