Screen refresh after web browser invocation and exit

pull/282/head
Daniel Schwarz 2022-12-22 13:40:22 -05:00 zatwierdzone przez Ivan Habunek
rodzic 6633b758bc
commit 13fffd9fc1
3 zmienionych plików z 17 dodań i 2 usunięć

Wyświetl plik

@ -210,6 +210,7 @@ class TUI(urwid.Frame):
urwid.connect_signal(timeline, "links", _links)
urwid.connect_signal(timeline, "zoom", _zoom)
urwid.connect_signal(timeline, "translate", self.async_translate)
urwid.connect_signal(timeline, "clear-screen", self.loop.screen.clear)
def build_timeline(self, name, statuses, local):
def _close(*args):
@ -347,6 +348,9 @@ class TUI(urwid.Frame):
title="Status source",
)
def _clear_screen(self, widget):
self.loop.screen.clear()
def show_links(self, status):
links = parse_content_links(status.data["content"]) if status else []
post_attachments = status.data["media_attachments"] or []
@ -355,8 +359,10 @@ class TUI(urwid.Frame):
url = a["remote_url"] or a["url"]
links.append((url, a["description"] if a["description"] else url))
if links:
sl_widget=StatusLinks(links)
urwid.connect_signal(sl_widget, "clear-screen", self._clear_screen)
self.open_overlay(
widget=StatusLinks(links),
widget=sl_widget,
title="Status links",
options={"height": len(links) + 2},
)

Wyświetl plik

@ -30,17 +30,23 @@ class StatusZoom(urwid.ListBox):
class StatusLinks(urwid.ListBox):
"""Shows status links."""
signals = ["clear-screen"]
def __init__(self, links):
def widget(url, title):
return Button(title or url, on_press=lambda btn: webbrowser.open(url))
return Button(title or url, on_press=lambda btn: self.browse(url))
walker = urwid.SimpleFocusListWalker(
[widget(url, title) for url, title in links]
)
super().__init__(walker)
def browse(self, url):
webbrowser.open(url)
# force a screen refresh; necessary with console browsers
self._emit("clear-screen")
class ExceptionStackTrace(urwid.ListBox):
"""Shows an exception stack trace."""

Wyświetl plik

@ -33,6 +33,7 @@ class Timeline(urwid.Columns):
"translate", # Translate status
"save", # Save current timeline
"zoom", # Open status in scrollable popup window
"clear-screen", # clear the screen (used internally)
]
def __init__(self, name, statuses, can_translate, focus=0, is_thread=False):
@ -182,6 +183,8 @@ class Timeline(urwid.Columns):
if key in ("v", "V"):
if status.original.url:
webbrowser.open(status.original.url)
# force a screen refresh; necessary with console browsers
self._emit("clear-screen")
return
if key in ("p", "P"):