This commit is contained in:
kramo
2023-04-14 14:44:44 +02:00
parent 3da6674dbb
commit 6edd85e80a
15 changed files with 148 additions and 172 deletions

View File

@@ -45,10 +45,10 @@ class Game(Gtk.Box):
game_options = Gtk.Template.Child()
hidden_game_options = Gtk.Template.Child()
def __init__(self, parent_widget, data, **kwargs):
def __init__(self, win, data, **kwargs):
super().__init__(**kwargs)
self.parent_widget = parent_widget
self.win = win
self.added = data["added"]
self.executable = data["executable"]
self.game_id = data["game_id"]
@@ -76,7 +76,7 @@ class Game(Gtk.Box):
self.event_contoller_motion.connect("enter", self.show_play)
self.event_contoller_motion.connect("leave", self.hide_play)
self.parent_widget.schema.connect("changed", self.schema_changed)
self.win.schema.connect("changed", self.schema_changed)
if self.hidden:
self.menu_button.set_menu_model(self.hidden_game_options)
@@ -108,19 +108,19 @@ class Game(Gtk.Box):
def toggle_hidden(self):
data = json.loads(
(self.parent_widget.games_dir / f"{self.game_id}.json").read_text("utf-8")
(self.win.games_dir / f"{self.game_id}.json").read_text("utf-8")
)
data["hidden"] = not data["hidden"]
save_game(self.parent_widget, data)
save_game(self.win, data)
def get_cover_path(self):
cover_path = self.parent_widget.covers_dir / f"{self.game_id}.gif"
cover_path = self.win.covers_dir / f"{self.game_id}.gif"
if cover_path.is_file():
return cover_path
cover_path = self.parent_widget.covers_dir / f"{self.game_id}.tiff"
cover_path = self.win.covers_dir / f"{self.game_id}.tiff"
if cover_path.is_file():
return cover_path
@@ -136,23 +136,23 @@ class Game(Gtk.Box):
self.title_revealer.set_reveal_child(True)
def launch_game(self, _widget, *_unused):
self.parent_widget.set_active_game(None, None, self.game_id)
self.parent_widget.get_application().on_launch_game_action(None)
self.win.set_active_game(None, None, self.game_id)
self.win.get_application().on_launch_game_action(None)
def cover_button_clicked(self, _widget):
if self.parent_widget.schema.get_boolean("cover-launches-game"):
if self.win.schema.get_boolean("cover-launches-game"):
self.launch_game(None)
else:
self.parent_widget.show_details_view(None, self.game_id)
self.win.show_details_view(None, self.game_id)
def play_button_clicked(self, _widget):
if self.parent_widget.schema.get_boolean("cover-launches-game"):
self.parent_widget.show_details_view(None, self.game_id)
if self.win.schema.get_boolean("cover-launches-game"):
self.win.show_details_view(None, self.game_id)
else:
self.launch_game(None)
def set_play_label(self):
if self.parent_widget.schema.get_boolean("cover-launches-game"):
if self.win.schema.get_boolean("cover-launches-game"):
self.play_button.set_label(_("Details"))
else:
self.play_button.set_label(_("Play"))

View File

@@ -25,8 +25,8 @@ import yaml
from .check_install import check_install
def bottles_importer(parent_widget):
schema = parent_widget.schema
def bottles_importer(win):
schema = win.schema
location_key = "bottles-location"
bottles_dir = Path(schema.get_string(location_key)).expanduser()
check = "library.yml"
@@ -39,7 +39,7 @@ def bottles_importer(parent_widget):
/ "com.usebottles.bottles"
/ "data"
/ "bottles",
parent_widget.data_dir / "bottles",
win.data_dir / "bottles",
)
bottles_dir = check_install(check, locations, (schema, location_key))
@@ -52,7 +52,7 @@ def bottles_importer(parent_widget):
library = yaml.load(data, Loader=yaml.Loader)
importer = parent_widget.importer
importer = win.importer
importer.total_queue += len(library)
importer.queue += len(library)
@@ -62,10 +62,7 @@ def bottles_importer(parent_widget):
values["game_id"] = f'bottles_{game["id"]}'
if (
values["game_id"] in parent_widget.games
and not parent_widget.games[values["game_id"]].removed
):
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
importer.save_game()
continue

View File

