From 2aea2fb377fb9dec7b86aa06f7e8dd164b467269 Mon Sep 17 00:00:00 2001 From: kramo Date: Sun, 18 Jun 2023 13:46:17 +0200 Subject: [PATCH] Move placeholders to Gdk.Texture --- data/cartridges.gresource.xml.in | 1 + data/library_placeholder_small.svg | 1 + src/game_cover.py | 25 +++++++++++++------------ src/window.py | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 data/library_placeholder_small.svg diff --git a/data/cartridges.gresource.xml.in b/data/cartridges.gresource.xml.in index 203edea..90d5c3b 100644 --- a/data/cartridges.gresource.xml.in +++ b/data/cartridges.gresource.xml.in @@ -9,5 +9,6 @@ gtk/style.css gtk/style-dark.css library_placeholder.svg + library_placeholder_small.svg diff --git a/data/library_placeholder_small.svg b/data/library_placeholder_small.svg new file mode 100644 index 0000000..541aec1 --- /dev/null +++ b/data/library_placeholder_small.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/game_cover.py b/src/game_cover.py index cca0eba..5a4621c 100644 --- a/src/game_cover.py +++ b/src/game_cover.py @@ -17,7 +17,7 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -from gi.repository import GdkPixbuf, Gio, GLib +from gi.repository import Gdk, GdkPixbuf, Gio, GLib from PIL import Image, ImageFilter, ImageStat from src import shared @@ -31,8 +31,11 @@ class GameCover: animation = None anim_iter = None - placeholder_pixbuf = GdkPixbuf.Pixbuf.new_from_resource_at_scale( - shared.PREFIX + "/library_placeholder.svg", 400, 600, False + placeholder = Gdk.Texture.new_from_resource( + shared.PREFIX + "/library_placeholder.svg" + ) + placeholder_small = Gdk.Texture.new_from_resource( + shared.PREFIX + "/library_placeholder_small.svg" ) def __init__(self, pictures, path=None): @@ -82,7 +85,7 @@ class GameCover: tmp_path = Gio.File.new_tmp(None)[0].get_path() image.save(tmp_path, "tiff", compression=None) - self.blurred = GdkPixbuf.Pixbuf.new_from_file(tmp_path) + self.blurred = Gdk.Texture.new_from_filename(tmp_path) stat = ImageStat.Stat(image.convert("L")) @@ -92,11 +95,8 @@ class GameCover: (stat.mean[0] + stat.extrema[0][1]) / 510, ) else: - self.blurred = GdkPixbuf.Pixbuf.new_from_resource_at_scale( - shared.PREFIX + "/library_placeholder.svg", 2, 2, False - ) - - self.luminance = (0.1, 0.8) + self.blurred = self.placeholder_small + self.luminance = (0.3, 0.5) return self.blurred @@ -113,9 +113,10 @@ class GameCover: self.animation = None else: for picture in self.pictures: - if not pixbuf: - pixbuf = self.placeholder_pixbuf - picture.set_pixbuf(pixbuf) + if pixbuf: + picture.set_pixbuf(pixbuf) + else: + picture.set_paintable(self.placeholder) def update_animation(self, data): if self.animation == data[1]: diff --git a/src/window.py b/src/window.py index 5e34973..9394020 100644 --- a/src/window.py +++ b/src/window.py @@ -179,7 +179,7 @@ class CartridgesWindow(Adw.ApplicationWindow): self.details_view_game_cover = game.game_cover self.details_view_game_cover.add_picture(self.details_view_cover) - self.details_view_blurred_cover.set_pixbuf( + self.details_view_blurred_cover.set_paintable( self.details_view_game_cover.get_blurred() )