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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
# !/usr/bin/python
# -*- coding: utf-8 -*-
# Glitter Toolkit
__authors__ = ["Jan Jokela <janjokela@gmail.com>"]
__licenses__ = ["LICENSE.LGPL"]
__description__ = "Container widget"
from widget import Widget
POLICY_NONE = 'POLICY_NONE'
POLICY_EXPAND = 'POLICY_EXPAND'
POLICY_MINIMUM = 'POLICY_MINIMUM'
class Container(Widget):
"""
A container widget provides a representation of a graphical container
that not only is intended as a placeholder for children but also as a base
class for other container-type widgets.
It offers powerfull layout capabilities through the usage of minimum and
natural sizes and positions. It also features resolution independence
through the use of relative values, millimeters and clutter units.
"""
def __init__(self):
""" Initialize the container """
super(Container, self).__init__()
self._natural_width = 0.0
self._natural_height = 0.0
self._minimum_width = 0.0
self._minimum_height = 0.0
self._natural_x = 0.0
self._natural_y = 0.0
self._minimum_x = 0
self._minimum_y = 0
self._h_offset = 0.0
self._v_offset = 0.0
self._size_ratio = 0.0
def _update_style(self, props=None):
""" Update style """
super(Container, self)._update_style(props)
if not props:
return
for key, value in props:
if key == 'natural-width':
self.natural_width = value
elif key == 'natural-height':
self.natural_height = value
elif key == 'minimum-width':
self.minimum_width = value
elif key == 'minimum-height':
self.minimum_height = value
elif key == 'natural-x':
self.natural_x = value
elif key == 'natural-y':
self.natural_y = value
elif key == 'minimum-x':
self.minimum_x = value
elif key == 'minimum-y':
self.minimum_y = value
elif key == 'h-offset':
self.h_offset = value
elif key == 'v-offset':
self.v_offset = value
def _update_layout(self):
""" Updates layout """
if self.get_parent():
# Natural an minimum sizes
n_width = int(self.natural_width * self.get_parent().get_widthu())
n_height = int(self.natural_height * self.get_parent().get_heightu())
m_width = self.minimum_width
m_height = self.minimum_height
# Preferred size is the natural one, except if lower than minimum
if n_width >= m_width:
tmp_width = n_width
else:
tmp_width = m_width
if n_height >= m_height:
tmp_height = n_height
else:
tmp_height = m_height
# Account for size ratios
if self.size_ratio > 0:
tmp_width = int(self.size_ratio * tmp_height)
elif self.size_ratio < 0:
tmp_height = int(-self.size_ratio * tmp_width)
# Set size
self.set_widthu(int(tmp_width))
self.set_heightu(int(tmp_height))
# Natural and minimum positions
n_x = self.natural_x * self.get_parent().get_widthu()
n_y = self.natural_y * self.get_parent().get_heightu()
m_x = self.minimum_x
m_y = self.minimum_y
if n_x >= m_x:
tmp_x = n_x
else:
tmp_x = m_x
if n_y >= m_y:
tmp_y = n_y
else:
tmp_y = m_y
tmp_x = int(tmp_x)
tmp_y = int(tmp_y)
self.set_position(tmp_x, tmp_y)
def get_natural_width(self):
""" Retrieve natural width """
return self._natural_width
def set_natural_width(self, value):
""" Sets natural width
value -- (float) Width as a factor of parent width
"""
self._natural_width = value
natural_width = property(get_natural_width, set_natural_width)
def get_natural_height(self):
""" Retrieve natural height """
return self._natural_height
def set_natural_height(self, value):
""" Sets natural height
value -- (float) Height as a factor of parent height
"""
self._natural_height = value
natural_height = property(get_natural_height, set_natural_height)
def get_minimum_width(self):
""" Retrieve minimum width """
return self._minimum_width
def set_minimum_width(self, value):
""" Sets minimum width
value -- (int) Minimum width in clutter units
"""
self._minimum_width = value
minimum_width = property(get_minimum_width, set_minimum_width)
def get_minimum_height(self):
""" Retrieve minimum height """
return self._minimum_height
def set_minimum_height(self, value):
""" Sets minimum height
value -- (int) Minimum height in clutter units
"""
self._minimum_height = value
minimum_height = property(get_minimum_height, set_minimum_height)
def get_size_ratio(self):
""" Retrieve size ratio """
return self._size_ratio
def set_size_ratio(self, value):
""" Sets size ratio
value -- (float) Size ratio. Positive values for width as a factor of
height. Negative values for height as a factor of width.
"""
self._size_ratio = value
size_ratio = property(get_size_ratio, set_size_ratio)
def get_width_policy(self):
""" Retrieve width policy """
return self._width_policy
def set_width_policy(self, value):
""" Sets width policy
value -- (str) NATURAL or MINIMUM width
"""
self._width_policy = value
width_policy = property(get_width_policy, set_width_policy)
def get_height_policy(self):
""" Retrieve height policy """
return self._height_policy
def set_height_policy(self, value):
""" Sets height policy
value -- (str) NATURAL or MINIMUM height
"""
self._height_policy = value
height_policy = property(get_height_policy, set_height_policy)
def get_natural_x(self):
""" Retrieve minimum x """
return self._natural_x
def set_natural_x(self, value):
""" Sets natural x
value -- (float) X position as a factor of parent width
"""
self._natural_x = value
natural_x = property(get_natural_x, set_natural_x)
def get_natural_y(self):
""" Retrieve natural y """
return self._natural_y
def set_natural_y(self, value):
""" Sets natural y
value -- (float) Y as a factor of parent height
"""
self._natural_y = value
natural_y = property(get_natural_y, set_natural_y)
def get_minimum_x(self):
""" Retrieve minimum y """
return self._minimum_y
def set_minimum_x(self, value):
""" Sets minimum x
value -- (float) Minimum x in clutter units
"""
self._minimum_x = value
minimum_x = property(get_minimum_x, set_minimum_x)
def get_minimum_y(self):
""" Retrieve minimum y """
return self._minimum_y
def set_minimum_y(self, value):
""" Sets minimum y
value -- (float) Minimum y in clutter units
"""
self._minimum_y = value
minimum_y = property(get_minimum_y, set_minimum_y)
def get_h_offset(self):
""" Retrieve horizontal offset """
return self._h_offset
def set_h_offset(self, value):
""" Sets horizontal offset. Overwrites values for natural x and width.
value -- (float) offset as a factor of parent width
"""
self._h_offset = value
self.natural_x = value
self.natural_width = 1.0 - 2 * value
h_offset = property(get_h_offset, set_h_offset)
def get_v_offset(self):
""" Retrieve vertical offset """
return self._v_offset
def set_v_offset(self, value):
""" Sets vertical offset. Overwrites values for natural y and height.
value -- (float) offset as a factor of parent height
"""
self._v_offset = value
self.natural_y = value
if self.natural_height > 0:
self.natural_height = self.natural_height - 2 * value
v_offset = property(get_v_offset, set_v_offset)
|