15
|
1 |
# -*- coding: utf-8 -*-
|
|
2 |
|
|
3 |
import logging
|
|
4 |
|
|
5 |
from .container import Container
|
|
6 |
from .layout import VerticalLayout, HorizontalLayout
|
|
7 |
from .button import Button
|
|
8 |
|
|
9 |
|
|
10 |
class Pager(Container):
|
|
11 |
'''Only one of children is visible at the time.'''
|
|
12 |
def __init__(self, width=20, height=20):
|
|
13 |
Container.__init__(self, width, height)
|
|
14 |
|
|
15 |
# selected child (only one visible)
|
|
16 |
self.selected = None
|
|
17 |
|
|
18 |
vert = VerticalLayout()
|
|
19 |
self.layout(vert)
|
|
20 |
|
|
21 |
self.buttons = Container(20, 1)
|
|
22 |
Container.add(self, self.buttons)
|
|
23 |
horz = HorizontalLayout()
|
|
24 |
self.buttons.layout(horz)
|
|
25 |
|
|
26 |
def add(self, widget, **kw):
|
|
27 |
Container.add(self, widget, **kw)
|
|
28 |
|
|
29 |
if self.selected is None:
|
|
30 |
self.selected = widget
|
|
31 |
widget.hidden = False
|
|
32 |
else:
|
|
33 |
widget.hidden = True
|
|
34 |
|
|
35 |
btn = Button(kw['title'])
|
|
36 |
btn.connect('click', lambda: self.select(widget))
|
|
37 |
self.buttons.add(btn)
|
|
38 |
|
|
39 |
def select(self, child):
|
|
40 |
log = logging.getLogger('tuikit')
|
|
41 |
log.debug('Pager: select %r', child)
|
|
42 |
|
|
43 |
self.selected.hidden = True
|
|
44 |
child.hidden = False
|
|
45 |
self.selected = child
|
|
46 |
|
|
47 |
self.resize()
|
|
48 |
|