Move shared values to shared

This commit is contained in:
kramo
2023-05-21 17:28:29 +02:00
parent ab21e8b38b
commit 203393dea0
14 changed files with 186 additions and 154 deletions

View File

@@ -19,6 +19,7 @@
from gi.repository import Adw, GLib, Gtk
from . import shared
from .create_dialog import create_dialog
from .game import Game
from .save_cover import resize_cover, save_cover
@@ -26,8 +27,8 @@ from .steamgriddb import SGDBSave
class Importer:
def __init__(self, win):
self.win = win
def __init__(self):
self.win = shared.win
self.total_queue = 0
self.queue = 0
self.games_no = 0
@@ -46,7 +47,7 @@ class Importer:
modal=True,
default_width=350,
default_height=-1,
transient_for=win,
transient_for=self.win,
deletable=False,
)
@@ -54,10 +55,10 @@ class Importer:
def save_game(self, values=None, cover_path=None):
if values:
game = Game(self.win, values)
game = Game(values)
if save_cover:
save_cover(self.win, game.game_id, resize_cover(self.win, cover_path))
save_cover(game.game_id, resize_cover(cover_path))
self.games.add(game)
@@ -74,7 +75,7 @@ class Importer:
self.queue = len(self.games)
self.import_statuspage.set_title(_("Importing Covers…"))
self.update_progressbar()
SGDBSave(self.win, self.games, self)
SGDBSave(self.games, self)
else:
self.done()

View File

@@ -27,7 +27,7 @@ from PIL import Image, ImageSequence
from . import shared
def resize_cover(win, cover_path=None, pixbuf=None):
def resize_cover(cover_path=None, pixbuf=None):
if not cover_path and not pixbuf:
return None
@@ -55,7 +55,7 @@ def resize_cover(win, cover_path=None, pixbuf=None):
image = image.convert("RGBA")
tmp_path = Path(Gio.File.new_tmp("XXXXXX.tiff")[0].get_path())
image.resize(win.image_size).save(
image.resize(shared.image_size).save(
tmp_path,
compression="tiff_adobe_deflate"
if shared.schema.get_boolean("high-quality-images")
@@ -65,11 +65,11 @@ def resize_cover(win, cover_path=None, pixbuf=None):
return tmp_path
def save_cover(win, game_id, cover_path):
win.covers_dir.mkdir(parents=True, exist_ok=True)
def save_cover(game_id, cover_path):
shared.covers_dir.mkdir(parents=True, exist_ok=True)
animated_path = win.covers_dir / f"{game_id}.gif"
static_path = win.covers_dir / f"{game_id}.tiff"
animated_path = shared.covers_dir / f"{game_id}.gif"
static_path = shared.covers_dir / f"{game_id}.tiff"
# Remove previous covers
animated_path.unlink(missing_ok=True)
@@ -83,7 +83,7 @@ def save_cover(win, game_id, cover_path):
animated_path if cover_path.suffix == ".gif" else static_path,
)
if game_id in win.game_covers:
win.game_covers[game_id].new_cover(
if game_id in shared.win.game_covers:
shared.win.game_covers[game_id].new_cover(
animated_path if cover_path.suffix == ".gif" else static_path
)

View File

@@ -9,8 +9,8 @@ from .save_cover import save_cover, resize_cover
class SGDBSave:
def __init__(self, win, games, importer=None):
self.win = win
def __init__(self, games, importer=None):
self.win = shared.win
self.importer = importer
self.exception = None
@@ -36,8 +36,8 @@ class SGDBSave:
and (
(shared.schema.get_boolean("sgdb-prefer"))
or not (
(self.win.covers_dir / f"{game.game_id}.gif").is_file()
or (self.win.covers_dir / f"{game.game_id}.tiff").is_file()
(shared.covers_dir / f"{game.game_id}.gif").is_file()
or (shared.covers_dir / f"{game.game_id}.tiff").is_file()
)
)
)
@@ -94,9 +94,8 @@ class SGDBSave:
Path(tmp_file.get_path()).write_bytes(response.content)
save_cover(
self.win,
game.game_id,
resize_cover(self.win, tmp_file.get_path()),
resize_cover(tmp_file.get_path()),
)
task.return_value(game)