tuikit/container.py
author Radek Brich <radek.brich@devl.cz>
Sat, 05 Jan 2013 00:37:11 +0100
changeset 46 2b43a7f38c34
parent 45 43b2279b06e1
child 62 2f61931520c9
permissions -rw-r--r--
Minor updates. Replace super() with direct class reference. Add demo_colors.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
18
e6c3a5ee91aa Eliminate relative imports.
Radek Brich <radek.brich@devl.cz>
parents: 16
diff changeset
     3
from tuikit.widget import Widget
40
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 38
diff changeset
     4
from tuikit.common import Borders, Coords
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
13
19ebde2fd594 Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents: 9
diff changeset
     6
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
class Container(Widget):
32
088b92ffb119 Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents: 23
diff changeset
     8
13
19ebde2fd594 Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents: 9
diff changeset
     9
    '''Container widget. Base for any widget which can contain other widgets.'''
32
088b92ffb119 Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents: 23
diff changeset
    10
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
    def __init__(self, width = 10, height = 10):
13
19ebde2fd594 Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents: 9
diff changeset
    12
        '''Create container of requested size.'''
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
        Widget.__init__(self, width, height)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
13
19ebde2fd594 Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents: 9
diff changeset
    15
        #: List of child widgets.
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
        self.children = []
32
088b92ffb119 Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents: 23
diff changeset
    17
40
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 38
diff changeset
    18
        #: Offset for child widgets
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 38
diff changeset
    19
        self.offset = Coords()
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 38
diff changeset
    20
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
    21
        self.focuschild = None
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
        self.mousechild = None
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
    24
        self.allow_focus = True
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
    25
13
19ebde2fd594 Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents: 9
diff changeset
    26
        #: Width of borders (left, top, right, bottom).
19ebde2fd594 Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents: 9
diff changeset
    27
        #: Child widgets are placed within borders.
16
8791a7da6835 Update VerticalLayout/HorizontalLayout. Add layout demo. Add Size, Borders to common. Update Coords, Rect.
Radek Brich <radek.brich@devl.cz>
parents: 15
diff changeset
    28
        self.borders = Borders()
32
088b92ffb119 Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents: 23
diff changeset
    29
15
c55b4749e562 Add Pager.
Radek Brich <radek.brich@devl.cz>
parents: 13
diff changeset
    30
        self._layout = None
32
088b92ffb119 Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents: 23
diff changeset
    31
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
        self.widthrequest = (None, None)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
        self.heightrequest = (None, None)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
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: 5
diff changeset
    35
        self.colorprefix = None
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: 5
diff changeset
    36
38
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    37
        self.trap_focus = False  # if True, tab cycles inside container
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: 5
diff changeset
    38
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
40
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 38
diff changeset
    40
    def add(self, widget, **kwargs):
13
19ebde2fd594 Add more generated documentation.
Radek Brich <radek.brich@devl.cz>
parents: 9
diff changeset
    41
        '''Add widget into this container.'''
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
        self.children.append(widget)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
        widget.parent = self
41
37b7dfc3eae6 Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents: 40
diff changeset
    44
        widget.top = self.top
40
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 38
diff changeset
    45
        widget.hints.update(kwargs)
38
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    46
        if self.focuschild is None and widget.can_focus():
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
    47
            self.focuschild = widget
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
42
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
    49
    @property
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
    50
    def layout(self):
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
    51
        return self._layout
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    52
42
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
    53
    @layout.setter
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
    54
    def layout(self, value):
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
    55
        """Layout manager for placing child widgets."""
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
    56
        self._layout = value
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
    57
        self._layout.container = self
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
41
37b7dfc3eae6 Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents: 40
diff changeset
    60
    def _set_top(self, value):
37b7dfc3eae6 Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents: 40
diff changeset
    61
        self._top = value
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62
        for child in self.children:
41
37b7dfc3eae6 Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents: 40
diff changeset
    63
            child.top = value
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    64
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    65
38
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    66
    def focus_next(self):
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    67
        """Focus next child.
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    68
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    69
        Sets focus to next child, if there is one
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    70
        which can be focused. Cycles from last child
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    71
        to first when needed. Return value depends on
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    72
        this cycling:
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    73
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    74
         * False means there wasn't any child to focus
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: 42
diff changeset
    75
           before end of list. Focus was either not changed
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: 42
diff changeset
    76
           or first child was focused.
38
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    77
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    78
         * True when focus is set to next child in normal
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    79
           way or when self.trap_focus is set.
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    80
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    81
        Return value is supposed to be returned from keypress
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    82
        event - in that case, True stops event propagation.
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    83
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    84
        """
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
    85
        idx_current = self.children.index(self.focuschild)
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: 42
diff changeset
    86
        idx_new = idx_current
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
    87
        cycled = False
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: 42
diff changeset
    88
        while 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: 42
diff changeset
    89
            idx_new += 1
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
    90
            if idx_new >= len(self.children):
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
    91
                idx_new = 0
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
    92
                cycled = True
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: 42
diff changeset
    93
            if idx_current == idx_new:
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: 42
diff changeset
    94
                return False
