Fix animated covers in the overview
This commit is contained in:
@@ -59,6 +59,21 @@ def create_details_window(parent_widget, game_id=None):
|
||||
margin_end=6,
|
||||
)
|
||||
|
||||
def update_animation(game_id, animation=None):
|
||||
new_id = (
|
||||
game_id if parent_widget.current_anim_edit != game_id else f"{game_id}_new"
|
||||
)
|
||||
parent_widget.current_anim_edit = new_id
|
||||
|
||||
display_animation(
|
||||
cover.set_pixbuf,
|
||||
animation_path if not animation else None,
|
||||
animation=animation,
|
||||
parent_widget=parent_widget,
|
||||
game_id=new_id,
|
||||
place="edit",
|
||||
)
|
||||
|
||||
def delete_pixbuf(_widget):
|
||||
nonlocal pixbuf
|
||||
nonlocal cover_deleted
|
||||
@@ -68,6 +83,8 @@ def create_details_window(parent_widget, game_id=None):
|
||||
pixbuf = None
|
||||
cover_deleted = True
|
||||
|
||||
parent_widget.current_anim_edit = None
|
||||
|
||||
cover_button_delete.connect("clicked", delete_pixbuf)
|
||||
|
||||
cover_button_delete_revealer = Gtk.Revealer(
|
||||
@@ -90,7 +107,8 @@ def create_details_window(parent_widget, game_id=None):
|
||||
parent_widget.data_dir / "cartridges" / "animated_covers" / game_id
|
||||
)
|
||||
if animation_path.is_file():
|
||||
display_animation(cover.set_pixbuf, animation_path)
|
||||
update_animation(game_id)
|
||||
|
||||
developer = Gtk.Entry.new_with_buffer(
|
||||
Gtk.EntryBuffer.new(games[game_id].developer, -1)
|
||||
)
|
||||
@@ -235,13 +253,15 @@ def create_details_window(parent_widget, game_id=None):
|
||||
try:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(path, 200, 300, False)
|
||||
cover.set_pixbuf(pixbuf)
|
||||
parent_widget.current_anim_edit = None
|
||||
except GLib.GError:
|
||||
animation_path = path
|
||||
animated_pixbuf = GdkPixbuf.PixbufAnimation.new_from_file(path)
|
||||
pixbuf = animated_pixbuf.get_static_image().scale_simple(
|
||||
200, 300, GdkPixbuf.InterpType.BILINEAR
|
||||
)
|
||||
display_animation(cover.set_pixbuf, animation=animated_pixbuf)
|
||||
|
||||
update_animation(game_id, animated_pixbuf)
|
||||
|
||||
cover_button_delete_revealer.set_reveal_child(True)
|
||||
|
||||
@@ -329,7 +349,11 @@ def create_details_window(parent_widget, game_id=None):
|
||||
(
|
||||
parent_widget.data_dir / "cartridges" / "covers" / f"{game_id}.tiff"
|
||||
).unlink(missing_ok=True)
|
||||
parent_widget.pixbufs.pop(game_id)
|
||||
(
|
||||
parent_widget.data_dir / "cartridges" / "animated_covers" / game_id
|
||||
).unlink(missing_ok=True)
|
||||
if game_id in parent_widget.pixbufs:
|
||||
parent_widget.pixbufs.pop(game_id)
|
||||
|
||||
if pixbuf:
|
||||
if game_id in parent_widget.pixbufs:
|
||||
@@ -353,7 +377,11 @@ def create_details_window(parent_widget, game_id=None):
|
||||
|
||||
parent_widget.update_games([game_id])
|
||||
window.close()
|
||||
parent_widget.show_overview(None, game_id)
|
||||
if parent_widget.stack.get_visible_child() != parent_widget.overview:
|
||||
parent_widget.show_overview(None, game_id)
|
||||
|
||||
if not animation_path:
|
||||
parent_widget.current_anim_overview = None
|
||||
|
||||
def focus_executable(_widget):
|
||||
window.set_focus(executable)
|
||||
|
||||
@@ -2,7 +2,7 @@ from gi.repository import GdkPixbuf, GLib
|
||||
|
||||
|
||||
def display_animation(
|
||||
function, path=None, animation=None, parent_widget=None, game_id=None
|
||||
function, path=None, animation=None, parent_widget=None, game_id=None, place=None
|
||||
):
|
||||
if not animation:
|
||||
animation = GdkPixbuf.PixbufAnimation.new_from_file(str(path))
|
||||
@@ -12,8 +12,12 @@ def display_animation(
|
||||
def update_animation():
|
||||
nonlocal anim_iter
|
||||
|
||||
if parent_widget and parent_widget.current_anim != game_id:
|
||||
return
|
||||
if place == "overview":
|
||||
if parent_widget.current_anim_overview != game_id:
|
||||
return
|
||||
elif place == "edit":
|
||||
if parent_widget.current_anim_edit != game_id:
|
||||
return
|
||||
|
||||
anim_iter.advance()
|
||||
pixbuf = anim_iter.get_pixbuf().scale_simple(
|
||||
|
||||
@@ -47,6 +47,8 @@ def save_cover(
|
||||
(animated_covers_dir / game_id).unlink(missing_ok=True)
|
||||
|
||||
if animation_path:
|
||||
if animation_path == animated_covers_dir / game_id:
|
||||
return
|
||||
animated_covers_dir.mkdir(parents=True, exist_ok=True)
|
||||
with animated_covers_dir / game_id as open_file:
|
||||
copyfile(animation_path, open_file)
|
||||
|
||||
@@ -100,7 +100,8 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
self.active_game_id = None
|
||||
self.loading = None
|
||||
self.scaled_pixbuf = None
|
||||
self.current_anim = None
|
||||
self.current_anim_overview = None
|
||||
self.current_anim_edit = None
|
||||
|
||||
self.overview.set_measure_overlay(self.overview_box, True)
|
||||
self.overview.set_clip_overlay(self.overview_box, False)
|
||||
@@ -288,9 +289,8 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
pixbuf = current_game.pixbuf
|
||||
self.overview_cover.set_pixbuf(pixbuf)
|
||||
|
||||
new_id = game_id if self.current_anim != game_id else f"{game_id}_new"
|
||||
|
||||
self.current_anim = new_id
|
||||
new_id = game_id if self.current_anim_overview != game_id else f"{game_id}_new"
|
||||
self.current_anim_overview = new_id
|
||||
|
||||
if current_game.animation_path.is_file():
|
||||
display_animation(
|
||||
@@ -298,6 +298,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
current_game.animation_path,
|
||||
parent_widget=self,
|
||||
game_id=new_id,
|
||||
place="overview",
|
||||
)
|
||||
|
||||
self.scaled_pixbuf = pixbuf.scale_simple(2, 3, GdkPixbuf.InterpType.BILINEAR)
|
||||
|
||||
Reference in New Issue
Block a user