Mercurial > boomslang
comparison pyntnclick/widgets/base.py @ 693:c8b683dd56d3 pyntnclick
Better modal message and result handling.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Tue, 14 Feb 2012 15:36:28 +0200 |
parents | d6ded808cc33 |
children | 58d78038a197 |
comparison
equal
deleted
inserted
replaced
692:d6ded808cc33 | 693:c8b683dd56d3 |
---|---|
141 super(ModalStackContainer, self).__init__(rect, gd) | 141 super(ModalStackContainer, self).__init__(rect, gd) |
142 if obscure_color is None: | 142 if obscure_color is None: |
143 obscure_color = gd.constants.modal_obscure_color | 143 obscure_color = gd.constants.modal_obscure_color |
144 self.obscure_color = convert_color(obscure_color) | 144 self.obscure_color = convert_color(obscure_color) |
145 | 145 |
146 @property | |
147 def top(self): | |
148 if self.children: | |
149 return self.children[-1] | |
150 return None | |
151 | |
146 def event(self, ev): | 152 def event(self, ev): |
147 """Only the topmost child gets events. | 153 """Only the topmost child gets events. |
148 """ | 154 """ |
149 self.mouseover_widget = self.children[-1].mouseover_widget | 155 self.mouseover_widget = self |
150 if self.children[-1].event(ev): | 156 if self.top: |
151 return True | 157 self.mouseover_widget = self.top.mouseover_widget |
152 | 158 if self.top.event(ev): |
159 return True | |
160 | |
161 # We skip Container's event() method and hop straight to its parent's. | |
153 if super(Container, self).event(ev): | 162 if super(Container, self).event(ev): |
154 return True | 163 return True |
155 | 164 |
156 def is_top(self, widget): | 165 def is_top(self, widget): |
157 if self.children: | 166 return self.top is widget |
158 return self.children[-1] is widget | |
159 return False | |
160 | 167 |
161 def draw(self, surface): | 168 def draw(self, surface): |
162 obscure = pygame.Surface(self.rect.size, SRCALPHA) | 169 obscure = pygame.Surface(self.rect.size, SRCALPHA) |
163 obscure.fill(self.obscure_color) | 170 obscure.fill(self.obscure_color) |
164 for child in self.children: | 171 for child in self.children: |
203 if isinstance(color, pygame.Color): | 210 if isinstance(color, pygame.Color): |
204 return color | 211 return color |
205 if isinstance(color, basestring): | 212 if isinstance(color, basestring): |
206 return pygame.Color(color) | 213 return pygame.Color(color) |
207 return pygame.Color(*color) | 214 return pygame.Color(*color) |
215 | |
216 | |
217 class ModalWrapper(Container): | |
218 "A wrapper around a widget that removes itself when a mouse click occurs" | |
219 | |
220 def __init__(self, widget, close_callback=None): | |
221 super(ModalWrapper, self).__init__(widget.rect, widget.gd) | |
222 self.close_callback = close_callback | |
223 self.add(widget) | |
224 widget.add_callback(MOUSEBUTTONDOWN, self.close) | |
225 | |
226 def close(self, ev, widget): | |
227 if self.parent: | |
228 self.parent.remove(self) | |
229 if self.close_callback: | |
230 self.close_callback() | |
231 return True |