author | Radek Brich <radek.brich@devl.cz> |
Wed, 26 Dec 2012 01:00:31 +0100 | |
changeset 40 | 5faa38c10b67 |
parent 38 | c6e170452c7f |
child 45 | 43b2279b06e1 |
permissions | -rw-r--r-- |
9
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
Event handling |
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
============== |
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
|
36 | 4 |
Draw event |
5 |
---------- |
|
6 |
||
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. |
|
9 |
Normal widgets should implement only on_draw() method, which is called from draw(). |
|
10 |
||
9
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
|
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
12 |
Keypress event |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
13 |
-------------- |
36 | 14 |
|
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 |
|
17 |
the walk. |
|
18 |
||
19 |
:: |
|
9
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
20 |
|
36 | 21 |
before after |
22 |
1 7 top window |
|
23 |
2 6 window |
|
24 |
3 5 container |
|
25 |
4 4 edit box |
|
26 |
||
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
27 |
Focus |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
28 |
----- |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
29 |
|
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
30 |
Basics: |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
31 |
* Only one node in hierarchy can have focus. |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
32 |
* All parent containers have focus, so they can relay events to focused child. |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
33 |
* Top container has always focus. |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
34 |
|
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
35 |
Each container maintains its focus child and allows to cycle focus between children (See Container.focus_next). Focus cycling works throughout |
36 | 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. |
37 |
||
38 |
When focus changes, two events are generated: focus on new widget, unfocus on previous one. |
|
39 |
Mousedown causes focus change when allowed (Widget.allow_focus). |
|
40 |
||
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
41 |
* Use grab_focus() on widget to make it receive keyboard events. This will clean old focus and set focus to this child. |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
42 |
* Global shortcuts can be handled in keypress event from top widget. All keyboard events go through there. |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
43 |
* Tab key changes focus to next widget. Shift-tab changes back to previous widget (FIXME: not implemented). |
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
44 |
* Hide on focused widget causes focus change like if tab key was pressed. |
36 | 45 |
|
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
36
diff
changeset
|
46 |
See Container.trap_focus, Widget.can_focus(), Widget.has_focus(), Widget.set_focus() for more information. |
9
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
47 |
|
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
48 |
|
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
49 |
Other event propagation |
7175ed629a76
Added ComboBox, HorizontalLayout, TreeNode, TreeModel, TreeView. Widget is now descendant of EventSource. Improved color management (color prefixes).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
50 |
----------------------- |
36 | 51 |
|
52 |
Normal events are propagated in top down order, to all children in each level, in order of child addition. |
|
53 |
Some events choose one or more of children for event propagation. In case of mouse events, child is chosen based on mouse cursor position. |
|
54 |