Mercurial > boomslang
comparison gamelib/widgets.py @ 122:d2f84f22def0
Move MessageDialog to widgets
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Tue, 24 Aug 2010 17:45:46 +0200 |
parents | d7c0a702a0b4 |
children | 97322b78d1c1 |
comparison
equal
deleted
inserted
replaced
121:2f672e98d488 | 122:d2f84f22def0 |
---|---|
1 # widgets.py | 1 # widgets.py |
2 # Copyright Boomslang team, 2010 (see COPYING File) | 2 # Copyright Boomslang team, 2010 (see COPYING File) |
3 | 3 |
4 """Custom Albow widgets""" | 4 """Custom Albow widgets""" |
5 | 5 |
6 import textwrap | |
7 | |
6 import albow.controls | 8 import albow.controls |
9 | |
10 from cursor import CursorWidget | |
7 | 11 |
8 | 12 |
9 class BoomLabel(albow.controls.Label): | 13 class BoomLabel(albow.controls.Label): |
10 | 14 |
11 def set_margin(self, margin): | 15 def set_margin(self, margin): |
14 w, h = self.size | 18 w, h = self.size |
15 d = margin - old_margin | 19 d = margin - old_margin |
16 self.margin = margin | 20 self.margin = margin |
17 self.size = (w + 2 * d, h + 2 * d) | 21 self.size = (w + 2 * d, h + 2 * d) |
18 | 22 |
23 class MessageDialog(BoomLabel, CursorWidget): | |
24 | |
25 def __init__(self, text, wrap_width, **kwds): | |
26 CursorWidget.__init__(self) | |
27 paras = text.split("\n\n") | |
28 text = "\n".join([textwrap.fill(para, wrap_width) for para in paras]) | |
29 albow.controls.Label.__init__(self, text, **kwds) | |
30 self.set_margin(5) | |
31 self.border_width = 1 | |
32 self.border_color = (0, 0, 0) | |
33 self.bg_color = (127, 127, 127) | |
34 self.fg_color = (0, 0, 0) | |
35 | |
36 def mouse_down(self, event): | |
37 self.dismiss() |