docs/events.rst
changeset 36 caf927c3f10b
parent 9 7175ed629a76
child 38 c6e170452c7f
equal deleted inserted replaced
35:f62c8269ded6 36:caf927c3f10b
     1 Event handling
     1 Event handling
     2 ==============
     2 ==============
     3 
     3 
     4 Keyboard event propagation
     4 Draw event
     5 --------------------------
     5 ----------
     6 
     6 
     7 top widget -> focuswidget -> focuswidget's parent -> focuswidget's parent's parent -> ...and so forth
     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().
     8 
    10 
     9 1 top window
    11 
    10 4   window
    12 Keypress event, focus
    11 3     container
    13 ---------------------
    12 2       edit box
    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 ::
       
    20 
       
    21   before  after
       
    22   1       7      top window
       
    23   2       6        window
       
    24   3       5          container
       
    25   4       4            edit box
       
    26 
       
    27 Each container maintains its focus child and allows to cycle focus between children (See Container.focusnext). 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.
       
    29 
       
    30 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).
       
    32 
       
    33  * tab key - change focus to next widget
       
    34  * shift-tab - previous widget (FIXME: not implemented)
       
    35 
       
    36 Hide on focused widget causes focus change like if tab key was pressed.
       
    37 
       
    38 See Container.trapfocus, Widget.canfocus(), Widget.hasfocus(), Widget.setfocus() for more information.
    13 
    39 
    14 
    40 
    15 Other event propagation
    41 Other event propagation
    16 -----------------------
    42 -----------------------
       
    43 
       
    44 Normal events are propagated in top down order, to all children in each level, in order of child addition.
       
    45 Some events choose one or more of children for event propagation. In case of mouse events, child is chosen based on mouse cursor position.
       
    46