38
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    95
            if self.children[idx_new].can_focus():
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    96
                self.children[idx_new].set_focus()
c6e170452c7f Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents: 36
diff changeset
    97
                return self.trap_focus or not cycled
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: 5
diff changeset
    98
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
    99
    def draw(self, driver, x, y):
36
caf927c3f10b Update docs.
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
   100
        """Draw the container and its children.
caf927c3f10b Update docs.
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
   101
caf927c3f10b Update docs.
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
   102
        This method should not be overriden by subclasses,
caf927c3f10b Update docs.
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
   103
        use on_draw instead.
caf927c3f10b Update docs.
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
   104
caf927c3f10b Update docs.
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
   105
        """
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
   106
        if self.hidden:
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
   107
            return True
5
ae128c885d0f New GridLayout. Change cursor behavior (hide on unfocus event). Change resize event to propagate through containers. Change container clipping - allowlayout=false children are clipped without borders. More Widget doc.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
   108
23
4e72fd2a0e14 Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents: 18
diff changeset
   109
        driver.clipstack.push(x, y, self.width, self.height)
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: 5
diff changeset
   110
        if self.colorprefix:
23
4e72fd2a0e14 Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents: 18
diff changeset
   111
            driver.pushcolorprefix(self.colorprefix)
5
ae128c885d0f New GridLayout. Change cursor behavior (hide on unfocus event). Change resize event to propagate through containers. Change container clipping - allowlayout=false children are clipped without borders. More Widget doc.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
   112
46
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
   113
        Widget.draw(self, driver, x, y)
5
ae128c885d0f New GridLayout. Change cursor behavior (hide on unfocus event). Change resize event to propagate through containers. Change container clipping - allowlayout=false children are clipped without borders. More Widget doc.
Radek Brich <radek.brich@devl.cz>
parents: 2
diff changeset
   114
46
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
   115
        for child in [ch for ch in self.children if not ch.allow_layout]:
23
4e72fd2a0e14 Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents: 18
diff changeset
   116
            child.draw(driver, x + child.x, y + child.y)
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   117
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   118
        l, t, r, b = self.borders
23
4e72fd2a0e14 Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents: 18
diff changeset
   119
        driver.clipstack.push(x+l, y+t, self.width-l-r, self.height-t-b)
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   120
46
2b43a7f38c34 Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
   121
        for child in [ch for ch in self.children if ch.allow_layout]:
40
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 38
diff changeset
   122
            child.draw(driver,
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 38
diff changeset
   123
                x + self.offset.x + child.x,
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents: 38
diff changeset
   124
                y + self.offset.y + child.y)
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   125
23
4e72fd2a0e14 Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents: 18
diff changeset
   126
        driver.clipstack.pop()
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   127
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: 5
diff changeset
   128
        if self.colorprefix:
23
4e72fd2a0e14 Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents: 18
diff changeset
   129
            driver.popcolorprefix()
4e72fd2a0e14 Rename BackendCurses to DriverCurses. Add DriverDummy - dummy driver for debugging purposes. Move clipping stack from driver to common.ClipStack class.
Radek Brich <radek.brich@devl.cz>
parents: 18
diff changeset
   130
        driver.clipstack.pop()
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   131
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: 42
diff changeset
   132
    def on_resize(self, ev):
42
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
   133
        for child in self.children:
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
   134
            child.emit('resize')
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
   135
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: 42
diff changeset
   136
    def on_keypress(self, ev):
42
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
   137
        if self.focuschild is not None:
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
   138
            handled = self.focuschild.emit('keypress', ev)
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
   139
            if handled:
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
   140
                return True
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
   141
        if ev.keyname == 'tab':
0224ce40792f Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
   142
            return self.focus_next()
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   143
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: 42
diff changeset
   144
    def on_mousedown(self, ev):
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   145
        handled = False
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   146
        for child in reversed(self.children):
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   147
            if child.enclose(ev.wx, ev.wy):
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   148
                childev = ev.childevent(child)
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
   149
                child.emit('mousedown', childev)
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   150
                self.mousechild = child
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   151
                handled = True
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   152
                break
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
   153
        return handled
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   154
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: 42
diff changeset
   155
    def on_mouseup(self, ev):
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   156
        if self.mousechild:
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   157
            childev = ev.childevent(self.mousechild)
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
   158
            self.mousechild.emit('mouseup', childev)
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   159
            self.mousechild = None
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
   160
            return True
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   161
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: 42
diff changeset
   162
    def on_mousemove(self, ev):
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   163
        if self.mousechild:
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   164
            childev = ev.childevent(self.mousechild)
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
   165
            self.mousechild.emit('mousemove', childev)
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
   166
            return True
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   167
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: 42
diff changeset
   168
    def on_mousewheel(self, ev):
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   169
        handled = False
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   170
        for child in reversed(self.children):
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   171
            if child.enclose(ev.wx, ev.wy):
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   172
                childev = ev.childevent(child)
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
   173
                child.emit('mousewheel', childev)
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   174
                handled = True
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   175
                break
34
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
   176
        return handled
e3beacd5e536 Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents: 32
diff changeset
   177