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)
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))
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)
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()
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()
def create_canvas(c=None): if not c: c = Canvas() b = MyBox() b.min_width = 20 b.min_height = 30 b.matrix = (1.0, 0.0, 0.0, 1, 20, 20) b.width = b.height = 40 c.add(b) bb = Box() 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() bb.matrix.rotate(math.pi / 1.567) 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( f"Aligned text {align_x:d}/{align_y:d}", 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
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