From 0a701c2b8500c0d5f01fc94bf6530f67f196fdbb Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Fri, 5 Nov 2010 22:53:04 -0400 Subject: [PATCH] add label --- kivy/uix/label.py | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 kivy/uix/label.py diff --git a/kivy/uix/label.py b/kivy/uix/label.py new file mode 100644 index 000000000..99d85286a --- /dev/null +++ b/kivy/uix/label.py @@ -0,0 +1,82 @@ +''' +Label: +''' + +__all__ = ('Label', ) + +from kivy.clock import Clock +from kivy.uix.widget import Widget +from kivy.core.text import Label as CoreLabel +from kivy.c_ext.properties import StringProperty, OptionProperty, \ + NumericProperty, BooleanProperty, ReferenceListProperty, \ + ListProperty, ObjectProperty + +class Label(Widget): + + #: Text written in the label + text = StringProperty('') + + #: Name of the font + font_name = StringProperty('fonts/DejaVuSans.ttf') + + #: Size of the font + font_size = NumericProperty(10) + + #: Activate bold style if available + bold = BooleanProperty(False) + + #: Activate italic style if available + italic = BooleanProperty(False) + + #: Padding X + padding_x = NumericProperty(0) + + #: Padding Y + padding_y = NumericProperty(0) + + #: Padding (x / y) + padding = ReferenceListProperty(padding_x, padding_y) + + #: Horizontal alignement + halign = OptionProperty('left', options=['left', 'center', 'right']) + + #: Vertical alignement + valign = OptionProperty('bottom', options=['bottom', 'middle', 'top']) + + #: Color + color = ListProperty([1, 1, 1, 1]) + + #: Texture of the label + texture = ObjectProperty(None, allownone=True) + + def __init__(self, **kwargs): + super(Label, self).__init__(**kwargs) + + # bind all the property for recreating the texture + d = ('text', 'font_size', 'font_name', 'bold', 'italic', 'halign', + 'valign', 'padding_x', 'padding_y') + dkw = dict(zip(d, [self._trigger_texture_update] * len(d))) + self.bind(**dkw) + + dkw = dict(zip(d, [getattr(self, x) for x in d])) + print dkw + self._label = CoreLabel(**dkw) + + # force the texture creation + self._trigger_texture_update() + + import pprint + def printm(sender, value): + print sender, value + self.bind(texture=printm) + + def _trigger_texture_update(self, source=None, value=None): + print '_trigger_texture_update()', source, value + if source: + self._label.options[source.name] = value + Clock.unschedule(self._texture_update) + Clock.schedule_once(self._texture_update) + + def _texture_update(self, *largs): + self._label.refresh() + self.texture = self._label.texture