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

Fix live updates to footers on Textual TUIs #597

Merged
merged 4 commits into from
May 20, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
tree: Give the main app its own textual.Screen
This is necessary pre-factoring for fixing the approach we use for
changing the descriptions of key bindings in the footer to work on the
latest versions of Textual.

Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
  • Loading branch information
godlygeek committed May 19, 2024
commit e8937b0306bf58220880b6971df7d797b46f3d69
20 changes: 17 additions & 3 deletions src/memray/reporters/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from textual.containers import Vertical
from textual.dom import DOMNode
from textual.reactive import reactive
from textual.screen import Screen
from textual.widget import Widget
from textual.widgets import Footer
from textual.widgets import Label
Expand Down Expand Up @@ -220,10 +221,10 @@ def node_is_not_import_system(node: Frame) -> bool:
return not node.import_system


class TreeApp(App[None]):
class TreeScreen(Screen[None]):
BINDINGS = [
Binding("ctrl+z", "suspend_process"),
Binding(key="q", action="quit", description="Quit the app"),
Binding("ctrl+z", "app.suspend_process"),
Binding(key="q", action="app.quit", description="Quit the app"),
Binding(
key="i", action="toggle_import_system", description="Hide import system"
),
Expand Down Expand Up @@ -381,6 +382,19 @@ def redraw_footer(self) -> None:
self.app.query_one(Footer).highlight_key = "q"
self.app.query_one(Footer).highlight_key = None


class TreeApp(App[None]):
def __init__(
self,
data: Frame,
elided_locations: ElidedLocations,
):
super().__init__()
self.tree_screen = TreeScreen(data, elided_locations)

def on_mount(self) -> None:
self.push_screen(self.tree_screen)

@property
def namespace_bindings(self) -> Dict[str, Tuple[DOMNode, Binding]]:
bindings = super().namespace_bindings.copy()
Expand Down