Create GameCover class
This commit is contained in:
@@ -25,6 +25,7 @@ import sys
|
||||
|
||||
from gi.repository import GdkPixbuf, Gio, Gtk
|
||||
|
||||
from .game_cover import GameCover
|
||||
from .save_game import save_game
|
||||
|
||||
|
||||
@@ -57,9 +58,9 @@ class game(Gtk.Box): # pylint: disable=invalid-name
|
||||
self.removed = "removed" in data
|
||||
self.blacklisted = "blacklisted" in data
|
||||
|
||||
self.pixbuf = self.get_cover()
|
||||
self.game_cover = GameCover(self.cover, self.get_cover())
|
||||
self.pixbuf = self.game_cover.get_pixbuf()
|
||||
|
||||
self.cover.set_pixbuf(self.pixbuf)
|
||||
self.title.set_label(self.name)
|
||||
|
||||
self.event_contoller_motion = Gtk.EventControllerMotion.new()
|
||||
@@ -134,8 +135,7 @@ class game(Gtk.Box): # pylint: disable=invalid-name
|
||||
self.parent_widget.pixbufs[self.game_id] = pixbuf
|
||||
return pixbuf
|
||||
|
||||
# Return the placeholder pixbuf
|
||||
return self.parent_widget.placeholder_pixbuf
|
||||
return None
|
||||
|
||||
def show_play(self, _widget, *_unused):
|
||||
self.play_revealer.set_reveal_child(True)
|
||||
|
||||
44
src/game_cover.py
Normal file
44
src/game_cover.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# game_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
|
||||
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
|
||||
class GameCover:
|
||||
placeholder_pixbuf = GdkPixbuf.Pixbuf.new_from_resource_at_scale(
|
||||
"/hu/kramo/Cartridges/library_placeholder.svg", 400, 600, False
|
||||
)
|
||||
|
||||
def __init__(self, picture, pixbuf=None, path=None):
|
||||
self.picture = picture
|
||||
self.pixbuf = pixbuf
|
||||
|
||||
if path:
|
||||
self.pixbuf = GdkPixbuf.Pixbuf.new_from_file(path)
|
||||
|
||||
if not self.pixbuf:
|
||||
self.pixbuf = self.placeholder_pixbuf
|
||||
|
||||
self.update_pixbuf()
|
||||
|
||||
def get_pixbuf(self):
|
||||
return self.pixbuf
|
||||
|
||||
def update_pixbuf(self):
|
||||
self.picture.set_pixbuf(self.pixbuf)
|
||||
@@ -22,6 +22,7 @@ cartridges_sources = [
|
||||
'window.py',
|
||||
'preferences.py',
|
||||
'game.py',
|
||||
'game_cover.py',
|
||||
'utils/importer.py',
|
||||
'utils/steamgriddb.py',
|
||||
'utils/steam_parser.py',
|
||||
|
||||
@@ -24,6 +24,7 @@ import time
|
||||
|
||||
from gi.repository import Adw, GdkPixbuf, Gio, GLib, GObject, Gtk
|
||||
|
||||
from .game_cover import GameCover
|
||||
from .create_dialog import create_dialog
|
||||
from .save_cover import save_cover
|
||||
from .save_game import save_game
|
||||
@@ -61,7 +62,8 @@ def create_details_window(parent_widget, game_id=None):
|
||||
nonlocal pixbuf
|
||||
nonlocal cover_deleted
|
||||
|
||||
cover.set_pixbuf(parent_widget.placeholder_pixbuf)
|
||||
GameCover(cover)
|
||||
|
||||
cover_button_delete_revealer.set_reveal_child(False)
|
||||
pixbuf = None
|
||||
cover_deleted = True
|
||||
@@ -74,16 +76,18 @@ def create_details_window(parent_widget, game_id=None):
|
||||
margin_end=40,
|
||||
)
|
||||
|
||||
cover = Gtk.Picture.new()
|
||||
|
||||
if not game_id:
|
||||
window.set_title(_("Add New Game"))
|
||||
cover = Gtk.Picture.new_for_pixbuf(parent_widget.placeholder_pixbuf)
|
||||
GameCover(cover)
|
||||
name = Gtk.Entry()
|
||||
developer = Gtk.Entry()
|
||||
executable = Gtk.Entry()
|
||||
apply_button = Gtk.Button.new_with_label(_("Confirm"))
|
||||
else:
|
||||
window.set_title(_("Edit Game Details"))
|
||||
cover = Gtk.Picture.new_for_pixbuf(parent_widget.games[game_id].pixbuf)
|
||||
GameCover(cover, parent_widget.games[game_id].pixbuf)
|
||||
developer = Gtk.Entry.new_with_buffer(
|
||||
Gtk.EntryBuffer.new(games[game_id].developer, -1)
|
||||
)
|
||||
@@ -93,7 +97,7 @@ def create_details_window(parent_widget, game_id=None):
|
||||
)
|
||||
apply_button = Gtk.Button.new_with_label(_("Apply"))
|
||||
|
||||
if parent_widget.games[game_id].pixbuf != parent_widget.placeholder_pixbuf:
|
||||
if parent_widget.games[game_id].pixbuf:
|
||||
cover_button_delete_revealer.set_reveal_child(True)
|
||||
|
||||
image_filter = Gtk.FileFilter(name=_("Images"))
|
||||
@@ -232,7 +236,7 @@ def create_details_window(parent_widget, game_id=None):
|
||||
)
|
||||
|
||||
cover_button_delete_revealer.set_reveal_child(True)
|
||||
cover.set_pixbuf(pixbuf)
|
||||
GameCover(cover, pixbuf)
|
||||
|
||||
def close_window(_widget, _callback=None):
|
||||
window.close()
|
||||
|
||||
@@ -60,7 +60,7 @@ def get_game(task, current_time, parent_widget, row):
|
||||
task.return_value((values, None))
|
||||
return
|
||||
|
||||
cover_pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale(
|
||||
game_cover = GdkPixbuf.Pixbuf.new_from_stream_at_scale(
|
||||
tmp_file.read(), 2, 2, False
|
||||
).scale_simple(400, 600, GdkPixbuf.InterpType.BILINEAR)
|
||||
|
||||
@@ -71,7 +71,7 @@ def get_game(task, current_time, parent_widget, row):
|
||||
GdkPixbuf.InterpType.BILINEAR,
|
||||
)
|
||||
itch_pixbuf.composite(
|
||||
cover_pixbuf,
|
||||
game_cover,
|
||||
0,
|
||||
(600 - itch_pixbuf.get_height()) / 2,
|
||||
itch_pixbuf.get_width(),
|
||||
@@ -84,9 +84,9 @@ def get_game(task, current_time, parent_widget, row):
|
||||
255,
|
||||
)
|
||||
else:
|
||||
cover_pixbuf = None
|
||||
game_cover = None
|
||||
|
||||
task.return_value((values, cover_pixbuf))
|
||||
task.return_value((values, game_cover))
|
||||
|
||||
|
||||
def get_games_async(parent_widget, rows, importer):
|
||||
|
||||
@@ -25,6 +25,7 @@ from shutil import rmtree
|
||||
|
||||
from gi.repository import Adw, GdkPixbuf, Gio, GLib, Gtk
|
||||
|
||||
from .game_cover import GameCover
|
||||
from .game import game
|
||||
from .get_games import get_games
|
||||
from .save_game import save_game
|
||||
@@ -104,9 +105,6 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
self.overview.set_clip_overlay(self.overview_box, False)
|
||||
|
||||
self.schema = Gio.Settings.new("hu.kramo.Cartridges")
|
||||
self.placeholder_pixbuf = GdkPixbuf.Pixbuf.new_from_resource_at_scale(
|
||||
"/hu/kramo/Cartridges/library_placeholder.svg", 400, 600, False
|
||||
)
|
||||
games = get_games(self)
|
||||
for game_id in games:
|
||||
if "removed" in games[game_id]:
|
||||
@@ -284,7 +282,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
self.active_game_id = game_id
|
||||
|
||||
pixbuf = current_game.pixbuf
|
||||
self.overview_cover.set_pixbuf(pixbuf)
|
||||
GameCover(self.overview_cover, pixbuf)
|
||||
|
||||
self.scaled_pixbuf = pixbuf.scale_simple(2, 3, GdkPixbuf.InterpType.BILINEAR)
|
||||
self.overview_blurred_cover.set_pixbuf(self.scaled_pixbuf)
|
||||
|
||||
Reference in New Issue
Block a user