1
# Copyright (c) 2009 Entertainer Developers - See COPYING - GPLv2
6
from entertainerlib.gui.widgets.base import Base
8
class Label(Base, clutter.Label):
9
"""Wrapper of a clutter label to encapsulate some label settings and have
10
knowledge of the stage size"""
12
def __init__(self, font_size, color_name, x_pos_percent, y_pos_percent,
13
text=None, name=None, font_weight=""):
14
"""Initialize the Label object"""
17
clutter.Label.__init__(self)
19
self.theme = self.config.theme
21
self._font_weight = font_weight
22
self._font_size = font_size
23
self._set_font_size(font_size)
25
self.set_color(self.theme.get_color(color_name))
28
self._set_position((x_pos_percent, y_pos_percent))
35
self._width = self._init_width()
36
self._height = self._init_height()
38
self.set_line_wrap(True)
40
def set_size(self, x_percent, y_percent):
41
"""Override clutter label set_size to calculate absolute size from a
43
self._width = x_percent
44
self._height = y_percent
45
clutter.Label.set_size(self,
46
self.get_abs_x(x_percent),
47
self.get_abs_y(y_percent))
49
def _init_width(self):
50
"""Generate the width of the label initially before the width property
51
is set to ensure width has a value"""
52
return float(self.get_width()) / self.config.get_stage_width()
55
"""Return the width as a percent of the stage size"""
58
def _set_width(self, x_percent):
59
"""Set the width based on a hozirontal percent of the stage size.
60
Provide clutter label set_width the absolute size from the percentage"""
61
self._width = x_percent
62
clutter.Label.set_width(self, self.get_abs_x(x_percent))
64
width = property(_get_width, _set_width)
66
def _get_position(self):
67
"""Return the position as a tuple of percents of the stage size"""
70
def _set_position(self, position_pair):
71
"""Translate a tuple of x and y percentages into an absolute position
72
within the display area"""
73
self._position = position_pair
75
(x_pos_percent, y_pos_percent) = position_pair
77
clutter.Label.set_position(self,
78
self.get_abs_x(x_pos_percent),
79
self.get_abs_y(y_pos_percent))
81
position = property(_get_position, _set_position)
83
def _init_height(self):
84
"""Generate the height of the label initially before the height property
85
is set to ensure height has a value"""
86
return float(self.get_height()) / self.config.get_stage_height()
88
def _get_height(self):
89
"""Return the height as a percent of the stage size"""
92
def _set_height(self, y_percent):
93
"""Set the height based on a vertical percent of the stage size.
94
Provide clutter label set_height the absolute size from the percentage
96
self._height = y_percent
97
clutter.Label.set_height(self, self.get_abs_y(y_percent))
99
height = property(_get_height, _set_height)
101
def _get_font_size(self):
102
"""Return the font size as a percent of the stage size"""
103
return self._font_size
105
def _set_font_size(self, y_percent):
106
"""Set the font size based on a vertical percent of the screen size"""
107
self._font_size = y_percent
108
self.set_font_name(self.theme.font + ", " + self._font_weight +
109
" " + str(self.get_abs_y(y_percent)) + "px")
111
font_size = property(_get_font_size, _set_font_size)