diff --git a/src/main.py b/src/main.py index 15ff0f4..0d8fa92 100644 --- a/src/main.py +++ b/src/main.py @@ -65,7 +65,6 @@ class CartridgesApplication(Adw.Application): self.win = None def do_activate(self): - # Create the main window self.win = self.props.active_window if not self.win: @@ -149,7 +148,6 @@ class CartridgesApplication(Adw.Application): self.win.update_games(games.keys()) def on_launch_game_action(self, _widget, _callback=None): - # Launch the game and update the last played value game_id = self.win.active_game_id @@ -178,7 +176,6 @@ class CartridgesApplication(Adw.Application): create_details_window(self.win) def on_remove_game_action(self, _widget, _callback=None): - # Add "removed=True" to the game properties so it can be deleted on next init game_id = self.win.active_game_id diff --git a/src/utils/bottles_parser.py b/src/utils/bottles_parser.py index a7a3827..a29b33b 100644 --- a/src/utils/bottles_parser.py +++ b/src/utils/bottles_parser.py @@ -84,9 +84,7 @@ def bottles_parser(parent_widget, action): _("Set Bottles Location"), ).connect("response", response) - if os.path.isfile(os.path.join(bottles_dir, "library.yml")): - pass - else: + if not os.path.isfile(os.path.join(bottles_dir, "library.yml")): bottles_not_found() return {} @@ -137,7 +135,7 @@ def bottles_parser(parent_widget, action): bottles_games[values["game_id"]] = values - if len(bottles_games) == 0: + if not bottles_games: create_dialog( parent_widget, _("No Games Found"), diff --git a/src/utils/create_details_window.py b/src/utils/create_details_window.py index 556dcc3..0ca5137 100644 --- a/src/utils/create_details_window.py +++ b/src/utils/create_details_window.py @@ -202,7 +202,6 @@ def create_details_window(parent_widget, game_id=None): final_executable = executable.get_buffer().get_text() if game_id is None: - if final_name == "": create_dialog( window, _("Couldn't Add Game"), _("Game title cannot be empty.") @@ -223,7 +222,7 @@ def create_details_window(parent_widget, game_id=None): if "imported_" in game: numbers.append(int(game.replace("imported_", ""))) - game_id = "imported_" + str(max(numbers) + 1) + game_id = f"imported_{str(max(numbers) + 1)}" values["game_id"] = game_id values["hidden"] = False @@ -252,7 +251,7 @@ def create_details_window(parent_widget, game_id=None): save_cover(None, parent_widget, None, pixbuf, game_id) values["name"] = final_name - values["developer"] = final_developer if final_developer else None + values["developer"] = final_developer or None values["executable"] = final_executable path = os.path.join( @@ -261,7 +260,7 @@ def create_details_window(parent_widget, game_id=None): or os.path.expanduser(os.path.join("~", ".local", "share")), "cartridges", "games", - game_id + ".json", + f"{game_id}.json", ) ) diff --git a/src/utils/get_cover.py b/src/utils/get_cover.py index 65d6ac7..cfe6730 100644 --- a/src/utils/get_cover.py +++ b/src/utils/get_cover.py @@ -31,10 +31,9 @@ def get_cover(game_id, parent_widget): or os.path.expanduser(os.path.join("~", ".local", "share")), "cartridges", "covers", - game_id + ".tiff", + f"{game_id}.tiff", ) - if not os.path.isfile(cover_path): - return parent_widget.placeholder_pixbuf - - return GdkPixbuf.Pixbuf.new_from_file(cover_path) + if os.path.isfile(cover_path): + return GdkPixbuf.Pixbuf.new_from_file(cover_path) + return parent_widget.placeholder_pixbuf diff --git a/src/utils/get_games.py b/src/utils/get_games.py index db892dc..d2e0423 100644 --- a/src/utils/get_games.py +++ b/src/utils/get_games.py @@ -33,12 +33,10 @@ def get_games(game_ids=None): if not os.path.exists(games_dir): return {} - if not game_ids: - game_files = os.listdir(games_dir) + if game_ids: + game_files = [f"{game_id}.json" for game_id in game_ids] else: - game_files = [] - for game_id in game_ids: - game_files.append(game_id + ".json") + game_files = os.listdir(games_dir) for game in game_files: with open(os.path.join(games_dir, game), "r") as open_file: diff --git a/src/utils/heroic_parser.py b/src/utils/heroic_parser.py index 73452dd..78aa852 100644 --- a/src/utils/heroic_parser.py +++ b/src/utils/heroic_parser.py @@ -90,9 +90,7 @@ def heroic_parser(parent_widget, action): _("Set Heroic Location"), ).connect("response", response) - if os.path.exists(os.path.join(heroic_dir, "config.json")): - pass - else: + if not os.path.exists(os.path.join(heroic_dir, "config.json")): heroic_not_found() return {} @@ -120,7 +118,7 @@ def heroic_parser(parent_widget, action): values = {} app_name = game["app_name"] - values["game_id"] = "heroic_epic_" + app_name + values["game_id"] = f"heroic_epic_{app_name}" if ( values["game_id"] in parent_widget.games @@ -131,9 +129,9 @@ def heroic_parser(parent_widget, action): values["name"] = game["title"] values["developer"] = game["developer"] values["executable"] = ( - "start heroic://launch/" + app_name + f"start heroic://launch/{app_name}" if os.name == "nt" - else "xdg-open heroic://launch/" + app_name + else f"xdg-open heroic://launch/{app_name}" ) values["hidden"] = False values["source"] = "heroic_epic" @@ -168,7 +166,7 @@ def heroic_parser(parent_widget, action): values = {} app_name = item["appName"] - values["game_id"] = "heroic_gog_" + app_name + values["game_id"] = f"heroic_gog_{app_name}" if ( values["game_id"] in parent_widget.games @@ -197,9 +195,9 @@ def heroic_parser(parent_widget, action): break values["executable"] = ( - "start heroic://launch/" + app_name + f"start heroic://launch/{app_name}" if os.name == "nt" - else "xdg-open heroic://launch/" + app_name + else f"xdg-open heroic://launch/{app_name}" ) values["hidden"] = False values["source"] = "heroic_gog" @@ -222,7 +220,7 @@ def heroic_parser(parent_widget, action): values = {} app_name = item["app_name"] - values["game_id"] = "heroic_sideload_" + app_name + values["game_id"] = f"heroic_sideload_{app_name}" if ( values["game_id"] in parent_widget.games @@ -232,9 +230,9 @@ def heroic_parser(parent_widget, action): values["name"] = item["title"] values["executable"] = ( - "start heroic://launch/" + app_name + f"start heroic://launch/{app_name}" if os.name == "nt" - else "xdg-open heroic://launch/" + app_name + else f"xdg-open heroic://launch/{app_name}" ) values["hidden"] = False values["source"] = "heroic_sideload" @@ -250,7 +248,7 @@ def heroic_parser(parent_widget, action): heroic_games[values["game_id"]] = values - if len(heroic_games) == 0: + if not heroic_games: create_dialog( parent_widget, _("No Games Found"), diff --git a/src/utils/run_command.py b/src/utils/run_command.py index 11d8756..1400128 100644 --- a/src/utils/run_command.py +++ b/src/utils/run_command.py @@ -26,7 +26,7 @@ from gi.repository import Gio def run_command(executable): subprocess.Popen( - ["flatpak-spawn --host " + executable] + [f"flatpak-spawn --host {executable}"] if os.getenv("FLATPAK_ID") == "hu.kramo.Cartridges" else executable.split() if os.name == "nt" diff --git a/src/utils/save_cover.py b/src/utils/save_cover.py index 7c5e395..c0d9c2c 100644 --- a/src/utils/save_cover.py +++ b/src/utils/save_cover.py @@ -42,7 +42,7 @@ def save_cover(game, parent_widget, file_path, pixbuf=None, game_id=None): if not os.path.exists(covers_dir): os.makedirs(covers_dir) - open_file = Gio.File.new_for_path(os.path.join(covers_dir, game_id + ".tiff")) + open_file = Gio.File.new_for_path(os.path.join(covers_dir, f"{game_id}.tiff")) parent_widget.pixbufs[game_id] = pixbuf pixbuf.save_to_streamv_async( open_file.replace(None, False, Gio.FileCreateFlags.NONE), diff --git a/src/utils/save_games.py b/src/utils/save_games.py index 270e2a9..858f08c 100644 --- a/src/utils/save_games.py +++ b/src/utils/save_games.py @@ -33,6 +33,6 @@ def save_games(games): os.makedirs(games_dir) for game in games: - with open(os.path.join(games_dir, game + ".json"), "w") as open_file: + with open(os.path.join(games_dir, f"{game}.json"), "w") as open_file: open_file.write(json.dumps(games[game], indent=4, sort_keys=True)) open_file.close() diff --git a/src/utils/toggle_hidden.py b/src/utils/toggle_hidden.py index 19ef822..9a69246 100644 --- a/src/utils/toggle_hidden.py +++ b/src/utils/toggle_hidden.py @@ -32,12 +32,12 @@ def toggle_hidden(game): if not os.path.exists(games_dir): return - with open(os.path.join(games_dir, game + ".json"), "r") as open_file: + with open(os.path.join(games_dir, f"{game}.json"), "r") as open_file: data = json.loads(open_file.read()) open_file.close() data["hidden"] = not data["hidden"] - with open(os.path.join(games_dir, game + ".json"), "w") as open_file: + with open(os.path.join(games_dir, f"{game}.json"), "w") as open_file: open_file.write(json.dumps(data, indent=4)) open_file.close() diff --git a/src/window.py b/src/window.py index 069cbc9..c536cf5 100644 --- a/src/window.py +++ b/src/window.py @@ -97,7 +97,7 @@ class CartridgesWindow(Adw.ApplicationWindow): or os.path.expanduser(os.path.join("~", ".local", "share")), "cartridges", "games", - current_game + ".json", + f"{current_game}.json", ) ) try: @@ -107,7 +107,7 @@ class CartridgesWindow(Adw.ApplicationWindow): or os.path.expanduser(os.path.join("~", ".local", "share")), "cartridges", "covers", - current_game + ".dat", + f"{current_game}.dat", ) ) except FileNotFoundError: @@ -290,36 +290,28 @@ class CartridgesWindow(Adw.ApplicationWindow): name2 = child2.get_first_child().name.lower() if name1 > name2: return -1 - if name1 < name2: - return 1 - return self.a_z_sort(child1, child2) + return 1 if name1 < name2 else self.a_z_sort(child1, child2) def newest_sort(self, child1, child2): time1 = self.games[child1.get_first_child().game_id].added time2 = self.games[child2.get_first_child().game_id].added if time1 > time2: return -1 - if time1 < time2: - return 1 - return self.a_z_sort(child1, child2) + return 1 if time1 < time2 else self.a_z_sort(child1, child2) def oldest_sort(self, child1, child2): time1 = self.games[child1.get_first_child().game_id].added time2 = self.games[child2.get_first_child().game_id].added if time1 > time2: return 1 - if time1 < time2: - return -1 - return self.a_z_sort(child1, child2) + return -1 if time1 < time2 else self.a_z_sort(child1, child2) def last_played_sort(self, child1, child2): time1 = self.games[child1.get_first_child().game_id].last_played time2 = self.games[child2.get_first_child().game_id].last_played if time1 > time2: return -1 - if time1 < time2: - return 1 - return self.a_z_sort(child1, child2) + return 1 if time1 < time2 else self.a_z_sort(child1, child2) def on_go_back_action(self, _widget, _unused, _x=None, _y=None): if self.stack.get_visible_child() == self.hidden_library_view: