tuikit/widgets/scrollview.py
author Radek Brich <radek.brich@devl.cz>
Sun, 15 Feb 2015 12:48:23 +0100
changeset 114 26c02bd94bd9
parent 77 tuikit/scrollview.py@fc1989059e19
child 117 8680c2333546
permissions -rw-r--r--
Add Widget.posreq. Add OffsetLayout.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
114
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
     1
from tuikit.core.container import Container
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
     2
from tuikit.layouts.offset import OffsetLayout
40
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
114
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
     4
#from tuikit.layout import AnchorLayout, OffsetLayout
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
     5
#from tuikit.scrollbar import VScrollbar, HScrollbar
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
     6
#from tuikit.common import Borders
40
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
114
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
     9
class Viewport(Container):
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    10
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    11
    """Viewport for partial view on widgets.
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    12
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    13
    Viewport is special type of Container, which shows partial view
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    14
    on its managed widgets. This view can be moved to show different part
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    15
    and thus allow "scrolling" over the content. Complete view with scrollbars
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    16
    is implemented in ScrollView.
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    17
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    18
    """
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    19
75
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    20
    def __init__(self):
114
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    21
        Container.__init__(self, OffsetLayout)
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    22
75
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    23
114
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    24
class Scrollview(Container):
75
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    25
114
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    26
    def __init__(self):
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 77
diff changeset
    27
        Container.__init__(self)
77
fc1989059e19 Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    28
75
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    29
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    30
class Scrolling:
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    31
    def __init__(self):
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    32
        self.vscroll = VScrollbar()
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    33
        self.vscroll.add_handler('change', self._on_vscroll_change)
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    34
        AnchorLayout.add(self, self.vscroll, halign='right', valign='fill')
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    35
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    36
        self.hscroll = HScrollbar()
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    37
        self.hscroll.add_handler('change', self._on_hscroll_change)
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    38
        AnchorLayout.add(self, self.hscroll, halign='fill', valign='bottom')
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    39
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    40
    def on_resize(self, ev):
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    41
        self._update_scroll_max()
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    42
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    43
    def _connect_child(self, widget):
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    44
        widget.add_handler('sizereq', self._on_child_sizereq)
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    45
        widget.add_handler('spotmove', self._on_child_spotmove)
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    46
        widget.add_handler('scrollreq', self._on_child_scrollreq)
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    47
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    48
    def _on_child_sizereq(self, ev):
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    49
        self._update_scroll_max()
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    50
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    51
    def _on_child_spotmove(self, ev):
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    52
        child = ev.originator
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    53
        # x
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    54
        spot_x = child.x - self._inner.offset.x + child.spot.x
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    55
        if spot_x < self.hscroll.scroll_pos:
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    56
            self.hscroll.scroll_pos = spot_x
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    57
        if spot_x > (self._inner.width - 1) + self.hscroll.scroll_pos:
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    58
            self.hscroll.scroll_pos = spot_x - (self._inner.width - 1)
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    59
        # y
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    60
        spot_y = child.y - self._inner.offset.y + child.spot.y
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    61
        if spot_y < self.vscroll.scroll_pos:
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    62
            self.vscroll.scroll_pos = spot_y
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    63
        if spot_y > (self._inner.height - 1) + self.vscroll.scroll_pos:
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    64
            self.vscroll.scroll_pos = spot_y - (self._inner.height - 1)
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    65
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    66
    def _on_child_scrollreq(self, ev):
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    67
        new_scroll_pos = self.vscroll.scroll_pos + ev.data
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    68
        if new_scroll_pos > self.vscroll.scroll_max:
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    69
            self.vscroll.scroll_pos = self.vscroll.scroll_max
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    70
        elif new_scroll_pos < 0:
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    71
            self.vscroll.scroll_pos = 0
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    72
        else:
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    73
            self.vscroll.scroll_pos = new_scroll_pos
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    74
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    75
    def _on_vscroll_change(self, ev):
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    76
        self._inner.offset.y = - self.vscroll.scroll_pos
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    77
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    78
    def _on_hscroll_change(self, ev):
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    79
        self._inner.offset.x = - self.hscroll.scroll_pos
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    80
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    81
    def _update_scroll_max(self):
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    82
        max_width = 0
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    83
        max_height = 0
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    84
        for child in self._inner.children:
76
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    85
            posx, posy = child.hint_value('position')
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    86
            child_width = posx + child.sizereq.w
75
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    87
            if child_width > max_width:
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    88
                max_width = child_width
76
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    89
            child_height = posy + child.sizereq.h
75
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    90
            if child_height > max_height:
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    91
                max_height = child_height
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
    92
        max_width += 1
76
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    93
        self.hscroll.scroll_max = max_width - self._inner.width
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    94
        self.vscroll.scroll_max = max_height - self._inner.height
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    95
        hscroll_hide = max_width < self._inner.width
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    96
        vscroll_hide = max_height < self._inner.height
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    97
        self._toggle_scrollers(hscroll_hide, vscroll_hide)
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    98
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
    99
    def _toggle_scrollers(self, hscroll_hide, vscroll_hide):
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   100
        if hscroll_hide:
75
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   101
            self.hscroll.hide()
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   102
        else:
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   103
            self.hscroll.show()
76
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   104
        if vscroll_hide:
75
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   105
            self.vscroll.hide()
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   106
        else:
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   107
            self.vscroll.show()
77
fc1989059e19 Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
   108
        # self._inner.need_resize()
75
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   109
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   110
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   111
class ScrollView(OffsetView, Scrolling):
40
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   112
    """Scrolling view
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   113
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   114
    Shows scrollbars when needed.
44
d77f1ae3786c Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
   115
    Scrolling area is determined according to child widget's size request.
40
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   116
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   117
    """
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   118
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 46
diff changeset
   119
    def __init__(self):
75
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   120
        OffsetView.__init__(self)
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   121
        Scrolling.__init__(self)
40
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   122
5faa38c10b67 Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   123
    def add(self, widget, **kwargs):
75
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   124
        OffsetView.add(self, widget, **kwargs)
2430c643838a Clean up hints - add methods update_hint, hint_value to Widget. Split ScrollView into OffsetView and Scrolling components. Reimplement ScrollWindow using Scrolling component.
Radek Brich <radek.brich@devl.cz>
parents: 64
diff changeset
   125
        self._connect_child(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:
diff changeset
   126
76
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   127
    def _toggle_scrollers(self, hscroll_hide, vscroll_hide):
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   128
        bpad = int(not hscroll_hide)
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   129
        self.vscroll.update_hint('margin', b=bpad)
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   130
        rpad = int(not vscroll_hide)
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   131
        self.hscroll.update_hint('margin', r=rpad)
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   132
        self._inner.update_hint('margin', b=bpad, r=rpad)
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   133
        Scrolling._toggle_scrollers(self, hscroll_hide, vscroll_hide)
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
   134