Debian Codegraph @

examples/events/window_platform_event.py

raw symbols SCIP
1 #!/usr/bin/env python
2 """Demonstrates how to handle a platform-specific event not defined in
3 pyglet by subclassing Window. This is not for the faint-hearted!
4
5 A message will be printed to stdout when the following events are caught:
6
7 - On Mac OS X, the window drag region is clicked.
8 - On Windows, the display resolution is changed.
9 - On Linux, the window properties are changed.
10
11 """
12
13
14 import pyglet
15
16
17 _have_cocoa = _have_win32 = _have_xlib = False
18
19 if pyglet.compat_platform.startswith('linux'):
20 _have_xlib = True
21 from pyglet.window.xlib import XlibEventHandler, xlib
22
23 elif pyglet.compat_platform == 'darwin':
24 _have_cocoa = True
25 # from pyglet.window.cocoa import *
26
27 elif pyglet.compat_platform in ('win32', 'cygwin'):
28 _have_win32 = True
29 from pyglet.window.win32 import Win32EventHandler, WM_DISPLAYCHANGE
30
31
32 # Subclass Window
33 class MyWindow(pyglet.window.Window):
34 if _have_cocoa:
35 # TODO This is currently not supported in Cocoa (#156).
36 pass
37
38 if _have_win32:
39 @Win32EventHandler(WM_DISPLAYCHANGE)
40 def _on_window_display_change(self, msg, lParam, wParam):
41 print('Display resolution changed.')
42 return 0
43
44 if _have_xlib:
45 @XlibEventHandler(xlib.PropertyNotify)
46 def _on_window_property_notify(self, event):
47 print('Property notify.')
48
49
50 if __name__ == '__main__':
51 window = MyWindow()
52 pyglet.app.run()