tuikit/layouts/offset.py
author Radek Brich <radek.brich@devl.cz>
Mon, 16 Feb 2015 21:17:43 +0100
changeset 117 8680c2333546
parent 115 b4ff7392003a
permissions -rw-r--r--
Update FixedLayout. Add demo launcher.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
114
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
from .layout import Layout
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
from tuikit.core.coords import Point
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
class OffsetLayout(Layout):
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
    """Offsets widget position. Used by Viewport and ScrollView."""
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
    def __init__(self):
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
        Layout.__init__(self)
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
        self._offset = Point()
117
8680c2333546 Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents: 115
diff changeset
    12
        self._widget_pos = {}
114
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
    @property
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
    def offset(self):
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
        """Offset of child widgets."""
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
        return self._offset
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
117
8680c2333546 Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents: 115
diff changeset
    19
    def add(self, widget, x=0, y=0):
8680c2333546 Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents: 115
diff changeset
    20
        Layout.add(self, widget)
8680c2333546 Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents: 115
diff changeset
    21
        self._widget_pos[widget] = (x, y)
8680c2333546 Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents: 115
diff changeset
    22
115
b4ff7392003a GridLayout: basic implementation.
Radek Brich <radek.brich@devl.cz>
parents: 114
diff changeset
    23
    def update(self, _w, _h):
114
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
        for widget in self._managed_widgets:
26c02bd94bd9 Add Widget.posreq. Add OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
            widget.resize(*widget.sizereq)
117
8680c2333546 Update FixedLayout. Add demo launcher.
Radek Brich <radek.brich@devl.cz>
parents: 115
diff changeset
    26
            widget.pos.update(*(self.offset + self._widget_pos[widget]))