From 8b5220195a0434cfe7d7eeacfdecbdc79116b6d2 Mon Sep 17 00:00:00 2001 From: Daniel Johnson Date: Sat, 23 Mar 2024 07:53:57 -0400 Subject: [PATCH] Provide a callback to initialize the edit-games-dialog before it is shown, to avoid the checkbox checking animation. Still can't be an __init__ argument with the games- we need to add games to an already open window. --- lutris/game_actions.py | 7 +++++-- lutris/gui/application.py | 10 ++++++++-- lutris/gui/config/edit_game_categories.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lutris/game_actions.py b/lutris/game_actions.py index c54ec1be6..dada1d2fb 100644 --- a/lutris/game_actions.py +++ b/lutris/game_actions.py @@ -159,8 +159,11 @@ class GameActions: def on_edit_game_categories(self, _widget): """Edit game categories""" - dlg = self.application.show_window(EditGameCategoriesDialog, parent=self.window) - dlg.add_games(self.get_games()) + + def add_games(window): + window.add_games(self.get_games()) + + self.application.show_window(EditGameCategoriesDialog, update_function=add_games, parent=self.window) class MultiGameActions(GameActions): diff --git a/lutris/gui/application.py b/lutris/gui/application.py index 39f737da6..97201c07d 100644 --- a/lutris/gui/application.py +++ b/lutris/gui/application.py @@ -361,11 +361,12 @@ class Application(Gtk.Application): return kwargs["game"].id return str(kwargs) - def show_window(self, window_class, **kwargs): + def show_window(self, window_class, /, update_function=None, **kwargs): """Instantiate a window keeping 1 instance max Params: window_class (Gtk.Window): class to create the instance from + update_function (Callable): Function to initialize or update the window (if possible before being shown) kwargs (dict): Additional arguments to pass to the instanciated window Returns: @@ -374,7 +375,10 @@ class Application(Gtk.Application): window_key = str(window_class.__name__) + self.get_window_key(**kwargs) if self.app_windows.get(window_key): self.app_windows[window_key].present() - return self.app_windows[window_key] + window_inst = self.app_windows[window_key] + if update_function: + update_function(window_inst) + return window_inst if issubclass(window_class, Gtk.Dialog): if "parent" in kwargs: window_inst = window_class(**kwargs) @@ -384,6 +388,8 @@ class Application(Gtk.Application): else: window_inst = window_class(application=self, **kwargs) window_inst.connect("destroy", self.on_app_window_destroyed, self.get_window_key(**kwargs)) + if update_function: + update_function(window_inst) self.app_windows[window_key] = window_inst logger.debug("Showing window %s", window_key) window_inst.show() diff --git a/lutris/gui/config/edit_game_categories.py b/lutris/gui/config/edit_game_categories.py index 3fa9b3cbd..4e693796a 100644 --- a/lutris/gui/config/edit_game_categories.py +++ b/lutris/gui/config/edit_game_categories.py @@ -31,7 +31,7 @@ class EditGameCategoriesDialog(SavableModelessDialog): self.vbox.pack_start(self._create_category_checkboxes(), True, True, 0) self.vbox.pack_start(self._create_add_category(), False, False, 0) - self.show_all() + self.vbox.show_all() def add_games(self, games: Sequence[Game]) -> None: def mark_category_checkbox(checkbox, included):