Cleanups
This commit is contained in:
14
src/game.py
14
src/game.py
@@ -54,6 +54,7 @@ class Game(Gtk.Box):
|
|||||||
developer = None
|
developer = None
|
||||||
removed = None
|
removed = None
|
||||||
blacklisted = None
|
blacklisted = None
|
||||||
|
game_cover = None
|
||||||
|
|
||||||
def __init__(self, win, data, **kwargs):
|
def __init__(self, win, data, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
@@ -94,17 +95,18 @@ class Game(Gtk.Box):
|
|||||||
"notify::visible", self.toggle_play, None
|
"notify::visible", self.toggle_play, None
|
||||||
)
|
)
|
||||||
self.menu_button.get_popover().connect(
|
self.menu_button.get_popover().connect(
|
||||||
"notify::visible", self.win.set_active_game, self.game_id
|
"notify::visible", self.win.set_active_game, self
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.game_id in self.win.game_covers:
|
if self.game_id in self.win.game_covers:
|
||||||
self.win.game_covers[self.game_id].add_picture(self.cover)
|
self.game_cover = self.win.game_covers[self.game_id]
|
||||||
|
self.game_cover.add_picture(self.cover)
|
||||||
else:
|
else:
|
||||||
game_cover = GameCover({self.cover}, self.get_cover_path())
|
self.game_cover = GameCover({self.cover}, self.get_cover_path())
|
||||||
self.win.game_covers[self.game_id] = game_cover
|
self.win.game_covers[self.game_id] = self.game_cover
|
||||||
|
|
||||||
if self.win.stack.get_visible_child() == self.win.details_view:
|
if self.win.stack.get_visible_child() == self.win.details_view:
|
||||||
self.win.show_details_view(None, self.game_id)
|
self.win.show_details_view(self)
|
||||||
|
|
||||||
if not self.removed and not self.blacklisted:
|
if not self.removed and not self.blacklisted:
|
||||||
if self.hidden:
|
if self.hidden:
|
||||||
@@ -230,7 +232,7 @@ class Game(Gtk.Box):
|
|||||||
if self.win.schema.get_boolean("cover-launches-game") ^ button:
|
if self.win.schema.get_boolean("cover-launches-game") ^ button:
|
||||||
self.launch()
|
self.launch()
|
||||||
else:
|
else:
|
||||||
self.win.show_details_view(None, self.game_id)
|
self.win.show_details_view(self)
|
||||||
|
|
||||||
def set_play_label(self):
|
def set_play_label(self):
|
||||||
self.play_button.set_label(
|
self.play_button.set_label(
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class GameCover:
|
|||||||
self.animation = GdkPixbuf.PixbufAnimation.new_from_file(str(path))
|
self.animation = GdkPixbuf.PixbufAnimation.new_from_file(str(path))
|
||||||
self.anim_iter = self.animation.get_iter()
|
self.anim_iter = self.animation.get_iter()
|
||||||
|
|
||||||
def wrapper(task, *_unused):
|
def wrapper(task, *_args):
|
||||||
self.update_animation((task, self.animation))
|
self.update_animation((task, self.animation))
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ def get_game(task, current_time, win, row):
|
|||||||
values["source"] = "itch"
|
values["source"] = "itch"
|
||||||
|
|
||||||
if row[3] or row[2]:
|
if row[3] or row[2]:
|
||||||
tmp_file = Gio.File.new_tmp(None)[0]
|
tmp_file = Gio.File.new_tmp()[0]
|
||||||
try:
|
try:
|
||||||
with requests.get(row[3] or row[2], timeout=5) as cover:
|
with requests.get(row[3] or row[2], timeout=5) as cover:
|
||||||
cover.raise_for_status()
|
cover.raise_for_status()
|
||||||
@@ -95,7 +95,7 @@ def get_games_async(win, rows, importer):
|
|||||||
|
|
||||||
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
|
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
|
||||||
def create_func(current_time, win, row):
|
def create_func(current_time, win, row):
|
||||||
def wrapper(task, *_unused):
|
def wrapper(task, *_args):
|
||||||
get_game(
|
get_game(
|
||||||
task,
|
task,
|
||||||
current_time,
|
current_time,
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ def get_games_async(win, appmanifests, steam_dir, importer):
|
|||||||
|
|
||||||
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
|
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
|
||||||
def create_func(datatypes, current_time, win, appmanifest, steam_dir):
|
def create_func(datatypes, current_time, win, appmanifest, steam_dir):
|
||||||
def wrapper(task, *_unused):
|
def wrapper(task, *_args):
|
||||||
get_game(
|
get_game(
|
||||||
task,
|
task,
|
||||||
datatypes,
|
datatypes,
|
||||||
|
|||||||
48
src/main.py
48
src/main.py
@@ -64,8 +64,6 @@ class CartridgesApplication(Adw.Application):
|
|||||||
"is-maximized", self.win, "maximized", Gio.SettingsBindFlags.DEFAULT
|
"is-maximized", self.win, "maximized", Gio.SettingsBindFlags.DEFAULT
|
||||||
)
|
)
|
||||||
|
|
||||||
self.win.present()
|
|
||||||
|
|
||||||
# Create actions
|
# Create actions
|
||||||
self.create_actions(
|
self.create_actions(
|
||||||
{
|
{
|
||||||
@@ -101,7 +99,9 @@ class CartridgesApplication(Adw.Application):
|
|||||||
self.win.add_action(sort_action)
|
self.win.add_action(sort_action)
|
||||||
self.win.on_sort_action(sort_action, state_settings.get_value("sort-mode"))
|
self.win.on_sort_action(sort_action, state_settings.get_value("sort-mode"))
|
||||||
|
|
||||||
def on_about_action(self, _widget, _callback=None):
|
self.win.present()
|
||||||
|
|
||||||
|
def on_about_action(self, *_args):
|
||||||
about = Adw.AboutWindow(
|
about = Adw.AboutWindow(
|
||||||
transient_for=self.win,
|
transient_for=self.win,
|
||||||
application_name=_("Cartridges"),
|
application_name=_("Cartridges"),
|
||||||
@@ -127,7 +127,7 @@ class CartridgesApplication(Adw.Application):
|
|||||||
about.present()
|
about.present()
|
||||||
|
|
||||||
def on_preferences_action(
|
def on_preferences_action(
|
||||||
self, _widget, _callback=None, page_name=None, expander_row=None
|
self, _action=None, _parameter=None, page_name=None, expander_row=None
|
||||||
):
|
):
|
||||||
win = PreferencesWindow(self.win)
|
win = PreferencesWindow(self.win)
|
||||||
if page_name:
|
if page_name:
|
||||||
@@ -136,21 +136,23 @@ class CartridgesApplication(Adw.Application):
|
|||||||
getattr(win, expander_row).set_expanded(True)
|
getattr(win, expander_row).set_expanded(True)
|
||||||
win.present()
|
win.present()
|
||||||
|
|
||||||
def on_launch_game_action(self, _widget=None, _callback=None):
|
def on_launch_game_action(self, *_args):
|
||||||
self.win.games[self.win.active_game_id].launch()
|
self.win.active_game.launch()
|
||||||
|
|
||||||
def on_hide_game_action(
|
def on_hide_game_action(
|
||||||
self, _widget=None, _callback=None, game_id=None, toast=True
|
self, _action=None, _parameter=None, game_id=None, toast=True
|
||||||
):
|
):
|
||||||
self.win.games[game_id or self.win.active_game_id].toggle_hidden(toast)
|
(self.win.games[game_id] if game_id else self.win.active_game).toggle_hidden(
|
||||||
|
toast
|
||||||
|
)
|
||||||
|
|
||||||
def on_edit_game_action(self, _widget, _callback=None):
|
def on_edit_game_action(self, *_args):
|
||||||
create_details_window(self.win, self.win.active_game_id)
|
create_details_window(self.win, self.win.active_game.game_id)
|
||||||
|
|
||||||
def on_add_game_action(self, _widget, _callback=None):
|
def on_add_game_action(self, *_args):
|
||||||
create_details_window(self.win)
|
create_details_window(self.win)
|
||||||
|
|
||||||
def on_import_action(self, _widget, _callback=None):
|
def on_import_action(self, *_args):
|
||||||
self.win.importer = Importer(self.win)
|
self.win.importer = Importer(self.win)
|
||||||
|
|
||||||
self.win.importer.blocker = True
|
self.win.importer.blocker = True
|
||||||
@@ -176,34 +178,32 @@ class CartridgesApplication(Adw.Application):
|
|||||||
self.win.importer.queue = 1
|
self.win.importer.queue = 1
|
||||||
self.win.importer.save_game()
|
self.win.importer.save_game()
|
||||||
|
|
||||||
def on_remove_game_action(self, _widget=None, _callback=None):
|
def on_remove_game_action(self, *_args):
|
||||||
self.win.games[self.win.active_game_id].remove_game()
|
self.win.active_game.remove_game()
|
||||||
|
|
||||||
def on_remove_game_details_view_action(self, _widget, _callback=None):
|
def on_remove_game_details_view_action(self, *_args):
|
||||||
if self.win.stack.get_visible_child() == self.win.details_view:
|
if self.win.stack.get_visible_child() == self.win.details_view:
|
||||||
self.on_remove_game_action()
|
self.on_remove_game_action()
|
||||||
|
|
||||||
def on_quit_action(self, _widget, _callback=None):
|
def on_quit_action(self, *_args):
|
||||||
self.quit()
|
self.quit()
|
||||||
|
|
||||||
def search(self, uri):
|
def search(self, uri):
|
||||||
Gio.AppInfo.launch_default_for_uri(
|
Gio.AppInfo.launch_default_for_uri(f"{uri}{self.win.active_game.name}")
|
||||||
f"{uri}{self.win.games[self.win.active_game_id].name}"
|
|
||||||
)
|
|
||||||
|
|
||||||
def on_igdb_search_action(self, _widget, _callback=None):
|
def on_igdb_search_action(self, *_args):
|
||||||
self.search("https://www.igdb.com/search?type=1&q=")
|
self.search("https://www.igdb.com/search?type=1&q=")
|
||||||
|
|
||||||
def on_sgdb_search_action(self, _widget, _callback=None):
|
def on_sgdb_search_action(self, *_args):
|
||||||
self.search("https://www.steamgriddb.com/search/grids?term=")
|
self.search("https://www.steamgriddb.com/search/grids?term=")
|
||||||
|
|
||||||
def on_protondb_search_action(self, _widget, _callback=None):
|
def on_protondb_search_action(self, *_args):
|
||||||
self.search("https://www.protondb.com/search?q=")
|
self.search("https://www.protondb.com/search?q=")
|
||||||
|
|
||||||
def on_lutris_search_action(self, _widget, _callback=None):
|
def on_lutris_search_action(self, *_args):
|
||||||
self.search("https://lutris.net/games?q=")
|
self.search("https://lutris.net/games?q=")
|
||||||
|
|
||||||
def on_hltb_search_action(self, _widget, _callback=None):
|
def on_hltb_search_action(self, *_args):
|
||||||
self.search("https://howlongtobeat.com/?q=")
|
self.search("https://howlongtobeat.com/?q=")
|
||||||
|
|
||||||
def create_actions(self, actions):
|
def create_actions(self, actions):
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class ImportPreferences:
|
|||||||
file_chooser_button,
|
file_chooser_button,
|
||||||
config=False,
|
config=False,
|
||||||
):
|
):
|
||||||
def set_dir(_source, result, _unused):
|
def set_dir(_source, result, *_args):
|
||||||
try:
|
try:
|
||||||
path = Path(win.file_chooser.select_folder_finish(result).get_path())
|
path = Path(win.file_chooser.select_folder_finish(result).get_path())
|
||||||
except GLib.GError:
|
except GLib.GError:
|
||||||
@@ -176,7 +176,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
else:
|
else:
|
||||||
self.steam_clear_button_revealer.set_reveal_child(False)
|
self.steam_clear_button_revealer.set_reveal_child(False)
|
||||||
|
|
||||||
def add_steam_dir(_source, result, _unused):
|
def add_steam_dir(_source, result, *_args):
|
||||||
try:
|
try:
|
||||||
value = self.schema.get_strv("steam-extra-dirs")
|
value = self.schema.get_strv("steam-extra-dirs")
|
||||||
value.append(self.file_chooser.select_folder_finish(result).get_path())
|
value.append(self.file_chooser.select_folder_finish(result).get_path())
|
||||||
@@ -185,7 +185,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
return
|
return
|
||||||
update_revealer()
|
update_revealer()
|
||||||
|
|
||||||
def clear_steam_dirs(*_unused):
|
def clear_steam_dirs(*_args):
|
||||||
self.schema.set_strv("steam-extra-dirs", [])
|
self.schema.set_strv("steam-extra-dirs", [])
|
||||||
update_revealer()
|
update_revealer()
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
Gio.SettingsBindFlags.DEFAULT,
|
Gio.SettingsBindFlags.DEFAULT,
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_cache_dir(_source, result, _unused):
|
def set_cache_dir(_source, result, *_args):
|
||||||
try:
|
try:
|
||||||
path = Path(self.file_chooser.select_folder_finish(result).get_path())
|
path = Path(self.file_chooser.select_folder_finish(result).get_path())
|
||||||
except GLib.GError:
|
except GLib.GError:
|
||||||
@@ -314,7 +314,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
Gio.SettingsBindFlags.DEFAULT,
|
Gio.SettingsBindFlags.DEFAULT,
|
||||||
)
|
)
|
||||||
|
|
||||||
def sgdb_key_changed(_widget):
|
def sgdb_key_changed(*_args):
|
||||||
self.schema.set_string("sgdb-key", self.sgdb_key_entry_row.get_text())
|
self.schema.set_string("sgdb-key", self.sgdb_key_entry_row.get_text())
|
||||||
|
|
||||||
self.sgdb_key_entry_row.set_text(self.schema.get_string("sgdb-key"))
|
self.sgdb_key_entry_row.set_text(self.schema.get_string("sgdb-key"))
|
||||||
@@ -331,7 +331,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
def choose_folder(self, _widget, function):
|
def choose_folder(self, _widget, function):
|
||||||
self.file_chooser.select_folder(self.win, None, function, None)
|
self.file_chooser.select_folder(self.win, None, function, None)
|
||||||
|
|
||||||
def undo_remove_all(self, _widget, _unused):
|
def undo_remove_all(self, *_args):
|
||||||
for game_id in self.removed_games:
|
for game_id in self.removed_games:
|
||||||
self.win.games[game_id].removed = False
|
self.win.games[game_id].removed = False
|
||||||
self.win.games[game_id].save()
|
self.win.games[game_id].save()
|
||||||
@@ -339,7 +339,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
self.removed_games = set()
|
self.removed_games = set()
|
||||||
self.toast.dismiss()
|
self.toast.dismiss()
|
||||||
|
|
||||||
def remove_all_games(self, _widget):
|
def remove_all_games(self, *_args):
|
||||||
for game in self.win.games.values():
|
for game in self.win.games.values():
|
||||||
if not game.removed:
|
if not game.removed:
|
||||||
self.removed_games.add(game.game_id)
|
self.removed_games.add(game.game_id)
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ def create_details_window(win, game_id=None):
|
|||||||
margin_end=6,
|
margin_end=6,
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete_pixbuf(_widget):
|
def delete_pixbuf(*_args):
|
||||||
nonlocal game_cover
|
nonlocal game_cover
|
||||||
nonlocal cover_changed
|
nonlocal cover_changed
|
||||||
|
|
||||||
@@ -217,10 +217,10 @@ def create_details_window(win, game_id=None):
|
|||||||
main_box.append(general_page)
|
main_box.append(general_page)
|
||||||
window.set_content(main_box)
|
window.set_content(main_box)
|
||||||
|
|
||||||
def choose_cover(_widget):
|
def choose_cover(*_args):
|
||||||
filechooser.open(window, None, set_cover, None)
|
filechooser.open(window, None, set_cover, None)
|
||||||
|
|
||||||
def set_cover(_source, result, _unused):
|
def set_cover(_source, result, *_args):
|
||||||
nonlocal game_cover
|
nonlocal game_cover
|
||||||
nonlocal cover_changed
|
nonlocal cover_changed
|
||||||
|
|
||||||
@@ -234,10 +234,10 @@ def create_details_window(win, game_id=None):
|
|||||||
|
|
||||||
game_cover.new_cover(resize_cover(win, path))
|
game_cover.new_cover(resize_cover(win, path))
|
||||||
|
|
||||||
def close_window(_widget, _callback=None):
|
def close_window(*_args):
|
||||||
window.close()
|
window.close()
|
||||||
|
|
||||||
def apply_preferences(_widget, _callback=None):
|
def apply_preferences(*_args):
|
||||||
nonlocal cover_changed
|
nonlocal cover_changed
|
||||||
nonlocal game_id
|
nonlocal game_id
|
||||||
nonlocal cover
|
nonlocal cover
|
||||||
@@ -323,9 +323,10 @@ def create_details_window(win, game_id=None):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if game_id in win.games:
|
if game_id in win.games:
|
||||||
win.games[game_id].update_values(values)
|
game = win.games[game_id]
|
||||||
|
game.update_values(values)
|
||||||
else:
|
else:
|
||||||
Game(win, values).save()
|
game = Game(win, values).save()
|
||||||
|
|
||||||
if not game_cover.pixbuf:
|
if not game_cover.pixbuf:
|
||||||
SGDBSave(win, {(game_id, values["name"])})
|
SGDBSave(win, {(game_id, values["name"])})
|
||||||
@@ -333,9 +334,9 @@ def create_details_window(win, game_id=None):
|
|||||||
win.game_covers[game_id].pictures.remove(cover)
|
win.game_covers[game_id].pictures.remove(cover)
|
||||||
|
|
||||||
window.close()
|
window.close()
|
||||||
win.show_details_view(None, game_id)
|
win.show_details_view(game)
|
||||||
|
|
||||||
def focus_executable(_widget):
|
def focus_executable(*_args):
|
||||||
window.set_focus(executable)
|
window.set_focus(executable)
|
||||||
|
|
||||||
cover_button_edit.connect("clicked", choose_cover)
|
cover_button_edit.connect("clicked", choose_cover)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class SGDBSave:
|
|||||||
|
|
||||||
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
|
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
|
||||||
def create_func(game):
|
def create_func(game):
|
||||||
def wrapper(task, *_unused):
|
def wrapper(task, *_args):
|
||||||
self.update_cover(
|
self.update_cover(
|
||||||
task,
|
task,
|
||||||
game,
|
game,
|
||||||
@@ -85,7 +85,7 @@ class SGDBSave:
|
|||||||
task.return_value(game[0])
|
task.return_value(game[0])
|
||||||
return
|
return
|
||||||
|
|
||||||
tmp_file = Gio.File.new_tmp(None)[0]
|
tmp_file = Gio.File.new_tmp()[0]
|
||||||
Path(tmp_file.get_path()).write_bytes(response.content)
|
Path(tmp_file.get_path()).write_bytes(response.content)
|
||||||
|
|
||||||
save_cover(
|
save_cover(
|
||||||
@@ -122,4 +122,4 @@ class SGDBSave:
|
|||||||
|
|
||||||
def response(self, _widget, response):
|
def response(self, _widget, response):
|
||||||
if response == "open_preferences":
|
if response == "open_preferences":
|
||||||
self.win.get_application().on_preferences_action(None, page_name="sgdb")
|
self.win.get_application().on_preferences_action(page_name="sgdb")
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
games = {}
|
games = {}
|
||||||
game_covers = {}
|
game_covers = {}
|
||||||
toasts = {}
|
toasts = {}
|
||||||
active_game_id = None
|
active_game = None
|
||||||
scaled_pixbuf = None
|
scaled_pixbuf = None
|
||||||
details_view_game_cover = None
|
details_view_game_cover = None
|
||||||
sort_state = "a-z"
|
sort_state = "a-z"
|
||||||
@@ -100,6 +100,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
self.covers_dir = self.data_dir / "cartridges" / "covers"
|
self.covers_dir = self.data_dir / "cartridges" / "covers"
|
||||||
|
|
||||||
self.schema = Gio.Settings.new("hu.kramo.Cartridges")
|
self.schema = Gio.Settings.new("hu.kramo.Cartridges")
|
||||||
|
|
||||||
scale_factor = max(
|
scale_factor = max(
|
||||||
monitor.get_scale_factor()
|
monitor.get_scale_factor()
|
||||||
for monitor in Gdk.Display.get_default().get_monitors()
|
for monitor in Gdk.Display.get_default().get_monitors()
|
||||||
@@ -169,6 +170,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
self.hidden_library_bin.set_child(hidden_child)
|
self.hidden_library_bin.set_child(hidden_child)
|
||||||
|
|
||||||
def filter_func(self, child):
|
def filter_func(self, child):
|
||||||
|
game = child.get_child()
|
||||||
hidden = self.stack.get_visible_child() == self.hidden_library_view
|
hidden = self.stack.get_visible_child() == self.hidden_library_view
|
||||||
text = (
|
text = (
|
||||||
(self.hidden_search_entry if hidden else self.search_entry)
|
(self.hidden_search_entry if hidden else self.search_entry)
|
||||||
@@ -176,8 +178,6 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
.lower()
|
.lower()
|
||||||
)
|
)
|
||||||
|
|
||||||
game = child.get_child()
|
|
||||||
|
|
||||||
filtered = text != "" and not (
|
filtered = text != "" and not (
|
||||||
text in game.name.lower() or text in game.developer.lower()
|
text in game.name.lower() or text in game.developer.lower()
|
||||||
if game.developer
|
if game.developer
|
||||||
@@ -185,13 +185,12 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
)
|
)
|
||||||
|
|
||||||
game.filtered = filtered
|
game.filtered = filtered
|
||||||
|
|
||||||
self.set_library_child()
|
self.set_library_child()
|
||||||
|
|
||||||
return not filtered
|
return not filtered
|
||||||
|
|
||||||
def set_active_game(self, _widget, _unused, game_id):
|
def set_active_game(self, _widget, _pspec, game):
|
||||||
self.active_game_id = game_id
|
self.active_game = game
|
||||||
|
|
||||||
def get_time(self, timestamp):
|
def get_time(self, timestamp):
|
||||||
date = datetime.datetime.fromtimestamp(timestamp)
|
date = datetime.datetime.fromtimestamp(timestamp)
|
||||||
@@ -207,20 +206,19 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
return GLib.DateTime.new_from_unix_utc(timestamp).format("%B")
|
return GLib.DateTime.new_from_unix_utc(timestamp).format("%B")
|
||||||
return GLib.DateTime.new_from_unix_utc(timestamp).format("%Y")
|
return GLib.DateTime.new_from_unix_utc(timestamp).format("%Y")
|
||||||
|
|
||||||
def show_details_view(self, _widget, game_id):
|
def show_details_view(self, game):
|
||||||
self.active_game_id = game_id
|
self.active_game = game
|
||||||
current_game = self.games[game_id]
|
|
||||||
|
|
||||||
self.details_view_cover.set_visible(not current_game.loading)
|
self.details_view_cover.set_visible(not game.loading)
|
||||||
self.details_view_spinner.set_spinning(current_game.loading)
|
self.details_view_spinner.set_spinning(game.loading)
|
||||||
|
|
||||||
if current_game.developer:
|
if game.developer:
|
||||||
self.details_view_developer.set_label(current_game.developer)
|
self.details_view_developer.set_label(game.developer)
|
||||||
self.details_view_developer.set_visible(True)
|
self.details_view_developer.set_visible(True)
|
||||||
else:
|
else:
|
||||||
self.details_view_developer.set_visible(False)
|
self.details_view_developer.set_visible(False)
|
||||||
|
|
||||||
if current_game.hidden:
|
if game.hidden:
|
||||||
self.details_view_hide_button.set_icon_name("view-reveal-symbolic")
|
self.details_view_hide_button.set_icon_name("view-reveal-symbolic")
|
||||||
self.details_view_hide_button.set_tooltip_text(_("Unhide"))
|
self.details_view_hide_button.set_tooltip_text(_("Unhide"))
|
||||||
else:
|
else:
|
||||||
@@ -229,7 +227,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
if self.details_view_game_cover:
|
if self.details_view_game_cover:
|
||||||
self.details_view_game_cover.pictures.remove(self.details_view_cover)
|
self.details_view_game_cover.pictures.remove(self.details_view_cover)
|
||||||
self.details_view_game_cover = self.game_covers[game_id]
|
self.details_view_game_cover = game.game_cover
|
||||||
self.details_view_game_cover.add_picture(self.details_view_cover)
|
self.details_view_game_cover.add_picture(self.details_view_cover)
|
||||||
|
|
||||||
self.scaled_pixbuf = (
|
self.scaled_pixbuf = (
|
||||||
@@ -238,17 +236,15 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
).scale_simple(2, 3, GdkPixbuf.InterpType.BILINEAR)
|
).scale_simple(2, 3, GdkPixbuf.InterpType.BILINEAR)
|
||||||
self.details_view_blurred_cover.set_pixbuf(self.scaled_pixbuf)
|
self.details_view_blurred_cover.set_pixbuf(self.scaled_pixbuf)
|
||||||
|
|
||||||
self.details_view_title.set_label(current_game.name)
|
self.details_view_title.set_label(game.name)
|
||||||
self.details_view_header_bar_title.set_title(current_game.name)
|
self.details_view_header_bar_title.set_title(game.name)
|
||||||
date = self.get_time(current_game.added)
|
date = self.get_time(game.added)
|
||||||
self.details_view_added.set_label(
|
self.details_view_added.set_label(
|
||||||
# The variable is the date when the game was added
|
# The variable is the date when the game was added
|
||||||
_("Added: {}").format(date)
|
_("Added: {}").format(date)
|
||||||
)
|
)
|
||||||
last_played_date = (
|
last_played_date = (
|
||||||
self.get_time(current_game.last_played)
|
self.get_time(game.last_played) if game.last_played != 0 else _("Never")
|
||||||
if current_game.last_played != 0
|
|
||||||
else _("Never")
|
|
||||||
)
|
)
|
||||||
self.details_view_last_played.set_label(
|
self.details_view_last_played.set_label(
|
||||||
# The variable is the date when the game was last played
|
# The variable is the date when the game was last played
|
||||||
@@ -261,7 +257,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
self.set_details_view_opacity()
|
self.set_details_view_opacity()
|
||||||
|
|
||||||
def set_details_view_opacity(self, _widget=None, _unused=None):
|
def set_details_view_opacity(self, *_args):
|
||||||
if self.stack.get_visible_child() == self.details_view:
|
if self.stack.get_visible_child() == self.details_view:
|
||||||
style_manager = Adw.StyleManager.get_default()
|
style_manager = Adw.StyleManager.get_default()
|
||||||
|
|
||||||
@@ -320,26 +316,26 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
return ((get_value(0) > get_value(1)) ^ order) * 2 - 1
|
return ((get_value(0) > get_value(1)) ^ order) * 2 - 1
|
||||||
|
|
||||||
def on_go_back_action(self, *_unused):
|
def on_go_back_action(self, *_args):
|
||||||
if self.stack.get_visible_child() == self.hidden_library_view:
|
if self.stack.get_visible_child() == self.hidden_library_view:
|
||||||
self.on_show_library_action(None, None)
|
self.on_show_library_action()
|
||||||
elif self.stack.get_visible_child() == self.details_view:
|
elif self.stack.get_visible_child() == self.details_view:
|
||||||
self.on_go_to_parent_action(None, None)
|
self.on_go_to_parent_action()
|
||||||
|
|
||||||
def on_go_to_parent_action(self, _widget, _unused):
|
def on_go_to_parent_action(self, *_args):
|
||||||
if self.stack.get_visible_child() == self.details_view:
|
if self.stack.get_visible_child() == self.details_view:
|
||||||
if self.previous_page == self.library_view:
|
if self.previous_page == self.library_view:
|
||||||
self.on_show_library_action(None, None)
|
self.on_show_library_action()
|
||||||
else:
|
else:
|
||||||
self.on_show_hidden_action(None, None)
|
self.on_show_hidden_action()
|
||||||
|
|
||||||
def on_show_library_action(self, _widget, _unused):
|
def on_show_library_action(self, *_args):
|
||||||
self.stack.set_transition_type(Gtk.StackTransitionType.UNDER_RIGHT)
|
self.stack.set_transition_type(Gtk.StackTransitionType.UNDER_RIGHT)
|
||||||
self.stack.set_visible_child(self.library_view)
|
self.stack.set_visible_child(self.library_view)
|
||||||
self.lookup_action("show_hidden").set_enabled(True)
|
self.lookup_action("show_hidden").set_enabled(True)
|
||||||
self.previous_page = self.library_view
|
self.previous_page = self.library_view
|
||||||
|
|
||||||
def on_show_hidden_action(self, _widget, _unused):
|
def on_show_hidden_action(self, *_args):
|
||||||
if self.stack.get_visible_child() == self.library_view:
|
if self.stack.get_visible_child() == self.library_view:
|
||||||
self.stack.set_transition_type(Gtk.StackTransitionType.OVER_LEFT)
|
self.stack.set_transition_type(Gtk.StackTransitionType.OVER_LEFT)
|
||||||
else:
|
else:
|
||||||
@@ -357,7 +353,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
"sort-mode", self.sort_state
|
"sort-mode", self.sort_state
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_toggle_search_action(self, _widget, _unused):
|
def on_toggle_search_action(self, *_args):
|
||||||
if self.stack.get_visible_child() == self.library_view:
|
if self.stack.get_visible_child() == self.library_view:
|
||||||
search_bar = self.search_bar
|
search_bar = self.search_bar
|
||||||
search_entry = self.search_entry
|
search_entry = self.search_entry
|
||||||
@@ -378,7 +374,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
else:
|
else:
|
||||||
search_entry.set_text("")
|
search_entry.set_text("")
|
||||||
|
|
||||||
def on_escape_action(self, _widget, _unused):
|
def on_escape_action(self, *_args):
|
||||||
if self.stack.get_visible_child() == self.details_view:
|
if self.stack.get_visible_child() == self.details_view:
|
||||||
self.on_go_back_action()
|
self.on_go_back_action()
|
||||||
return
|
return
|
||||||
@@ -416,6 +412,6 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
self.toasts[(game_id, undo)].dismiss()
|
self.toasts[(game_id, undo)].dismiss()
|
||||||
self.toasts.pop((game_id, undo))
|
self.toasts.pop((game_id, undo))
|
||||||
|
|
||||||
def on_open_menu_action(self, _widget, _unused):
|
def on_open_menu_action(self, *_args):
|
||||||
if self.stack.get_visible_child() != self.details_view:
|
if self.stack.get_visible_child() != self.details_view:
|
||||||
self.primary_menu_button.set_active(True)
|
self.primary_menu_button.set_active(True)
|
||||||
|
|||||||
Reference in New Issue
Block a user