@@ -26,8 +26,8 @@ from time import time
from .check_install import check_install
def heroic_importer(parent_widget):
schema = parent_widget.schema
def heroic_importer(win):
schema = win.schema
location_key = "heroic-location"
heroic_dir = Path(schema.get_string(location_key)).expanduser()
check = "config.json"
@@ -40,7 +40,7 @@ def heroic_importer(parent_widget):
/ "com.heroicgameslauncher.hgl"
/ "config"
/ "heroic",
parent_widget.config_dir / "heroic",
win.config_dir / "heroic",
)
if os.name == "nt":
@@ -50,12 +50,12 @@ def heroic_importer(parent_widget):
if not heroic_dir:
return
schema = parent_widget.schema
schema = win.schema
check = "config.json"
current_time = int(time())
importer = parent_widget.importer
importer = win.importer
# Import Epic games
if not schema.get_boolean("heroic-import-epic"):
@@ -80,8 +80,8 @@ def heroic_importer(parent_widget):
values["game_id"] = f"heroic_epic_{app_name}"
if (
values["game_id"] in parent_widget.games
and not parent_widget.games[values["game_id"]].removed
values["game_id"] in win.games
and not win.games[values["game_id"]].removed
):
importer.save_game()
continue
@@ -128,8 +128,8 @@ def heroic_importer(parent_widget):
values["game_id"] = f"heroic_gog_{app_name}"
if (
values["game_id"] in parent_widget.games
and not parent_widget.games[values["game_id"]].removed
values["game_id"] in win.games
and not win.games[values["game_id"]].removed
):
importer.save_game()
continue
@@ -176,8 +176,8 @@ def heroic_importer(parent_widget):
values["game_id"] = f"heroic_sideload_{app_name}"
if (
values["game_id"] in parent_widget.games
and not parent_widget.games[values["game_id"]].removed
values["game_id"] in win.games
and not win.games[values["game_id"]].removed
):
importer.save_game()
continue

View File

