mirror of
https://github.com/ihabunek/toot.git
synced 2025-01-03 14:56:37 -05:00
Add goto hash timeline
This commit is contained in:
parent
350138324b
commit
51afcf7e34
@ -12,7 +12,7 @@ from .constants import PALETTE
|
|||||||
from .entities import Status
|
from .entities import Status
|
||||||
from .timeline import Timeline
|
from .timeline import Timeline
|
||||||
from .utils import show_media
|
from .utils import show_media
|
||||||
from .widgets import Button
|
from .widgets import Button, EditBox
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -296,14 +296,14 @@ class TUI(urwid.Frame):
|
|||||||
menu = GotoMenu()
|
menu = GotoMenu()
|
||||||
urwid.connect_signal(menu, "home_timeline",
|
urwid.connect_signal(menu, "home_timeline",
|
||||||
lambda x: self.goto_home_timeline())
|
lambda x: self.goto_home_timeline())
|
||||||
urwid.connect_signal(menu, "local_public_timeline",
|
urwid.connect_signal(menu, "public_timeline",
|
||||||
lambda x: self.goto_public_timeline(True))
|
lambda x, local: self.goto_public_timeline(local))
|
||||||
urwid.connect_signal(menu, "global_public_timeline",
|
urwid.connect_signal(menu, "hashtag_timeline",
|
||||||
lambda x: self.goto_public_timeline(False))
|
lambda x, tag, local: self.goto_tag_timeline(tag, local=local))
|
||||||
|
|
||||||
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=8,
|
valign="middle", height=9,
|
||||||
))
|
))
|
||||||
|
|
||||||
def goto_home_timeline(self):
|
def goto_home_timeline(self):
|
||||||
@ -318,6 +318,12 @@ class TUI(urwid.Frame):
|
|||||||
promise = self.async_load_timeline(is_initial=True, timeline_name="public")
|
promise = self.async_load_timeline(is_initial=True, timeline_name="public")
|
||||||
promise.add_done_callback(lambda *args: self.close_overlay())
|
promise.add_done_callback(lambda *args: self.close_overlay())
|
||||||
|
|
||||||
|
def goto_tag_timeline(self, tag, local):
|
||||||
|
self.timeline_generator = api.tag_timeline_generator(
|
||||||
|
self.app.instance, tag, local=local, limit=40)
|
||||||
|
promise = self.async_load_timeline(is_initial=True, timeline_name="#{}".format(tag))
|
||||||
|
promise.add_done_callback(lambda *args: self.close_overlay())
|
||||||
|
|
||||||
def show_media(self, status):
|
def show_media(self, status):
|
||||||
urls = [m["url"] for m in status.data["media_attachments"]]
|
urls = [m["url"] for m in status.data["media_attachments"]]
|
||||||
if urls:
|
if urls:
|
||||||
@ -455,19 +461,41 @@ class ExceptionStackTrace(urwid.ListBox):
|
|||||||
class GotoMenu(urwid.ListBox):
|
class GotoMenu(urwid.ListBox):
|
||||||
signals = [
|
signals = [
|
||||||
"home_timeline",
|
"home_timeline",
|
||||||
"local_public_timeline",
|
"public_timeline",
|
||||||
"global_public_timeline",
|
"hashtag_timeline",
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.hash_edit = EditBox(caption="Hashtag: ")
|
||||||
|
|
||||||
actions = list(self.generate_actions())
|
actions = list(self.generate_actions())
|
||||||
walker = urwid.SimpleFocusListWalker(actions)
|
walker = urwid.SimpleFocusListWalker(actions)
|
||||||
super().__init__(walker)
|
super().__init__(walker)
|
||||||
|
|
||||||
|
def get_hashtag(self):
|
||||||
|
return self.hash_edit.edit_text.strip()
|
||||||
|
|
||||||
def generate_actions(self):
|
def generate_actions(self):
|
||||||
yield Button("Home timeline",
|
def _home(button):
|
||||||
on_press=lambda b: self._emit("home_timeline"))
|
self._emit("home_timeline")
|
||||||
yield Button("Local public timeline",
|
|
||||||
on_press=lambda b: self._emit("local_public_timeline"))
|
def _local_public(button):
|
||||||
yield Button("Global public timeline",
|
self._emit("public_timeline", True)
|
||||||
on_press=lambda b: self._emit("global_public_timeline"))
|
|
||||||
|
def _global_public(button):
|
||||||
|
self._emit("public_timeline", False)
|
||||||
|
|
||||||
|
def _hashtag(local):
|
||||||
|
hashtag = self.get_hashtag()
|
||||||
|
if hashtag:
|
||||||
|
self._emit("hashtag_timeline", hashtag, local)
|
||||||
|
else:
|
||||||
|
self.set_focus(4)
|
||||||
|
|
||||||
|
yield Button("Home timeline", on_press=_home)
|
||||||
|
yield Button("Local public timeline", on_press=_local_public)
|
||||||
|
yield Button("Global public timeline", on_press=_global_public)
|
||||||
|
yield urwid.Divider()
|
||||||
|
yield self.hash_edit
|
||||||
|
yield Button("Local hashtag timeline", on_press=lambda x: _hashtag(True))
|
||||||
|
yield Button("Public hashtag timeline", on_press=lambda x: _hashtag(False))
|
||||||
|
@ -14,7 +14,7 @@ class StatusComposer(urwid.Frame):
|
|||||||
|
|
||||||
def __init__(self, in_reply_to=None):
|
def __init__(self, in_reply_to=None):
|
||||||
self.in_reply_to = in_reply_to
|
self.in_reply_to = in_reply_to
|
||||||
self.content_edit = EditBox()
|
self.content_edit = EditBox(multiline=True, allow_tab=True)
|
||||||
|
|
||||||
self.cw_edit = None
|
self.cw_edit = None
|
||||||
self.cw_add_button = Button("Add content warning",
|
self.cw_add_button = Button("Add content warning",
|
||||||
@ -81,7 +81,7 @@ class StatusComposer(urwid.Frame):
|
|||||||
self.walker.set_focus(7 if self.cw_edit else 4)
|
self.walker.set_focus(7 if self.cw_edit else 4)
|
||||||
|
|
||||||
def add_content_warning(self, button):
|
def add_content_warning(self, button):
|
||||||
self.cw_edit = EditBox()
|
self.cw_edit = EditBox(multiline=True, allow_tab=True)
|
||||||
self.refresh()
|
self.refresh()
|
||||||
self.walker.set_focus(4)
|
self.walker.set_focus(4)
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ class SelectableColumns(Clickable, urwid.Columns):
|
|||||||
|
|
||||||
class EditBox(urwid.AttrWrap):
|
class EditBox(urwid.AttrWrap):
|
||||||
"""Styled edit box."""
|
"""Styled edit box."""
|
||||||
def __init__(self):
|
def __init__(self, *args, **kwargs):
|
||||||
edit = urwid.Edit(multiline=True, allow_tab=True)
|
edit = urwid.Edit(*args, **kwargs)
|
||||||
return super().__init__(edit, "editbox", "editbox_focused")
|
return super().__init__(edit, "editbox", "editbox_focused")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user