[pygtk] DrawingArea and mouse events

John Hunter jdh2358 at gmail.com
Tue Nov 13 00:05:51 WST 2007


On Nov 12, 2007 8:56 AM, Donn <donn.ingle at gmail.com> wrote:

> Well, I am a simple guy and you mention things I don't know about. I could
> (and will) go look those up, but here is my current approach:

> So, I think I'm going to run into problems with timing. The loop is a
> gobject.timeout_add(self.speed, self.tick). At the moment I am all kinds of
> fuzzy on how to separate the drawing from the handling of events. My code
> does them on the same beat, but if the animation is too slow, the events will
> also be consumed slowly and may start going out of synch.

This is basically what draw_idle and the idle handlers are designed to
do.  draw_idle tells the canvas to redraw only if not busy, so it will
avoid the build up problem and dramatically increase the
responsiveness of your app.

Here is the basic design:

        def __init__(self):
            self._idleID = 0

    def draw_idle(self):
        def idle_draw(*args):
            self.draw()
            self._idleID = 0
            return False
        if self._idleID == 0:
            self._idleID = gobject.idle_add(idle_draw)

Repeated calls to draw_idle during a mouse motion will no longer "pile up"

JDH


More information about the pygtk mailing list