1#!/usr/bin/python
2# $Id:$
3
4from __future__ import print_function
5
6import pyglet
7
8window = pyglet.window.Window()
9tablets = pyglet.input.get_tablets()
10canvases = []
11
12if tablets:
13    print('Tablets:')
14    for i, tablet in enumerate(tablets):
15        print('  (%d) %s' % (i + 1, tablet.name))
16    print('Press number key to open corresponding tablet device.')
17else:
18    print('No tablets found.')
19
20
21@window.event
22def on_text(text):
23    try:
24        index = int(text) - 1
25    except ValueError:
26        return
27
28    if not (0 <= index < len(tablets)):
29        return
30
31    name = tablets[i].name
32
33    try:
34        canvas = tablets[i].open(window)
35    except pyglet.input.DeviceException:
36        print('Failed to open tablet %d on window' % index)
37
38    print('Opened %s' % name)
39
40    @canvas.event
41    def on_enter(cursor):
42        print('%s: on_enter(%r)' % (name, cursor))
43
44    @canvas.event
45    def on_leave(cursor):
46        print('%s: on_leave(%r)' % (name, cursor))
47
48    @canvas.event
49    def on_motion(cursor, x, y, pressure):
50        print('%s: on_motion(%r, %r, %r, %r)' % (name, cursor, x, y, pressure))
51
52
53@window.event
54def on_mouse_press(x, y, button, modifiers):
55    print('on_mouse_press(%r, %r, %r, %r' % (x, y, button, modifiers))
56
57
58@window.event
59def on_mouse_release(x, y, button, modifiers):
60    print('on_mouse_release(%r, %r, %r, %r' % (x, y, button, modifiers))
61
62
63pyglet.app.run()
64