Refactor to use pathlib

This commit is contained in:
kramo
2023-04-01 11:33:48 +02:00
parent 397f267522
commit 3bcbf8457c
13 changed files with 169 additions and 266 deletions

View File

@@ -105,22 +105,17 @@ class game(Gtk.Box): # pylint: disable=invalid-name
sys.exit()
def toggle_hidden(self):
games_dir = os.path.join(
os.getenv("XDG_DATA_HOME")
or os.path.expanduser(os.path.join("~", ".local", "share")),
"cartridges",
"games",
)
games_dir = self.parent_widget.data_dir / "cartridges" / "games"
if not os.path.exists(games_dir):
if not games_dir.exists():
return
with open(os.path.join(games_dir, f"{self.game_id}.json"), "r") as open_file:
with open((games_dir / f"{self.game_id}.json") / "r") as open_file:
data = json.loads(open_file.read())
data["hidden"] = not data["hidden"]
save_game(data)
save_game(self.parent_widget, data)
def get_cover(self):
@@ -129,16 +124,15 @@ class game(Gtk.Box): # pylint: disable=invalid-name
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",
cover_path = (
self.parent_widget.data_dir
/ "cartridges"
/ "covers"
/ f"{self.game_id}.tiff"
)
if os.path.isfile(cover_path):
return GdkPixbuf.Pixbuf.new_from_file(cover_path)
if cover_path.is_file():
return GdkPixbuf.Pixbuf.new_from_file(str(cover_path))
# Return the placeholder pixbuf
return self.parent_widget.placeholder_pixbuf