Mercurial > mamba
changeset 155:9afea431af36
Move common widget defauts (mainly colours) to constants
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Tue, 13 Sep 2011 22:41:49 +0200 |
parents | acfcd3db4bca |
children | 77ea895e4d37 |
files | mamba/constants.py mamba/widgets/imagebutton.py mamba/widgets/text.py |
diffstat | 3 files changed, 12 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mamba/constants.py Tue Sep 13 22:37:41 2011 +0200 +++ b/mamba/constants.py Tue Sep 13 22:41:49 2011 +0200 @@ -20,6 +20,11 @@ # For easy access later DEFAULT_FONT = 'DejaVuSans.ttf' +FONT_SIZE = 16 + +# Colours +FOCUS_COLOR = 'yellow' +COLOR = 'black' # Default command-line options DEFAULTS = {
--- a/mamba/widgets/imagebutton.py Tue Sep 13 22:37:41 2011 +0200 +++ b/mamba/widgets/imagebutton.py Tue Sep 13 22:41:49 2011 +0200 @@ -1,5 +1,6 @@ import pygame +from mamba.constants import COLOR, FONT_SIZE, FOCUS_COLOR from mamba.widgets.base import Button from mamba.widgets.text import TextWidget @@ -7,9 +8,9 @@ class ImageButtonWidget(Button, TextWidget): """Text label with image on the left""" - def __init__(self, rect, image, text, fontsize=16, color='black'): + def __init__(self, rect, image, text, fontsize=FONT_SIZE, color=COLOR): self.image = image - self.focus_color = pygame.Color('yellow') + self.focus_color = pygame.Color(FOCUS_COLOR) self.padding = 5 self.border = 2 super(ImageButtonWidget, self).__init__(rect, text, fontsize, color) @@ -17,7 +18,7 @@ def prepare(self): super(ImageButtonWidget, self).prepare() - text_surface = self.font.render(self.text, True, self.color) + text_surface = self.surface # Image is already a surface self._focussed = self.focussed color = self.focus_color if self.focussed else self.color
--- a/mamba/widgets/text.py Tue Sep 13 22:37:41 2011 +0200 +++ b/mamba/widgets/text.py Tue Sep 13 22:41:49 2011 +0200 @@ -1,5 +1,6 @@ import pygame +from mamba.constants import COLOR, FONT_SIZE, FOCUS_COLOR from mamba.widgets.base import Widget, Button from mamba.data import filepath from mamba.constants import DEFAULT_FONT @@ -8,7 +9,7 @@ class TextWidget(Widget): fontcache = {} - def __init__(self, rect, text, fontsize=16, color='black'): + def __init__(self, rect, text, fontsize=FONT_SIZE, color=COLOR): super(TextWidget, self).__init__(rect) self.text = text self.fontsize = fontsize @@ -34,7 +35,7 @@ class TextButton(Button, TextWidget): def __init__(self, *args, **kwargs): - self.focus_color = kwargs.pop('focus_color', 'red') + self.focus_color = kwargs.pop('focus_color', FOCUS_COLOR) self.padding = kwargs.pop('padding', 10) self.border = kwargs.pop('border', 3) super(TextButton, self).__init__(*args, **kwargs)