Mercurial > boomslang
comparison pyntnclick/widgets/text.py @ 726:efa58c92b304 pyntnclick
Move prepare out of __init__ and into everywhere else
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Tue, 15 Jan 2013 22:44:50 +0200 |
parents | c8b683dd56d3 |
children | bdaffaa8b6bf |
comparison
equal
deleted
inserted
replaced
725:65e9b5c40233 | 726:efa58c92b304 |
---|---|
13 self.text = text | 13 self.text = text |
14 constants = self.gd.constants | 14 constants = self.gd.constants |
15 self.fontname = fontname or constants.font | 15 self.fontname = fontname or constants.font |
16 self.fontsize = fontsize or constants.font_size | 16 self.fontsize = fontsize or constants.font_size |
17 self.color = color or constants.text_color | 17 self.color = color or constants.text_color |
18 self.prepare() | |
19 | 18 |
20 def prepare(self): | 19 def prepare(self): |
21 self.font = self.resource.get_font(self.fontname, self.fontsize) | 20 self.font = self.resource.get_font(self.fontname, self.fontsize) |
22 self.color = convert_color(self.color) | 21 self.color = convert_color(self.color) |
23 self.surface = self.font.render(self.text, True, self.color) | 22 self.surface = self.font.render(self.text, True, self.color) |
25 width, height = self.surface.get_rect().size | 24 width, height = self.surface.get_rect().size |
26 self.rect.width = max(self.rect.width, width) | 25 self.rect.width = max(self.rect.width, width) |
27 self.rect.height = max(self.rect.height, height) | 26 self.rect.height = max(self.rect.height, height) |
28 | 27 |
29 def draw(self, surface): | 28 def draw(self, surface): |
29 self.do_prepare() | |
30 surface.blit(self.surface, self.rect) | 30 surface.blit(self.surface, self.rect) |
31 | 31 |
32 | 32 |
33 class LabelWidget(TextWidget): | 33 class LabelWidget(TextWidget): |
34 def __init__(self, rect, gd, *args, **kwargs): | 34 def __init__(self, rect, gd, *args, **kwargs): |
55 new_surface.get_rect(), | 55 new_surface.get_rect(), |
56 self.border) | 56 self.border) |
57 self.surface = new_surface | 57 self.surface = new_surface |
58 | 58 |
59 def draw(self, surface): | 59 def draw(self, surface): |
60 self.do_prepare() | |
60 surface.blit(self.surface, self.rect) | 61 surface.blit(self.surface, self.rect) |
61 | 62 |
62 | 63 |
63 class TextButton(Button, TextWidget): | 64 class TextButton(Button, TextWidget): |
64 def __init__(self, rect, gd, *args, **kwargs): | 65 def __init__(self, rect, gd, *args, **kwargs): |
106 def __init__(self, rect, gd, *args, **kwargs): | 107 def __init__(self, rect, gd, *args, **kwargs): |
107 self.max_width = kwargs.pop('max_width', gd.constants.screen[0] - 50) | 108 self.max_width = kwargs.pop('max_width', gd.constants.screen[0] - 50) |
108 self._wrap_width = None | 109 self._wrap_width = None |
109 self._text_lines = None | 110 self._text_lines = None |
110 super(WrappedTextLabel, self).__init__(rect, gd, *args, **kwargs) | 111 super(WrappedTextLabel, self).__init__(rect, gd, *args, **kwargs) |
111 self.prepare() | |
112 | 112 |
113 def prepare(self): | 113 def prepare(self): |
114 if self._wrap_width is None: | 114 if self._wrap_width is None: |
115 # Start without wrapping | 115 # Start without wrapping |
116 self._wrap_width = len(self.text) + 1 | 116 self._wrap_width = len(self.text) + 1 |