Update code style
This commit is contained in:
@@ -22,9 +22,9 @@ from gi.repository import Gtk
|
||||
from .get_cover import get_cover
|
||||
|
||||
|
||||
@Gtk.Template(resource_path='/hu/kramo/Cartridges/gtk/game.ui')
|
||||
@Gtk.Template(resource_path="/hu/kramo/Cartridges/gtk/game.ui")
|
||||
class game(Gtk.Box):
|
||||
__gtype_name__ = 'game'
|
||||
__gtype_name__ = "game"
|
||||
|
||||
overlay = Gtk.Template.Child()
|
||||
title = Gtk.Template.Child()
|
||||
|
||||
81
src/main.py
81
src/main.py
@@ -41,10 +41,14 @@ from .window import CartridgesWindow
|
||||
|
||||
class CartridgesApplication(Adw.Application):
|
||||
def __init__(self):
|
||||
super().__init__(application_id="hu.kramo.Cartridges", flags=Gio.ApplicationFlags.FLAGS_NONE)
|
||||
super().__init__(
|
||||
application_id="hu.kramo.Cartridges", flags=Gio.ApplicationFlags.FLAGS_NONE
|
||||
)
|
||||
self.create_action("quit", self.on_quit_action, ["<primary>q"])
|
||||
self.create_action("about", self.on_about_action)
|
||||
self.create_action("preferences", self.on_preferences_action, ["<primary>comma"])
|
||||
self.create_action(
|
||||
"preferences", self.on_preferences_action, ["<primary>comma"]
|
||||
)
|
||||
self.create_action("steam_import", self.on_steam_import_action)
|
||||
self.create_action("heroic_import", self.on_heroic_import_action)
|
||||
self.create_action("bottles_import", self.on_bottles_import_action)
|
||||
@@ -63,39 +67,62 @@ class CartridgesApplication(Adw.Application):
|
||||
|
||||
# Save window geometry
|
||||
state_settings = Gio.Settings(schema_id="hu.kramo.Cartridge.State")
|
||||
state_settings.bind("width", self.win, "default-width", Gio.SettingsBindFlags.DEFAULT)
|
||||
state_settings.bind("height", self.win, "default-height", Gio.SettingsBindFlags.DEFAULT)
|
||||
state_settings.bind("is-maximized", self.win, "maximized", Gio.SettingsBindFlags.DEFAULT)
|
||||
state_settings.bind(
|
||||
"width", self.win, "default-width", Gio.SettingsBindFlags.DEFAULT
|
||||
)
|
||||
state_settings.bind(
|
||||
"height", self.win, "default-height", Gio.SettingsBindFlags.DEFAULT
|
||||
)
|
||||
state_settings.bind(
|
||||
"is-maximized", self.win, "maximized", Gio.SettingsBindFlags.DEFAULT
|
||||
)
|
||||
|
||||
self.win.present()
|
||||
|
||||
# Create actions for the main window
|
||||
self.create_action("show_hidden", self.win.on_show_hidden_action, ["<primary>h"], self.win)
|
||||
self.create_action("go_back", self.win.on_go_back_action, ["<alt>Left"], self.win)
|
||||
self.create_action("go_to_parent", self.win.on_go_to_parent_action, ["<alt>Up"], self.win)
|
||||
self.create_action("toggle_search", self.win.on_toggle_search_action, ["<primary>f"], self.win)
|
||||
self.create_action(
|
||||
"show_hidden", self.win.on_show_hidden_action, ["<primary>h"], self.win
|
||||
)
|
||||
self.create_action(
|
||||
"go_back", self.win.on_go_back_action, ["<alt>Left"], self.win
|
||||
)
|
||||
self.create_action(
|
||||
"go_to_parent", self.win.on_go_to_parent_action, ["<alt>Up"], self.win
|
||||
)
|
||||
self.create_action(
|
||||
"toggle_search", self.win.on_toggle_search_action, ["<primary>f"], self.win
|
||||
)
|
||||
self.create_action("escape", self.win.on_escape_action, ["Escape"], self.win)
|
||||
self.create_action("undo_remove", self.win.on_undo_remove_action, ["<primary>z"], self.win)
|
||||
self.create_action(
|
||||
"undo_remove", self.win.on_undo_remove_action, ["<primary>z"], self.win
|
||||
)
|
||||
self.create_action("open_menu", self.win.on_open_menu_action, ["F10"], self.win)
|
||||
self.win.sort = Gio.SimpleAction.new_stateful("sort_by", GLib.VariantType.new("s"), GLib.Variant("s", "a-z"))
|
||||
self.win.sort = Gio.SimpleAction.new_stateful(
|
||||
"sort_by", GLib.VariantType.new("s"), GLib.Variant("s", "a-z")
|
||||
)
|
||||
self.win.add_action(self.win.sort)
|
||||
self.win.sort.connect("activate", self.win.on_sort_action)
|
||||
self.win.on_sort_action(self.win.sort, state_settings.get_value("sort-mode"))
|
||||
|
||||
def on_about_action(self, widget, callback=None):
|
||||
about = Adw.AboutWindow(transient_for=self.win,
|
||||
application_name=_("Cartridges"),
|
||||
application_icon="hu.kramo.Cartridges",
|
||||
developer_name="kramo",
|
||||
version="0.1.2",
|
||||
developers=["kramo https://kramo.hu", "Paweł Lidwin https://github.com/imLinguin"],
|
||||
designers=["kramo https://kramo.hu"],
|
||||
copyright="© 2022 kramo",
|
||||
license_type=Gtk.License.GPL_3_0,
|
||||
issue_url="https://github.com/kra-mo/cartridges/issues/new",
|
||||
website="https://github.com/kra-mo/cartridges",
|
||||
# Translators: Replace this with your name for it to show up in the about window.
|
||||
translator_credits=_("translator_credits"))
|
||||
about = Adw.AboutWindow(
|
||||
transient_for=self.win,
|
||||
application_name=_("Cartridges"),
|
||||
application_icon="hu.kramo.Cartridges",
|
||||
developer_name="kramo",
|
||||
version="0.1.2",
|
||||
developers=[
|
||||
"kramo https://kramo.hu",
|
||||
"Paweł Lidwin https://github.com/imLinguin",
|
||||
],
|
||||
designers=["kramo https://kramo.hu"],
|
||||
copyright="© 2022 kramo",
|
||||
license_type=Gtk.License.GPL_3_0,
|
||||
issue_url="https://github.com/kra-mo/cartridges/issues/new",
|
||||
website="https://github.com/kra-mo/cartridges",
|
||||
# Translators: Replace this with your name for it to show up in the about window.
|
||||
translator_credits=_("translator_credits"),
|
||||
)
|
||||
about.present()
|
||||
|
||||
def on_preferences_action(self, widget, callback=None):
|
||||
@@ -124,7 +151,7 @@ class CartridgesApplication(Adw.Application):
|
||||
|
||||
data = get_games([game_id])[game_id]
|
||||
data["last_played"] = int(time.time())
|
||||
save_games({game_id : data})
|
||||
save_games({game_id: data})
|
||||
|
||||
run_command(self.win, self.win.games[self.win.active_game_id].executable)
|
||||
|
||||
@@ -152,7 +179,7 @@ class CartridgesApplication(Adw.Application):
|
||||
|
||||
data = get_games([game_id])[game_id]
|
||||
data["removed"] = True
|
||||
save_games({game_id : data})
|
||||
save_games({game_id: data})
|
||||
|
||||
self.win.update_games([game_id])
|
||||
if self.win.stack.get_visible_child() == self.win.overview:
|
||||
@@ -181,7 +208,7 @@ class CartridgesApplication(Adw.Application):
|
||||
if shortcuts:
|
||||
self.set_accels_for_action(f"win.{name}", shortcuts)
|
||||
|
||||
|
||||
def main(version):
|
||||
app = CartridgesApplication()
|
||||
return app.run(sys.argv)
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
from gi.repository import Adw, Gio, GLib, Gtk
|
||||
|
||||
|
||||
@Gtk.Template(resource_path='/hu/kramo/Cartridges/gtk/preferences.ui')
|
||||
@Gtk.Template(resource_path="/hu/kramo/Cartridges/gtk/preferences.ui")
|
||||
class PreferencesWindow(Adw.PreferencesWindow):
|
||||
__gtype_name__ = 'PreferencesWindow'
|
||||
__gtype_name__ = "PreferencesWindow"
|
||||
|
||||
exit_after_launch_switch = Gtk.Template.Child()
|
||||
import_epic_games_switch = Gtk.Template.Child()
|
||||
@@ -38,28 +38,57 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
|
||||
self.set_transient_for(parent_widget)
|
||||
schema = parent_widget.schema
|
||||
schema.bind("exit-after-launch", self.exit_after_launch_switch, "active", Gio.SettingsBindFlags.DEFAULT)
|
||||
schema.bind("heroic-import-epic", self.import_epic_games_switch, "active", Gio.SettingsBindFlags.DEFAULT)
|
||||
schema.bind("heroic-import-gog", self.import_gog_games_switch, "active", Gio.SettingsBindFlags.DEFAULT)
|
||||
schema.bind("heroic-import-sideload", self.import_sideload_games_switch, "active", Gio.SettingsBindFlags.DEFAULT)
|
||||
schema.bind(
|
||||
"exit-after-launch",
|
||||
self.exit_after_launch_switch,
|
||||
"active",
|
||||
Gio.SettingsBindFlags.DEFAULT,
|
||||
)
|
||||
schema.bind(
|
||||
"heroic-import-epic",
|
||||
self.import_epic_games_switch,
|
||||
"active",
|
||||
Gio.SettingsBindFlags.DEFAULT,
|
||||
)
|
||||
schema.bind(
|
||||
"heroic-import-gog",
|
||||
self.import_gog_games_switch,
|
||||
"active",
|
||||
Gio.SettingsBindFlags.DEFAULT,
|
||||
)
|
||||
schema.bind(
|
||||
"heroic-import-sideload",
|
||||
self.import_sideload_games_switch,
|
||||
"active",
|
||||
Gio.SettingsBindFlags.DEFAULT,
|
||||
)
|
||||
|
||||
filechooser = Gtk.FileDialog()
|
||||
|
||||
def set_steam_dir(source, result, user_data):
|
||||
try:
|
||||
schema.set_string("steam-location", filechooser.select_folder_finish(result).get_path())
|
||||
schema.set_string(
|
||||
"steam-location",
|
||||
filechooser.select_folder_finish(result).get_path(),
|
||||
)
|
||||
except GLib.GError:
|
||||
pass
|
||||
|
||||
def set_heroic_dir(source, result, user_data):
|
||||
try:
|
||||
schema.set_string("heroic-location", filechooser.select_folder_finish(result).get_path())
|
||||
schema.set_string(
|
||||
"heroic-location",
|
||||
filechooser.select_folder_finish(result).get_path(),
|
||||
)
|
||||
except GLib.GError:
|
||||
pass
|
||||
|
||||
def set_bottles_dir(source, result, user_data):
|
||||
try:
|
||||
schema.set_string("bottles-location", filechooser.select_folder_finish(result).get_path())
|
||||
schema.set_string(
|
||||
"bottles-location",
|
||||
filechooser.select_folder_finish(result).get_path(),
|
||||
)
|
||||
except GLib.GError:
|
||||
pass
|
||||
|
||||
@@ -67,5 +96,9 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
filechooser.select_folder(parent_widget, None, function, None)
|
||||
|
||||
self.steam_file_chooser_button.connect("clicked", choose_folder, set_steam_dir)
|
||||
self.heroic_file_chooser_button.connect("clicked", choose_folder, set_heroic_dir)
|
||||
self.bottles_file_chooser_button.connect("clicked", choose_folder, set_bottles_dir)
|
||||
self.heroic_file_chooser_button.connect(
|
||||
"clicked", choose_folder, set_heroic_dir
|
||||
)
|
||||
self.bottles_file_chooser_button.connect(
|
||||
"clicked", choose_folder, set_bottles_dir
|
||||
)
|
||||
|
||||
@@ -32,18 +32,28 @@ def bottles_parser(parent_widget, action):
|
||||
bottles_dir = os.path.expanduser(schema.get_string("bottles-location"))
|
||||
|
||||
def bottles_not_found():
|
||||
if os.path.exists(os.path.expanduser("~/.var/app/com.usebottles.bottles/data/bottles/")):
|
||||
schema.set_string("bottles-location", "~/.var/app/com.usebottles.bottles/data/bottles/")
|
||||
if os.path.exists(
|
||||
os.path.expanduser("~/.var/app/com.usebottles.bottles/data/bottles/")
|
||||
):
|
||||
schema.set_string(
|
||||
"bottles-location", "~/.var/app/com.usebottles.bottles/data/bottles/"
|
||||
)
|
||||
action(None, None)
|
||||
elif os.path.exists(os.path.join(os.environ.get("XDG_DATA_HOME"), "bottles")):
|
||||
schema.set_string("bottles-location", os.path.join(os.environ.get("XDG_DATA_HOME"), "bottles"))
|
||||
schema.set_string(
|
||||
"bottles-location",
|
||||
os.path.join(os.environ.get("XDG_DATA_HOME"), "bottles"),
|
||||
)
|
||||
action(None, None)
|
||||
else:
|
||||
filechooser = Gtk.FileDialog.new()
|
||||
|
||||
def set_bottles_dir(source, result, _):
|
||||
try:
|
||||
schema.set_string("bottles-location", filechooser.select_folder_finish(result).get_path())
|
||||
schema.set_string(
|
||||
"bottles-location",
|
||||
filechooser.select_folder_finish(result).get_path(),
|
||||
)
|
||||
action(None, None)
|
||||
except GLib.GError:
|
||||
return
|
||||
@@ -55,7 +65,13 @@ def bottles_parser(parent_widget, action):
|
||||
if response == "choose_folder":
|
||||
choose_folder(widget)
|
||||
|
||||
create_dialog(parent_widget, _("Couldn't Import Games"), _("The Bottles directory cannot be found."), "choose_folder", _("Set Bottles Location")).connect("response", response)
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("Couldn't Import Games"),
|
||||
_("The Bottles directory cannot be found."),
|
||||
"choose_folder",
|
||||
_("Set Bottles Location"),
|
||||
).connect("response", response)
|
||||
|
||||
if os.path.isfile(os.path.join(bottles_dir, "library.yml")):
|
||||
pass
|
||||
@@ -80,25 +96,56 @@ def bottles_parser(parent_widget, action):
|
||||
|
||||
values["game_id"] = "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 parent_widget.games
|
||||
and not parent_widget.games[values["game_id"]].removed
|
||||
):
|
||||
continue
|
||||
|
||||
values["name"] = game["name"]
|
||||
values["executable"] = "xdg-open bottles:run/" + game["bottle"]["name"] + "/" + game["name"]
|
||||
values["executable"] = (
|
||||
"xdg-open bottles:run/" + game["bottle"]["name"] + "/" + game["name"]
|
||||
)
|
||||
values["hidden"] = False
|
||||
values["source"] = "bottles"
|
||||
values["added"] = current_time
|
||||
values["last_played"] = 0
|
||||
|
||||
if game["thumbnail"]:
|
||||
save_cover(values, parent_widget, os.path.join(bottles_dir, "bottles", game["bottle"]["path"], "grids", game["thumbnail"].split(":")[1]))
|
||||
save_cover(
|
||||
values,
|
||||
parent_widget,
|
||||
os.path.join(
|
||||
bottles_dir,
|
||||
"bottles",
|
||||
game["bottle"]["path"],
|
||||
"grids",
|
||||
game["thumbnail"].split(":")[1],
|
||||
),
|
||||
)
|
||||
|
||||
bottles_games[values["game_id"]] = values
|
||||
|
||||
if len(bottles_games) == 0:
|
||||
create_dialog(parent_widget, _("No Games Found"), _("No new games were found in the Bottles library."))
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("No Games Found"),
|
||||
_("No new games were found in the Bottles library."),
|
||||
)
|
||||
elif len(bottles_games) == 1:
|
||||
create_dialog(parent_widget, _("Bottles Games Imported"), _("Successfully imported 1 game."))
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("Bottles Games Imported"),
|
||||
_("Successfully imported 1 game."),
|
||||
)
|
||||
elif len(bottles_games) > 1:
|
||||
create_dialog(parent_widget, _("Bottles Games Imported"), _("Successfully imported") + " " + str(len(bottles_games)) + " " + _("games."))
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("Bottles Games Imported"),
|
||||
_("Successfully imported")
|
||||
+ " "
|
||||
+ str(len(bottles_games))
|
||||
+ " "
|
||||
+ _("games."),
|
||||
)
|
||||
return bottles_games
|
||||
|
||||
@@ -29,12 +29,9 @@ from .save_cover import save_cover
|
||||
from .save_games import save_games
|
||||
|
||||
|
||||
def create_details_window(parent_widget, game_id = None):
|
||||
def create_details_window(parent_widget, game_id=None):
|
||||
window = Adw.Window(
|
||||
modal = True,
|
||||
default_width = 450,
|
||||
default_height = 650,
|
||||
transient_for = parent_widget
|
||||
modal=True, default_width=450, default_height=650, transient_for=parent_widget
|
||||
)
|
||||
|
||||
games = parent_widget.games
|
||||
@@ -50,12 +47,12 @@ def create_details_window(parent_widget, game_id = None):
|
||||
window.set_title(_("Edit Game Details"))
|
||||
cover = Gtk.Picture.new_for_pixbuf(get_cover(game_id, parent_widget))
|
||||
name = Gtk.Entry.new_with_buffer(Gtk.EntryBuffer.new(games[game_id].name, -1))
|
||||
executable = Gtk.Entry.new_with_buffer(Gtk.EntryBuffer.new((games[game_id].executable), -1))
|
||||
executable = Gtk.Entry.new_with_buffer(
|
||||
Gtk.EntryBuffer.new((games[game_id].executable), -1)
|
||||
)
|
||||
apply_button = Gtk.Button.new_with_label(_("Apply"))
|
||||
|
||||
image_filter = Gtk.FileFilter(
|
||||
name= _("Images")
|
||||
)
|
||||
image_filter = Gtk.FileFilter(name=_("Images"))
|
||||
image_filter.add_pixbuf_formats()
|
||||
file_filters = Gio.ListStore.new(Gtk.FileFilter)
|
||||
file_filters.append(image_filter)
|
||||
@@ -66,38 +63,38 @@ def create_details_window(parent_widget, game_id = None):
|
||||
cover.set_size_request(200, 300)
|
||||
|
||||
cover_button = Gtk.Button(
|
||||
icon_name = "document-edit-symbolic",
|
||||
halign = Gtk.Align.END,
|
||||
valign = Gtk.Align.END,
|
||||
margin_bottom = 6,
|
||||
margin_end = 6,
|
||||
css_classes = ["circular", "osd"],
|
||||
icon_name="document-edit-symbolic",
|
||||
halign=Gtk.Align.END,
|
||||
valign=Gtk.Align.END,
|
||||
margin_bottom=6,
|
||||
margin_end=6,
|
||||
css_classes=["circular", "osd"],
|
||||
)
|
||||
|
||||
cover_overlay = Gtk.Overlay(
|
||||
child = cover,
|
||||
halign = Gtk.Align.CENTER,
|
||||
valign = Gtk.Align.CENTER,
|
||||
child=cover,
|
||||
halign=Gtk.Align.CENTER,
|
||||
valign=Gtk.Align.CENTER,
|
||||
)
|
||||
cover_overlay.add_overlay(cover_button)
|
||||
|
||||
cover_clamp = Adw.Clamp(
|
||||
maximum_size = 200,
|
||||
child = cover_overlay,
|
||||
maximum_size=200,
|
||||
child=cover_overlay,
|
||||
)
|
||||
|
||||
cover_group = Adw.PreferencesGroup()
|
||||
cover_group.add(cover_clamp)
|
||||
|
||||
title_group = Adw.PreferencesGroup(
|
||||
title = _("Title"),
|
||||
description = _("The title of the game"),
|
||||
title=_("Title"),
|
||||
description=_("The title of the game"),
|
||||
)
|
||||
title_group.add(name)
|
||||
|
||||
exec_group = Adw.PreferencesGroup(
|
||||
title = _("Executable"),
|
||||
description = _("File to open or command to run when launching the game"),
|
||||
title=_("Executable"),
|
||||
description=_("File to open or command to run when launching the game"),
|
||||
)
|
||||
exec_group.add(executable)
|
||||
|
||||
@@ -111,8 +108,8 @@ def create_details_window(parent_widget, game_id = None):
|
||||
apply_button.add_css_class("suggested-action")
|
||||
|
||||
header_bar = Adw.HeaderBar(
|
||||
show_start_title_buttons = False,
|
||||
show_end_title_buttons = False,
|
||||
show_start_title_buttons=False,
|
||||
show_end_title_buttons=False,
|
||||
)
|
||||
header_bar.pack_start(cancel_button)
|
||||
header_bar.pack_end(apply_button)
|
||||
@@ -128,7 +125,9 @@ def create_details_window(parent_widget, game_id = None):
|
||||
def set_cover(source, result, _):
|
||||
nonlocal pixbuf
|
||||
try:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(filechooser.open_finish(result).get_path(), 200, 300, False)
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||
filechooser.open_finish(result).get_path(), 200, 300, False
|
||||
)
|
||||
cover.set_pixbuf(pixbuf)
|
||||
except GLib.GError:
|
||||
return
|
||||
@@ -148,11 +147,15 @@ def create_details_window(parent_widget, game_id = None):
|
||||
if game_id == None:
|
||||
|
||||
if final_name == "":
|
||||
create_dialog(window, _("Couldn't Add Game"), _("Game title cannot be empty."))
|
||||
create_dialog(
|
||||
window, _("Couldn't Add Game"), _("Game title cannot be empty.")
|
||||
)
|
||||
return
|
||||
|
||||
if final_executable == "":
|
||||
create_dialog(window, _("Couldn't Add Game"), _("Executable cannot be empty."))
|
||||
create_dialog(
|
||||
window, _("Couldn't Add Game"), _("Executable cannot be empty.")
|
||||
)
|
||||
return
|
||||
|
||||
# Increment the number after the game id (eg. imported_1, imported_2)
|
||||
@@ -163,7 +166,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 = "imported_" + str(max(numbers) + 1)
|
||||
|
||||
values["game_id"] = game_id
|
||||
values["hidden"] = False
|
||||
@@ -173,11 +176,19 @@ def create_details_window(parent_widget, game_id = None):
|
||||
|
||||
else:
|
||||
if final_name == "":
|
||||
create_dialog(window, _("Couldn't Apply Preferences"), _("Game title cannot be empty."))
|
||||
create_dialog(
|
||||
window,
|
||||
_("Couldn't Apply Preferences"),
|
||||
_("Game title cannot be empty."),
|
||||
)
|
||||
return
|
||||
|
||||
if final_executable == "":
|
||||
create_dialog(window, _("Couldn't Apply Preferences"), _("Executable cannot be empty."))
|
||||
create_dialog(
|
||||
window,
|
||||
_("Couldn't Apply Preferences"),
|
||||
_("Executable cannot be empty."),
|
||||
)
|
||||
return
|
||||
|
||||
if pixbuf != None:
|
||||
@@ -186,16 +197,23 @@ def create_details_window(parent_widget, game_id = None):
|
||||
values["name"] = final_name
|
||||
values["executable"] = final_executable
|
||||
|
||||
path = os.path.join(os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games", game_id + ".json"))
|
||||
path = os.path.join(
|
||||
os.path.join(
|
||||
os.environ.get("XDG_DATA_HOME"),
|
||||
"cartridges",
|
||||
"games",
|
||||
game_id + ".json",
|
||||
)
|
||||
)
|
||||
|
||||
if os.path.exists(path):
|
||||
open_file = open(path, "r")
|
||||
data = json.loads(open_file.read())
|
||||
open_file.close()
|
||||
data.update(values)
|
||||
save_games({game_id : data})
|
||||
save_games({game_id: data})
|
||||
else:
|
||||
save_games({game_id : values})
|
||||
save_games({game_id: values})
|
||||
|
||||
parent_widget.update_games([game_id])
|
||||
if parent_widget.stack.get_visible_child() == parent_widget.overview:
|
||||
@@ -213,9 +231,13 @@ def create_details_window(parent_widget, game_id = None):
|
||||
executable.connect("activate", apply_preferences)
|
||||
|
||||
shortcut_controller = Gtk.ShortcutController()
|
||||
shortcut_controller.add_shortcut(Gtk.Shortcut.new(Gtk.ShortcutTrigger.parse_string('Escape'), Gtk.CallbackAction.new(close_window)))
|
||||
shortcut_controller.add_shortcut(
|
||||
Gtk.Shortcut.new(
|
||||
Gtk.ShortcutTrigger.parse_string("Escape"),
|
||||
Gtk.CallbackAction.new(close_window),
|
||||
)
|
||||
)
|
||||
|
||||
window.add_controller(shortcut_controller)
|
||||
window.set_focus(name)
|
||||
window.present()
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ from gi.repository import Adw, Gtk
|
||||
|
||||
def create_dialog(parent_widget, heading, body, extra_option=None, extra_label=None):
|
||||
dialog = Adw.MessageDialog.new(parent_widget, _(heading), body)
|
||||
dialog.add_response("dismiss", _("Dismiss"))
|
||||
dialog.add_response("dismiss", _("Dismiss"))
|
||||
|
||||
if extra_option:
|
||||
dialog.add_response(extra_option, _(extra_label))
|
||||
|
||||
@@ -25,7 +25,9 @@ from gi.repository import GdkPixbuf
|
||||
def get_cover(game_id, parent_widget):
|
||||
if game_id in parent_widget.pixbufs.keys():
|
||||
return parent_widget.pixbufs[game_id]
|
||||
cover_path = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers", game_id + ".png")
|
||||
cover_path = os.path.join(
|
||||
os.environ.get("XDG_DATA_HOME"), "cartridges", "covers", game_id + ".png"
|
||||
)
|
||||
|
||||
if not os.path.isfile(cover_path):
|
||||
return parent_widget.placeholder_pixbuf
|
||||
|
||||
@@ -33,18 +33,29 @@ def heroic_parser(parent_widget, action):
|
||||
heroic_dir = os.path.expanduser(schema.get_string("heroic-location"))
|
||||
|
||||
def heroic_not_found():
|
||||
if os.path.exists(os.path.expanduser("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/")):
|
||||
schema.set_string("heroic-location", "~/.var/app/com.heroicgameslauncher.hgl/config/heroic/")
|
||||
if os.path.exists(
|
||||
os.path.expanduser("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/")
|
||||
):
|
||||
schema.set_string(
|
||||
"heroic-location",
|
||||
"~/.var/app/com.heroicgameslauncher.hgl/config/heroic/",
|
||||
)
|
||||
action(None, None)
|
||||
elif os.path.exists(os.path.join(os.environ.get("XDG_CONFIG_HOME"), "heroic")):
|
||||
schema.set_string("heroic-location", os.path.join(os.environ.get("XDG_CONFIG_HOME"), "heroic"))
|
||||
schema.set_string(
|
||||
"heroic-location",
|
||||
os.path.join(os.environ.get("XDG_CONFIG_HOME"), "heroic"),
|
||||
)
|
||||
action(None, None)
|
||||
else:
|
||||
filechooser = Gtk.FileDialog.new()
|
||||
|
||||
def set_heroic_dir(source, result, _):
|
||||
try:
|
||||
schema.set_string("heroic-location", filechooser.select_folder_finish(result).get_path())
|
||||
schema.set_string(
|
||||
"heroic-location",
|
||||
filechooser.select_folder_finish(result).get_path(),
|
||||
)
|
||||
action(None, None)
|
||||
except GLib.GError:
|
||||
return
|
||||
@@ -56,7 +67,13 @@ def heroic_parser(parent_widget, action):
|
||||
if response == "choose_folder":
|
||||
choose_folder(widget)
|
||||
|
||||
create_dialog(parent_widget, _("Couldn't Import Games"), _("The Heroic directory cannot be found."), "choose_folder", _("Set Heroic Location")).connect("response", response)
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("Couldn't Import Games"),
|
||||
_("The Heroic directory cannot be found."),
|
||||
"choose_folder",
|
||||
_("Set Heroic Location"),
|
||||
).connect("response", response)
|
||||
|
||||
if os.path.exists(os.path.join(heroic_dir, "config.json")):
|
||||
pass
|
||||
@@ -87,7 +104,10 @@ def heroic_parser(parent_widget, action):
|
||||
app_name = game["app_name"]
|
||||
values["game_id"] = "heroic_epic_" + app_name
|
||||
|
||||
if values["game_id"] in parent_widget.games and not parent_widget.games[values["game_id"]].removed:
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
and not parent_widget.games[values["game_id"]].removed
|
||||
):
|
||||
continue
|
||||
|
||||
values["name"] = game["title"]
|
||||
@@ -97,7 +117,13 @@ def heroic_parser(parent_widget, action):
|
||||
values["added"] = current_time
|
||||
values["last_played"] = 0
|
||||
|
||||
image_path = os.path.join(heroic_dir, "images-cache", hashlib.sha256((game["art_square"] + "?h=400&resize=1&w=300").encode()).hexdigest())
|
||||
image_path = os.path.join(
|
||||
heroic_dir,
|
||||
"images-cache",
|
||||
hashlib.sha256(
|
||||
(game["art_square"] + "?h=400&resize=1&w=300").encode()
|
||||
).hexdigest(),
|
||||
)
|
||||
if os.path.exists(image_path):
|
||||
save_cover(values, parent_widget, image_path)
|
||||
|
||||
@@ -117,7 +143,10 @@ def heroic_parser(parent_widget, action):
|
||||
|
||||
values["game_id"] = "heroic_gog_" + app_name
|
||||
|
||||
if values["game_id"] in parent_widget.games and not parent_widget.games[values["game_id"]].removed:
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
and not parent_widget.games[values["game_id"]].removed
|
||||
):
|
||||
continue
|
||||
|
||||
# Get game title from library.json as it's not present in installed.json
|
||||
@@ -128,8 +157,11 @@ def heroic_parser(parent_widget, action):
|
||||
for game in library["games"]:
|
||||
if game["app_name"] == app_name:
|
||||
values["name"] = game["title"]
|
||||
image_path = os.path.join(heroic_dir, "images-cache",
|
||||
hashlib.sha256(game["art_square"].encode()).hexdigest())
|
||||
image_path = os.path.join(
|
||||
heroic_dir,
|
||||
"images-cache",
|
||||
hashlib.sha256(game["art_square"].encode()).hexdigest(),
|
||||
)
|
||||
if os.path.exists(image_path):
|
||||
save_cover(values, parent_widget, image_path)
|
||||
break
|
||||
@@ -156,7 +188,10 @@ def heroic_parser(parent_widget, action):
|
||||
|
||||
values["game_id"] = "heroic_sideload_" + app_name
|
||||
|
||||
if values["game_id"] in parent_widget.games and not parent_widget.games[values["game_id"]].removed:
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
and not parent_widget.games[values["game_id"]].removed
|
||||
):
|
||||
continue
|
||||
|
||||
values["name"] = item["title"]
|
||||
@@ -165,18 +200,36 @@ def heroic_parser(parent_widget, action):
|
||||
values["source"] = "heroic_sideload"
|
||||
values["added"] = current_time
|
||||
values["last_played"] = 0
|
||||
image_path = os.path.join(heroic_dir, "images-cache",
|
||||
hashlib.sha256(item["art_square"].encode()).hexdigest())
|
||||
image_path = os.path.join(
|
||||
heroic_dir,
|
||||
"images-cache",
|
||||
hashlib.sha256(item["art_square"].encode()).hexdigest(),
|
||||
)
|
||||
if os.path.exists(image_path):
|
||||
save_cover(values, parent_widget, image_path)
|
||||
|
||||
heroic_games[values["game_id"]] = values
|
||||
|
||||
if len(heroic_games) == 0:
|
||||
create_dialog(parent_widget, _("No Games Found"), _("No new games were found in the Heroic library."))
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("No Games Found"),
|
||||
_("No new games were found in the Heroic library."),
|
||||
)
|
||||
elif len(heroic_games) == 1:
|
||||
create_dialog(parent_widget, _("Heroic Games Imported"), _("Successfully imported 1 game."))
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("Heroic Games Imported"),
|
||||
_("Successfully imported 1 game."),
|
||||
)
|
||||
elif len(heroic_games) > 1:
|
||||
create_dialog(parent_widget, _("Heroic Games Imported"),
|
||||
_("Successfully imported") + " " + str(len(heroic_games)) + " " + _("games."))
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("Heroic Games Imported"),
|
||||
_("Successfully imported")
|
||||
+ " "
|
||||
+ str(len(heroic_games))
|
||||
+ " "
|
||||
+ _("games."),
|
||||
)
|
||||
return heroic_games
|
||||
|
||||
@@ -24,7 +24,9 @@ from gi.repository import Gio
|
||||
|
||||
|
||||
def run_command(parent_widget, executable):
|
||||
subprocess.Popen(["flatpak-spawn --host " + executable], shell=True, start_new_session=True)
|
||||
subprocess.Popen(
|
||||
["flatpak-spawn --host " + executable], shell=True, start_new_session=True
|
||||
)
|
||||
|
||||
if Gio.Settings.new("hu.kramo.Cartridges").get_boolean("exit-after-launch"):
|
||||
sys.exit()
|
||||
|
||||
@@ -22,7 +22,7 @@ import os
|
||||
from gi.repository import GdkPixbuf, Gio
|
||||
|
||||
|
||||
def save_cover(game, parent_widget, file_path, pixbuf = None, game_id = None):
|
||||
def save_cover(game, parent_widget, file_path, pixbuf=None, game_id=None):
|
||||
covers_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers")
|
||||
if os.path.exists(covers_dir) == False:
|
||||
os.makedirs(covers_dir)
|
||||
@@ -40,4 +40,11 @@ def save_cover(game, parent_widget, file_path, pixbuf = None, game_id = None):
|
||||
|
||||
file = Gio.File.new_for_path(os.path.join(covers_dir, game_id + ".png"))
|
||||
parent_widget.pixbufs[game_id] = pixbuf
|
||||
pixbuf.save_to_streamv_async(file.replace(None, False, Gio.FileCreateFlags.NONE), "png", None, None, None, cover_callback)
|
||||
pixbuf.save_to_streamv_async(
|
||||
file.replace(None, False, Gio.FileCreateFlags.NONE),
|
||||
"png",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
cover_callback,
|
||||
)
|
||||
|
||||
@@ -32,8 +32,12 @@ def steam_parser(parent_widget, action):
|
||||
steam_dir = os.path.expanduser(schema.get_string("steam-location"))
|
||||
|
||||
def steam_not_found():
|
||||
if os.path.exists(os.path.expanduser("~/.var/app/com.valvesoftware.Steam/data/Steam/")):
|
||||
schema.set_string("steam-location", "~/.var/app/com.valvesoftware.Steam/data/Steam/")
|
||||
if os.path.exists(
|
||||
os.path.expanduser("~/.var/app/com.valvesoftware.Steam/data/Steam/")
|
||||
):
|
||||
schema.set_string(
|
||||
"steam-location", "~/.var/app/com.valvesoftware.Steam/data/Steam/"
|
||||
)
|
||||
action(None, None)
|
||||
elif os.path.exists(os.path.expanduser("~/.steam/steam/")):
|
||||
schema.set_string("steam-location", "~/.steam/steam/")
|
||||
@@ -43,7 +47,10 @@ def steam_parser(parent_widget, action):
|
||||
|
||||
def set_steam_dir(source, result, _):
|
||||
try:
|
||||
schema.set_string("steam-location", filechooser.select_folder_finish(result).get_path())
|
||||
schema.set_string(
|
||||
"steam-location",
|
||||
filechooser.select_folder_finish(result).get_path(),
|
||||
)
|
||||
action(None, None)
|
||||
except GLib.GError:
|
||||
return
|
||||
@@ -55,7 +62,13 @@ def steam_parser(parent_widget, action):
|
||||
if response == "choose_folder":
|
||||
choose_folder(widget)
|
||||
|
||||
create_dialog(parent_widget, _("Couldn't Import Games"), _("The Steam directory cannot be found."), "choose_folder", _("Set Steam Location")).connect("response", response)
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("Couldn't Import Games"),
|
||||
_("The Steam directory cannot be found."),
|
||||
"choose_folder",
|
||||
_("Set Steam Location"),
|
||||
).connect("response", response)
|
||||
|
||||
if os.path.exists(os.path.join(steam_dir, "steamapps")):
|
||||
pass
|
||||
@@ -85,12 +98,15 @@ def steam_parser(parent_widget, action):
|
||||
data = open_file.read()
|
||||
open_file.close()
|
||||
for datatype in datatypes:
|
||||
value = re.findall("\"" + datatype + "\"\t\t\"(.*)\"\n", data)
|
||||
value = re.findall('"' + datatype + '"\t\t"(.*)"\n', data)
|
||||
values[datatype] = value[0]
|
||||
|
||||
values["game_id"] = "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 parent_widget.games
|
||||
and not parent_widget.games[values["game_id"]].removed
|
||||
):
|
||||
continue
|
||||
|
||||
values["executable"] = "xdg-open steam://rungameid/" + values["appid"]
|
||||
@@ -99,15 +115,45 @@ def steam_parser(parent_widget, action):
|
||||
values["added"] = current_time
|
||||
values["last_played"] = 0
|
||||
|
||||
if os.path.isfile(os.path.join(steam_dir, "appcache", "librarycache", values["appid"] + "_library_600x900.jpg")):
|
||||
save_cover(values, parent_widget, os.path.join(steam_dir, "appcache", "librarycache", values["appid"] + "_library_600x900.jpg"))
|
||||
if os.path.isfile(
|
||||
os.path.join(
|
||||
steam_dir,
|
||||
"appcache",
|
||||
"librarycache",
|
||||
values["appid"] + "_library_600x900.jpg",
|
||||
)
|
||||
):
|
||||
save_cover(
|
||||
values,
|
||||
parent_widget,
|
||||
os.path.join(
|
||||
steam_dir,
|
||||
"appcache",
|
||||
"librarycache",
|
||||
values["appid"] + "_library_600x900.jpg",
|
||||
),
|
||||
)
|
||||
|
||||
steam_games[values["game_id"]] = values
|
||||
|
||||
if len(steam_games) == 0:
|
||||
create_dialog(parent_widget, _("No Games Found"), _("No new games were found in the Steam library."))
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("No Games Found"),
|
||||
_("No new games were found in the Steam library."),
|
||||
)
|
||||
elif len(steam_games) == 1:
|
||||
create_dialog(parent_widget, _("Steam Games Imported"), _("Successfully imported 1 game."))
|
||||
create_dialog(
|
||||
parent_widget, _("Steam Games Imported"), _("Successfully imported 1 game.")
|
||||
)
|
||||
elif len(steam_games) > 1:
|
||||
create_dialog(parent_widget, _("Steam Games Imported"), _("Successfully imported") + " " + str(len(steam_games)) + " " + _("games."))
|
||||
create_dialog(
|
||||
parent_widget,
|
||||
_("Steam Games Imported"),
|
||||
_("Successfully imported")
|
||||
+ " "
|
||||
+ str(len(steam_games))
|
||||
+ " "
|
||||
+ _("games."),
|
||||
)
|
||||
return steam_games
|
||||
|
||||
@@ -83,13 +83,29 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
self.overview.set_clip_overlay(self.overview_box, False)
|
||||
|
||||
self.schema = Gio.Settings.new("hu.kramo.Cartridges")
|
||||
self.placeholder_pixbuf = GdkPixbuf.Pixbuf.new_from_resource_at_scale("/hu/kramo/Cartridges/library_placeholder.svg", 200, 300, False)
|
||||
self.placeholder_pixbuf = GdkPixbuf.Pixbuf.new_from_resource_at_scale(
|
||||
"/hu/kramo/Cartridges/library_placeholder.svg", 200, 300, False
|
||||
)
|
||||
games = get_games()
|
||||
for game in games:
|
||||
if "removed" in games[game].keys():
|
||||
os.remove(os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games", game + ".json"))
|
||||
os.remove(
|
||||
os.path.join(
|
||||
os.environ.get("XDG_DATA_HOME"),
|
||||
"cartridges",
|
||||
"games",
|
||||
game + ".json",
|
||||
)
|
||||
)
|
||||
try:
|
||||
os.remove(os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers", game + ".dat"))
|
||||
os.remove(
|
||||
os.path.join(
|
||||
os.environ.get("XDG_DATA_HOME"),
|
||||
"cartridges",
|
||||
"covers",
|
||||
game + ".dat",
|
||||
)
|
||||
)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
@@ -136,7 +152,9 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
self.hidden_library.append(entry)
|
||||
|
||||
entry.cover_button.connect("clicked", self.show_overview, game_id)
|
||||
entry.menu_button.get_popover().connect("notify::visible", self.set_active_game, game_id)
|
||||
entry.menu_button.get_popover().connect(
|
||||
"notify::visible", self.set_active_game, game_id
|
||||
)
|
||||
entry.get_parent().set_focusable(False)
|
||||
|
||||
if self.visible_widgets == {}:
|
||||
@@ -225,11 +243,17 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
self.active_game_id = game_id
|
||||
pixbuf = get_cover(self.active_game_id, self)
|
||||
self.overview_cover.set_pixbuf(pixbuf)
|
||||
self.overview_blurred_cover.set_pixbuf(pixbuf.scale_simple(2, 3, GdkPixbuf.InterpType.BILINEAR))
|
||||
self.overview_blurred_cover.set_pixbuf(
|
||||
pixbuf.scale_simple(2, 3, GdkPixbuf.InterpType.BILINEAR)
|
||||
)
|
||||
self.overview_title.set_label(game.name)
|
||||
self.overview_header_bar_title.set_title(game.name)
|
||||
self.overview_added.set_label(_("Added:") + " " + self.get_time(game.added))
|
||||
self.overview_last_played.set_label(_("Last played:") + " " + self.get_time(game.last_played) if game.last_played != 0 else _("Last played: Never"))
|
||||
self.overview_last_played.set_label(
|
||||
_("Last played:") + " " + self.get_time(game.last_played)
|
||||
if game.last_played != 0
|
||||
else _("Last played: Never")
|
||||
)
|
||||
|
||||
def a_z_sort(self, child1, child2):
|
||||
name1 = child1.get_first_child().name.lower()
|
||||
@@ -314,7 +338,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
|
||||
def on_sort_action(self, action, state):
|
||||
action.set_state(state)
|
||||
state = str(state).strip("\'")
|
||||
state = str(state).strip("'")
|
||||
|
||||
if state == "a-z":
|
||||
sort_func = self.a_z_sort
|
||||
@@ -331,7 +355,9 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
elif state == "last_played":
|
||||
sort_func = self.last_played_sort
|
||||
|
||||
Gio.Settings(schema_id="hu.kramo.Cartridge.State").set_string("sort-mode", state)
|
||||
Gio.Settings(schema_id="hu.kramo.Cartridge.State").set_string(
|
||||
"sort-mode", state
|
||||
)
|
||||
self.library.set_sort_func(sort_func)
|
||||
self.hidden_library.set_sort_func(sort_func)
|
||||
|
||||
@@ -377,7 +403,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
search_entry.set_text("")
|
||||
|
||||
def on_undo_remove_action(self, widget, game_id=None):
|
||||
# Remove the "removed=True" property from the game and dismiss the toast
|
||||
# Remove the "removed=True" property from the game and dismiss the toast
|
||||
|
||||
if not game_id:
|
||||
try:
|
||||
@@ -386,7 +412,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
return
|
||||
data = get_games([game_id])[game_id]
|
||||
data.pop("removed")
|
||||
save_games({game_id : data})
|
||||
save_games({game_id: data})
|
||||
self.update_games([game_id])
|
||||
self.toasts[game_id].dismiss()
|
||||
self.toasts.pop(game_id)
|
||||
|
||||
Reference in New Issue
Block a user