36 lines
958 B
Python
36 lines
958 B
Python
# Copyright 2019 (c) Anna Schumaker.
|
|
from .. import gtk
|
|
from gi.repository import GdkPixbuf, Gtk
|
|
|
|
Default = Gtk.IconTheme.get_default().load_icon("applications-multimedia-symbolic", 512, 0)
|
|
Image = gtk.Builder.get_object("album_artwork")
|
|
Paned = gtk.Builder.get_object("sidebar_pane")
|
|
Pixbuf = Default
|
|
|
|
def reset():
|
|
global Pixbuf
|
|
Pixbuf = Default
|
|
set_scaled_image()
|
|
|
|
def resize(*args):
|
|
if Pixbuf != None:
|
|
set_scaled_image()
|
|
Paned.connect_after("notify::position", resize)
|
|
|
|
def set_image(data):
|
|
global Pixbuf
|
|
|
|
loader = GdkPixbuf.PixbufLoader()
|
|
loader.write(data)
|
|
Pixbuf = loader.get_pixbuf()
|
|
loader.close()
|
|
set_scaled_image()
|
|
|
|
def set_scaled_image():
|
|
new_w = Paned.get_position()
|
|
new_h = (Pixbuf.get_height() * new_w) / Pixbuf.get_width()
|
|
if new_h > 0:
|
|
pix = Pixbuf.scale_simple(new_w, new_h, GdkPixbuf.InterpType.BILINEAR)
|
|
Image.set_from_pixbuf(pix)
|
|
set_scaled_image()
|