7 Draw event is generating for all widgets in top down order - top window is drawn first, then its children etc. |
7 Draw event is generating for all widgets in top down order - top window is drawn first, then its children etc. |
8 See TopWindow.draw(), Container.draw(), Widget.draw() - these methods control the draw event propagation. |
8 See TopWindow.draw(), Container.draw(), Widget.draw() - these methods control the draw event propagation. |
9 Normal widgets should implement only on_draw() method, which is called from draw(). |
9 Normal widgets should implement only on_draw() method, which is called from draw(). |
10 |
10 |
11 |
11 |
12 Keypress event, focus |
12 Keypress event |
13 --------------------- |
13 -------------- |
14 |
14 |
15 Keyboard events go in top down order, from top window to focused widget in each level. When implementing on_keypress method, |
15 Keyboard events go in top down order, from top window to focused widget in each level. When implementing on_keypress method, |
16 add super().on_keypress(). Anything before that will be executed in top down walk, anything after in bottom up. Return True if you want to stop |
16 add super().on_keypress(). Anything before that will be executed in top down walk, anything after in bottom up. Return True if you want to stop |
17 the walk. |
17 the walk. |
18 |
18 |
22 1 7 top window |
22 1 7 top window |
23 2 6 window |
23 2 6 window |
24 3 5 container |
24 3 5 container |
25 4 4 edit box |
25 4 4 edit box |
26 |
26 |
27 Each container maintains its focus child and allows to cycle focus between children (See Container.focusnext). Focus cycling works throughout |
27 Focus |
|
28 ----- |
|
29 |
|
30 Basics: |
|
31 * Only one node in hierarchy can have focus. |
|
32 * All parent containers have focus, so they can relay events to focused child. |
|
33 * Top container has always focus. |
|
34 |
|
35 Each container maintains its focus child and allows to cycle focus between children (See Container.focus_next). Focus cycling works throughout |
28 container levels - if focus was on last child and would go to the first, 'tab' key is not handled thus allowing parent level to cycle focus. |
36 container levels - if focus was on last child and would go to the first, 'tab' key is not handled thus allowing parent level to cycle focus. |
29 |
37 |
30 When focus changes, two events are generated: focus on new widget, unfocus on previous one. |
38 When focus changes, two events are generated: focus on new widget, unfocus on previous one. |
31 Mousedown causes focus change when allowed (Widget.allow_focus). |
39 Mousedown causes focus change when allowed (Widget.allow_focus). |
32 |
40 |
33 * tab key - change focus to next widget |
41 * Use grab_focus() on widget to make it receive keyboard events. This will clean old focus and set focus to this child. |
34 * shift-tab - previous widget (FIXME: not implemented) |
42 * Global shortcuts can be handled in keypress event from top widget. All keyboard events go through there. |
|
43 * Tab key changes focus to next widget. Shift-tab changes back to previous widget (FIXME: not implemented). |
|
44 * Hide on focused widget causes focus change like if tab key was pressed. |
35 |
45 |
36 Hide on focused widget causes focus change like if tab key was pressed. |
46 See Container.trap_focus, Widget.can_focus(), Widget.has_focus(), Widget.set_focus() for more information. |
37 |
|
38 See Container.trapfocus, Widget.canfocus(), Widget.hasfocus(), Widget.setfocus() for more information. |
|
39 |
47 |
40 |
48 |
41 Other event propagation |
49 Other event propagation |
42 ----------------------- |
50 ----------------------- |
43 |
51 |