mirror of
https://github.com/1j01/textual-paint.git
synced 2025-01-04 21:21:35 +03:00
Focus default control within window after opening
This commit is contained in:
parent
ec4d044f8a
commit
8a51bd325c
13
windows.py
13
windows.py
@ -52,6 +52,7 @@ class Window(Container):
|
||||
self.content = Container(classes="window_content")
|
||||
# must be after title_bar is defined
|
||||
self.title = title
|
||||
self.can_focus = True
|
||||
|
||||
def on_mount(self) -> None:
|
||||
"""Called when the widget is mounted."""
|
||||
@ -61,6 +62,15 @@ class Window(Container):
|
||||
# (I peaked into mouse over handling and it calls update_styles.)
|
||||
# This can still briefly show the incorrect layout, since it relies on a timer.
|
||||
self.set_timer(0.01, lambda: self.app.update_styles(self))
|
||||
# Set focus. (In the future, some windows will not want default focus...)
|
||||
self.set_timer(0.01, lambda: self.focus())
|
||||
|
||||
def on_focus(self, event: events.Focus) -> None:
|
||||
"""Called when the window is focused."""
|
||||
# TODO: focus last focused widget if re-focusing
|
||||
controls = self.content.query(".submit, Input, Button")
|
||||
if controls:
|
||||
controls[0].focus()
|
||||
|
||||
# def compose(self) -> ComposeResult:
|
||||
# """Add our widgets."""
|
||||
@ -157,6 +167,9 @@ class DialogWindow(Window):
|
||||
if event.button in self.content.query("Button").nodes:
|
||||
self.handle_button(event.button)
|
||||
|
||||
# def on_input_submitted(self, event: Input.Submitted) -> None:
|
||||
# """Called when a the enter key is pressed in an Input."""
|
||||
|
||||
|
||||
class CharacterSelectorDialog(DialogWindow):
|
||||
"""A dialog window that lets the user select a character."""
|
||||
|
Loading…
Reference in New Issue
Block a user