1 from tuikit.core.theme import default_theme |
1 from tuikit.core.widget import Widget |
2 |
2 |
3 |
3 |
4 class Container: |
4 class Container(Widget): |
5 |
5 |
6 """Container for widgets.""" |
6 """Container widget. |
|
7 |
|
8 Can contain other widgets to create hierarchical structure. |
|
9 |
|
10 """ |
7 |
11 |
8 def __init__(self): |
12 def __init__(self): |
|
13 Widget.__init__(self) |
9 #: List of child widgets. |
14 #: List of child widgets. |
10 self.children = [] |
15 self.children = [] |
11 self.theme = default_theme |
|
12 |
16 |
13 def add(self, widget, **kwargs): |
17 def add(self, widget): |
14 """Add widget into container.""" |
18 """Add widget into container.""" |
15 self.children.append(widget) |
19 self.children.append(widget) |
16 widget.parent = self |
20 widget.parent = self |
17 widget.window = self.window if hasattr(self, 'window') else self |
21 widget.window = self.window |
18 widget.set_theme(self.theme) |
22 widget.set_theme(self.theme) |
19 |
|
20 def set_theme(self, theme): |
|
21 self.theme = theme |
|
22 for child in self.children: |
|
23 child.set_theme(theme) |
|
24 |
23 |
25 def draw(self, buffer, x=0, y=0): |
24 def draw(self, buffer, x=0, y=0): |
26 """Draw child widgets.""" |
25 """Draw child widgets.""" |
27 for child in self.children: |
26 for child in self.children: |
28 child.draw(buffer, |
27 child.draw(buffer, |
29 x + child.x, |
28 x + child.x, |
30 y + child.y) |
29 y + child.y) |
|
30 |
|
31 def set_theme(self, theme): |
|
32 Widget.set_theme(self, theme) |
|
33 for child in self.children: |
|
34 child.set_theme(theme) |