[Edu-sig] Elementary graphics library

Paul D. Fernhout pdfernhout at kurtz-fernhout.com
Tue May 30 20:18:05 CEST 2006


My head is spinning. :-)

Especially as I am contemplating backend issues for PataPata / PySqueak.

Some more things I've come across building on your search:

The obvious in retrospect:
   http://www.python.org/doc/faq/gui.html
    Python Graphic User Interface FAQ

=== a wx issue and plug for Cairo

http://wiki.osafoundation.org/pub/Journal/PhilippeBossutNotes/TheFrameworkIssue.htm
"Chandler is developed in Python and uses wxPython/wxWidgets as its 
crossplatform UI framework. The decision to use wxWidgets has been made 
early in the project and needs to be reevaluated against progress in 
competing frameworks. The goal of this document is to continue observing 
advances in other frameworks as well as learn from what we had to go 
through in developing with wxWidgets for Chandler."
Related to:
http://lists.freedesktop.org/archives/cairo/2005-July/004549.html
"I've been trying to figure out if there is a way of using Cairo with
wxPython. I've found some old conversations (over a year old) on this
list but I'm curious if anyone can point me to some actual bindings or
instructions? We're struggling with the wx graphics primitives on the
Chandler and Cairo looks like a  answer to our prayers..."

And:
   http://matplotlib.sourceforge.net/faq.html#WHICHBACKEND

====== At length:

"Which backend should I use?

Each of the backends offers different strengths. I'll summarize some of them.
Image generation
For pure image generation (no GUI) you can choose from the Agg, Cairo, PS, 
SVG, Paint, GD or EMF backends. At this point, I advise people to use the 
agg backend because:

     * it's the fastest
     * it uses freetype2 (as does GD) which renders nicely even at small 
resolutions
     * there are clipping issues with GD and Paint
     * it supports fast antialiased drawing and alpha blending
     * it supports mathtext
     * it supports images with imshow

It is likely that with time many of these limitiations or problems will be 
fixed on the other backends.

For publication submission or use with TeX, however, the postscript 
backend is naturally a good choice.
GUI
Currently there are several choices for GUIs: GTK, GTKAgg, GTKCairo, WX, 
WXAgg, TkAgg and FltkAgg, with different advantages.

     * Speed: TkAgg and GTKAgg are likely to be the fastest since most of 
Agg is renderered in C extension code
     * Stability: GTK was the first backend and thus has been most 
thoroughly vetted for bugs. The GTKAgg and GTKCairo backends reuse the GTK 
widget code, so should likewise be quite stable
     * Interactivity: All of the GUI backends can be used interactively 
from a python shell (see interactive) but TkAgg is the hands-down winner 
here since it can be use from any python shell whereas the GTK and Wx 
backends require a GUI specific shell
     * Pretty widgets: If you want to embed matplotlib in an application 
and pretty GUIs are important to you, Wx, GTK, GTKAgg or GTKCairo are 
probably your best best. Tk widgets are not visually stunning."

==========

My brain hurts! Actually, I've always just wanted to use TK (because it 
comes with Python), but I have never been able to figure out how to blit 
arbitrary bitmaps to a TK canvas (though last I tried was years ago).

By the way, also jumping from your links, I came across the Enthought 
"traits" package:
   http://code.enthought.com/traits/
which is something like what I added to PataPata for properties to wrap wx 
widgets. They came at it also from wrapping GUI widgets originally it 
looks like. But I'm not sure their framework is extensible to prototypes 
the way I want to use them. So, anyway, funny how some of these deeper 
language issues come up with looking at various graphics libraries. And it 
clearly shows that the "property" concept in Python could benefit from 
some more generalization. I added things like side-effects (and plan to 
add something I might term dependency paths); they added things like 
validation (a good point, as they said otherwise graphics errors tend to 
occur far in the code from where values are set). We both want to add 
Smalltalk-like "changed" or "notify" events. They have a nice general 
purpose solution, though it is class-oriented, not Prototype oriented. 
Hopefully Python3K might address improving properties? It seems to me that 
if one wants ot make graphcis easy to use, havign a consistent way to 
address graphical objects using soem form of properties might be very 
important. Certainly VB and Delphi have had great success wrapping 
arbitrary components with properties (and I think this might apply whether 
or not the user could interact with them).

Just a thought: rather than a new GUI implementation, improving the Python 
GUI FAQ with lots of this information and pros and cons and so on might be 
a very valuable effort just by itself. So much of choices depends on 
specifics and tiny details. For example, I'm fairly happy with wx, but 
there is this bug with dragging certain widgets under GTK 2.6. And of 
course, I also want platform independent fonts (and I'm not sure how to 
get those best, wx uses sizers to get platform independent dialog looks, 
but the sizes may still vary across platforms). Maybe this 2D, 3D, and 
Python GUI efforts needs a web site or blog or something? Some place where 
the nitty gritty details gets hashed out? Might be one already? Kind of 
like this one for programming languages?
     http://lambda-the-ultimate.org/
But specific to Python and graphics and user interaction?
   http://www.google.com/search?hl=en&q=python+graphics
Might be something to think about if it does not already exist.

--Paul Fernhout

Dethe Elza wrote:
> On 5/28/06, Paul D. Fernhout <pdfernhout at kurtz-fernhout.com> wrote:
> 
>> If you haven't already, you could check out:
> 
> 
> Also:
> 
> PIL.ImageDraw
>    http://www.esrf.fr/computing/bliss/python2/pil/PIL.ImageDraw.html
>    http://www.pythonware.com/library/pil/handbook/imagedraw.htm
>    "The ImageDraw module provide simple 2D graphics for Image
> objects. You can use this module to create new images, annotate or
> retouch existing images, and to generate graphics on the fly for web
> use."
> 
> Aggdraw
>    http://effbot.org/zone/draw-agg.htm
>    "The aggdraw module implements the basic WCK 2D Drawing Interface
> on top of the AGG library. This library provides high-quality drawing,
> with anti-aliasing and alpha compositing, while being fully compatible
> with the WCK renderer."
> 
> Matplotlib
>    http://matplotlib.sourceforge.net/
>    "matplotlib is a python 2D plotting library which produces
> publication quality figures in a variety of hardcopy formats and
> interactive environments across platforms. matplotlib can be used in
> python scripts, the python and ipython shell (ala matlab or
> mathematica), web application servers, and six graphical user
> interface toolkits."
> 
> Kiva
>   http://code.enthought.com/kiva/
>   "Kiva is a multi-platform DisplayPDF drawing engine that supports
> multiple output backends, including Windows, GTK, and Macintosh native
> windowing systems, a variety of raster image formats, PDF, and
> Postscript."
> 
> DrawBot/NodeBox (OS X only, but useful as examples of simple 2D systems)
>    http://drawbot.com/index.html
>    http://nodebox.net/manual/reference/topics.php
>    "DrawBot is an powerful, free application for MacOSX that invites
> you to write simple Python scripts to generate two-dimensional
> graphics. The builtin graphics primitives support rectangles, ovals,
> (bezier) paths, polygons, text objects and transparency."
> 
> PyCairo
>    http://cairographics.org/pycairo
>    "Cairo is a library for drawing vector graphics. Vector graphics
> are interesting because when they appear on screen, they don't lose
> clarity when resized or transformed."
> 
> --Dethe
> 
> 


More information about the Edu-sig mailing list