Pyglet #743

merged 6 commits into from Sep 13, 2011


None yet

4 participants


This is the experimental pyglet event loop integration.
It requires pyglet.

IPython member

I'm not experienced with pyglet, but this looks fine to me. You may want to fix the one remaining 'wxPython' hanging around in inputhook, from the copy/paste from the wx section.

IPython member

This looks good overall, but I can't seem to close the window of the demo applet when I run it. Do you know why? Ideally, we'd offer users the ability to run a script, close all of its windows and then run it again as many times as they want, without ever losing the interactive shell. That works right now for the wx/gtk/qt event loops, so let's try to get the two GL ones in similar shape, if possible.

Also, fixing the wx references Min pointed out would be good.

Finally, if you can figure out what's going on with the window closing, we only have one more issue to sort out: any option supported by the gui magic should also be supported by the --gui command-line flag, so users can start ipython in gui mode if they want to from the beginning.

The code that defines these options is here:

so it should gain a 'pyglet' option. Once that is working, it should be 100% equivalent to type at the system shell:

ipython --gui pyglet

or at the IPython prompt:

%gui pyglet

Thanks a lot for the good work! I realize these GL event loops are proving a little hard to get right, but hopefully we can finish the process and merge both of your pull requests. We just want to make sure they work reliably and correctly in the intended manner. If ultimately some of it can't be made to work that's OK, but then we'd want to add code that informs the user in a visible manner what the limitations are of a given GL option.


Adding the following lines to docs/examples/lib/

def on_close():

should fix the window closing issue.

IPython member

Thanks for the tip! It almost works, as in that now I can close the window, but then a nasty traceback goes to the terminal with:

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 295, in 'calling callback function'
  File "/home/fperez/usr/lib/python2.6/site-packages/IPython/lib/", line 65, in inputhook_pyglet
  File "/usr/lib/pymodules/python2.6/pyglet/window/xlib/", line 797, in flip
    self._config._fbconfig, self._window, None)
AttributeError: 'NoneType' object has no attribute '_fbconfig'

Any idea what to do about that?


A similar traceback has been reported here:

Apparently it does not occur on Windows, and I can't reproduce it either on my mac.

IPython member

Thanks for the info @jalalhugo, it looks to be a pyglet bug then. If anyone knows how to work around it, that would be great; otherwise we'll just have to live with it in linux (it doesn't actually crash ipython, it just dumps a bunch of info to the screen).

With that info, @rougier, I think we can proceed as follows:

  • go ahead and incorporate the suggestion above into the example
  • add support for --gui pyglet at the command line as indicated above.

Let me know if you need any help. It seems we'll be able to merge this one pretty soon then :)

@fperez fperez merged commit db9640d into ipython:master Sep 13, 2011
IPython member

Great, thanks! If you look, I added one more commit with a few minor tweaks: fe30ce1. This way we silence that annoying traceback on linux, without slowing down other platforms with a try/except.

I also changed the definition of stdin_ready() to make it platform dependent, that way the platform check happens only once when it's loaded instead of on every call.

Thanks again for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment