Merge pull request #1131 from auouymous/move-scale_pixbuf-to-util
Move scale_pixbuf to util.py and apply #1107 refactoring.
This commit is contained in:
commit
78bff43731
|
@ -164,7 +164,7 @@ class gPodderChannel(BuilderWidget):
|
|||
def set_cover(channel, pixbuf):
|
||||
if self.channel == channel:
|
||||
if pixbuf is not None:
|
||||
self.imgCover.set_from_pixbuf(self.scale_pixbuf(pixbuf))
|
||||
self.imgCover.set_from_pixbuf(util.scale_pixbuf(pixbuf, self.MAX_SIZE))
|
||||
if self.show_on_cover_load:
|
||||
self.main_window.show()
|
||||
self.show_on_cover_load = False
|
||||
|
@ -193,22 +193,6 @@ class gPodderChannel(BuilderWidget):
|
|||
def on_gPodderChannel_destroy(self, widget, *args):
|
||||
self.cover_downloader.unregister('cover-available', self.cover_download_finished)
|
||||
|
||||
def scale_pixbuf(self, pixbuf):
|
||||
|
||||
# Resize if width is too large
|
||||
if pixbuf.get_width() > self.MAX_SIZE:
|
||||
f = float(self.MAX_SIZE) / pixbuf.get_width()
|
||||
(width, height) = (int(pixbuf.get_width() * f), int(pixbuf.get_height() * f))
|
||||
pixbuf = pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.BILINEAR)
|
||||
|
||||
# Resize if height is too large
|
||||
if pixbuf.get_height() > self.MAX_SIZE:
|
||||
f = float(self.MAX_SIZE) / pixbuf.get_height()
|
||||
(width, height) = (int(pixbuf.get_width() * f), int(pixbuf.get_height() * f))
|
||||
pixbuf = pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.BILINEAR)
|
||||
|
||||
return pixbuf
|
||||
|
||||
# Title editing callbacks
|
||||
def on_title_edit_button_clicked(self, button):
|
||||
self.title_save_button_saves = True
|
||||
|
|
|
@ -2292,3 +2292,20 @@ def mount_volume_for_file(file, op=None):
|
|||
file.mount_enclosing_volume(Gio.MountMountFlags.NONE, op, None, callback)
|
||||
Gtk.main()
|
||||
return result, message
|
||||
|
||||
|
||||
def scale_pixbuf(pixbuf, max):
|
||||
import gi
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
w_cur = pixbuf.get_width()
|
||||
h_cur = pixbuf.get_height()
|
||||
|
||||
if w_cur <= max and h_cur <= max:
|
||||
return pixbuf
|
||||
|
||||
f = max / (w_cur if w_cur >= h_cur else h_cur)
|
||||
w_new = int(w_cur * f)
|
||||
h_new = int(h_cur * f)
|
||||
|
||||
return pixbuf.scale_simple(w_new, h_new, GdkPixbuf.InterpType.BILINEAR)
|
||||
|
|
Loading…
Reference in New Issue