On 2010.06.10 22:44:40 +0530, Jeenu V wrote:
> On Thu, Jun 10, 2010 at 8:23 PM, David Ripton <drip...@ripton.net> wrote:
> > Yes, of course you can just use PyCairo rather than a canvas.  It's just
> > more work that way.  I ended up having to go this route at work because
> > we're stuck on RHEL 5 which has ancient versions of GTK+ and Cairo, and
> > all the nice new canvases I tried require newer versions.
> 
> Alright. If you've anything that can be shared about how you took the
> long(er) route, please consider doing so.  

Cairo is basically immediate mode.  Which means you need to redraw
everything in the exposed area every time.  A canvas is retained mode.
Meaning you build some objects that know how to redraw themselves every
time they are exposed, with support for placing them and possibly
overlapping them and only drawing what's on top.  If your drawing is
simple enough then it's easier to just use Cairo; the more objects you
throw onto the screen, the more sense it makes to use a full canvas to
subdivide the work so you don't end up with a gigantic unmaintainable
draw method.

I needed a canvas that would work well with the old versions of
libraries on RHEL 5 and not have license problems, and couldn't find one
(GnomeCanvas didn't let me rescale things well, GooCanvas didn't work
well for me for some reason I've forgotten and was also a pain to build,
the one from OLPC was GPL licensed), so I wrote my own.  Basically
inherits from DrawingArea and does Cairo calls in the draw methods.  The
canvas is only 850 lines of Python, but it's the kind of fiddly
lower-level GUI code that's a pain to write.  There are classes for
rectangles, lines with arrows on the ends of them (which require some
trig to draw correctly), SVG images (rsvg module), text (pango and
pangocairo).  A general-purpose canvas library would have more stuff,
but that's all I needed.  Performance is fine for a small number of
displayed objects but doesn't scale well to hundreds of objects.  I'd
like to obsolete this code when we can switch to RHEL 6.

I highly recommend reusing one of the existing canvases rather than
writing your own if at all possible.

-- 
David Ripton    drip...@ripton.net
_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to