Skip to content

Commit

Permalink
Large Album Cover Now Updates When Song Changes
Browse files Browse the repository at this point in the history
The large album cover will now change when the song playing changes.
  • Loading branch information
Eoin-ONeill-Yokai committed Sep 16, 2018
1 parent b66bc9f commit f28270f
Showing 1 changed file with 63 additions and 39 deletions.
102 changes: 63 additions & 39 deletions quodlibet/quodlibet/qltk/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,51 @@ def __init__(self, title, fileobj, parent):
parent = qltk.get_top_parent(parent)
self.set_transient_for(parent)

self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)

self.set_image(fileobj, parent)

event_box = Gtk.EventBox()
event_box.add(self.__image)

frame = Gtk.Frame()
frame.set_shadow_type(Gtk.ShadowType.OUT)
frame.add(event_box)

self.add(frame)

event_box.connect('button-press-event', self.__destroy)
event_box.connect('key-press-event', self.__destroy)

self.get_child().show_all()

def set_image(self, file, parent):
scale_factor = self.get_scale_factor()

(width, height) = self.__calculate_screen_width(parent)

pixbuf = None
try:
pixbuf = pixbuf_from_file(file, (width, height), scale_factor)
except GLib.GError:
pass

# failed to load, abort
if not pixbuf:
self.destroy()
return

self.__image = Gtk.Image()
self.__image.set_from_surface(get_surface_for_pixbuf(self, pixbuf))

def __calculate_screen_width(self, parent):
if qltk.is_wayland():
# no screen size with wayland, the parent window is
# the next best thing..
width, height = parent.get_size()
width = int(width / 1.1)
height = int(height / 1.1)
return (width, height)
else:
win = parent.get_window()
if win:
Expand All @@ -56,40 +95,11 @@ def __init__(self, title, fileobj, parent):
rect = screen.get_monitor_geometry(mon_num)
width = int(rect.width / 1.8)
height = int(rect.height / 1.8)
return (width, height)
else:
width = int(Gdk.Screen.width() / 1.8)
height = int(Gdk.Screen.height() / 1.8)

self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)

scale_factor = self.get_scale_factor()

pixbuf = None
try:
pixbuf = pixbuf_from_file(fileobj, (width, height), scale_factor)
except GLib.GError:
pass

# failed to load, abort
if not pixbuf:
self.destroy()
return

image = Gtk.Image()
image.set_from_surface(get_surface_for_pixbuf(self, pixbuf))

event_box = Gtk.EventBox()
event_box.add(image)

frame = Gtk.Frame()
frame.set_shadow_type(Gtk.ShadowType.OUT)
frame.add(event_box)

self.add(frame)

event_box.connect('button-press-event', self.__destroy)
event_box.connect('key-press-event', self.__destroy)
self.get_child().show_all()
return (width, height)

def __destroy(self, *args):
self.destroy()
Expand Down Expand Up @@ -241,7 +251,7 @@ def __init__(self, resize=False, size=70, song=None):
self.__cancellable = None

self.add(ResizeImage(resize, size))
self.connect('button-press-event', self.__show_cover)
self.connect('button-press-event', self.__album_clicked)
self.set_song(song)
self.get_child().show_all()

Expand All @@ -264,41 +274,55 @@ def cb(success, result):
try:
self.set_image(result)
self.emit('cover-visible', success)
self.update_bci(result)
# If this widget is already 'destroyed', we will get
# following error.
except AttributeError:
pass
else:
self.update_bci(None)
app.cover_manager.acquire_cover(cb, cancellable, song)

def refresh(self):
self.set_song(self.__song)

def update_bci(self, file):
#if there's a big image displaying, it should update.
if self.__current_bci is not None:
self.__current_bci.destroy()
if file is not None:
self.__current_bci
self.__show_cover(self.__song)

def __nonzero__(self):
return bool(self.__file)

def __reset_bci(self, bci):
self.__current_bci = None

def __show_cover(self, box, event):
"""Show the cover as a detached BigCenteredImage.
If one is already showing, destroy it instead
If there is no image, run the AlbumArt plugin
"""

def __album_clicked(self, box, event):
song = self.__song
if not song:
return

if event.button != Gdk.BUTTON_PRIMARY or \
event.type != Gdk.EventType.BUTTON_PRESS:
return
return False

return self.__show_cover(song)

def __show_cover(self, song):
"""Show the cover as a detached BigCenteredImage.
If one is already showing, destroy it instead
If there is no image, run the AlbumArt plugin
"""
if not self.__file and song.is_file:
from quodlibet.qltk.songsmenu import SongsMenu
from quodlibet import app

SongsMenu.plugins.handle(ALBUM_ART_PLUGIN_ID, app.library,
qltk.get_top_parent(self), [song])

return True

if self.__current_bci is not None:
Expand Down

0 comments on commit f28270f

Please sign in to comment.