[Sugar-devel] GASP - summer internship

Benjamin M. Schwartz bmschwar at fas.harvard.edu
Wed Jun 3 15:32:42 EDT 2009


Jamie Boisture wrote:
"""
One of the problems with using gtk in this way is that gtk.main() can not
be called when begin_graphics is called because it would not allow the
rest of the user's program to execute.  Instead it has to launch a thread
that will update the screen and call gtk.main_iteration().  This is not
ideal, but I do not see an alternative.
"""

There's nothing wrong with using threads for drawing; there's even a
tutorial on how to do it right on the Cairo website. [1]  Section 20 of
the PyGTK FAQ is also helpful. [2]

However, you can avoid threading while maintaining a responsive user
interface, even if rendering is slow.  The trick is to break rendering up
into many small steps, and switch control back to the mainloop between
steps.  This way, if the user makes an action, there will not be a long
delay before the mainloop can process the input.

This programming style is sometimes called a "coroutine".  There's a nice
example at [3], which is also referenced in PyGTK FAQ 20.9.

--Ben

[1] http://cairographics.org/threaded_animation_with_cairo/
[2] http://faq.pygtk.org/
[3] http://www.daa.com.au/pipermail/pygtk/2001-October/002056.html

P.S.  In practice, I doubt this will be a problem.  If users only get
input feedback once a new frame is rendered, then it hardly matters how
quickly their input is received.  Therefore, you can probably render whole
frames at once, single-threaded, and just not worry about it.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
Url : http://lists.sugarlabs.org/archive/sugar-devel/attachments/20090603/e0b067a7/attachment.pgp 


More information about the Sugar-devel mailing list