Mercurial > pyntnclick
view gamelib/widgets.py @ 154:d2f94f42edf3
Monkey patch albow
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Tue, 24 Aug 2010 23:42:07 +0200 |
parents | 97322b78d1c1 |
children | fbfd8e748ac0 |
line wrap: on
line source
# widgets.py # Copyright Boomslang team, 2010 (see COPYING File) """Custom Albow widgets""" import textwrap import albow.controls from cursor import CursorWidget class BoomLabel(albow.controls.Label): def set_margin(self, margin): """Add a set_margin method that recalculates the label size""" old_margin = self.margin w, h = self.size d = margin - old_margin 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()