|
1 #!/usr/bin/env python3 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 import sys |
|
5 sys.path.append('..') |
|
6 |
|
7 from tuikit.events import Emitter, KeyboardEvent |
|
8 |
|
9 class A(Emitter): |
|
10 def __init__(self): |
|
11 self.add_events('keypress', KeyboardEvent) |
|
12 |
|
13 def on_keypress(self, ev): |
|
14 """A""" |
|
15 print('A on', ev.keyname, self) |
|
16 |
|
17 def after_keypress(self, ev): |
|
18 """A""" |
|
19 print('A after', ev.keyname, self) |
|
20 |
|
21 |
|
22 class B(A): |
|
23 def __init__(self): |
|
24 super().__init__() |
|
25 |
|
26 def on_keypress(self, ev): |
|
27 """B""" |
|
28 print('B on', ev.keyname, self) |
|
29 #return True |
|
30 |
|
31 def after_keypress(self, ev): |
|
32 """B""" |
|
33 print('B after', ev.keyname, self) |
|
34 |
|
35 |
|
36 class C(B): |
|
37 def __init__(self): |
|
38 super().__init__() |
|
39 |
|
40 |
|
41 def on_keypress(ev): |
|
42 """global""" |
|
43 print('global on', ev.keyname) |
|
44 |
|
45 |
|
46 def after_keypress(ev): |
|
47 """global""" |
|
48 print('global after', ev.keyname) |
|
49 |
|
50 |
|
51 if __name__ == '__main__': |
|
52 c = C() |
|
53 c.add_handler('keypress', after_keypress, last=True) |
|
54 c.add_handler('keypress', on_keypress) |
|
55 |
|
56 for x in c._event_handlers['keypress']: |
|
57 print(x, x.__doc__) |
|
58 |
|
59 print() |
|
60 c.emit('keypress', keyname='XKey', char=None) |
|
61 |