def test_get_set_child_property(self): c = goocanvas.Canvas() r = c.get_root_item() t = goocanvas.Table(parent=r) i = self.make_rect_item(parent=t, x=100, y=100, height=100, width=100) t.set_child_property(i, "bottom_padding", 3) res = t.get_child_property(i, "bottom_padding") self.failUnlessEqual(res, 3.0)
def test_get_set_child_properties(self): c = goocanvas.Canvas() r = c.get_root_item() t = goocanvas.Table(parent=r) i = self.make_rect_item(parent=t, x=100, y=100, height=100, width=100) t.set_child_properties(i, bottom_padding=3, columns=2, x_align=0.4) res = t.get_child_properties(i, "bottom_padding", "columns", "x_align") self.failUnlessEqual(res, (3.0, 2, 0.4))
def create_width_for_height_table(root, x, y, width, height, rotation): text = "This is a long paragraph that will have to be split over a few \ lines so we can see if its allocated height changes when its \ allocated width is changed." table = goocanvas.Table(parent=root, width=width, height=height) table.translate(x, y) table.rotate(rotation, 0, 0) item = goocanvas.Rect(parent=table, x=0.0, y=0.0, width=width - 2, height=10.0, fill_color="red") table.set_child_properties(item, row=0, column=0, x_shrink=True) item = goocanvas.Text(parent=table, text=text, x=0, y=0, width=-1, anchor=gtk.ANCHOR_NW) table.set_child_properties(item, row=1, column=0, x_expand=True, x_fill=True, x_shrink=True, y_expand=True, y_fill=True) item.set_data("id", "Text Item") item.connect("button_press_event", on_button_press) item = goocanvas.Rect(parent=table, x=0.0, y=0.0, width=width - 2, height=10.0, fill_color="red") table.set_child_properties(item, row=2, column=0, x_shrink=True)
def create_demo_table(root, x, y, width, height): table = goocanvas.Table(parent=root, row_spacing=4.0, column_spacing=4.0, width=width, height=height) table.translate(x, y) square = goocanvas.Rect(parent=table, x=0.0, y=0.0, width=50.0, height=50.0, fill_color="red") table.set_child_properties(square, row=0, column=0, x_shrink=True) square.set_data("id", "Red square") square.connect("button_press_event", on_button_press) circle = goocanvas.Ellipse(parent=table, center_x=0, center_y=0, radius_x=25, radius_y=25, fill_color="blue") table.set_child_properties(circle, row=0, column=1, x_shrink=True) circle.set_data("id", "Blue circle") circle.connect("button_press_event", on_button_press) p = goocanvas.Points([(25, 0), (0, 50), (50, 50)]) triangle = goocanvas.Polyline(parent=table, close_path=True, points=p, fill_color="yellow") table.set_child_properties(triangle, row=0, column=2, x_shrink=True) triangle.set_data("id", "Yellow triangle") triangle.connect("button_press_event", on_button_press)
def create_table(parent, row, column, embedding_level, x, y, rotation, scale, demo_item_type): table = goocanvas.Table(parent=parent, row_spacing=4.0, column_spacing=4.0) table.translate(x, y) table.rotate(rotation, 0, 0) table.scale(scale, scale) if row != -1: parent.set_child_properties(table, row=row, column=column, x_expand=True, x_fill=True) if embedding_level: level = embedding_level - 1 create_table(table, 0, 0, level, 50, 50, 0, 0.7, demo_item_type) create_table(table, 0, 1, level, 50, 50, 45, 1.0, demo_item_type) create_table(table, 0, 2, level, 50, 50, 90, 1.0, demo_item_type) create_table(table, 1, 0, level, 50, 50, 135, 1.0, demo_item_type) create_table(table, 1, 1, level, 50, 50, 180, 1.5, demo_item_type) create_table(table, 1, 2, level, 50, 50, 225, 1.0, demo_item_type) create_table(table, 2, 0, level, 50, 50, 270, 1.0, demo_item_type) create_table(table, 2, 1, level, 50, 50, 315, 1.0, demo_item_type) create_table(table, 2, 2, level, 50, 50, 360, 2.0, demo_item_type) else: create_demo_item(table, demo_item_type, 0, 0, 1, 1, "(0,0)") create_demo_item(table, demo_item_type, 0, 1, 1, 1, "(1,0)") create_demo_item(table, demo_item_type, 0, 2, 1, 1, "(2,0)") create_demo_item(table, demo_item_type, 1, 0, 1, 1, "(0,1)") create_demo_item(table, demo_item_type, 1, 1, 1, 1, "(1,1)") create_demo_item(table, demo_item_type, 1, 2, 1, 1, "(2,1)") create_demo_item(table, demo_item_type, 2, 0, 1, 1, "(0,2)") create_demo_item(table, demo_item_type, 2, 1, 1, 1, "(1,2)") create_demo_item(table, demo_item_type, 2, 2, 1, 1, "(2,2)") return table
def make_table_item(self, **kwargs): item = goocanvas.Table(**kwargs) return item
def setup_canvas (canvas): root = canvas.get_root_item () #Plain items without clip path. item = goocanvas.Ellipse (parent = root, center_x = 0, center_y = 0, radius_x = 50, radius_y = 30, fill_color = "blue") item.translate (100, 100) item.rotate (30, 0, 0) item.connect ("button_press_event", on_button_press, "Blue ellipse (unclipped)") item = goocanvas.Rect (parent = root, x = 200, y = 50, width = 100, height = 100, fill_color = "red", clip_fill_rule = cairo.FILL_RULE_EVEN_ODD) item.connect ("button_press_event", on_button_press, "Red rectangle (unclipped)") item = goocanvas.Rect (parent = root, x = 380, y = 50, width = 100, height = 100, fill_color = "yellow") item.connect ("button_press_event", on_button_press, "Yellow rectangle (unclipped)") # Clipped items. item = goocanvas.Ellipse (parent = root, center_x = 0, center_y = 0, radius_x = 50, radius_y = 30, fill_color = "blue", clip_path = "M 0 0 h 100 v 100 h -100 Z") item.translate (100, 300) item.rotate (30, 0, 0) item.connect ("button_press_event", on_button_press, "Blue ellipse") item = goocanvas.Rect (parent = root, x = 200, y = 250, width = 100, height = 100, fill_color = "red", clip_path = "M 250 300 h 100 v 100 h -100 Z", clip_fill_rule = cairo.FILL_RULE_EVEN_ODD) item.connect ("button_press_event", on_button_press, "Red rectangle") item = goocanvas.Rect (parent = root, x = 380, y = 250, width = 100, height = 100, fill_color = "yellow", clip_path = "M480,230 l40,100 l-80 0 z") item.connect ("button_press_event", on_button_press, "Yellow rectangle") # Table with clipped items. table = goocanvas.Table (parent = root) table.translate (200, 400) table.rotate (30, 0, 0) item = goocanvas.Ellipse (parent = table, center_x = 0, center_y = 0, radius_x = 50, radius_y = 30, fill_color = "blue", clip_path = "M 0 0 h 100 v 100 h -100 Z") item.translate (100, 300) item.rotate (30, 0, 0) item.connect ("button_press_event", on_button_press, "Blue ellipse") item = goocanvas.Rect (parent = table, x = 200, y = 250, width = 100, height = 100, fill_color = "red", clip_path = "M 250 300 h 100 v 100 h -100 Z", clip_fill_rule = cairo.FILL_RULE_EVEN_ODD) item.connect ("button_press_event", on_button_press, "Red rectangle") table.set_child_properties (item, column = 1) item = goocanvas.Rect (parent = table, x = 380, y = 250, width = 100, height = 100, fill_color = "yellow", clip_path = "M480,230 l40,100 l-80 0 z") item.connect ("button_press_event", on_button_press, "Yellow rectangle") table.set_child_properties (item, column = 2)