[SciPy-user] Pyglet + Chaco (was Re: pyqwt or matplotlib)

Peter Wang pwang at enthought.com
Thu Aug 28 19:25:40 EDT 2008


On Aug 28, 2008, at 4:49 PM, Bryan Cole wrote:

> The GL backend for Chaco is an exciting development. Althought the
> examples worked fine with the pyglet backend, when I tried to  
> experiment
> with it I couldn't see how to use it within the context of a full
> TraitsUI/wx application. Pyglet doesn't seem to integrate with any  
> other
> toolkit event loop.

Yep, there be the dragons.  I started working on this late Tuesday  
night but haven't finished it yet.  It is certainly possible to do,  
it's just that my test code is still doing funky things. :)  The goal  
that Stefan and I were talking about is to embed a Pyglet-based  
CoverFlow into a Traits UI editor.  (My personal goal is to then stick  
live Chaco plots on the CoverFlow covers. ;)

> Can the gl_graphics_context be "dropped in" in place of the standard  
> agg
> gc? Is there an easy switch to set this up?

You can set the KIVA_WISHLIST environment variable to "gl", and then  
subsequent imports of GraphicsContext from enthought.kiva will use the  
GC from backend_gl.py.  This doesn't get you nice event handling  
through Enable, but it does work.

You can also directly import the graphics context and play with it:


from enthought.kiva.backend_gl import GraphicsContext
from enthought.kiva import Font
from pyglet import clock, window

def main():
     clock.set_fps_limit(60)

     win = window.Window()
     win.set_size(480, 320)
     win.set_caption("Backend GL + Pyglet")

     gc = GraphicsContext((480, 320))
     gc.gl_init()

     exit = False
     while not exit:
         win.dispatch_events()

         gc.clear()
         gc.set_stroke_color((1, 0, 0, 1))
         gc.set_line_width(2)
         gc.rect(100, 100, 200, 75)
         gc.stroke_path()

         gc.set_fill_color((0,0,1,1))
         font = Font("Arial", 48)
         gc.set_font(font)
         gc.show_text_at_point("Kiva GL!", 110, 110)

         win.flip()
         clock.tick()
         if win.has_exit:
             exit = True
     return

if __name__ == "__main__":
     main()



-Peter



More information about the SciPy-User mailing list