From 0b78dc748e9803cd2f54f294bc91a119c7707568 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 9 Dec 2023 08:35:03 +0800 Subject: [PATCH 1/4] Correct issues with event handlers and app startup. --- textual/src/toga_textual/app.py | 2 ++ textual/src/toga_textual/widgets/button.py | 2 +- textual/src/toga_textual/widgets/textinput.py | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/textual/src/toga_textual/app.py b/textual/src/toga_textual/app.py index fed7a0bce2..d922448ddb 100644 --- a/textual/src/toga_textual/app.py +++ b/textual/src/toga_textual/app.py @@ -23,6 +23,8 @@ def on_mount(self) -> None: class App: def __init__(self, interface): self.interface = interface + self.interface._impl = self + self.loop = asyncio.new_event_loop() self.native = TogaApp(self) diff --git a/textual/src/toga_textual/widgets/button.py b/textual/src/toga_textual/widgets/button.py index 2ad28bc9a6..e907de3737 100644 --- a/textual/src/toga_textual/widgets/button.py +++ b/textual/src/toga_textual/widgets/button.py @@ -12,7 +12,7 @@ def __init__(self, impl): self.impl = impl def on_button_pressed(self, event: TextualButton.Pressed) -> None: - self.interface.on_press(None) + self.interface.on_press() class Button(Widget): diff --git a/textual/src/toga_textual/widgets/textinput.py b/textual/src/toga_textual/widgets/textinput.py index bedc193704..df2bbcd0b2 100644 --- a/textual/src/toga_textual/widgets/textinput.py +++ b/textual/src/toga_textual/widgets/textinput.py @@ -12,13 +12,13 @@ def __init__(self, impl): self.impl = impl def on_focus(self, event: TextualInput.Changed) -> None: - self.interface.on_gain_focus(None) + self.interface.on_gain_focus() def on_input_changed(self, event: TextualInput.Changed) -> None: - self.interface.on_change(None) + self.interface.on_change() def on_input_submitted(self, event: TextualInput.Submitted) -> None: - self.interface.on_confirm(None) + self.interface.on_confirm() class TextInput(Widget): From d616d06d226617391bf66cb826bf0f8a0ed02efe Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 9 Dec 2023 08:37:37 +0800 Subject: [PATCH 2/4] Add changenote. --- changes/2267.misc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/2267.misc.rst diff --git a/changes/2267.misc.rst b/changes/2267.misc.rst new file mode 100644 index 0000000000..165e2bd80b --- /dev/null +++ b/changes/2267.misc.rst @@ -0,0 +1 @@ +Corrected event handling and app impl assignment on the Textual backend. From 1d3d2725834b2fa54f35820d2e43fe2a91bea690 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 9 Dec 2023 09:09:14 +0800 Subject: [PATCH 3/4] More API regressions. --- textual/src/toga_textual/app.py | 2 +- textual/src/toga_textual/dialogs.py | 14 +++++++------- textual/src/toga_textual/window.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/textual/src/toga_textual/app.py b/textual/src/toga_textual/app.py index d922448ddb..ff71825494 100644 --- a/textual/src/toga_textual/app.py +++ b/textual/src/toga_textual/app.py @@ -7,7 +7,7 @@ class MainWindow(Window): def textual_close(self): - self.interface.app.on_exit(None) + self.interface.app.on_exit() class TogaApp(TextualApp): diff --git a/textual/src/toga_textual/dialogs.py b/textual/src/toga_textual/dialogs.py index 553379d48c..b0ab26e7f4 100644 --- a/textual/src/toga_textual/dialogs.py +++ b/textual/src/toga_textual/dialogs.py @@ -15,12 +15,12 @@ def __init__(self, impl): self.impl = impl def compose(self) -> ComposeResult: - self.title = TitleBar(self.impl.title) + self.titlebar = TitleBar(self.impl.title) self.impl.compose_content(self) self.buttons = self.impl.create_buttons() self.button_box = Horizontal(*self.buttons) self.container = Vertical( - self.title, + self.titlebar, self.content, self.button_box, id="dialog", @@ -75,7 +75,7 @@ def textual_close(self): self.native.dismiss(None) def on_close(self, result: bool): - self.on_result(self, result) + self.on_result(result) self.interface.future.set_result(result) @@ -298,7 +298,7 @@ def __init__( title, initial_directory, file_types, - multiselect, + multiple_select, on_result=None, ): super().__init__( @@ -315,7 +315,7 @@ def __init__( else: self.filter_func = None - self.multiselect = multiselect + self.multiple_select = multiple_select def compose_content(self, dialog): dialog.directory_tree = FilteredDirectoryTree(self) @@ -359,7 +359,7 @@ def __init__( interface, title, initial_directory, - multiselect, + multiple_select, on_result=None, ): super().__init__( @@ -370,7 +370,7 @@ def __init__( ) self.initial_directory = initial_directory if initial_directory else Path.cwd() self.filter_func = lambda path: path.is_dir() - self.multiselect = multiselect + self.multiple_select = multiple_select def compose_content(self, dialog): dialog.directory_tree = FilteredDirectoryTree(self) diff --git a/textual/src/toga_textual/window.py b/textual/src/toga_textual/window.py index 2ce56e954f..239a8568c1 100644 --- a/textual/src/toga_textual/window.py +++ b/textual/src/toga_textual/window.py @@ -161,7 +161,7 @@ def get_visible(self): return True def textual_close(self): - self.interface.on_close(self) + self.interface.on_close() def close(self): self.native.dismiss(None) From 34c3849ebda35aa4efc27abd3e89a85d75d977e4 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 9 Dec 2023 09:10:28 +0800 Subject: [PATCH 4/4] Set a minimum textual version. --- textual/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/textual/pyproject.toml b/textual/pyproject.toml index 15f6c7ed8a..7d22f57ffb 100644 --- a/textual/pyproject.toml +++ b/textual/pyproject.toml @@ -63,7 +63,7 @@ root = ".." [tool.setuptools_dynamic_dependencies] dependencies = [ - "textual", + "textual >= 0.44.0", "toga-core == {version}", ]