Skip to content

Commit

Permalink
Add zoom command to open status in scrollable popup window
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Fidelman authored and ihabunek committed Nov 29, 2022
1 parent 916b4cc commit 1d26ecd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion toot/tui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .compose import StatusComposer
from .constants import PALETTE
from .entities import Status
from .overlays import ExceptionStackTrace, GotoMenu, Help, StatusSource, StatusLinks
from .overlays import ExceptionStackTrace, GotoMenu, Help, StatusSource, StatusLinks, StatusZoom
from .overlays import StatusDeleteConfirmation
from .timeline import Timeline
from .utils import parse_content_links, show_media
Expand Down Expand Up @@ -192,6 +192,9 @@ def _media(timeline, status):
def _menu(timeline, status):
self.show_context_menu(status)

def _zoom(timeline, status_details):
self.show_status_zoom(status_details)

urwid.connect_signal(timeline, "compose", _compose)
urwid.connect_signal(timeline, "delete", _delete)
urwid.connect_signal(timeline, "favourite", self.async_toggle_favourite)
Expand All @@ -202,6 +205,7 @@ def _menu(timeline, status):
urwid.connect_signal(timeline, "reply", _reply)
urwid.connect_signal(timeline, "source", _source)
urwid.connect_signal(timeline, "links", _links)
urwid.connect_signal(timeline, "zoom", _zoom)

def build_timeline(self, name, statuses, local):
def _close(*args):
Expand Down Expand Up @@ -337,6 +341,12 @@ def show_links(self, status):
options={"height": len(links) + 2},
)

def show_status_zoom(self, status_details):
self.open_overlay(
widget=StatusZoom(status_details),
title="Status zoom",
)

def show_exception(self, exception):
self.open_overlay(
widget=ExceptionStackTrace(exception),
Expand Down
9 changes: 9 additions & 0 deletions toot/tui/overlays.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def __init__(self, status):
super().__init__(walker)


class StatusZoom(urwid.ListBox):
"""Opens status in scrollable popup window"""
def __init__(self, status_details):
ll = list(filter(lambda x: getattr(x, "rows", None), status_details.widget_list))
walker = urwid.SimpleFocusListWalker(ll)
super().__init__(walker)


class StatusLinks(urwid.ListBox):
"""Shows status links."""

Expand Down Expand Up @@ -162,6 +170,7 @@ def link(text, url):
yield urwid.Text(h(" [L] - Show the status links"))
yield urwid.Text(h(" [U] - Show the status data in JSON as received from the server"))
yield urwid.Text(h(" [V] - Open status in default browser"))
yield urwid.Text(h(" [Z] - Open status in scrollable popup window"))
yield urwid.Divider()
yield urwid.Text(("bold", "Links"))
yield urwid.Divider()
Expand Down
6 changes: 6 additions & 0 deletions toot/tui/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Timeline(urwid.Columns):
"links", # Show status links
"thread", # Show thread for status
"save", # Save current timeline
"zoom", # Open status in scrollable popup window
]

def __init__(self, name, statuses, focus=0, is_thread=False):
Expand Down Expand Up @@ -173,6 +174,10 @@ def keypress(self, size, key):
self._emit("save", status)
return

if key in ("z", "Z"):
self._emit("zoom", self.status_details)
return

return super().keypress(size, key)

def append_status(self, status):
Expand Down Expand Up @@ -305,6 +310,7 @@ def content_generator(self, status, reblogged_by):
"[L]inks",
"[R]eply",
"So[u]rce",
"[Z]oom",
"[H]elp",
]
options = " ".join(o for o in options if o)
Expand Down

0 comments on commit 1d26ecd

Please sign in to comment.