Merge pull request #339 from danschwarz/goto_redesign

Restructured Goto Menu items for clarity, added error display
This commit is contained in:
Ivan Habunek 2023-03-13 13:18:07 +01:00 committed by GitHub
commit 9006517cc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View File

@ -472,7 +472,7 @@ class TUI(urwid.Frame):
self.open_overlay(menu, title="Go to", options=dict( self.open_overlay(menu, title="Go to", options=dict(
align="center", width=("relative", 60), align="center", width=("relative", 60),
valign="middle", height=11 + len(user_timelines), valign="middle", height=16 + len(user_timelines),
)) ))
def show_help(self): def show_help(self):

View File

@ -106,13 +106,14 @@ class GotoMenu(urwid.ListBox):
def __init__(self, user_timelines): def __init__(self, user_timelines):
self.hash_edit = EditBox(caption="Hashtag: ") self.hash_edit = EditBox(caption="Hashtag: ")
self.message_widget = urwid.Text("")
actions = list(self.generate_actions(user_timelines)) actions = list(self.generate_actions(user_timelines))
walker = urwid.SimpleFocusListWalker(actions) walker = urwid.SimpleFocusListWalker(actions)
super().__init__(walker) super().__init__(walker)
def get_hashtag(self): def get_hashtag(self):
return self.hash_edit.edit_text.strip() return self.hash_edit.edit_text.strip().lstrip("#")
def generate_actions(self, user_timelines): def generate_actions(self, user_timelines):
def _home(button): def _home(button):
@ -134,11 +135,12 @@ class GotoMenu(urwid.ListBox):
self._emit("conversation_timeline", False) self._emit("conversation_timeline", False)
def _hashtag(local): def _hashtag(local):
self.message_widget.set_text("")
hashtag = self.get_hashtag() hashtag = self.get_hashtag()
if hashtag: if hashtag:
self._emit("hashtag_timeline", hashtag, local) self._emit("hashtag_timeline", hashtag, local)
else: else:
self.set_focus(4) self.message_widget.set_text(("warning", "Hashtag name required"))
def mk_on_press_user_hashtag(tag, local): def mk_on_press_user_hashtag(tag, local):
def on_press(btn): def on_press(btn):
@ -146,21 +148,28 @@ class GotoMenu(urwid.ListBox):
return on_press return on_press
yield Button("Home timeline", on_press=_home) 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("Local public timeline", on_press=_local_public)
yield Button("Global public timeline", on_press=_global_public) yield Button("Global public timeline", on_press=_global_public)
yield Button("Bookmarks", on_press=_bookmarks) yield Button("Bookmarks", on_press=_bookmarks)
yield Button("Notifications", on_press=_notifications) yield Button("Notifications", on_press=_notifications)
yield Button("Conversations", on_press=_conversations) yield Button("Conversations", on_press=_conversations)
if len(user_timelines):
yield urwid.Divider()
yield urwid.Text(("bold", "Shortcuts:"))
# show all hashtag shortcuts
for tag, cfg in sorted(user_timelines.items()):
is_local = cfg["local"]
yield Button(f"#{tag}" + (" (local)" if is_local else ""),
on_press=mk_on_press_user_hashtag(tag, is_local))
yield urwid.Divider() yield urwid.Divider()
yield self.hash_edit yield self.hash_edit
yield Button("Local hashtag timeline", on_press=lambda x: _hashtag(True)) yield Button("Local hashtag timeline", on_press=lambda x: _hashtag(True))
yield Button("Public hashtag timeline", on_press=lambda x: _hashtag(False)) yield Button("Public hashtag timeline", on_press=lambda x: _hashtag(False))
yield urwid.Divider()
yield self.message_widget
class Help(urwid.Padding): class Help(urwid.Padding):