Mercurial > mamba
annotate mamba/widgets/messagebox.py @ 601:915de6c7d342 default tip
Add support for making the editor fullscreen too.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 14 Jan 2023 19:34:26 +0100 |
parents | 8604b8d660f6 |
children |
rev | line source |
---|---|
543
8604b8d660f6
Add fontsize keyword to messagebox
Neil Muller <drnlmuller@gmail.com>
parents:
532
diff
changeset
|
1 from mamba.constants import FONT_SIZE |
383 | 2 from mamba.widgets.base import Box |
190 | 3 from mamba.widgets.text import TextWidget, TextButton |
4 | |
5 | |
383 | 6 class MessageBox(Box): |
190 | 7 |
543
8604b8d660f6
Add fontsize keyword to messagebox
Neil Muller <drnlmuller@gmail.com>
parents:
532
diff
changeset
|
8 def __init__(self, rect, text, post_callback=None, color='red', |
8604b8d660f6
Add fontsize keyword to messagebox
Neil Muller <drnlmuller@gmail.com>
parents:
532
diff
changeset
|
9 fontsize=FONT_SIZE): |
190 | 10 super(MessageBox, self).__init__(rect) |
11 self.text = text | |
543
8604b8d660f6
Add fontsize keyword to messagebox
Neil Muller <drnlmuller@gmail.com>
parents:
532
diff
changeset
|
12 self.font_size = fontsize |
190 | 13 self.post_callback = post_callback |
14 self.color = color | |
15 self.prepare() | |
210
b92f705bd8ea
Modal dialogs, and focus stealing bugfixes
Stefano Rivera <stefano@rivera.za.net>
parents:
190
diff
changeset
|
16 self.modal = True |
190 | 17 |
18 def prepare(self): | |
543
8604b8d660f6
Add fontsize keyword to messagebox
Neil Muller <drnlmuller@gmail.com>
parents:
532
diff
changeset
|
19 cont = TextWidget((0, 0), "Press [OK] or Enter to continue", |
8604b8d660f6
Add fontsize keyword to messagebox
Neil Muller <drnlmuller@gmail.com>
parents:
532
diff
changeset
|
20 fontsize=self.font_size) |
303 | 21 widgets = [] |
22 width = cont.rect.width | |
23 for line in self.text.split('\n'): | |
543
8604b8d660f6
Add fontsize keyword to messagebox
Neil Muller <drnlmuller@gmail.com>
parents:
532
diff
changeset
|
24 message = TextWidget((0, 0), line, color=self.color, |
8604b8d660f6
Add fontsize keyword to messagebox
Neil Muller <drnlmuller@gmail.com>
parents:
532
diff
changeset
|
25 fontsize=self.font_size) |
303 | 26 widgets.append(message) |
27 width = max(width, message.rect.width) | |
28 widgets.append(cont) | |
29 top = self.rect.top + 10 | |
30 left = self.rect.left + 5 | |
31 for widget in widgets: | |
32 pos = (left + width / 2 - widget.rect.width / 2, top) | |
33 widget.rect.topleft = pos | |
34 top += widget.rect.height + 5 | |
35 self.add(widget) | |
210
b92f705bd8ea
Modal dialogs, and focus stealing bugfixes
Stefano Rivera <stefano@rivera.za.net>
parents:
190
diff
changeset
|
36 self.ok_button = ok_button = TextButton((0, 0), 'OK') |
190 | 37 ok_pos = (self.rect.left + 5 + width / 2 - ok_button.rect.width / 2, |
303 | 38 top + 5) |
190 | 39 ok_button.rect.topleft = ok_pos |
40 ok_button.add_callback('clicked', self.close) | |
41 self.add(ok_button) | |
383 | 42 self.rect.height += 5 |
190 | 43 |
44 def close(self, ev, widget): | |
337
170d4a43c00e
Don't edit the level when interacting with dialogs
Neil Muller <drnlmuller@gmail.com>
parents:
303
diff
changeset
|
45 if hasattr(self.parent, 'paused'): |
170d4a43c00e
Don't edit the level when interacting with dialogs
Neil Muller <drnlmuller@gmail.com>
parents:
303
diff
changeset
|
46 self.parent.paused = False |
190 | 47 self.parent.remove(self) |
48 if self.post_callback: | |
49 self.post_callback() | |
454
8cfa757dd7d3
Epic level editor reworking.
Jeremy Thurgood <firxen@gmail.com>
parents:
383
diff
changeset
|
50 if getattr(self, 'parent_modal', False): |
8cfa757dd7d3
Epic level editor reworking.
Jeremy Thurgood <firxen@gmail.com>
parents:
383
diff
changeset
|
51 self.parent.modal = True |
210
b92f705bd8ea
Modal dialogs, and focus stealing bugfixes
Stefano Rivera <stefano@rivera.za.net>
parents:
190
diff
changeset
|
52 |
b92f705bd8ea
Modal dialogs, and focus stealing bugfixes
Stefano Rivera <stefano@rivera.za.net>
parents:
190
diff
changeset
|
53 def grab_focus(self): |
b92f705bd8ea
Modal dialogs, and focus stealing bugfixes
Stefano Rivera <stefano@rivera.za.net>
parents:
190
diff
changeset
|
54 return self.ok_button.grab_focus() |