author | Radek Brich <radek.brich@devl.cz> |
Fri, 14 Dec 2012 10:20:14 +0100 | |
changeset 32 | 088b92ffb119 |
parent 30 | 05500124d7fb |
child 34 | e3beacd5e536 |
permissions | -rw-r--r-- |
15 | 1 |
# -*- coding: utf-8 -*- |
2 |
||
3 |
import logging |
|
4 |
||
18
e6c3a5ee91aa
Eliminate relative imports.
Radek Brich <radek.brich@devl.cz>
parents:
17
diff
changeset
|
5 |
from tuikit.container import Container |
e6c3a5ee91aa
Eliminate relative imports.
Radek Brich <radek.brich@devl.cz>
parents:
17
diff
changeset
|
6 |
from tuikit.layout import VerticalLayout, HorizontalLayout |
e6c3a5ee91aa
Eliminate relative imports.
Radek Brich <radek.brich@devl.cz>
parents:
17
diff
changeset
|
7 |
from tuikit.button import Button |
15 | 8 |
|
9 |
||
10 |
class Pager(Container): |
|
30
05500124d7fb
Add setup script. Add Checkbox widget + demo. Updates.
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
11 |
'''Only one of children is visible at the time. |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
12 |
|
30
05500124d7fb
Add setup script. Add Checkbox widget + demo. Updates.
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
13 |
Pages are switched using buttons at top (tabs). |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
14 |
|
30
05500124d7fb
Add setup script. Add Checkbox widget + demo. Updates.
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
15 |
page_one = Container() |
05500124d7fb
Add setup script. Add Checkbox widget + demo. Updates.
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
16 |
pager.add(page_one, title="page one") |
05500124d7fb
Add setup script. Add Checkbox widget + demo. Updates.
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
17 |
pager.select(page_one) |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
18 |
|
30
05500124d7fb
Add setup script. Add Checkbox widget + demo. Updates.
Radek Brich <radek.brich@devl.cz>
parents:
18
diff
changeset
|
19 |
''' |
15 | 20 |
def __init__(self, width=20, height=20): |
21 |
Container.__init__(self, width, height) |
|
22 |
||
23 |
# selected child (only one visible) |
|
24 |
self.selected = None |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
25 |
|
15 | 26 |
vert = VerticalLayout() |
27 |
self.layout(vert) |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
28 |
|
15 | 29 |
self.buttons = Container(20, 1) |
17
5be7cc43402e
Handle curses resize event.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
30 |
self.buttons.sizereq.h = 1 |
15 | 31 |
Container.add(self, self.buttons) |
17
5be7cc43402e
Handle curses resize event.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
32 |
horz = HorizontalLayout(homogeneous=True, spacing=1) |
15 | 33 |
self.buttons.layout(horz) |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
34 |
|
15 | 35 |
def add(self, widget, **kw): |
17
5be7cc43402e
Handle curses resize event.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
36 |
Container.add(self, widget, expand=True, fill=True) |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
37 |
|
15 | 38 |
if self.selected is None: |
39 |
self.selected = widget |
|
40 |
widget.hidden = False |
|
41 |
else: |
|
42 |
widget.hidden = True |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
43 |
|
15 | 44 |
btn = Button(kw['title']) |
45 |
btn.connect('click', lambda: self.select(widget)) |
|
17
5be7cc43402e
Handle curses resize event.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
46 |
self.buttons.add(btn, fill=True) |
15 | 47 |
|
48 |
def select(self, child): |
|
49 |
log = logging.getLogger('tuikit') |
|
50 |
log.debug('Pager: select %r', child) |
|
51 |
||
52 |
self.selected.hidden = True |
|
53 |
child.hidden = False |
|
54 |
self.selected = child |
|
55 |
||
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
56 |
self.handle('resize') |
15 | 57 |