def __init__(self, text, bgColor = '#96abcb', fgColor = '#384a5c'): Canvas.__init__(self) root = self.get_root_item() self.styleBgColor = self.style.bg[STATE_PRELIGHT].to_string() self.styleFont = self.style.font_desc self.textString = text self.bgColor = bgColor self.fgColor = fgColor self.bgRect = Rect( stroke_color = self.styleBgColor, fill_color = self.styleBgColor, line_width = 0.0) self.rect = Rect( stroke_color = self.fgColor, fill_color = self.bgColor, line_width = 2.0, radius_x = 5, radius_y = 5) self.text = Text( text = self.textString, anchor = ANCHOR_CENTER, fill_color = self.fgColor, font_desc = self.styleFont) root.add_child(self.bgRect, -1) root.add_child(self.rect, -1) root.add_child(self.text, -1) self.connect('size-allocate', self.size_allocated, None) self.connect('size-request', self.size_request, None)
def __init__(self, **args): GooCanvas.__init__(self, **args) # infinite world should replace scroll_region self.set_properties( automatic_bounds=True, integer_layout=False, bounds_from_origin=False, bounds_padding=100, ) self.root = self.get_root_item() self.root.set_properties(fill_color="white") polyline_new_line(self.root, -5, 0, 5, 0, stroke_color="red") polyline_new_line(self.root, 0, -5, 0, 5, stroke_color="red") self.zoom = False # GooCanvas will transmit all keyboard events to # its parent unless one of its item has focus. self.parent.connect_object("key_press_event", Canvas.eventhandler, self) self.parent.connect_object("key_release_event", Canvas.eventhandler, self) self.connect("event", Canvas.eventhandler)
class DrawArea(ScrolledWindow): def __init__(self): ScrolledWindow.__init__(self) self.set_policy(POLICY_ALWAYS, POLICY_ALWAYS) self.table = Table(3, 3) self.hRuler = HRuler() self.vRuler = VRuler() self.canvas = Canvas() self.canvas.connect('size-allocate', self.area_allocate, None) self.canvas.connect('motion-notify-event', self.area_motion, None) self.table.attach(self.hRuler, 1, 2, 0, 1, SHRINK | FILL, SHRINK | FILL) self.table.attach(self.vRuler, 0, 1, 1, 2, SHRINK | FILL, SHRINK | FILL) self.table.attach(self.canvas, 1, 2, 1, 2) self.add_with_viewport(self.table) def area_allocate(self, widget, allocation, data): self.hRuler.set_range(0, self.canvas.allocation[2], 10, self.canvas.allocation[2]) self.vRuler.set_range(0, self.canvas.allocation[3], 10, self.canvas.allocation[3]) def area_motion(self, widget, event, data): self.hRuler.set_range(0, self.canvas.allocation[2], event.x, self.canvas.allocation[2]) self.vRuler.set_range(0, self.canvas.allocation[3], event.y, self.canvas.allocation[3])
def __init__(self): ScrolledWindow.__init__(self) self.set_policy(POLICY_ALWAYS, POLICY_ALWAYS) self.table = Table(3, 3) self.hRuler = HRuler() self.vRuler = VRuler() self.canvas = Canvas() self.canvas.connect('size-allocate', self.area_allocate, None) self.canvas.connect('motion-notify-event', self.area_motion, None) self.table.attach(self.hRuler, 1, 2, 0, 1, SHRINK | FILL, SHRINK | FILL) self.table.attach(self.vRuler, 0, 1, 1, 2, SHRINK | FILL, SHRINK | FILL) self.table.attach(self.canvas, 1, 2, 1, 2) self.add_with_viewport(self.table)
def __init__(self): Canvas.__init__(self)