author | Radek Brich <radek.brich@devl.cz> |
Sat, 05 Jan 2013 00:37:11 +0100 | |
changeset 46 | 2b43a7f38c34 |
parent 45 | 43b2279b06e1 |
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 |
''' |
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
20 |
|
15 | 21 |
def __init__(self, width=20, height=20): |
22 |
Container.__init__(self, width, height) |
|
23 |
||
24 |
# selected child (only one visible) |
|
25 |
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
|
26 |
|
42
0224ce40792f
Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents:
40
diff
changeset
|
27 |
self.layout = VerticalLayout() |
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 |
42
0224ce40792f
Make Container.layout a property.
Radek Brich <radek.brich@devl.cz>
parents:
40
diff
changeset
|
31 |
self.buttons.layout = HorizontalLayout(homogeneous=True, spacing=1) |
46
2b43a7f38c34
Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
32 |
Container.add(self, self.buttons) |
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
|
33 |
|
15 | 34 |
def add(self, widget, **kw): |
46
2b43a7f38c34
Minor updates. Replace super() with direct class reference. Add demo_colors.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
35 |
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
|
36 |
|
15 | 37 |
if self.selected is None: |
38 |
self.selected = widget |
|
39 |
widget.hidden = False |
|
40 |
else: |
|
41 |
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
|
42 |
|
15 | 43 |
btn = Button(kw['title']) |
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
|
44 |
btn.add_handler('click', lambda: self.select(widget)) |
17
5be7cc43402e
Handle curses resize event.
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
45 |
self.buttons.add(btn, fill=True) |
15 | 46 |
|
47 |
def select(self, child): |
|
48 |
log = logging.getLogger('tuikit') |
|
49 |
log.debug('Pager: select %r', child) |
|
50 |
||
51 |
self.selected.hidden = True |
|
52 |
child.hidden = False |
|
53 |
self.selected = child |
|
54 |
||
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
32
diff
changeset
|
55 |
self.emit('resize') |
15 | 56 |