mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Actions
This commit is contained in:
@@ -6,7 +6,7 @@ from sys import argv
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.binding import Binding
|
||||
from textual.reactive import var
|
||||
from textual.widgets import Footer, KeyPanel, MarkdownViewer
|
||||
from textual.widgets import Footer, MarkdownViewer
|
||||
|
||||
|
||||
class MarkdownApp(App):
|
||||
@@ -33,7 +33,6 @@ class MarkdownApp(App):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Footer()
|
||||
yield MarkdownViewer()
|
||||
yield KeyPanel()
|
||||
|
||||
async def on_mount(self) -> None:
|
||||
"""Go to the first path when the app starts."""
|
||||
|
||||
@@ -3504,6 +3504,19 @@ class App(Generic[ReturnType], DOMNode):
|
||||
"""An [action](/guide/actions) to focus the previous widget."""
|
||||
self.screen.focus_previous()
|
||||
|
||||
def action_hide_keys(self) -> None:
|
||||
"""Hide the keys panel (if present)."""
|
||||
self.screen.query("KeyPanel").remove()
|
||||
|
||||
def action_show_keys(self) -> None:
|
||||
"""Show the keys panel."""
|
||||
from .widgets import KeyPanel
|
||||
|
||||
try:
|
||||
self.query_one(KeyPanel)
|
||||
except NoMatches:
|
||||
self.mount(KeyPanel())
|
||||
|
||||
def _on_terminal_supports_synchronized_output(
|
||||
self, message: messages.TerminalSupportsSynchronizedOutput
|
||||
) -> None:
|
||||
|
||||
@@ -24,9 +24,9 @@ class SystemCommands(Provider):
|
||||
"""
|
||||
|
||||
@property
|
||||
def _system_commands(self) -> tuple[tuple[str, IgnoreReturnCallbackType, str], ...]:
|
||||
def _system_commands(self) -> list[tuple[str, IgnoreReturnCallbackType, str]]:
|
||||
"""The system commands to reveal to the command palette."""
|
||||
return (
|
||||
commands = [
|
||||
(
|
||||
"Toggle light/dark mode",
|
||||
self.app.action_toggle_dark,
|
||||
@@ -37,7 +37,22 @@ class SystemCommands(Provider):
|
||||
self.app.action_quit,
|
||||
"Quit the application as soon as possible",
|
||||
),
|
||||
)
|
||||
]
|
||||
if self.screen.query("KeyPanel"):
|
||||
commands.append(
|
||||
("Hide keys", self.app.action_hide_keys, "Hide the keys panel")
|
||||
)
|
||||
else:
|
||||
commands.append(
|
||||
(
|
||||
"Show keys",
|
||||
self.app.action_show_keys,
|
||||
"Show a summary of available keys",
|
||||
)
|
||||
)
|
||||
commands.sort(key=lambda command: command[0])
|
||||
|
||||
return commands
|
||||
|
||||
async def discover(self) -> Hits:
|
||||
"""Handle a request for the discovery commands for this provider.
|
||||
|
||||
@@ -10,7 +10,7 @@ from ._directory_tree import DirectoryTree as DirectoryTree
|
||||
from ._footer import Footer as Footer
|
||||
from ._header import Header as Header
|
||||
from ._input import Input as Input
|
||||
from ._key_panel import KeyPanel
|
||||
from ._key_panel import KeyPanel as KeyPanel
|
||||
from ._label import Label as Label
|
||||
from ._list_item import ListItem as ListItem
|
||||
from ._list_view import ListView as ListView
|
||||
|
||||
Reference in New Issue
Block a user