Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct issues with event handlers and app startup in Textual backend #2267

Merged
merged 4 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/2267.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Corrected event handling and app impl assignment on the Textual backend.
2 changes: 1 addition & 1 deletion textual/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ root = ".."

[tool.setuptools_dynamic_dependencies]
dependencies = [
"textual",
"textual >= 0.44.0",
"toga-core == {version}",
]

Expand Down
4 changes: 3 additions & 1 deletion textual/src/toga_textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down
14 changes: 7 additions & 7 deletions textual/src/toga_textual/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -298,7 +298,7 @@ def __init__(
title,
initial_directory,
file_types,
multiselect,
multiple_select,
on_result=None,
):
super().__init__(
Expand All @@ -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)
Expand Down Expand Up @@ -359,7 +359,7 @@ def __init__(
interface,
title,
initial_directory,
multiselect,
multiple_select,
on_result=None,
):
super().__init__(
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion textual/src/toga_textual/widgets/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions textual/src/toga_textual/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion textual/src/toga_textual/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down