# HG changeset patch # User Stefano Rivera # Date 1316282569 -7200 # Node ID 93ba8c966cb959ba07914e1462058f3fb2898fbc # Parent 3017612e613e0be153c3e60275e2a5e621faceae Disableable text buttons diff -r 3017612e613e -r 93ba8c966cb9 mamba/widgets/base.py --- a/mamba/widgets/base.py Sat Sep 17 19:54:07 2011 +0200 +++ b/mamba/widgets/base.py Sat Sep 17 20:02:49 2011 +0200 @@ -19,6 +19,7 @@ self.focussed = False self.modal = False self.parent = None + self.disabled = False self.callbacks = collections.defaultdict(list) def add_callback(self, eventtype, callback, *args): @@ -26,6 +27,9 @@ def event(self, ev): "Don't override this without damn good reason" + if self.disabled: + return True + type_ = ev.type if type_ == USEREVENT: for k in self.callbacks.iterkeys(): @@ -79,6 +83,21 @@ return True return False + def disable(self): + if not self.disabled: + self.disabled = True + self._focussable_when_enabled = self.focussable + self.focussable = False + if hasattr(self, 'prepare'): + self.prepare() + + def enable(self): + if self.disabled: + self.disabled = False + self.focussable = self._focussable_when_enabled + if hasattr(self, 'prepare'): + self.prepare() + class Button(Widget): diff -r 3017612e613e -r 93ba8c966cb9 mamba/widgets/text.py --- a/mamba/widgets/text.py Sat Sep 17 19:54:07 2011 +0200 +++ b/mamba/widgets/text.py Sat Sep 17 20:02:49 2011 +0200 @@ -50,7 +50,12 @@ text = self.surface text_rect = text.get_rect() self._focussed = self.focussed - color = self.focus_color if self.focussed else self.color + if self.disabled: + color = pygame.Color('#666666') + elif self.focussed: + color = self.focus_color + else: + color = self.color self.rect.width = text_rect.width + self.padding * 2 self.rect.height = text_rect.height + self.padding * 2