Skip to content

Instantly share code, notes, and snippets.

@maphew
Last active September 15, 2023 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maphew/13df2cd2f368e4ac42c577652009e2b8 to your computer and use it in GitHub Desktop.
Save maphew/13df2cd2f368e4ac42c577652009e2b8 to your computer and use it in GitHub Desktop.
Attempting to make 'q' to Quit (exit) app to work
Textual Development Console v0.37.0
▌Run a Textual app with textual run --dev my_app.py to connect.
▌Press Ctrl+C to quit.
────────────────────────────────────────────────────────────────────── Client '127.0.0.1' connected ───────────────────────────────────────────────────────────────────────
[15:46:44] SYSTEM app.py:2036
Connected to devtools ( ws://127.0.0.1:8081 )
[15:46:44] SYSTEM app.py:2040
---
[15:46:44] SYSTEM app.py:2042
driver=<class 'textual.drivers.windows_driver.WindowsDriver'>
[15:46:44] SYSTEM app.py:2043
loop=<ProactorEventLoop running=True closed=False debug=False>
[15:46:44] SYSTEM app.py:2044
features=frozenset({'devtools', 'debug'})
[15:46:44] EVENT message_pump.py:684
Load() >>> ActionsApp(title='ActionsApp', classes={'-dark-mode'}) method=None
[15:46:44] EVENT message_pump.py:684
Mount() >>> ActionsApp(title='ActionsApp', classes={'-dark-mode'}) method=None
[15:46:44] EVENT message_pump.py:675
Mount() >>> ToastRack(id='textual-toastrack') method=<Widget.on_mount>
[15:46:44] EVENT message_pump.py:675
Mount() >>> Tooltip(id='textual-tooltip') method=<Widget.on_mount>
[15:46:44] EVENT message_pump.py:675
Resize(size=Size(width=173, height=29), virtual_size=Size(width=173, height=29)) >>> ActionsApp(title='ActionsApp', classes={'-dark-mode'}) method=<App.on_resize>
[15:46:44] EVENT message_pump.py:675
Mount() >>> Screen(id='_default') method=<Widget.on_mount>
[15:46:44] EVENT message_pump.py:675
ScreenResume() >>> Screen(id='_default') method=<Screen.on_screen_resume>
[15:46:44] EVENT message_pump.py:675
Resize(size=Size(width=173, height=29), virtual_size=Size(width=173, height=29)) >>> Screen(id='_default') method=<Screen.on_resize>
[15:46:44] EVENT message_pump.py:684
Show() >>> Screen(id='_default') method=None
[15:46:44] EVENT message_pump.py:684
Ready() >>> ActionsApp(title='ActionsApp', classes={'-dark-mode'}) method=None
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[15:46:45] EVENT message_pump.py:675
Key(key='r', character='r', name='r', is_printable=True) >>> Screen(id='_default') method=<Widget.on_key>
[15:46:45] EVENT message_pump.py:675
Key(key='r', character='r', name='r', is_printable=True) >>> ActionsApp(title='ActionsApp', classes={'-dark-mode'}) method=<ActionsApp.on_key>
[15:46:45] EVENT message_pump.py:675
Key(key='r', character='r', name='r', is_printable=True) >>> ActionsApp(title='ActionsApp', classes={'-dark-mode'}) method=<App.on_key>
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[15:46:46] EVENT message_pump.py:675
Key(key='q', character='q', name='q', is_printable=True) >>> Screen(id='_default') method=<Widget.on_key>
[15:46:46] EVENT message_pump.py:675
Key(key='q', character='q', name='q', is_printable=True) >>> ActionsApp(title='ActionsApp', classes={'-dark-mode'}) method=<ActionsApp.on_key>
[15:46:46] EVENT message_pump.py:675
Key(key='q', character='q', name='q', is_printable=True) >>> ActionsApp(title='ActionsApp', classes={'-dark-mode'}) method=<App.on_key>
[15:46:46] INFO app.py:2588
<action> namespace=ActionsApp(title='ActionsApp', classes={'-dark-mode'}) action_name='quit,Quit' params=()
[15:46:46] INFO app.py:2604
<action> 'quit,Quit' has no target. Could not find methods '_action_quit,Quit' or 'action_quit,Quit'
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[15:46:47] INFO app.py:2588
<action> namespace=ActionsApp(title='ActionsApp', classes={'-dark-mode'}) action_name='quit' params=()
[15:46:47] EVENT message_pump.py:675
Unmount() >>> ToastRack(id='textual-toastrack') method=<Widget.on_unmount>
[15:46:47] EVENT message_pump.py:675
Unmount() >>> Tooltip(id='textual-tooltip') method=<Widget.on_unmount>
[15:46:47] EVENT message_pump.py:675
Unmount() >>> Screen(id='_default') method=<Widget.on_unmount>
[15:46:47] EVENT message_pump.py:684
Unmount() >>> ActionsApp(title='ActionsApp', classes={'-dark-mode'}) method=None
───────────────────────────────────────────────────────────────────── Client '127.0.0.1' disconnected ─────────────────────────────────────────────────────────────────────
'''Attempting to make 'q' to Quit (exit) app to work
Adapted from https://textual.textualize.io/guide/actions/
'''
from textual.app import App
from textual import events
from textual.binding import Binding
class ActionsApp(App):
BINDINGS = [Binding("q", "quit," "Quit")]
def action_set_background(self, color: str) -> None:
self.screen.styles.background = color
def on_key(self, event: events.Key) -> None:
if event.key == "r":
self.action_set_background("red")
if __name__ == "__main__":
app = ActionsApp()
app.run()
@maphew
Copy link
Author

maphew commented Sep 15, 2023

The console log is the output from textual console while other terminal is executing textual run --dev sqint\xaction.py followed by pressing r, then q, then ctrl-c.

@maphew
Copy link
Author

maphew commented Sep 15, 2023

Doh!, note comma in wrong place, inside the quotes instead of between: BINDINGS = [Binding("q", "quit," "Quit")]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment