Mercurial > mamba
diff mamba/widgets/messagebox.py @ 210:b92f705bd8ea
Modal dialogs, and focus stealing bugfixes
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Wed, 14 Sep 2011 20:49:48 +0200 |
parents | c9cee22934be |
children | c068190c0b1d |
line wrap: on
line diff
--- a/mamba/widgets/messagebox.py Wed Sep 14 20:31:16 2011 +0200 +++ b/mamba/widgets/messagebox.py Wed Sep 14 20:49:48 2011 +0200 @@ -1,5 +1,5 @@ import pygame -from pygame.constants import SRCALPHA, K_RETURN, KEYDOWN +from pygame.constants import SRCALPHA from mamba.widgets.base import Container from mamba.widgets.text import TextWidget, TextButton @@ -14,7 +14,7 @@ self.post_callback = post_callback self.color = color self.prepare() - self.focussable = True + self.modal = True def prepare(self): cont = TextWidget((0, 0), "Press [OK] or Enter to continue") @@ -34,7 +34,7 @@ cont.rect.topleft = cont_pos self.add(message) self.add(cont) - ok_button = TextButton((0, 0), 'OK') + self.ok_button = ok_button = TextButton((0, 0), 'OK') ok_pos = (self.rect.left + 5 + width / 2 - ok_button.rect.width / 2, cont_pos[1] + 5 + cont.rect.height) ok_button.rect.topleft = ok_pos @@ -47,13 +47,10 @@ surface.blit(background, self.rect) super(MessageBox, self).draw(surface) - def event(self, ev): - if ev.type == KEYDOWN and ev.key == K_RETURN: - self.close(ev, self) - return True - return super(MessageBox, self).event(ev) - def close(self, ev, widget): self.parent.remove(self) if self.post_callback: self.post_callback() + + def grab_focus(self): + return self.ok_button.grab_focus()