Update code style
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user