2
# -*- coding: utf-8 -*-
6
__authors__ = ["Jan Jokela <janjokela@gmail.com>"]
7
__licenses__ = ["LICENSE.LGPL"]
8
__description__ = "Container widget"
10
from widget import Widget
12
POLICY_NONE = 'POLICY_NONE'
13
POLICY_EXPAND = 'POLICY_EXPAND'
14
POLICY_MINIMUM = 'POLICY_MINIMUM'
16
class Container(Widget):
18
A container widget provides a representation of a graphical container
19
that not only is intended as a placeholder for children but also as a base
20
class for other container-type widgets.
22
It offers powerfull layout capabilities through the usage of minimum and
23
natural sizes and positions. It also features resolution independence
24
through the use of relative values, millimeters and clutter units.
29
""" Initialize the container """
31
super(Container, self).__init__()
33
self._natural_width = 0.0
34
self._natural_height = 0.0
35
self._minimum_width = 0.0
36
self._minimum_height = 0.0
42
self._size_ratio = 0.0
44
def _update_style(self, props=None):
47
super(Container, self)._update_style(props)
52
for key, value in props:
53
if key == 'natural-width':
54
self.natural_width = value
55
elif key == 'natural-height':
56
self.natural_height = value
57
elif key == 'natural-width':
58
self.natural_width = value
59
elif key == 'natural-height':
60
self.natural_height = value
61
elif key == 'natural-x':
62
self.natural_x = value
63
elif key == 'natural-y':
64
self.natural_y = value
65
elif key == 'minimum-x':
66
self.minimum_x = value
67
elif key == 'minimum-y':
68
self.minimum_y = value
71
def _update_layout(self):
72
""" Updates layout """
74
# Natural an minimum sizes
75
n_width = int(self.natural_width * self.get_parent().get_widthu())
76
n_height = int(self.natural_height * self.get_parent().get_heightu())
78
m_width = self.minimum_width
79
m_height = self.minimum_height
81
# Preferred size is the natural one, except if lower than minimum
82
if n_width >= m_width:
86
if n_height >= m_height:
91
# Account for size ratios
92
if self.size_ratio > 0:
93
tmp_width = int(self.size_ratio * tmp_height)
94
elif self.size_ratio < 0:
95
tmp_height = int(self.size_ratio * tmp_width)
98
self.set_widthu(int(tmp_width))
99
self.set_heightu(int(tmp_height))
101
# Natural and minimum positions
102
n_x = int(self.natural_x * self.get_parent().get_widthu())
103
n_y = int(self.natural_y * self.get_parent().get_heightu())
120
def get_natural_width(self):
121
""" Retrieve natural width """
123
return self._natural_width
125
def set_natural_width(self, value):
126
""" Sets natural width
128
value -- (float) Width as a factor of parent width
131
self._natural_width = value
133
natural_width = property(get_natural_width, set_natural_width)
135
def get_natural_height(self):
136
""" Retrieve natural height """
138
return self._natural_height
140
def set_natural_height(self, value):
141
""" Sets natural height
143
value -- (float) Height as a factor of parent height
146
self._natural_height = value
148
natural_height = property(get_natural_height, set_natural_height)
150
def get_minimum_width(self):
151
""" Retrieve minimum width """
153
return self._minimum_width
155
def set_minimum_width(self, value):
156
""" Sets minimum width
158
value -- (int) Minimum width in clutter units
161
self._minimum_width = value
163
minimum_width = property(get_minimum_width, set_minimum_width)
165
def get_minimum_height(self):
166
""" Retrieve minimum height """
168
return self._minimum_height
170
def set_minimum_height(self, value):
171
""" Sets minimum height
173
value -- (int) Minimum height in clutter units
176
self._minimum_height = value
178
minimum_height = property(get_minimum_height, set_minimum_height)
180
def get_size_ratio(self):
181
""" Retrieve size ratio """
183
return self._size_ratio
185
def set_size_ratio(self, value):
188
value -- (float) Size ratio. Positive values for width as a factor of
189
height. Negative values for height as a factor of width.
192
self._size_ratio = value
194
size_ratio = property(get_size_ratio, set_size_ratio)
196
def get_width_policy(self):
197
""" Retrieve width policy """
199
return self._width_policy
201
def set_width_policy(self, value):
202
""" Sets width policy
204
value -- (str) NATURAL or MINIMUM width
207
self._width_policy = value
209
width_policy = property(get_width_policy, set_width_policy)
211
def get_height_policy(self):
212
""" Retrieve height policy """
214
return self._height_policy
216
def set_height_policy(self, value):
217
""" Sets height policy
219
value -- (str) NATURAL or MINIMUM height
222
self._height_policy = value
224
height_policy = property(get_height_policy, set_height_policy)
226
def get_natural_x(self):
227
""" Retrieve minimum x """
229
return self._natural_x
231
def set_natural_x(self, value):
234
value -- (float) X position as a factor of parent width
237
self._natural_x = value
239
natural_x = property(get_natural_x, set_natural_x)
241
def get_natural_y(self):
242
""" Retrieve natural y """
244
return self._natural_y
246
def set_natural_y(self, value):
249
value -- (float) Y as a factor of parent height
252
self._natural_y = value
254
natural_y = property(get_natural_y, set_natural_y)
256
def get_minimum_x(self):
257
""" Retrieve minimum y """
259
return self._minimum_y
261
def set_minimum_x(self, value):
264
value -- (float) Minimum x in clutter units
267
self._minimum_x = value
269
minimum_x = property(get_minimum_x, set_minimum_x)
271
def get_minimum_y(self):
272
""" Retrieve minimum y """
274
return self._minimum_y
276
def set_minimum_y(self, value):
279
value -- (float) Minimum y in clutter units
282
self._minimum_y = value
284
minimum_y = property(get_minimum_y, set_minimum_y)