Skip to content

Commit

Permalink
Trap AttributeError in window.flip() under linux - pyglet bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
fperez committed Sep 13, 2011
1 parent db9640d commit fe30ce1
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions IPython/lib/inputhookpyglet.py
@@ -1,9 +1,12 @@
# encoding: utf-8

"""
Enable pyglet to be used interacive by setting PyOS_InputHook.
Authors: Nicolas P. Rougier
Authors
-------
* Nicolas P. Rougier
* Fernando Perez
"""

#-----------------------------------------------------------------------------
Expand All @@ -24,26 +27,45 @@
from timeit import default_timer as clock
import pyglet

if os.name == 'posix':
import select
elif sys.platform == 'win32':
import msvcrt

#-----------------------------------------------------------------------------
# Code
# Platform-dependent imports and functions
#-----------------------------------------------------------------------------

def stdin_ready():
if os.name == 'posix':
if os.name == 'posix':
import select

def stdin_ready():
infds, outfds, erfds = select.select([sys.stdin],[],[],0)
if infds:
return True
else:
return False
elif sys.platform == 'win32':

elif sys.platform == 'win32':
import msvcrt

def stdin_ready():
return msvcrt.kbhit()


# On linux only, window.flip() has a bug that causes an AttributeError on
# window close. For details, see:
# http://groups.google.com/group/pyglet-users/browse_thread/thread/47c1aab9aa4a3d23/c22f9e819826799e?#c22f9e819826799e

if sys.platform.startswith('linux'):
def flip(window):
try:
window.flip()
except AttributeError:
pass
else:
def flip(window):
window.flip()

#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------

def inputhook_pyglet():
"""Run the pyglet event loop by processing pending events only.
Expand All @@ -62,7 +84,7 @@ def inputhook_pyglet():
window.switch_to()
window.dispatch_events()
window.dispatch_event('on_draw')
window.flip()
flip(window)

# We need to sleep at this point to keep the idle CPU load
# low. However, if sleep to long, GUI response is poor. As
Expand Down

0 comments on commit fe30ce1

Please sign in to comment.