add action buttons and rearrange post elements

This commit is contained in:
Morgan McMillian 2021-02-24 20:37:14 -08:00
parent 6dc0c2c367
commit 4f30269207

View file

@ -280,6 +280,9 @@ class Timeline(Gtk.Box):
continue continue
postitem = PostItem(item) postitem = PostItem(item)
postitem.connect('menu-pressed', self.show_menu) postitem.connect('menu-pressed', self.show_menu)
postitem.connect('reply-pressed', self.on_reply_all_btn)
postitem.connect('repost-pressed', self.on_repost_btn)
postitem.connect('bookmark-pressed', self.on_bookmark_btn)
self.view.add(postitem) self.view.add(postitem)
self.show_all() self.show_all()
@ -317,24 +320,46 @@ class Timeline(Gtk.Box):
replyuser = "@" + self.post_data.user.username + " " replyuser = "@" + self.post_data.user.username + " "
self.emit('reply', self.post_data.id, replyuser) self.emit('reply', self.post_data.id, replyuser)
def on_reply_btn(self, widget):
replyuser = "@" + widget.post.user.username + " "
self.emit('reply', widget.post.id, replyuser)
def on_reply_all(self, action, param): def on_reply_all(self, action, param):
replyuser = "@" + self.post_data.user.username + " " replyuser = "@" + self.post_data.user.username + " "
for mention in self.post_data.content.entities.mentions: for mention in self.post_data.content.entities.mentions:
replyuser += "@" + mention.text + " " replyuser += "@" + mention.text + " "
self.emit('reply', self.post_data.id, replyuser) self.emit('reply', self.post_data.id, replyuser)
def on_reply_all_btn(self, widget):
replyuser = "@" + widget.post.user.username + " "
for mention in widget.post.content.entities.mentions:
replyuser += "@" + mention.text + " "
self.emit('reply', widget.post.id, replyuser)
def on_bookmark(self, action, param): def on_bookmark(self, action, param):
if self.post_data.you_bookmarked: if self.post_data.you_bookmarked:
pnutpy.api.unbookmark_post(self.post_data.id) pnutpy.api.unbookmark_post(self.post_data.id)
else: else:
pnutpy.api.bookmark_post(self.post_data.id) pnutpy.api.bookmark_post(self.post_data.id)
def on_bookmark_btn(self, widget):
if widget.post.you_bookmarked:
pnutpy.api.unbookmark_post(widget.post.id)
else:
pnutpy.api.bookmark_post(widget.post.id)
def on_repost(self, action, param): def on_repost(self, action, param):
if self.post_data.you_bookmarked: if self.post_data.you_bookmarked:
pnutpy.api.unrepost_post(self.post_data.id) pnutpy.api.unrepost_post(self.post_data.id)
else: else:
pnutpy.api.repost_post(self.post_data.id) pnutpy.api.repost_post(self.post_data.id)
def on_repost_btn(self, widget):
if widget.post.you_bookmarked:
pnutpy.api.unrepost_post(widget.post.id)
else:
pnutpy.api.repost_post(widget.post.id)
def on_quote(self, action, param): def on_quote(self, action, param):
quote = " >> @" + self.post_data.user.username + ": " quote = " >> @" + self.post_data.user.username + ": "
quote += self.post_data.content.text quote += self.post_data.content.text
@ -357,9 +382,15 @@ class Timeline(Gtk.Box):
class PostItem(Gtk.ListBoxRow): class PostItem(Gtk.ListBoxRow):
__gsignals__ = { __gsignals__ = {
'menu-pressed': (GObject.SIGNAL_RUN_FIRST, None, (int,)) 'menu-pressed': (GObject.SIGNAL_RUN_FIRST, None, (int,)),
'reply-pressed': (GObject.SIGNAL_RUN_FIRST, None, ()),
'repost-pressed': (GObject.SIGNAL_RUN_FIRST, None, ()),
'bookmark-pressed': (GObject.SIGNAL_RUN_FIRST, None, ())
} }
# TODO:
# fix rending link entities or something like that?
def __init__(self, post): def __init__(self, post):
super(Gtk.ListBoxRow, self).__init__() super(Gtk.ListBoxRow, self).__init__()
if 'repost_of' in post: if 'repost_of' in post:
@ -375,7 +406,8 @@ class PostItem(Gtk.ListBoxRow):
self.avatar = Gtk.Image.new_from_pixbuf(self.get_avatar(48, post.user.content.avatar_image)) self.avatar = Gtk.Image.new_from_pixbuf(self.get_avatar(48, post.user.content.avatar_image))
# Source # Source
self.source = Gtk.Label(label=post.source.name, xalign=1) source_label = Gtk.Label(xalign=1)
source_label.set_markup('<span size="small">via ' + post.source.name + '</span>')
self.username = Gtk.Label(label="@" + post.user.username, xalign=0) self.username = Gtk.Label(label="@" + post.user.username, xalign=0)
self.name = Gtk.Label(xalign=0) self.name = Gtk.Label(xalign=0)
@ -393,6 +425,14 @@ class PostItem(Gtk.ListBoxRow):
self.menu_button = Gtk.Button.new_from_icon_name('view-more-symbolic', 1) self.menu_button = Gtk.Button.new_from_icon_name('view-more-symbolic', 1)
self.menu_button.connect('clicked', self.show_menu) self.menu_button.connect('clicked', self.show_menu)
# post actions
reply_button = Gtk.Button.new_from_icon_name('mail-reply-sender-symbolic', 1)
reply_button.connect('clicked', self.reply)
repost_button = Gtk.Button.new_from_icon_name('media-playlist-repeat-symbolic', 1)
repost_button.connect('clicked', self.repost)
bookmark_button = Gtk.Button.new_from_icon_name('non-starred-symbolic', 1)
bookmark_button.connect('clicked', self.bookmark)
self.box = Gtk.Box(orientation='vertical') self.box = Gtk.Box(orientation='vertical')
self.add(self.box) self.add(self.box)
@ -405,7 +445,7 @@ class PostItem(Gtk.ListBoxRow):
self.h_box = Gtk.Box(orientation='horizontal') self.h_box = Gtk.Box(orientation='horizontal')
self.h_box.pack_start(self.avatar, False, False, 10) self.h_box.pack_start(self.avatar, False, False, 10)
self.h_box.pack_start(self.name_box, False, False, 0) self.h_box.pack_start(self.name_box, False, False, 0)
#self.h_box.pack_end(self.source, False, False, 10) #self.h_box.pack_end(source_label, False, False, 10)
#self.h_box.pack_end(datetime_label, False, False, 10) #self.h_box.pack_end(datetime_label, False, False, 10)
# content container # content container
@ -449,28 +489,34 @@ class PostItem(Gtk.ListBoxRow):
# footer container # footer container
self.f_box = Gtk.Box(orientation='horizontal') self.f_box = Gtk.Box(orientation='horizontal')
self.f_box.pack_end(self.menu_button, False, False, 5) self.f_box.pack_end(self.menu_button, False, False, 5)
self.f_box.pack_end(datetime_label, False, False, 5) self.f_box.pack_end(repost_button, False, False, 5)
#self.f_box.pack_end(self.source, False, False, 5) self.f_box.pack_end(bookmark_button, False, False, 5)
self.f_box.pack_end(reply_button, False, False, 5)
self.f_box.pack_start(datetime_label, False, False, 5)
self.f_box.pack_start(source_label, False, False, 0)
# counters
pad = Gtk.Label(label="") pad = Gtk.Label(label="")
self.f_box.pack_start(pad, False, False, 5) self.h_box.pack_end(pad, False, False, 5)
if post.id != int(post.thread_id): if post.id != int(post.thread_id):
thread_icon = Gtk.Image.new_from_icon_name("user-available-symbolic", Gtk.IconSize.SMALL_TOOLBAR) thread_icon = Gtk.Image.new_from_icon_name("user-available-symbolic", Gtk.IconSize.SMALL_TOOLBAR)
self.f_box.pack_start(thread_icon, False, False, 5) self.h_box.pack_end(thread_icon, False, False, 5)
if post.counts.bookmarks > 0: if post.counts.bookmarks > 0:
if post.you_bookmarked: if post.you_bookmarked:
star_icon = Gtk.Image.new_from_icon_name("starred-symbolic", Gtk.IconSize.SMALL_TOOLBAR) star_icon = Gtk.Image.new_from_icon_name("starred-symbolic", Gtk.IconSize.SMALL_TOOLBAR)
else: else:
star_icon = Gtk.Image.new_from_icon_name("non-starred-symbolic", Gtk.IconSize.SMALL_TOOLBAR) star_icon = Gtk.Image.new_from_icon_name("non-starred-symbolic", Gtk.IconSize.SMALL_TOOLBAR)
star_count = Gtk.Label(label=post.counts.bookmarks) star_count = Gtk.Label(label=post.counts.bookmarks)
self.f_box.pack_start(star_icon, False, False, 5) self.h_box.pack_end(star_icon, False, False, 5)
self.f_box.pack_start(star_count, False, False, 0) self.h_box.pack_end(star_count, False, False, 0)
if post.counts.reposts > 0: if post.counts.reposts > 0:
repost_icon = Gtk.Image.new_from_icon_name("media-playlist-repeat-symbolic", Gtk.IconSize.SMALL_TOOLBAR) repost_icon = Gtk.Image.new_from_icon_name("media-playlist-repeat-symbolic", Gtk.IconSize.SMALL_TOOLBAR)
repost_count = Gtk.Label(label=post.counts.reposts) repost_count = Gtk.Label(label=post.counts.reposts)
self.f_box.pack_start(repost_icon, False, False, 5) self.h_box.pack_end(repost_icon, False, False, 5)
self.f_box.pack_start(repost_count, False, False, 0) self.h_box.pack_end(repost_count, False, False, 0)
#postid = Gtk.Label(label=post.id)
#self.f_box.pack_start(postid, False, False, 5)
self.box.pack_start(self.h_box, True, True, 10) self.box.pack_start(self.h_box, True, True, 10)
self.box.pack_start(self.c_box, True, True, 10) self.box.pack_start(self.c_box, True, True, 10)
@ -522,3 +568,12 @@ class PostItem(Gtk.ListBoxRow):
def show_menu(self, widget): def show_menu(self, widget):
self.emit('menu-pressed', self.get_index()) self.emit('menu-pressed', self.get_index())
def reply(self, widget):
self.emit('reply-pressed')
def repost(self, widget):
self.emit('repost-pressed')
def bookmark(self, widget):
self.emit('bookmark-pressed')