adjust avatar scaling

This commit is contained in:
Morgan McMillian 2020-12-22 07:59:03 -08:00
parent 1d2d13d26e
commit ac39977be7

View file

@ -339,7 +339,7 @@ class PostItem(Gtk.ListBoxRow):
# header container # header container
self.h_box = Gtk.Box(orientation='horizontal') self.h_box = Gtk.Box(orientation='horizontal')
self.avatar = Handy.Avatar(size=48, text=post.user.username, show_initials=True) self.avatar = Handy.Avatar(size=48, text=post.user.username, show_initials=True)
self.avatar.set_image_load_func(self.get_avatar, post.user.content.avatar_image.link) self.avatar.set_image_load_func(self.get_avatar, post.user.content.avatar_image)
#self.avatar = Gtk.Image.new_from_pixbuf(self.get_avatar(48, post.user.content.avatar_image.link)) #self.avatar = Gtk.Image.new_from_pixbuf(self.get_avatar(48, post.user.content.avatar_image.link))
self.source = Gtk.Label(label=post.source.name, xalign=1, yalign=0) self.source = Gtk.Label(label=post.source.name, xalign=1, yalign=0)
self.h_box.pack_start(self.avatar, False, False, 10) self.h_box.pack_start(self.avatar, False, False, 10)
@ -397,15 +397,19 @@ class PostItem(Gtk.ListBoxRow):
self.box.pack_start(self.c_box, True, True, 10) self.box.pack_start(self.c_box, True, True, 10)
self.box.pack_start(self.f_box, True, True, 10) self.box.pack_start(self.f_box, True, True, 10)
def get_avatar(self, size, url): def get_avatar(self, size, avatar):
# TODO: needs a cache # TODO: needs a cache
# TODO: can I make it not round? # TODO: can I make it not round?
r = requests.get(url) r = requests.get(avatar.link)
loader = GdkPixbuf.PixbufLoader() loader = GdkPixbuf.PixbufLoader()
loader.write(r.content) loader.write(r.content)
loader.close() loader.close()
pixbuf = loader.get_pixbuf() pixbuf = loader.get_pixbuf()
return pixbuf.scale_simple(size,size,GdkPixbuf.InterpType.BILINEAR) old_width = avatar.width
old_height = avatar.height
ratio = old_width / old_height
new_height = size / ratio
return pixbuf.scale_simple(size,new_height,GdkPixbuf.InterpType.BILINEAR)
def get_oembed_thumb(self, oembed): def get_oembed_thumb(self, oembed):
url = oembed.thumbnail_url url = oembed.thumbnail_url