Display saved timelines in "goto" menu

We introduce "saved timelines" as a new entry in configuration file. For
now, we only save whether the timeline is local or not. Timeline save is
not implemented yet, only retrieval from config file and display is
handled at the moment. Saved timelines in the goto menu.
This commit is contained in:
Denis Laxalde 2020-01-26 15:58:40 +01:00 committed by Ivan Habunek
parent 3b5769acc0
commit 9d3d38552e
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
2 changed files with 19 additions and 6 deletions

View File

@ -3,7 +3,7 @@ import urwid
from concurrent.futures import ThreadPoolExecutor
from toot import api, __version__
from toot import api, config, __version__
from .compose import StatusComposer
from .constants import PALETTE
@ -88,6 +88,7 @@ class TUI(urwid.Frame):
def __init__(self, app, user):
self.app = app
self.user = user
self.config = config.load_config()
self.loop = None # set in `create`
self.executor = ThreadPoolExecutor(max_workers=1)
@ -334,7 +335,8 @@ class TUI(urwid.Frame):
self.open_overlay(composer, title="Compose status")
def show_goto_menu(self):
menu = GotoMenu()
user_timelines = self.config.get("timelines", {})
menu = GotoMenu(user_timelines)
urwid.connect_signal(menu, "home_timeline",
lambda x: self.goto_home_timeline())
urwid.connect_signal(menu, "public_timeline",
@ -344,7 +346,7 @@ class TUI(urwid.Frame):
self.open_overlay(menu, title="Go to", options=dict(
align="center", width=("relative", 60),
valign="middle", height=9,
valign="middle", height=9 + len(user_timelines),
))
def show_help(self):

View File

@ -68,17 +68,17 @@ class GotoMenu(urwid.ListBox):
"hashtag_timeline",
]
def __init__(self):
def __init__(self, user_timelines):
self.hash_edit = EditBox(caption="Hashtag: ")
actions = list(self.generate_actions())
actions = list(self.generate_actions(user_timelines))
walker = urwid.SimpleFocusListWalker(actions)
super().__init__(walker)
def get_hashtag(self):
return self.hash_edit.edit_text.strip()
def generate_actions(self):
def generate_actions(self, user_timelines):
def _home(button):
self._emit("home_timeline")
@ -95,7 +95,18 @@ class GotoMenu(urwid.ListBox):
else:
self.set_focus(4)
def mk_on_press_user_hashtag(tag, local):
def on_press(btn):
self._emit("hashtag_timeline", tag, local)
return on_press
yield Button("Home timeline", on_press=_home)
for tag, cfg in user_timelines.items():
is_local = cfg["local"]
yield Button("#{}".format(tag) + (" (local)" if is_local else ""),
on_press=mk_on_press_user_hashtag(tag, is_local))
yield Button("Local public timeline", on_press=_local_public)
yield Button("Global public timeline", on_press=_global_public)
yield urwid.Divider()