Debian Codegraph @

examples/input/tablet.py

raw symbols SCIP
1 #!/usr/bin/python
2
3 import pyglet
4 pyglet.options["debug_input"] = True
5
6 window = pyglet.window.Window()
7 tablets = pyglet.input.get_tablets()
8 canvases = []
9
10 if tablets:
11 print('Tablets:')
12 for i, tablet in enumerate(tablets):
13 print(f' ({i + 1}) {tablet.name}')
14 print('Press number key to open corresponding tablet device.')
15 else:
16 print('No tablets found.')
17
18
19 @window.event
20 def on_text(text):
21 try:
22 index = int(text) - 1
23 except ValueError:
24 return
25
26 if not (0 <= index < len(tablets)):
27 return
28
29 name = tablets[index].name
30
31 try:
32 canvas = tablets[index].open(window)
33 except pyglet.input.DeviceException:
34 print(f'Failed to open tablet {index} on window')
35 return
36
37 print(f'Opened {name}')
38
39 @canvas.event
40 def on_enter(cursor):
41 print(f'{name}: on_enter({cursor!r})')
42
43
44 @canvas.event
45 def on_leave(cursor):
46 print(f'{name}: on_leave({cursor!r})')
47
48 @canvas.event
49 def on_motion(cursor, x, y, pressure, tilt_x, tilt_y, buttons):
50 print(f'{name}: on_motion({cursor!r}, {x!r}, {y!r}, {pressure!r}, {tilt_x!r}, {tilt_y!r}, {buttons!r})')
51
52 # If ExpressKey is supported for the OS, the events will be supported.
53 if 'on_express_key_press' in canvas.event_types:
54 @canvas.event
55 def on_express_key_press(control_id, location_id):
56 print(f'on_express_key_press(control_id={control_id}, location_id={location_id}')
57
58 @canvas.event
59 def on_express_key_release(control_id, location_id):
60 print(f'on_express_key_release(control_id={control_id}, location_id={location_id}')
61
62 @window.event
63 def on_mouse_press(x, y, button, modifiers):
64 print(f'on_mouse_press({x!r}, {y!r}, {button!r}, {modifiers!r}')
65
66
67 @window.event
68 def on_mouse_release(x, y, button, modifiers):
69 print(f'on_mouse_release{x!r}, {y!r}, {button!r}, {modifiers!r}')
70
71
72 pyglet.app.run()