Remove redundant get_cover function

This commit is contained in:
kramo
2023-03-24 23:09:56 +01:00
parent fc2932f7dd
commit 6b103c996b
5 changed files with 27 additions and 47 deletions

View File

@@ -17,9 +17,9 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
from gi.repository import Gtk
import os
from .get_cover import get_cover
from gi.repository import GdkPixbuf, Gtk
@Gtk.Template(resource_path="/hu/kramo/Cartridges/gtk/game.ui")
@@ -50,7 +50,7 @@ class game(Gtk.Box): # pylint: disable=invalid-name
self.removed = "removed" in data.keys()
self.blacklisted = "blacklisted" in data.keys()
self.pixbuf = get_cover(self.game_id, self.parent_widget)
self.pixbuf = self.get_cover()
self.cover.set_pixbuf(self.pixbuf)
self.title.set_label(self.name)
@@ -64,6 +64,27 @@ class game(Gtk.Box): # pylint: disable=invalid-name
self.event_contoller_motion.connect("leave", self.hide_play)
self.menu_button.get_popover().connect("notify::visible", self.hide_play)
def get_cover(self):
# If the cover is already in memory, return
if self.game_id in self.parent_widget.pixbufs.keys():
return self.parent_widget.pixbufs[self.game_id]
# Create a new pixbuf
cover_path = os.path.join(
os.getenv("XDG_DATA_HOME")
or os.path.expanduser(os.path.join("~", ".local", "share")),
"cartridges",
"covers",
f"{self.game_id}.tiff",
)
if os.path.isfile(cover_path):
return GdkPixbuf.Pixbuf.new_from_file(cover_path)
# Return the placeholder pixbuf
return self.parent_widget.placeholder_pixbuf
def show_play(self, _widget, *_unused):
self.play_revealer.set_reveal_child(True)
self.title_revealer.set_reveal_child(False)

View File

@@ -27,7 +27,6 @@ cartridges_sources = [
'utils/bottles_parser.py',
'utils/run_command.py',
'utils/get_games.py',
'utils/get_cover.py',
'utils/save_games.py',
'utils/save_cover.py',
'utils/toggle_hidden.py',

View File

@@ -25,7 +25,6 @@ import time
from gi.repository import Adw, GdkPixbuf, Gio, GLib, GObject, Gtk
from .create_dialog import create_dialog
from .get_cover import get_cover
from .save_cover import save_cover
from .save_games import save_games
@@ -47,7 +46,7 @@ def create_details_window(parent_widget, game_id=None):
apply_button = Gtk.Button.new_with_label(_("Confirm"))
else:
window.set_title(_("Edit Game Details"))
cover = Gtk.Picture.new_for_pixbuf(get_cover(game_id, parent_widget))
cover = Gtk.Picture.new_for_pixbuf(parent_widget.games[game_id].pixbuf)
developer = Gtk.Entry.new_with_buffer(
Gtk.EntryBuffer.new(games[game_id].developer, -1)
)

View File

@@ -1,39 +0,0 @@
# get_cover.py
#
# Copyright 2022-2023 kramo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
import os
from gi.repository import GdkPixbuf
def get_cover(game_id, parent_widget):
if game_id in parent_widget.pixbufs.keys():
return parent_widget.pixbufs[game_id]
cover_path = os.path.join(
os.getenv("XDG_DATA_HOME")
or os.path.expanduser(os.path.join("~", ".local", "share")),
"cartridges",
"covers",
f"{game_id}.tiff",
)
if os.path.isfile(cover_path):
return GdkPixbuf.Pixbuf.new_from_file(cover_path)
return parent_widget.placeholder_pixbuf

View File

@@ -23,7 +23,6 @@ import os
from gi.repository import Adw, GdkPixbuf, Gio, GLib, Gtk
from .game import game
from .get_cover import get_cover
from .get_games import get_games
from .save_games import save_games
@@ -252,7 +251,8 @@ class CartridgesWindow(Adw.ApplicationWindow):
self.stack.set_visible_child(self.overview)
self.active_game_id = game_id
pixbuf = get_cover(self.active_game_id, self)
pixbuf = current_game.pixbuf
self.overview_cover.set_pixbuf(pixbuf)
self.overview_blurred_cover.set_pixbuf(
pixbuf.scale_simple(2, 3, GdkPixbuf.InterpType.BILINEAR)