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

Update for Textual v0.23.0 #30

Merged
merged 17 commits into from
May 8, 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
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Changed

- Updated to work with [Textual](https://github.com/Textualize/textual) v0.23.0.

### Added

- Added a `changelog` command -- loads the Frogmouth ChangeLog from the
Expand Down
26 changes: 12 additions & 14 deletions frogmouth/dialogs/input_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

from textual import on
from textual.app import ComposeResult
from textual.binding import Binding
from textual.containers import Horizontal, Vertical
Expand Down Expand Up @@ -82,17 +83,14 @@ def on_mount(self) -> None:
"""Set up the dialog once the DOM is ready."""
self.query_one(Input).focus()

def on_button_pressed(self, event: Button.Pressed) -> None:
"""Handle one of the dialog's buttons been pressed.

Args:
event: The button press event.
"""
if event.button.id == "cancel":
self.app.pop_screen()
elif event.button.id == "ok" and self.query_one(Input).value.strip():
self.dismiss(self.query_one(Input).value)

def on_input_submitted(self) -> None:
"""Do default processing when the user hits enter in the input."""
self.query_one("#ok", Button).press()
@on(Button.Pressed, "#cancel")
def cancel_input(self) -> None:
"""Cancel the input operation."""
self.app.pop_screen()

@on(Input.Submitted)
@on(Button.Pressed, "#ok")
def accept_input(self) -> None:
"""Accept and return the input."""
if value := self.query_one(Input).value.strip():
self.dismiss(value)
14 changes: 6 additions & 8 deletions frogmouth/screens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,15 @@ def on_omnibox_contents_command(self) -> None:
"""Handle being asked to show the table of contents."""
self.action_table_of_contents()

async def on_omnibox_local_files_command(self) -> None:
def on_omnibox_local_files_command(self) -> None:
"""Handle being asked to view the local files picker."""
await self.action_local_files()
self.action_local_files()

def on_omnibox_bookmarks_command(self) -> None:
"""Handle being asked to view the bookmarks."""
self.action_bookmarks()

async def on_omnibox_local_chdir_command(
self, event: Omnibox.LocalChdirCommand
) -> None:
def on_omnibox_local_chdir_command(self, event: Omnibox.LocalChdirCommand) -> None:
"""Handle being asked to view a new directory in the local files picker.

Args:
Expand All @@ -219,7 +217,7 @@ async def on_omnibox_local_chdir_command(
ErrorDialog("Not a directory", f"{event.target} is not a directory.")
)
else:
await self.query_one(Navigation).jump_to_local_files(event.target)
self.query_one(Navigation).jump_to_local_files(event.target)

def on_omnibox_history_command(self) -> None:
"""Handle being asked to view the history."""
Expand Down Expand Up @@ -435,9 +433,9 @@ def action_table_of_contents(self) -> None:
"""Display and focus the table of contents pane."""
self.query_one(Navigation).jump_to_contents()

async def action_local_files(self) -> None:
def action_local_files(self) -> None:
"""Display and focus the local files selection pane."""
await self.query_one(Navigation).jump_to_local_files()
self.query_one(Navigation).jump_to_local_files()

def action_bookmarks(self) -> None:
"""Display and focus the bookmarks selection pane."""
Expand Down
4 changes: 2 additions & 2 deletions frogmouth/widgets/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def history(self) -> History:
"""The history widget."""
return self._history

async def jump_to_local_files(self, target: Path | None = None) -> Self:
def jump_to_local_files(self, target: Path | None = None) -> Self:
"""Switch to and focus the local files pane.

Returns:
Expand All @@ -128,7 +128,7 @@ async def jump_to_local_files(self, target: Path | None = None) -> Self:
else:
self.popped_out = True
if target is not None:
await self._local_files.chdir(target)
self._local_files.chdir(target)
self._local_files.activate().set_focus_within()
return self

Expand Down
17 changes: 7 additions & 10 deletions frogmouth/widgets/navigation_panes/local_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,13 @@ def compose(self) -> ComposeResult:
"""Compose the child widgets."""
yield FilteredDirectoryTree(Path("~").expanduser())

async def chdir(self, path: Path) -> None:
"""Change the filesystem view to the given directory."""
# At the moment Textual's DirectoryTree doesn't support changing
# directory to a new root, so here we're going to remove it and
# mount a fresh one with a new root.
#
# Once https://github.com/Textualize/textual/issues/2056 is taken
# care of update this to use whatever new approach is taken.
await self.query_one(FilteredDirectoryTree).remove()
await self.mount(FilteredDirectoryTree(path))
def chdir(self, path: Path) -> None:
"""Change the filesystem view to the given directory.

Args:
path: The path to change to.
"""
self.query_one(FilteredDirectoryTree).path = path

def set_focus_within(self) -> None:
"""Focus the directory tree.."""
Expand Down
12 changes: 11 additions & 1 deletion frogmouth/widgets/navigation_panes/table_of_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ def set_focus_within(self) -> None:

def compose(self) -> ComposeResult:
"""Compose the child widgets."""
yield MarkdownTableOfContents()
# Note the use of a throwaway Markdown object. Textual 0.24
# introduced a requirement for MarkdownTableOfContents to take a
# reference to a Markdown document; this is a problem if you're
# composing the ToC in a location somewhere unrelated to the
# document itself, such that you can't guarantee the order in which
# they're compose. I'm not using the ToC in a way that's
# tightly-coupled to the document, neither am I using multiple ToCs
# and documents. So... we make one and ignore it.
#
# https://github.com/Textualize/textual/issues/2516
yield MarkdownTableOfContents(Markdown())

def on_table_of_contents_updated(
self, event: Markdown.TableOfContentsUpdated
Expand Down
50 changes: 25 additions & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.8"
textual = {version = "^0.22.2"}
textual = {version = "^0.24.0"}
typing-extensions = "^4.5.0"
httpx = "^0.23.3"
xdg = "^6.0.0"


[tool.poetry.group.dev.dependencies]
textual = {extras = ["dev"], version = "^0.22.2"}
textual = {extras = ["dev"], version = "^0.24.0"}
mypy = "^1.1.1"
pylint = "^2.17.1"
pre-commit = "^3.2.1"
Expand Down