X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Fwidgets%2Ftext.py;h=1ddab05915122bf9c22bdbf033f78da57ea0a13f;hb=87a82ccb10b6f7b07c48f8e9993243b9592e00b4;hp=ca653e89c5e512e816a3032d6f1295162baebd16;hpb=b3e10ee7a1a522f2145596ea97fb15bf7dc0eaa4;p=naja.git diff --git a/naja/widgets/text.py b/naja/widgets/text.py index ca653e8..1ddab05 100644 --- a/naja/widgets/text.py +++ b/naja/widgets/text.py @@ -16,9 +16,14 @@ MARKUP_MAP = { 'WINTOKEN': ('glyphs/win.png', PALETTE.DARK_OLIVE), 'KEY': ('glyphs/key.png', None), 'MSB': ('glyphs/msb.png', None), - 'REDKEY': ('glyphs/key.png', PALETTE.ORANGE), - 'GREENKEY': ('glyphs/key.png', PALETTE.GREEN), - 'BLUEKEY': ('glyphs/key.png', PALETTE.BLUE), + 'RED': ('glyphs/key.png', PALETTE.ORANGE), + 'GREEN': ('glyphs/key.png', PALETTE.GREEN), + 'BLUE': ('glyphs/key.png', PALETTE.BLUE), + 'CLOCKWISE': ('glyphs/clockwise.png', None), + 'ANTICLOCKWISE': ('glyphs/anticlockwise.png', None), + + 'HEALTH_NOCOLOUR': ('glyphs/health.png', None), + 'WINTOKEN_NOCOLOUR': ('glyphs/win.png', None), } @@ -32,16 +37,22 @@ class Glyph(object): class TextWidget(Widget): def __init__(self, pos, text, size=None, fontname=None, fontsize=None, - colour=None): + colour=None, unselectable_colour=None): super(TextWidget, self).__init__(pos, size) self.text = text self.fontname = fontname or FONT self.fontsize = (fontsize or FONT_SIZE) // EIGHT_BIT_SCALE self.colour = convert_colour(colour or PALETTE.BLACK) + if unselectable_colour is not None: + unselectable_colour = convert_colour(unselectable_colour) + self.unselectable_colour = unselectable_colour def render_line(self, text): - text_surf = self.font.render(text, True, self.colour) + colour = self.colour + if not self.is_selectable() and self.unselectable_colour is not None: + colour = self.unselectable_colour + text_surf = self.font.render(text, True, colour) text_rect = text_surf.get_rect() return pygame.transform.scale( text_surf, (text_rect.width * EIGHT_BIT_SCALE, @@ -58,7 +69,7 @@ class TextWidget(Widget): class TextBoxWidget(TextWidget): def __init__(self, *args, **kwargs): - self.padding = kwargs.pop('padding', 5) + self.padding = kwargs.pop('padding', 4) self.border = kwargs.pop('border', 2) self.bg_colour = convert_colour(kwargs.pop('bg_colour', PALETTE.LIGHT_VIOLET)) @@ -97,8 +108,6 @@ class TextBoxWidget(TextWidget): subwords = word[1:-1].split(',') if all(subword in MARKUP_MAP for subword in subwords): return Glyph(word + suffix, subwords, suffix) - elif word in MARKUP_MAP: - return Glyph(word + suffix, [word], suffix) return None @@ -134,6 +143,7 @@ class TextBoxWidget(TextWidget): word = glyph.markup_text remaining_words.insert(0, word) if current_words and words_fit(current_words): + line_count += 1 yield ' '.join(current_words) def prepare(self):