Refactor to use pathlib
This commit is contained in:
28
src/game.py
28
src/game.py
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user