Show More
@@ -1,9 +1,12 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | ||
|
3 | 2 | """ |
|
4 | 3 | Enable pyglet to be used interacive by setting PyOS_InputHook. |
|
5 | 4 | |
|
6 | Authors: Nicolas P. Rougier | |
|
5 | Authors | |
|
6 | ------- | |
|
7 | ||
|
8 | * Nicolas P. Rougier | |
|
9 | * Fernando Perez | |
|
7 | 10 | """ |
|
8 | 11 | |
|
9 | 12 | #----------------------------------------------------------------------------- |
@@ -24,26 +27,45 b' import time' | |||
|
24 | 27 | from timeit import default_timer as clock |
|
25 | 28 | import pyglet |
|
26 | 29 | |
|
27 | if os.name == 'posix': | |
|
28 | import select | |
|
29 | elif sys.platform == 'win32': | |
|
30 | import msvcrt | |
|
31 | ||
|
32 | 30 | #----------------------------------------------------------------------------- |
|
33 | # Code | |
|
31 | # Platform-dependent imports and functions | |
|
34 | 32 | #----------------------------------------------------------------------------- |
|
35 | 33 | |
|
36 | def stdin_ready(): | |
|
37 | if os.name == 'posix': | |
|
34 | if os.name == 'posix': | |
|
35 | import select | |
|
36 | ||
|
37 | def stdin_ready(): | |
|
38 | 38 | infds, outfds, erfds = select.select([sys.stdin],[],[],0) |
|
39 | 39 | if infds: |
|
40 | 40 | return True |
|
41 | 41 | else: |
|
42 | 42 | return False |
|
43 | elif sys.platform == 'win32': | |
|
43 | ||
|
44 | elif sys.platform == 'win32': | |
|
45 | import msvcrt | |
|
46 | ||
|
47 | def stdin_ready(): | |
|
44 | 48 | return msvcrt.kbhit() |
|
45 | 49 | |
|
46 | 50 | |
|
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 | ||
|
47 | 69 | def inputhook_pyglet(): |
|
48 | 70 | """Run the pyglet event loop by processing pending events only. |
|
49 | 71 | |
@@ -62,7 +84,7 b' def inputhook_pyglet():' | |||
|
62 | 84 | window.switch_to() |
|
63 | 85 | window.dispatch_events() |
|
64 | 86 | window.dispatch_event('on_draw') |
|
65 |
|
|
|
87 | flip(window) | |
|
66 | 88 | |
|
67 | 89 | # We need to sleep at this point to keep the idle CPU load |
|
68 | 90 | # low. However, if sleep to long, GUI response is poor. As |
General Comments 0
You need to be logged in to leave comments.
Login now