dynamic channel cover icon based on tree text size

See #590
This commit is contained in:
Eric Le Lay 2019-01-24 19:03:42 +01:00
parent 1ad321def7
commit a36a9ace22
3 changed files with 12 additions and 4 deletions

View file

@ -302,6 +302,7 @@ def cake_size_from_widget(widget=None):
layout = Pango.Layout(pango_context)
layout.set_font_description(font_desc)
layout.set_text("1", -1)
# use text height as size
return layout.get_pixel_size()[1]

View file

@ -77,8 +77,6 @@ N_ = gpodder.ngettext
class gPodder(BuilderWidget, dbus.service.Object):
# Width (in pixels) of episode list icon
EPISODE_LIST_ICON_WIDTH = 40
def __init__(self, app, bus_name, gpodder_core, options):
dbus.service.Object.__init__(self, object_path=gpodder.dbus_gui_object_path, bus_name=bus_name)
@ -734,10 +732,12 @@ class gPodder(BuilderWidget, dbus.service.Object):
self.entry_search_podcasts.set_position(-1)
def init_podcast_list_treeview(self):
size = cake_size_from_widget(self.treeChannels) * 2
self.podcast_list_model.set_max_image_size(size)
# Set up podcast channel tree view widget
column = Gtk.TreeViewColumn('')
iconcell = Gtk.CellRendererPixbuf()
iconcell.set_property('width', 45)
iconcell.set_property('width', size + 10)
column.pack_start(iconcell, False)
column.add_attribute(iconcell, 'pixbuf', PodcastListModel.C_COVER)
column.add_attribute(iconcell, 'visible', PodcastListModel.C_COVER_VISIBLE)

View file

@ -598,6 +598,10 @@ class PodcastListModel(Gtk.ListStore):
def _show_row_separator(self, model, iter):
return model.get_value(iter, self.C_SEPARATOR)
def set_max_image_size(self, size):
self._max_image_side = size
self._cover_cache = {}
def _resize_pixbuf_keep_ratio(self, url, pixbuf):
"""
Resizes a GTK Pixbuf but keeps its aspect ratio.
@ -663,7 +667,10 @@ class PodcastListModel(Gtk.ListStore):
loader = GdkPixbuf.PixbufLoader()
loader.write(channel.cover_thumb)
loader.close()
return loader.get_pixbuf()
pixbuf = loader.get_pixbuf()
if self._max_image_side not in (pixbuf.get_width(), pixbuf.get_height()):
logger.debug("cached thumb wrong size: %r != %i", (pixbuf.get_width(), pixbuf.get_height()), self._max_image_side)
return None
except Exception as e:
logger.warn('Could not load cached cover art for %s', channel.url, exc_info=True)
channel.cover_thumb = None