[pygtk] DrawingArea and mouse events
Donn
donn.ingle at gmail.com
Mon Nov 12 23:56:17 WST 2007
> if your object can describe itself as a polygon, you can use a "point
> in polygon" test. matplotlib provides some code to do this which is
> extremely fast.
Thanks. I solved this a few days ago. I understand the concept behind the
point in poly (so clever!) but the implementation is a black box to me.
Happily, I managed to convert some C code to Python and it works. After that
I discovered that Cairo already has a hit test built in. Ah well. :)
(I put a recipe up on the Cairo website.)
> > For the "bubbling" of events through my objects, I think I have an angle
> > on it and can start hacking.
> Is this something that either using "draw_idle" or an idle handler
> will help with?
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:
* always running: In one object (subclass of gtk.DrawingArea) I detect
general mouse events and set flags.
1. Recurse through my tree of objects
2. Push markers onto a stack depending on the objects
3. Go through the stack, popping and drawing each object (by calling its
draw() function if it has one)
4. Per each stack element check the mouse flags, call onClick() of object if
it has one.
5. Flush the stack
6. Loop to 1
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.
It's tricky because the thing I'm trying to do is frame-based, and a click on
a thing can cause that thing to advance to another frame.
The idea is to prototype a general animation frame/tween based API that can
be used to create other applications -- so no gui right now. It could very
well be used to write it's own gui, but I've only so many brain cells :)
Ah well, I see I am rambling and not making much sense. I'll get it running
from a single loop and a single stack before I even hope to appreciate some
kind of divorce between them. :)
Thanks for your input!
\d
More information about the pygtk
mailing list