def draw(self, surface):
surface.blit(self.surface, self.rect)
+
class TextBoxWidget(TextWidget):
def __init__(self, *args, **kwargs):
self.padding = kwargs.pop('padding', 5)
(0, 0, 0)))
self.box_width = kwargs.pop('box_width', 0)
- super(TextBoxWidget,self).__init__(*args, **kwargs)
+ super(TextBoxWidget, self).__init__(*args, **kwargs)
def prepare(self):
self.font = resources.get_font(self.fontname, self.fontsize)
current_line_rendered = None
for word in line.split(' '):
if len(current_line) > 0:
- current_line += ' '+ word
+ current_line += ' ' + word
else:
current_line = word
line = self.font.render(current_line, True, self.colour)
elif current_line_rendered is not None:
line_rect = current_line_rendered.get_rect()
self.lines.append(pygame.transform.scale(
- current_line_rendered,(line_rect.width * 2,
- line_rect.height * 2)))
+ current_line_rendered, (line_rect.width * 2,
+ line_rect.height * 2)))
current_line = word
- current_line_rendered = self.font.render(word, True, self.colour)
+ current_line_rendered = self.font.render(
+ word, True, self.colour)
else:
- raise Exception('Line too long. Please resize or rephrase')
+ raise Exception(
+ 'Line too long. Please resize or rephrase')
if current_line_rendered is not None:
line_rect = current_line_rendered.get_rect()
self.lines.append(pygame.transform.scale(
- current_line_rendered,(line_rect.width * 2,
- line_rect.height * 2)))
+ current_line_rendered, (line_rect.width * 2,
+ line_rect.height * 2)))
else:
line = self.font.render(line, True, self.colour)
line_rect = line.get_rect()
width = max(width, line.get_rect().width)
height += line.get_rect().height
- self.lines.append(pygame.transform.scale(line, (line_rect.width * 2,
- line_rect.height * 2)))
+ self.lines.append(pygame.transform.scale(
+ line, (line_rect.width * 2, line_rect.height * 2)))
width += 2 + self.padding
height += 2 + self.padding
self.text_rect = surface.get_rect()
if not self.size:
self.rect.size = self.text_rect.size
-