[pygtk] custom cairo widget

Pietro Battiston toobaz at email.it
Sat Sep 5 21:56:52 WST 2009


Il giorno sab, 05/09/2009 alle 12.22 +0200, M.B. ha scritto:
> hi all,
> im trying write my first custom widget.
> its cairo slider. on my first look im happy :) but i know that code is
> ugly. if this code running, Xorg is on 50% and python thread is on 49%
> CPU !!!. ( using 'top' in console ).
> Kick me to the right way with this code snipet pls.
> where is error ? Why too much cpu power ?
> 
> PS: sry for my english.

Your mistake is that you continuously redraw, since "expose" calls
"queue_redraw" which (almost immediately) calls (it's its job) "expose".
This way, you have live animation, but you spend _all_ the time drawing.
And indeed, notice you aren't using at all events for mouse, which
however you did register (with self.area.add_events)!

For this widget, you need _two_ handlers:
- a handler for expose which _just draws_
- a handler for pointer click and/or movement which updates self.old_y,
and then calls queue_redraw

bye

Pietro
-------------- parte successiva --------------
Un allegato non testuale è stato rimosso....
Nome:        non disponibile
Tipo:        application/pgp-signature
Dimensione:  197 bytes
Descrizione: Questa =?ISO-8859-1?Q?=E8?= una parte del messaggio
 firmata digitalmente
Url:         http://www.daa.com.au/pipermail/pygtk/attachments/20090905/cc693271/attachment.pgp 


More information about the pygtk mailing list