mirror of
https://github.com/ihabunek/toot
synced 2024-12-24 16:10:52 +01:00
Use direct invocation istead of signals
This commit is contained in:
parent
7726b01000
commit
6d60ecee4d
@ -180,60 +180,7 @@ class TUI(urwid.Frame):
|
||||
return future
|
||||
|
||||
def connect_default_timeline_signals(self, timeline):
|
||||
def _account(timeline, account_id):
|
||||
self.show_account(account_id)
|
||||
|
||||
def _compose(*args):
|
||||
self.show_compose()
|
||||
|
||||
def _delete(timeline, status):
|
||||
if status.is_mine:
|
||||
self.show_delete_confirmation(status)
|
||||
|
||||
def _reply(timeline, status):
|
||||
self.show_compose(status)
|
||||
|
||||
def _source(timeline, status):
|
||||
self.show_status_source(status)
|
||||
|
||||
def _links(timeline, status):
|
||||
self.show_links(status)
|
||||
|
||||
def _media(timeline, status):
|
||||
self.show_media(status)
|
||||
|
||||
def _menu(timeline, status):
|
||||
self.show_context_menu(status)
|
||||
|
||||
def _poll(timeline, status):
|
||||
self.show_poll(status)
|
||||
|
||||
def _zoom(timeline, status_details):
|
||||
self.show_status_zoom(status_details)
|
||||
|
||||
def _clear(*args):
|
||||
self.clear_screen()
|
||||
|
||||
def _copy(timeline, status):
|
||||
self.copy_status(status)
|
||||
|
||||
urwid.connect_signal(timeline, "account", _account)
|
||||
urwid.connect_signal(timeline, "bookmark", self.async_toggle_bookmark)
|
||||
urwid.connect_signal(timeline, "compose", _compose)
|
||||
urwid.connect_signal(timeline, "delete", _delete)
|
||||
urwid.connect_signal(timeline, "favourite", self.async_toggle_favourite)
|
||||
urwid.connect_signal(timeline, "focus", self.refresh_footer)
|
||||
urwid.connect_signal(timeline, "media", _media)
|
||||
urwid.connect_signal(timeline, "menu", _menu)
|
||||
urwid.connect_signal(timeline, "poll", _poll)
|
||||
urwid.connect_signal(timeline, "reblog", self.async_toggle_reblog)
|
||||
urwid.connect_signal(timeline, "reply", _reply)
|
||||
urwid.connect_signal(timeline, "source", _source)
|
||||
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", _clear)
|
||||
urwid.connect_signal(timeline, "copy-status", _copy)
|
||||
|
||||
def build_timeline(self, name, statuses, local):
|
||||
def _close(*args):
|
||||
@ -242,9 +189,6 @@ class TUI(urwid.Frame):
|
||||
def _next(*args):
|
||||
self.async_load_timeline(is_initial=False)
|
||||
|
||||
def _thread(timeline, status):
|
||||
self.show_thread(status)
|
||||
|
||||
def _toggle_save(timeline, status):
|
||||
if not timeline.name.startswith("#"):
|
||||
return
|
||||
@ -265,7 +209,6 @@ class TUI(urwid.Frame):
|
||||
self.connect_default_timeline_signals(timeline)
|
||||
urwid.connect_signal(timeline, "next", _next)
|
||||
urwid.connect_signal(timeline, "close", _close)
|
||||
urwid.connect_signal(timeline, "thread", _thread)
|
||||
urwid.connect_signal(timeline, "save", _toggle_save)
|
||||
|
||||
return timeline
|
||||
|
@ -22,27 +22,10 @@ class Timeline(urwid.Columns):
|
||||
Displays a list of statuses to the left, and status details on the right.
|
||||
"""
|
||||
signals = [
|
||||
"account", # Display account info and actions
|
||||
"close", # Close thread
|
||||
"compose", # Compose a new toot
|
||||
"delete", # Delete own status
|
||||
"favourite", # Favourite status
|
||||
"focus", # Focus changed
|
||||
"bookmark", # Bookmark status
|
||||
"media", # Display media attachments
|
||||
"menu", # Show a context menu
|
||||
"next", # Fetch more statuses
|
||||
"poll", # Vote in a poll
|
||||
"reblog", # Reblog status
|
||||
"reply", # Compose a reply to a status
|
||||
"source", # Show status source
|
||||
"links", # Show status links
|
||||
"thread", # Show thread for status
|
||||
"translate", # Translate status
|
||||
"save", # Save current timeline
|
||||
"zoom", # Open status in scrollable popup window
|
||||
"clear-screen", # Clear the screen (used internally)
|
||||
"copy-status", # Copy status to clipboard
|
||||
"close", # Close thread
|
||||
"focus", # Focus changed
|
||||
"next", # Fetch more statuses
|
||||
"save", # Save current timeline
|
||||
]
|
||||
|
||||
def __init__(
|
||||
@ -98,7 +81,7 @@ class Timeline(urwid.Columns):
|
||||
def build_list_item(self, status):
|
||||
item = StatusListItem(status)
|
||||
urwid.connect_signal(item, "click", lambda *args:
|
||||
self._emit("menu", status))
|
||||
self.tui.show_context_menu(status))
|
||||
return urwid.AttrMap(item, None, focus_map={
|
||||
"blue": "green_selected",
|
||||
"green": "green_selected",
|
||||
@ -188,27 +171,29 @@ class Timeline(urwid.Columns):
|
||||
self._emit("next")
|
||||
|
||||
if key in ("a", "A"):
|
||||
self._emit("account", status.original.data['account']['id'])
|
||||
account_id = status.original.data["account"]["id"]
|
||||
self.tui.show_account(account_id)
|
||||
return
|
||||
|
||||
if key in ("b", "B"):
|
||||
self._emit("reblog", status)
|
||||
self.tui.async_toggle_reblog(self, status)
|
||||
return
|
||||
|
||||
if key in ("c", "C"):
|
||||
self._emit("compose")
|
||||
self.tui.show_compose()
|
||||
return
|
||||
|
||||
if key in ("d", "D"):
|
||||
self._emit("delete", status)
|
||||
if status.is_mine:
|
||||
self.tui.show_delete_confirmation(status)
|
||||
return
|
||||
|
||||
if key in ("f", "F"):
|
||||
self._emit("favourite", status)
|
||||
self.tui.async_toggle_favourite(self, status)
|
||||
return
|
||||
|
||||
if key in ("m", "M"):
|
||||
self._emit("media", status)
|
||||
self.tui.show_media(status)
|
||||
return
|
||||
|
||||
if key in ("q", "Q"):
|
||||
@ -220,7 +205,7 @@ class Timeline(urwid.Columns):
|
||||
return
|
||||
|
||||
if key in ("r", "R"):
|
||||
self._emit("reply", status)
|
||||
self.tui.show_compose(status)
|
||||
return
|
||||
|
||||
if key in ("s", "S"):
|
||||
@ -229,31 +214,31 @@ class Timeline(urwid.Columns):
|
||||
return
|
||||
|
||||
if key in ("o", "O"):
|
||||
self._emit("bookmark", status)
|
||||
self.tui.async_toggle_bookmark(self, status)
|
||||
return
|
||||
|
||||
if key in ("l", "L"):
|
||||
self._emit("links", status)
|
||||
self.tui.show_links(status)
|
||||
return
|
||||
|
||||
if key in ("n", "N"):
|
||||
if self.tui.can_translate:
|
||||
self._emit("translate", status)
|
||||
self.tui.async_translate(self, status)
|
||||
return
|
||||
|
||||
if key in ("t", "T"):
|
||||
self._emit("thread", status)
|
||||
self.tui.show_thread(status)
|
||||
return
|
||||
|
||||
if key in ("u", "U"):
|
||||
self._emit("source", status)
|
||||
self.tui.show_status_source(status)
|
||||
return
|
||||
|
||||
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")
|
||||
self.tui.clear_screen()
|
||||
return
|
||||
|
||||
if key in ("e", "E"):
|
||||
@ -261,17 +246,17 @@ class Timeline(urwid.Columns):
|
||||
return
|
||||
|
||||
if key in ("z", "Z"):
|
||||
self._emit("zoom", self.status_details)
|
||||
self.tui.show_status_zoom(self.status_details)
|
||||
return
|
||||
|
||||
if key in ("p", "P"):
|
||||
poll = status.original.data.get("poll")
|
||||
if poll and not poll["expired"]:
|
||||
self._emit("poll", status)
|
||||
self.tui.show_poll(status)
|
||||
return
|
||||
|
||||
if key in ("y", "Y"):
|
||||
self._emit("copy-status", status)
|
||||
self.tui.copy_status(status)
|
||||
return
|
||||
|
||||
return super().keypress(size, key)
|
||||
|
Loading…
Reference in New Issue
Block a user