@@ -29,15 +29,12 @@ from gi.repository import GdkPixbuf, Gio
from .check_install import check_install
def get_game(task, current_time, parent_widget, row):
def get_game(task, current_time, win, row):
values = {}
values["game_id"] = f"itch_{row[0]}"
if (
values["game_id"] in parent_widget.games
and not parent_widget.games[values["game_id"]].removed
):
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
task.return_value((None, None))
return
@@ -64,23 +61,22 @@ def get_game(task, current_time, parent_widget, row):
game_cover = GdkPixbuf.Pixbuf.new_from_stream_at_scale(
tmp_file.read(), 2, 2, False
).scale_simple(*parent_widget.image_size, GdkPixbuf.InterpType.BILINEAR)
).scale_simple(*win.image_size, GdkPixbuf.InterpType.BILINEAR)
itch_pixbuf = GdkPixbuf.Pixbuf.new_from_stream(tmp_file.read())
itch_pixbuf = itch_pixbuf.scale_simple(
parent_widget.image_size[0],
itch_pixbuf.get_height()
* (parent_widget.image_size[0] / itch_pixbuf.get_width()),
win.image_size[0],
itch_pixbuf.get_height() * (win.image_size[0] / itch_pixbuf.get_width()),
GdkPixbuf.InterpType.BILINEAR,
)
itch_pixbuf.composite(
game_cover,
0,
(parent_widget.image_size[1] - itch_pixbuf.get_height()) / 2,
(win.image_size[1] - itch_pixbuf.get_height()) / 2,
itch_pixbuf.get_width(),
itch_pixbuf.get_height(),
0,
(parent_widget.image_size[1] - itch_pixbuf.get_height()) / 2,
(win.image_size[1] - itch_pixbuf.get_height()) / 2,
1.0,
1.0,
GdkPixbuf.InterpType.BILINEAR,
@@ -92,16 +88,16 @@ def get_game(task, current_time, parent_widget, row):
task.return_value((values, game_cover))
def get_games_async(parent_widget, rows, importer):
def get_games_async(win, rows, importer):
current_time = int(time())
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
def create_func(current_time, parent_widget, row):
def create_func(current_time, win, row):
def wrapper(task, *_unused):
get_game(
task,
current_time,
parent_widget,
win,
row,
)
@@ -114,11 +110,11 @@ def get_games_async(parent_widget, rows, importer):
for row in rows:
task = Gio.Task.new(None, None, update_games)
task.run_in_thread(create_func(current_time, parent_widget, row))
task.run_in_thread(create_func(current_time, win, row))
def itch_importer(parent_widget):
schema = parent_widget.schema
def itch_importer(win):
schema = win.schema
location_key = "itch-location"
itch_dir = Path(schema.get_string(location_key)).expanduser()
check = Path("db") / "butler.db"
@@ -126,7 +122,7 @@ def itch_importer(parent_widget):
if not (itch_dir / check).is_file():
locations = (
Path.home() / ".var" / "app" / "io.itch.itch" / "config" / "itch",
parent_widget.config_dir / "itch",
win.config_dir / "itch",
)
if os.name == "nt":
@@ -137,7 +133,7 @@ def itch_importer(parent_widget):
database_path = (Path(schema.get_string(location_key)) / "db").expanduser()
db_cache_dir = parent_widget.cache_dir / "cartridges" / "itch"
db_cache_dir = win.cache_dir / "cartridges" / "itch"
db_cache_dir.mkdir(parents=True, exist_ok=True)
# Copy the file because sqlite3 doesn't like databases in /run/user/
@@ -169,8 +165,8 @@ def itch_importer(parent_widget):
# No need to unlink temp files as they disappear when the connection is closed
database_tmp_path.unlink(missing_ok=True)
importer = parent_widget.importer
importer = win.importer
importer.total_queue += len(rows)
importer.queue += len(rows)
get_games_async(parent_widget, rows, importer)
get_games_async(win, rows, importer)

View File

@@ -25,8 +25,8 @@ from time import time
from .check_install import check_install
def lutris_importer(parent_widget):
schema = parent_widget.schema
def lutris_importer(win):
schema = win.schema
location_key = "lutris-location"
lutris_dir = Path(schema.get_string(location_key)).expanduser()
check = "pga.db"
@@ -34,7 +34,7 @@ def lutris_importer(parent_widget):
if not (lutris_dir / check).is_file():
locations = (
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "data" / "lutris",
parent_widget.data_dir / "lutris",
win.data_dir / "lutris",
)
lutris_dir = check_install(check, locations, (schema, location_key))
@@ -48,7 +48,7 @@ def lutris_importer(parent_widget):
if not (cache_dir / cache_check).exists():
cache_locations = (
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "cache" / "lutris",
parent_widget.cache_dir / "lutris",
win.cache_dir / "lutris",
)
cache_dir = check_install(check, cache_locations, (schema, location_key))
@@ -58,7 +58,7 @@ def lutris_importer(parent_widget):
database_path = (Path(schema.get_string(location_key))).expanduser()
cache_dir = Path(schema.get_string(cache_key)).expanduser()
db_cache_dir = parent_widget.cache_dir / "cartridges" / "lutris"
db_cache_dir = win.cache_dir / "cartridges" / "lutris"
db_cache_dir.mkdir(parents=True, exist_ok=True)
# Copy the file because sqlite3 doesn't like databases in /run/user/
@@ -92,7 +92,7 @@ def lutris_importer(parent_widget):
current_time = int(time())
importer = parent_widget.importer
importer = win.importer
importer.total_queue += len(rows)
importer.queue += len(rows)
@@ -101,10 +101,7 @@ def lutris_importer(parent_widget):
values["game_id"] = f"lutris_{row[3]}_{row[0]}"
if (
values["game_id"] in parent_widget.games
and not parent_widget.games[values["game_id"]].removed
):
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
importer.save_game()
continue

View File

@@ -42,7 +42,7 @@ def update_values_from_data(content, values):
return values
def get_game(task, datatypes, current_time, parent_widget, appmanifest, steam_dir):
def get_game(task, datatypes, current_time, win, appmanifest, steam_dir):
values = {}
data = appmanifest.read_text("utf-8")
@@ -56,10 +56,7 @@ def get_game(task, datatypes, current_time, parent_widget, appmanifest, steam_di
values["game_id"] = f'steam_{values["appid"]}'
if (
values["game_id"] in parent_widget.games
and not parent_widget.games[values["game_id"]].removed
):
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
task.return_value((None, None))
return
@@ -95,18 +92,18 @@ def get_game(task, datatypes, current_time, parent_widget, appmanifest, steam_di
task.return_value((values, image_path if image_path.exists() else None))
def get_games_async(parent_widget, appmanifests, steam_dir, importer):
def get_games_async(win, appmanifests, steam_dir, importer):
datatypes = ["appid", "name"]
current_time = int(time())
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
def create_func(datatypes, current_time, parent_widget, appmanifest, steam_dir):
def create_func(datatypes, current_time, win, appmanifest, steam_dir):
def wrapper(task, *_unused):
get_game(
task,
datatypes,
current_time,
parent_widget,
win,
appmanifest,
steam_dir,
)
@@ -121,12 +118,12 @@ def get_games_async(parent_widget, appmanifests, steam_dir, importer):
for appmanifest in appmanifests:
task = Gio.Task.new(None, None, update_games)
task.run_in_thread(
create_func(datatypes, current_time, parent_widget, appmanifest, steam_dir)
create_func(datatypes, current_time, win, appmanifest, steam_dir)
)
def steam_importer(parent_widget):
schema = parent_widget.schema
def steam_importer(win):
schema = win.schema
location_key = "steam-location"
steam_dir = Path(schema.get_string(location_key)).expanduser()
check = "steamapps"
@@ -135,8 +132,8 @@ def steam_importer(parent_widget):
subdirs = ("steam", "Steam")
locations = (
Path.home() / ".steam" / "steam",
parent_widget.data_dir / "Steam",
Path.home() / ".steam",
win.data_dir / "Steam",
Path.home() / ".var" / "app" / "com.valvesoftware.Steam" / "data" / "Steam",
)
@@ -161,8 +158,8 @@ def steam_importer(parent_widget):
if open_file.is_file() and "appmanifest" in open_file.name:
appmanifests.append(open_file)
importer = parent_widget.importer
importer = win.importer
importer.total_queue += len(appmanifests)
importer.queue += len(appmanifests)
get_games_async(parent_widget, appmanifests, directory, importer)
get_games_async(win, appmanifests, directory, importer)

View File

@@ -50,7 +50,7 @@ class ImportPreferences:
if not any((path / current_path).exists() for current_path in paths):
create_dialog(
window.parent_widget,
window.win,
_("Installation Not Found"),
# The variable is the name of the game launcher
_("Select the {} configuration directory.").format(name)
@@ -122,12 +122,12 @@ class PreferencesWindow(Adw.PreferencesWindow):
sgdb_prefer_switch = Gtk.Template.Child()
sgdb_animated_switch = Gtk.Template.Child()
def __init__(self, parent_widget, **kwargs):
def __init__(self, win, **kwargs):
super().__init__(**kwargs)
self.schema = parent_widget.schema
self.parent_widget = parent_widget
self.schema = win.schema
self.win = win
self.file_chooser = Gtk.FileDialog()
self.set_transient_for(parent_widget)
self.set_transient_for(win)
self.toast = Adw.Toast.new(_("All games removed"))
self.toast.set_button_label(_("Undo"))
@@ -233,7 +233,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
if not (path / "coverart").exists():
create_dialog(
self.parent_widget,
self.win,
_("Cache Not Found"),
_("Select the Lutris cache directory."),
"choose_folder",
@@ -348,18 +348,16 @@ class PreferencesWindow(Adw.PreferencesWindow):
)
def choose_folder(self, _widget, function):
self.file_chooser.select_folder(self.parent_widget, None, function, None)
self.file_chooser.select_folder(self.win, None, function, None)
def undo_remove_all(self, _widget, _unused):
deleted_covers_dir = (
self.parent_widget.cache_dir / "cartridges" / "deleted_covers"
)
deleted_covers_dir = self.win.cache_dir / "cartridges" / "deleted_covers"
for game_id in self.removed_games:
data = get_games(self.parent_widget, [game_id])[game_id]
data = get_games(self.win, [game_id])[game_id]
if "removed" in data:
data.pop("removed")
save_game(self.parent_widget, data)
save_game(self.win, data)
cover_path = deleted_covers_dir / f"{game_id}.tiff"
if not cover_path.is_file():
@@ -367,36 +365,31 @@ class PreferencesWindow(Adw.PreferencesWindow):
if not cover_path.is_file():
continue
move(cover_path, self.parent_widget.covers_dir, copyfile)
move(cover_path, self.win.covers_dir, copyfile)
self.parent_widget.update_games(self.removed_games)
self.win.update_games(self.removed_games)
self.removed_games = []
self.toast.dismiss()
def remove_all_games(self, _widget):
deleted_covers_dir = (
self.parent_widget.cache_dir / "cartridges" / "deleted_covers"
)
deleted_covers_dir = self.win.cache_dir / "cartridges" / "deleted_covers"
deleted_covers_dir.mkdir(parents=True, exist_ok=True)
for game in get_games(self.parent_widget).values():
for game in get_games(self.win).values():
if "removed" not in game:
self.removed_games.append(game["game_id"])
game["removed"] = True
save_game(self.parent_widget, game)
save_game(self.win, game)
cover_path = self.parent_widget.games[game["game_id"]].get_cover_path()
cover_path = self.win.games[game["game_id"]].get_cover_path()
if not cover_path:
continue
if cover_path.is_file():
move(cover_path, deleted_covers_dir, copyfile)
self.parent_widget.update_games(self.parent_widget.games)
if (
self.parent_widget.stack.get_visible_child()
== self.parent_widget.details_view
):
self.parent_widget.on_go_back_action(None, None)
self.win.update_games(self.win.games)
if self.win.stack.get_visible_child() == self.win.details_view:
self.win.on_go_back_action(None, None)
self.add_toast(self.toast)

View File

@@ -27,6 +27,6 @@ def check_install(check, locations, setting=None, subdirs=(Path(),)):
location / subdir / check
).exists():
if setting:
setting[0].set_string(setting[1], str(location))
setting[0].set_string(setting[1], str(location / subdir))
return location
return location / subdir

View File

@@ -31,12 +31,12 @@ from .save_game import save_game
from .steamgriddb import SGDBSave
def create_details_window(parent_widget, game_id=None):
def create_details_window(win, game_id=None):
window = Adw.Window(
modal=True, default_width=500, default_height=-1, transient_for=parent_widget
modal=True, default_width=500, default_height=-1, transient_for=win
)
games = parent_widget.games
games = win.games
cover_deleted = False
cover_button_edit = Gtk.Button(
@@ -85,7 +85,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"))
game_cover.new_pixbuf(path=parent_widget.games[game_id].get_cover_path())
game_cover.new_pixbuf(path=win.games[game_id].get_cover_path())
developer = Gtk.Entry.new_with_buffer(
Gtk.EntryBuffer.new(games[game_id].developer, -1)
)
@@ -95,7 +95,7 @@ def create_details_window(parent_widget, game_id=None):
)
apply_button = Gtk.Button.new_with_label(_("Apply"))
if parent_widget.games[game_id].get_cover_path():
if win.games[game_id].get_cover_path():
cover_button_delete_revealer.set_reveal_child(True)
image_filter = Gtk.FileFilter(name=_("Images"))
@@ -314,33 +314,33 @@ def create_details_window(parent_widget, game_id=None):
values["executable"] = final_executable_split
if cover_deleted:
(parent_widget.covers_dir / f"{game_id}.tiff").unlink(missing_ok=True)
(parent_widget.covers_dir / f"{game_id}.gif").unlink(missing_ok=True)
(win.covers_dir / f"{game_id}.tiff").unlink(missing_ok=True)
(win.covers_dir / f"{game_id}.gif").unlink(missing_ok=True)
save_cover(
parent_widget,
win,
game_id,
None,
game_cover.get_pixbuf(),
game_cover.get_animation(),
)
path = parent_widget.games_dir / f"{game_id}.json"
path = win.games_dir / f"{game_id}.json"
if path.exists():
data = json.loads(path.read_text("utf-8"))
data.update(values)
save_game(parent_widget, data)
save_game(win, data)
else:
save_game(parent_widget, values)
save_game(win, values)
if game_cover.get_pixbuf():
parent_widget.update_games([game_id])
win.update_games([game_id])
else:
SGDBSave(parent_widget, {(game_id, values["name"])})
SGDBSave(win, {(game_id, values["name"])})
window.close()
parent_widget.show_details_view(None, game_id)
win.show_details_view(None, game_id)
def focus_executable(_widget):
window.set_focus(executable)

View File

@@ -20,8 +20,8 @@
from gi.repository import Adw
def create_dialog(parent_widget, heading, body, extra_option=None, extra_label=None):
dialog = Adw.MessageDialog.new(parent_widget, heading, body)
def create_dialog(win, heading, body, extra_option=None, extra_label=None):
dialog = Adw.MessageDialog.new(win, heading, body)
dialog.add_response("dismiss", _("Dismiss"))
if extra_option:

View File

@@ -20,18 +20,16 @@
import json
def get_games(parent_widget, game_ids=None):
def get_games(win, game_ids=None):
games = {}
if not parent_widget.games_dir.exists():
if not win.games_dir.exists():
return {}
if game_ids:
game_files = [
parent_widget.games_dir / f"{game_id}.json" for game_id in game_ids
]
game_files = [win.games_dir / f"{game_id}.json" for game_id in game_ids]
else:
game_files = parent_widget.games_dir.iterdir()
game_files = win.games_dir.iterdir()
for game in game_files:
data = json.loads(game.read_text("utf-8"))

View File

@@ -28,8 +28,8 @@ from .steamgriddb import SGDBSave
class Importer:
def __init__(self, parent_widget):
self.parent_widget = parent_widget
def __init__(self, win):
self.win = win
self.total_queue = 0
self.queue = 0
self.games_no = 0
@@ -48,7 +48,7 @@ class Importer:
modal=True,
default_width=350,
default_height=-1,
transient_for=parent_widget,
transient_for=win,
deletable=False,
)
@@ -56,10 +56,10 @@ class Importer:
def save_game(self, values=None, cover_path=None, pixbuf=None):
if values:
save_game(self.parent_widget, values)
save_game(self.win, values)
if cover_path or pixbuf:
save_cover(self.parent_widget, values["game_id"], cover_path, pixbuf)
save_cover(self.win, values["game_id"], cover_path, pixbuf)
self.games.add((values["game_id"], values["name"]))
@@ -76,7 +76,7 @@ class Importer:
self.queue = len(self.games)
self.import_statuspage.set_title(_("Importing Covers…"))
self.update_progressbar()
SGDBSave(self.parent_widget, self.games, self)
SGDBSave(self.win, self.games, self)
else:
self.done()
@@ -87,7 +87,7 @@ class Importer:
if self.games_no == 0:
create_dialog(
self.parent_widget,
self.win,
_("No Games Found"),
_("No new games were found on your system."),
"open_preferences",
@@ -96,14 +96,14 @@ class Importer:
elif self.games_no == 1:
create_dialog(
self.parent_widget,
self.win,
_("Game Imported"),
_("Successfully imported 1 game."),
).connect("response", self.response, "import")
elif self.games_no > 1:
games_no = self.games_no
create_dialog(
self.parent_widget,
self.win,
_("Games Imported"),
# The variable is the number of games
_("Successfully imported {} games.").format(games_no),
@@ -111,12 +111,12 @@ class Importer:
def response(self, _widget, response, page_name=None, expander_row=None):
if response == "open_preferences":
self.parent_widget.get_application().on_preferences_action(
self.win.get_application().on_preferences_action(
None, page_name=page_name, expander_row=expander_row
)
elif self.sgdb_exception:
create_dialog(
self.parent_widget,
self.win,
_("Couldn't Connect to SteamGridDB"),
self.sgdb_exception,
"open_preferences",
@@ -124,12 +124,12 @@ class Importer:
).connect("response", self.response, "sgdb")
self.sgdb_exception = None
elif (
self.parent_widget.schema.get_boolean("steam")
and self.parent_widget.schema.get_boolean("steam-extra-dirs-hint")
and not self.parent_widget.schema.get_strv("steam-extra-dirs")
self.win.schema.get_boolean("steam")
and self.win.schema.get_boolean("steam-extra-dirs-hint")
and not self.win.schema.get_strv("steam-extra-dirs")
):
steam_library_path = (
Path(self.parent_widget.schema.get_string("steam-location"))
Path(self.win.schema.get_string("steam-location"))
/ "steamapps"
/ "libraryfolders.vdf"
)
@@ -137,9 +137,9 @@ class Importer:
steam_library_path.exists()
and steam_library_path.read_text("utf-8").count('"path"') > 1
):
self.parent_widget.schema.set_boolean("steam-extra-dirs-hint", False)
self.win.schema.set_boolean("steam-extra-dirs-hint", False)
create_dialog(
self.parent_widget,
self.win,
_("Extra Steam Libraries"),
_(
"Looks like you have multiple Steam libraries. Would you like to add them in preferences?"

View File

@@ -43,32 +43,32 @@ def resize_animation(cover_path):
def save_cover(
parent_widget,
win,
game_id,
cover_path=None,
pixbuf=None,
animation_path=None,
):
parent_widget.covers_dir.mkdir(parents=True, exist_ok=True)
win.covers_dir.mkdir(parents=True, exist_ok=True)
# Remove previous covers
(parent_widget.covers_dir / f"{game_id}.tiff").unlink(missing_ok=True)
(parent_widget.covers_dir / f"{game_id}.gif").unlink(missing_ok=True)
(win.covers_dir / f"{game_id}.tiff").unlink(missing_ok=True)
(win.covers_dir / f"{game_id}.gif").unlink(missing_ok=True)
if animation_path:
copyfile(animation_path, parent_widget.covers_dir / f"{game_id}.gif")
copyfile(animation_path, win.covers_dir / f"{game_id}.gif")
return
if not pixbuf:
if not cover_path:
return
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
str(cover_path), *parent_widget.image_size, False
str(cover_path), *win.image_size, False
)
pixbuf.savev(
str(parent_widget.covers_dir / f"{game_id}.tiff"),
str(win.covers_dir / f"{game_id}.tiff"),
"tiff",
["compression"],
["8"] if parent_widget.schema.get_boolean("high-quality-images") else ["7"],
["8"] if win.schema.get_boolean("high-quality-images") else ["7"],
)

View File

@@ -20,9 +20,9 @@
import json
def save_game(parent_widget, game):
parent_widget.games_dir.mkdir(parents=True, exist_ok=True)
def save_game(win, game):
win.games_dir.mkdir(parents=True, exist_ok=True)
(parent_widget.games_dir / f'{game["game_id"]}.json').write_text(
(win.games_dir / f'{game["game_id"]}.json').write_text(
json.dumps(game, indent=4, sort_keys=True), "utf-8"
)

View File

@@ -8,8 +8,8 @@ from .save_cover import save_cover, resize_animation
class SGDBSave:
def __init__(self, parent_widget, games, importer=None):
self.parent_widget = parent_widget
def __init__(self, win, games, importer=None):
self.win = win
self.importer = importer
self.exception = None
@@ -27,19 +27,19 @@ class SGDBSave:
Gio.Task.new(None, None, self.task_done).run_in_thread(create_func(game))
def update_cover(self, task, game):
if self.parent_widget.schema.get_boolean("sgdb") and (
self.parent_widget.schema.get_boolean("sgdb-prefer")
if self.win.schema.get_boolean("sgdb") and (
self.win.schema.get_boolean("sgdb-prefer")
or (
not (self.parent_widget.covers_dir / f"{game[0]}.gif").is_file()
and not (self.parent_widget.covers_dir / f"{game[0]}.tiff").is_file()
not (self.win.covers_dir / f"{game[0]}.gif").is_file()
and not (self.win.covers_dir / f"{game[0]}.tiff").is_file()
)
):
if not self.importer:
self.parent_widget.games[game[0]].set_loading(1)
self.win.games[game[0]].set_loading(1)
url = "https://www.steamgriddb.com/api/v2/"
headers = {
"Authorization": f'Bearer {self.parent_widget.schema.get_string("sgdb-key")}'
"Authorization": f'Bearer {self.win.schema.get_string("sgdb-key")}'
}
try:
@@ -63,7 +63,7 @@ class SGDBSave:
response = None
try:
if self.parent_widget.schema.get_boolean("sgdb-animated"):
if self.win.schema.get_boolean("sgdb-animated"):
try:
grid = requests.get(
f'{url}grids/game/{search_result.json()["data"][0]["id"]}?dimensions=600x900&types=animated',
@@ -91,7 +91,7 @@ class SGDBSave:
Path(tmp_file.get_path()).write_bytes(response.content)
save_cover(
self.parent_widget,
self.win,
game[0],
tmp_file.get_path(),
animation_path=resize_animation(tmp_file.get_path())
@@ -109,7 +109,7 @@ class SGDBSave:
if self.exception:
create_dialog(
self.parent_widget,
self.win,
_("Couldn't Connect to SteamGridDB"),
self.exception,
"open_preferences",
@@ -117,10 +117,8 @@ class SGDBSave:
).connect("response", self.response)
game_id = result.propagate_value()[1]
self.parent_widget.update_games([game_id])
self.win.update_games([game_id])
def response(self, _widget, response):
if response == "open_preferences":
self.parent_widget.get_application().on_preferences_action(
None, page_name="sgdb"
)
self.win.get_application().on_preferences_action(None, page_name="sgdb")