author | Radek Brich <radek.brich@devl.cz> |
Sat, 05 Jan 2013 00:37:11 +0100 | |
changeset 46 | 2b43a7f38c34 |
parent 45 | 43b2279b06e1 |
permissions | -rwxr-xr-x |
45
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python3 |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
import sys |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
sys.path.append('..') |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
from tuikit.events import Emitter, KeyboardEvent |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
9 |
class A(Emitter): |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
10 |
def __init__(self): |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
self.add_events('keypress', KeyboardEvent) |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
12 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
13 |
def on_keypress(self, ev): |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
"""A""" |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
15 |
print('A on', ev.keyname, self) |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
16 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
17 |
def after_keypress(self, ev): |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
"""A""" |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
19 |
print('A after', ev.keyname, self) |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
20 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
22 |
class B(A): |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
23 |
def __init__(self): |
46
2b43a7f38c34
Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
24 |
A.__init__(self) |
45
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
25 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
26 |
def on_keypress(self, ev): |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
27 |
"""B""" |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
28 |
print('B on', ev.keyname, self) |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
29 |
#return True |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
30 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
31 |
def after_keypress(self, ev): |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
32 |
"""B""" |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
33 |
print('B after', ev.keyname, self) |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
34 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
35 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
36 |
class C(B): |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
37 |
def __init__(self): |
46
2b43a7f38c34
Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
38 |
B.__init__(self) |
45
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
39 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
40 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
41 |
def on_keypress(ev): |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
42 |
"""global""" |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
43 |
print('global on', ev.keyname) |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
44 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
45 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
46 |
def after_keypress(ev): |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
47 |
"""global""" |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
48 |
print('global after', ev.keyname) |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
49 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
50 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
51 |
if __name__ == '__main__': |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
52 |
c = C() |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
53 |
c.add_handler('keypress', after_keypress, last=True) |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
54 |
c.add_handler('keypress', on_keypress) |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
55 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
56 |
for x in c._event_handlers['keypress']: |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
57 |
print(x, x.__doc__) |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
58 |
|
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
59 |
print() |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
60 |
c.emit('keypress', keyname='XKey', char=None) |
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
61 |