2
# -*- coding: utf-8 -*-
6
__authors__ = ["Jan Jokela <janjokela@gmail.com>"]
7
__licenses__ = ["LICENSE.LGPL"]
8
__description__ = "Horizontal and vertical box widgets"
14
from container import Container
18
A box is a special type of container for displaying multiple children in
19
an horizontal or vertical layout.
24
""" Initialize box """
26
super(Box, self).__init__()
30
self.packed_children = []
32
self._update_style(self.style)
34
def _update_style(self, props=None):
37
super(Box, self)._update_style(props)
39
for key, value in props:
42
elif key == 'alignment':
43
self.alignment = value
45
def _update_layout(self):
48
super(Box, self)._update_layout()
50
def pack(self, child):
51
""" Packs a child into the box """
53
self.packed_children.append(child)
56
def get_spacing(self):
57
""" Retrieve child spacing """
61
def set_spacing(self, value):
62
""" Sets child spacing
64
value -- (float) Spacing between children
69
spacing = property(get_spacing, set_spacing)
71
def get_alignment(self):
72
""" Retrieve alignment """
74
return self._alignment
76
def set_alignment(self, value):
77
""" Sets children alignment
79
value -- (str) [ALINGMENT.START, ALIGNMENT.END, ALIGNMENT.CENTER]
82
self._alignment = value
84
alignment = property(get_alignment, set_alignment)
88
""" An HBox layouts children in an horizontal fashion """
91
""" Initialize horizontal box """
93
super(HBox, self).__init__()
95
self._update_style(self.style)
97
def _update_style(self, props=None):
100
super(HBox, self)._update_style(props)
102
def _update_layout(self):
103
""" Updates layout """
105
super(HBox, self)._update_layout()
107
fixed_width_children = []
109
for child in self.packed_children:
110
if child.size_ratio > 0:
111
fixed_width_children.append(child)
114
for child in self.packed_children:
115
child.set_natural_x(current_x)
116
if child not in fixed_width_children:
117
child_width = 1.0 / len(self.packed_children) - \
118
len(fixed_width_children)
119
child.set_natural_width(child_width)
120
child._update_layout()
121
current_x += child.get_widthu() * 1.0 / self.get_widthu()
122
current_x += self.spacing