Esempio n. 1
0
class SimpleCanvas(gtk.DrawingArea):

    __gtype_name__ = "SimpleCanvas"
    framerate = 25

    def __init__(self, *args, **kwargs):
        gtk.DrawingArea.__init__(self, *args, **kwargs)
        self._width = 0
        self._height = 0
        self.connect("configure-event", self._configure_event_cb)
        self.connect("expose-event", self._expose_event_cb)
        self.root = CanvasItem()
        self.start = time.time()
        self.clock = 0
        gobject.timeout_add(1000 / self.framerate, self._paint_clock)

    def _paint_clock(self):
        self.queue_draw()
        self.clock = time.time() - self.start
        return True

    def _configure_event_cb(self, self2, event):
        self._width = event.width
        self._height = event.height

    def _expose_event_cb(self, self2, event):
        context = self.window.cairo_create()
        context.rectangle(*event.area)
        context.clip()
        self.paint(context)
        return False

    def paint(self, cr):
        self.root.paint(cr)
Esempio n. 2
0
 def __init__(self, *args, **kwargs):
     gtk.DrawingArea.__init__(self, *args, **kwargs)
     self._width = 0
     self._height = 0
     self.connect("configure-event", self._configure_event_cb)
     self.connect("expose-event", self._expose_event_cb)
     self.root = CanvasItem()
     self.start = time.time()
     self.clock = 0
     gobject.timeout_add(1000 / self.framerate, self._paint_clock)