2
# -*- coding: utf-8 -*-
6
__authors__ = ["Jan Jokela <janjokela@gmail.com>"]
7
__licenses__ = ["LICENSE.LGPL"]
8
__description__ = "Label widget"
14
from container import Container
16
class Label(Container):
18
A label widget represents a text label which can be drawn in any pango
19
supported font, colored, ellipsized and line wrapped.
23
def __init__(self, text='Label', ellipsize=True, line_wrap=False):
24
""" Initialize label """
26
super(Label, self).__init__()
29
self._ellipsize = ellipsize
30
self._line_wrap = line_wrap
33
self._update_style(self.style)
36
def _init_elements(self):
37
""" Initializes visual elements """
40
self._label = clutter.Label()
41
self._label.set_text(self.text)
43
self._label.set_ellipsize(pango.ELLIPSIZE_END)
44
self._label.set_line_wrap(self.line_wrap)
48
def _update_layout(self):
49
""" Updates layout """
51
super(Label, self)._update_layout()
53
# Ajust text font size to height and calculate minimum width
54
height = self.get_height()
55
self._label.set_font_name(self.font + ' ' + str(height) + 'px')
56
self.minimum_width = self._label.get_widthu()
58
# Update the label to account for the new minimum width
59
super(Label, self)._update_layout()
62
width = self.get_width()
63
self.set_clip(0, 0, width, height)
65
def _update_style(self, props=None):
66
""" Updates widget style """
68
super(Label, self)._update_style(props)
73
for key, value in props:
74
if key == 'font-name':
82
""" Retrieve label text
84
return (str) -- label text
89
def set_text(self, text):
92
text (str) -- label text
97
text = property(get_text, set_text)
107
def set_font(self, font):
110
font (str) -- font name
114
height = self.get_height()
115
self._label.set_font_name(self._font + ' ' + str(height) + 'px')
117
font = property(get_font, set_font)
122
return (int, int, int, int) -- color in rgba format
127
def set_color(self, color):
130
color (int, int, int, int) -- color in rgba format
134
self._label.set_color(self._color)
136
color = property(get_color, set_color)
138
def get_ellipsize(self):
139
""" Retrieve whether text is to be ellipsized
141
return (bool) -- ellipsize
144
return self._ellipsize
146
def set_ellipsize(self, ellipsize):
147
""" Sets whether text is to be ellipsized
149
ellipsize (bool) -- ellipsize
152
self._ellipsize = ellipsize
154
self._label.set_ellipsize(pango.ELLIPSIZE_END)
156
ellipsize = property(get_ellipsize, set_ellipsize)
158
def get_line_wrap(self):
159
""" Retrieve whether text is to be line wrapped
161
return (bool) -- line wrap
164
return self._line_wrap
166
def set_line_wrap(self, line_wrap):
167
""" Sets whether text is to be line wrapped
169
line_wrap (bool) -- line wrap
172
self._line_wrap = line_wrap
173
self._label.set_line_wrap(line_wrap)
175
line_wrap = property(get_line_wrap, set_line_wrap)