Move bits of warning_message_box that need App back into App

This commit is contained in:
Isaiah Odhner 2023-04-20 18:09:49 -04:00
parent 37ff810616
commit 093a314d60
2 changed files with 11 additions and 10 deletions

View File

@ -24,7 +24,7 @@ from textual.widget import Widget
from textual.widgets import Button, Static, Input, DirectoryTree, Header
from textual.color import Color
from menus import MenuBar, Menu, MenuItem, Separator
from windows import Window, DialogWindow, CharacterSelectorDialogWindow, warning_message_box
from windows import Window, DialogWindow, CharacterSelectorDialogWindow, create_warning_message_box
from localization.i18n import get as _, load_language
@ -1151,7 +1151,14 @@ class PaintApp(App):
restart_program()
def warning_message_box(self, title: str, message_widget: Widget, button_types: str = "ok", callback = None) -> None:
warning_message_box(self, title, message_widget, button_types, callback)
for old_window in self.query("#message_box").nodes:
old_window.close()
self.bell()
window = create_warning_message_box(title, message_widget, button_types, callback)
self.mount(window)
def action_open(self) -> None:
"""Show dialog to open an image from a file."""

View File

@ -227,16 +227,10 @@ class CharacterSelectorDialogWindow(DialogWindow):
self.content.mount(Button("Cancel", classes="cancel"))
def warning_message_box(app, title: str, message_widget: Widget, button_types: str = "ok", callback = None) -> None:
def create_warning_message_box(title: str, message_widget: Widget, button_types: str = "ok", callback = None) -> None:
if isinstance(message_widget, str):
message_widget = Static(message_widget, markup=False)
for old_window in app.query("#message_box").nodes:
old_window.close()
app.bell()
def handle_button(button):
if callback:
callback(button)
@ -318,4 +312,4 @@ def warning_message_box(app, title: str, message_widget: Widget, button_types: s
)
)
)
app.mount(window)
return window