File: stacked_container_demo.py

package info (click to toggle)
python-enable 4.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,280 kB
  • ctags: 13,899
  • sloc: cpp: 48,447; python: 28,502; ansic: 9,004; makefile: 315; sh: 44
file content (46 lines) | stat: -rw-r--r-- 1,637 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from enable.example_support import DemoFrame, demo_main

from enable.api import Container, Window, TextField
from enable.stacked_container import VStackedContainer, HStackedContainer


size = (240, 240)


class MyFrame(DemoFrame):

    def _create_window(self):

        stack = VStackedContainer(position=[0,0],
            halign='center', valign='center', #border_visible=True,
            fit_components='hv', auto_size=True, stack_order='top_to_bottom',
            bgcolor='red')

        strings = ["apple", "banana", "cherry", "durian",
                         "eggfruit", "fig", "grape", "honeydew"]

        for i, s in enumerate(strings):
            label = TextField(text=s, resizable='', bounds=[100+i*10,20],
                bgcolor='red', #border_visible=True,
                text_offset=1)
            number = TextField(text=str(i+1), resizable='',
                bgcolor='blue', #border_visible=True,
                text_offset=1, can_edit=False, bounds=[20, 20])
            row = HStackedContainer(fit_components='hv', auto_size=True,
                resizable='',
                valign='top', border_visible=True)
            row.add(number)
            row.add(label)
            stack.add(row)

        container = Container(position=[20, 20], bounds=size)
        container.add(stack)
        container2 = Container(bounds=size)
        container2.add(container)
        return Window(self, -1, component=container2)


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(MyFrame, size=size)