added basic media handling including avatars
This commit is contained in:
parent
52efdacbe5
commit
7ce61494b1
1 changed files with 30 additions and 7 deletions
|
@ -20,10 +20,12 @@ import gi
|
|||
import os
|
||||
import pnutpy
|
||||
import logging
|
||||
import requests
|
||||
|
||||
gi.require_version('GdkPixbuf', '2.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import GObject, Gdk, Gtk
|
||||
from gi.repository import GObject, GdkPixbuf, Gdk, Gtk
|
||||
|
||||
gi.require_version('Handy', '1')
|
||||
from gi.repository import Handy
|
||||
|
@ -192,7 +194,7 @@ class Timeline(Gtk.Box):
|
|||
|
||||
def load_timeline(self):
|
||||
if self.stream == 'unified':
|
||||
posts, meta = pnutpy.api.users_post_streams_unified()
|
||||
posts, meta = pnutpy.api.users_post_streams_unified(include_raw=1)
|
||||
elif self.stream == 'mentions':
|
||||
posts, meta = pnutpy.api.users_mentioned_posts('me')
|
||||
elif self.stream == 'bookmarks':
|
||||
|
@ -232,20 +234,41 @@ class PostItem(Gtk.ListBoxRow):
|
|||
|
||||
# header container
|
||||
self.h_box = Gtk.Box(orientation='horizontal')
|
||||
self.avatar = Handy.Avatar(size=32)
|
||||
# TODO: get the actual image
|
||||
self.avatar = Handy.Avatar(size=48, text=post.user.username, show_initials=True)
|
||||
self.avatar.set_image_load_func(self.get_image, post.user.content.avatar_image.link)
|
||||
#self.avatar = Gtk.Image.new_from_pixbuf(self.get_image(48, post.user.content.avatar_image.link))
|
||||
self.h_box.pack_start(self.avatar, False, False, 18)
|
||||
self.h_box.pack_start(self.name_box, False, False, 0)
|
||||
|
||||
# content container
|
||||
self.c_box = Gtk.Box(orientation='horizontal')
|
||||
self.c_box = Gtk.Box(orientation='vertical')
|
||||
self.t_box = Gtk.Box(orientation='horizontal')
|
||||
self.content = Gtk.Label(wrap=True, xalign=0)
|
||||
# TODO: parse content links
|
||||
if 'content' in post:
|
||||
self.content.set_text(post.content.text)
|
||||
# TODO: add media
|
||||
self.c_box.pack_start(self.content, True, True, 18)
|
||||
self.t_box.pack_start(self.content, False, False, 18)
|
||||
self.c_box.pack_start(self.t_box, False, False, 18)
|
||||
|
||||
if 'raw' in post:
|
||||
for raw in post.raw:
|
||||
logging.debug(raw.type)
|
||||
if raw.type == "io.pnut.core.oembed":
|
||||
oembed = raw.value
|
||||
if oembed.type == "photo":
|
||||
photo = Gtk.Image.new_from_pixbuf(self.get_image(256, oembed.thumbnail_url))
|
||||
self.c_box.pack_end(photo, False, False, 18)
|
||||
|
||||
self.box.pack_start(self.h_box, True, True, 10)
|
||||
self.box.pack_start(self.c_box, True, True, 10)
|
||||
|
||||
def get_image(self, size, url):
|
||||
# TODO: needs a cache
|
||||
# TODO: can I make it not round?
|
||||
r = requests.get(url)
|
||||
loader = GdkPixbuf.PixbufLoader()
|
||||
loader.write(r.content)
|
||||
loader.close()
|
||||
pixbuf = loader.get_pixbuf()
|
||||
return pixbuf.scale_simple(size,size,GdkPixbuf.InterpType.BILINEAR)
|
||||
|
||||
|
|
Loading…
Reference in a new issue