[pygtk] window.invalidate_rect speed
Donn
donn.ingle at gmail.com
Mon Dec 10 17:17:48 WST 2007
Nathaniel,
Thanks for your response. I will try to better explain:
> What do you mean by "out of synch"? Why is it so urgent that the
> redraw happen quickly?
I mean that *if* the expose event takes too long to run, the loop may have
begun again and the state of the app will have changed.
I am building a 'stack' of objects that represent the state -- what gets
drawn where and in what order. It goes like this:
This is the loop in my _stack(gtk.DrawingArea) class:
def _tick(self):
1. self.MainTimeline._tick()
2. _stack._draw()
3. if _stack.quitApp:
4. gtk.main_quit()
5. return True # spawn timeout again.
This function is initially called by:
gobject.timeout_add(self.speed, self._tick)
gtk.main()
_stack.draw() is:
def _draw(self):
if not self.quitApp:
self.alloc = self.get_allocation()
rect = gtk.gdk.Rectangle(self.alloc.x, self.alloc.y,
self.alloc.width, self.alloc.height)
self.window.invalidate_rect(rect, True)
So, it forces an expose event in the _stack class that goes through the stack
and draws all the graphics to the DrawingArea.
> No -- invalidate_rect will generally *not* trigger the expose event
> until after you return to the main loop, i.e., after your _timer
> callback finishes.
Actually, on my fairly fast machine, the expose event *is* running *and*
finishing before the return from _tick(). I am worried that this is unplanned
and that on other machines it may take even longer to run.
So, I need to ensure (somehow) that line 5 (above) does *not* get reached
until the expose event (triggered by line 2) has finished.
I can use flags to prevent line 1 from running until expose has finished, but
I thought I'd try to get a better picture about the timing of these events.
Is there a better, faster, way to force an expose? I don't suppose I can call
the expose handler directly?
> If you do a busy-loop like this, then not only
> will you be living in a state of sin (busy-loops are bad!), but you
> will never receive the expose event at all.
As I am actually getting the expose event, I must be doing something right :)
> What are you trying to do?
I'm writing a retained-mode API to do vector animation using Cairo.
So far it's working far better than I had hoped. The user will import my
module and use the simple API to setup tweens and parent-child relationships.
Each object gets a draw() method where the user can use Cairo to draw stuff.
(I suppose they can use anything they want that will draw in a DrawingArea,
but I am using Cairo-specific matrixes for controlling everything.
I hope that's clearer!
\d
More information about the pygtk
mailing list