Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe30ce1

Browse files
committed
Trap AttributeError in window.flip() under linux - pyglet bug.
1 parent db9640d commit fe30ce1

1 file changed

Lines changed: 34 additions & 12 deletions

File tree

IPython/lib/inputhookpyglet.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# encoding: utf-8
2-
32
"""
43
Enable pyglet to be used interacive by setting PyOS_InputHook.
54
6-
Authors: Nicolas P. Rougier
5+
Authors
6+
-------
7+
8+
* Nicolas P. Rougier
9+
* Fernando Perez
710
"""
811

912
#-----------------------------------------------------------------------------
@@ -24,26 +27,45 @@
2427
from timeit import default_timer as clock
2528
import pyglet
2629

27-
if os.name == 'posix':
28-
import select
29-
elif sys.platform == 'win32':
30-
import msvcrt
31-
3230
#-----------------------------------------------------------------------------
33-
# Code
31+
# Platform-dependent imports and functions
3432
#-----------------------------------------------------------------------------
3533

36-
def stdin_ready():
37-
if os.name == 'posix':
34+
if os.name == 'posix':
35+
import select
36+
37+
def stdin_ready():
3838
infds, outfds, erfds = select.select([sys.stdin],[],[],0)
3939
if infds:
4040
return True
4141
else:
4242
return False
43-
elif sys.platform == 'win32':
43+
44+
elif sys.platform == 'win32':
45+
import msvcrt
46+
47+
def stdin_ready():
4448
return msvcrt.kbhit()
4549

4650

51+
# On linux only, window.flip() has a bug that causes an AttributeError on
52+
# window close. For details, see:
53+
# http://groups.google.com/group/pyglet-users/browse_thread/thread/47c1aab9aa4a3d23/c22f9e819826799e?#c22f9e819826799e
54+
55+
if sys.platform.startswith('linux'):
56+
def flip(window):
57+
try:
58+
window.flip()
59+
except AttributeError:
60+
pass
61+
else:
62+
def flip(window):
63+
window.flip()
64+
65+
#-----------------------------------------------------------------------------
66+
# Code
67+
#-----------------------------------------------------------------------------
68+
4769
def inputhook_pyglet():
4870
"""Run the pyglet event loop by processing pending events only.
4971
@@ -62,7 +84,7 @@ def inputhook_pyglet():
6284
window.switch_to()
6385
window.dispatch_events()
6486
window.dispatch_event('on_draw')
65-
window.flip()
87+
flip(window)
6688

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

0 commit comments

Comments
 (0)