Mercurial > pyntnclick
diff 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 |
line wrap: on
line diff
--- a/gamelib/widgets.py Tue Aug 24 17:33:37 2010 +0200 +++ b/gamelib/widgets.py Tue Aug 24 17:45:46 2010 +0200 @@ -3,8 +3,12 @@ """Custom Albow widgets""" +import textwrap + import albow.controls +from cursor import CursorWidget + class BoomLabel(albow.controls.Label): @@ -16,3 +20,18 @@ self.margin = margin self.size = (w + 2 * d, h + 2 * d) +class MessageDialog(BoomLabel, CursorWidget): + + def __init__(self, text, wrap_width, **kwds): + CursorWidget.__init__(self) + paras = text.split("\n\n") + text = "\n".join([textwrap.fill(para, wrap_width) for para in paras]) + albow.controls.Label.__init__(self, text, **kwds) + self.set_margin(5) + self.border_width = 1 + self.border_color = (0, 0, 0) + self.bg_color = (127, 127, 127) + self.fg_color = (0, 0, 0) + + def mouse_down(self, event): + self.dismiss()