diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-07-05 15:05:56 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-07-05 15:05:56 +0300 |
| commit | 63c86b7d5a54a9a3723e29658c479e409bcd9599 (patch) | |
| tree | de34bd1f324f4b40c7df58a9874d7a319422248b | |
| parent | 7420ca85c6d5996cb6b47e569de1d34da91bfb92 (diff) | |
| download | fungus-launcher-63c86b7d5a54a9a3723e29658c479e409bcd9599.tar.gz fungus-launcher-63c86b7d5a54a9a3723e29658c479e409bcd9599.tar.xz | |
pick better name for new global env implementatio and reduce tooltip-related copypasta
| -rw-r--r-- | fungus/add_game_dialog.py | 15 | ||||
| -rw-r--r-- | fungus/game_launcher.py | 14 | ||||
| -rw-r--r-- | fungus/settings_dialog.py | 30 | ||||
| -rw-r--r-- | fungus/utils.py | 39 | ||||
| -rw-r--r-- | tests/test_run_manager.py | 2 |
5 files changed, 55 insertions, 45 deletions
diff --git a/fungus/add_game_dialog.py b/fungus/add_game_dialog.py index 6f6fc5b..25e12bf 100644 --- a/fungus/add_game_dialog.py +++ b/fungus/add_game_dialog.py @@ -960,19 +960,8 @@ class AddGame(EntryTooltipMixin, Gtk.Dialog): self.liststore_environment.append([""]) def _on_env_query_tooltip(self, widget, x, y, keyboard_mode, tooltip): - """Show a tooltip with the cell value when hovering over a treeview row.""" - result = widget.get_path_at_pos(x, y) - if result is not None: - path, *_ = result - try: - tree_iter = self.liststore_environment.get_iter(path) - except ValueError: - return False - value = self.liststore_environment.get_value(tree_iter, 0) - if value.strip(): - tooltip.set_text(value) - return True - return False + """Tooltip handler for the environment variable treeview.""" + return self.on_list_query_tooltip(widget, x, y, keyboard_mode, tooltip, self.liststore_environment) def on_env_key_press(self, widget, event): """Allow deleting environment variable rows via the Delete key (but not the last empty row).""" diff --git a/fungus/game_launcher.py b/fungus/game_launcher.py index 7630c53..1382b15 100644 --- a/fungus/game_launcher.py +++ b/fungus/game_launcher.py @@ -221,7 +221,7 @@ class GameLauncher: self, game: Game | None = None, game_dirs: list[str] | None = None, - env_from_file: dict[str, str] | None = None, + global_env: dict[str, str] | None = None, per_game_env: dict[str, str] | None = None, ) -> tuple[list[str], dict[str, str], list[str]]: """Construct the bwrap sandbox and inner command. @@ -232,8 +232,8 @@ class GameLauncher: game = self.game if game_dirs is None: game_dirs = [] - if env_from_file is None: - env_from_file = {} + if global_env is None: + global_env = {} if per_game_env is None: per_game_env = {} @@ -253,8 +253,8 @@ class GameLauncher: ]) # ── Environment variables from env file (base layer) ──────── - if env_from_file: - sandbox_env.update(env_from_file) + if global_env: + sandbox_env.update(global_env) # ── Per-game environment (override layer) ────────────────── sandbox_env.update(per_game_env) @@ -404,7 +404,7 @@ class GameLauncher: return LaunchHandle(None, 0) # ── Load global env ───────────────────────────────────────── - self.env_from_file = self.load_global_env() + self.global_env = self.load_global_env() # ── Build per-game environment ────────────────────────────── per_game_env = self._build_per_game_env() @@ -427,7 +427,7 @@ class GameLauncher: self._on_sandbox_warning(exec_path, valid_dirs) bwrap_cmd, sandbox_env, inner_cmd = self.build_bwrap_command( - self.game, valid_dirs, self.env_from_file, per_game_env, + self.game, valid_dirs, self.global_env, per_game_env, ) log.info(f"final bwrap command: {bwrap_cmd}") diff --git a/fungus/settings_dialog.py b/fungus/settings_dialog.py index 9eb5ca1..5f2e8f9 100644 --- a/fungus/settings_dialog.py +++ b/fungus/settings_dialog.py @@ -60,7 +60,7 @@ class SettingsDialog(EntryTooltipMixin, Gtk.Dialog): self.treeview_game_dirs = Gtk.TreeView(model=self.liststore_game_dirs) self.treeview_game_dirs.set_has_tooltip(True) - self.treeview_game_dirs.connect("query-tooltip", self.on_query_tooltip) + self.treeview_game_dirs.connect("query-tooltip", self._on_gamedirs_query_tooltip) self.treeview_game_dirs.connect("button-press-event", self.on_gamedirs_button_press) renderer_game_dirs = Gtk.CellRendererText() @@ -208,7 +208,7 @@ class SettingsDialog(EntryTooltipMixin, Gtk.Dialog): treeview = Gtk.TreeView(model=self.liststore) treeview.set_has_tooltip(True) - treeview.connect("query-tooltip", self.on_query_tooltip) + treeview.connect("query-tooltip", self._on_env_query_tooltip) treeview.connect("key-press-event", self.on_envar_key_press) renderer = Gtk.CellRendererText() @@ -448,25 +448,13 @@ class SettingsDialog(EntryTooltipMixin, Gtk.Dialog): total /= 1024.0 return f"{total:.1f} TB" - def on_query_tooltip(self, widget, x, y, keyboard_mode, tooltip): - """Show a tooltip with the cell value when hovering over a treeview row.""" - result = widget.get_path_at_pos(x, y) - if result is not None: - path, *_ = result - liststore = self.liststore - try: - tree_iter = liststore.get_iter(path) - except ValueError: - liststore = self.liststore_game_dirs - try: - tree_iter = liststore.get_iter(path) - except ValueError: - return False - value = liststore.get_value(tree_iter, 0) - if value.strip(): - tooltip.set_text(value) - return True - return False + def _on_env_query_tooltip(self, widget, x, y, keyboard_mode, tooltip): + """Tooltip handler for the environment variable treeview.""" + return self.on_list_query_tooltip(widget, x, y, keyboard_mode, tooltip, self.liststore) + + def _on_gamedirs_query_tooltip(self, widget, x, y, keyboard_mode, tooltip): + """Tooltip handler for the game directories treeview.""" + return self.on_list_query_tooltip(widget, x, y, keyboard_mode, tooltip, self.liststore_game_dirs) def on_cell_edited(self, widget, path, text, column_index): """Update the liststore cell and normalize empty rows.""" diff --git a/fungus/utils.py b/fungus/utils.py index e9ae9dc..923628e 100644 --- a/fungus/utils.py +++ b/fungus/utils.py @@ -122,10 +122,14 @@ def pick_folder(title: str, transient_for, current_folder: str | None = None) -> class EntryTooltipMixin: - """Mixin providing a standard ``query-tooltip`` handler for GTK Entry widgets. + """Mixin providing standard ``query-tooltip`` handlers for GTK widgets. - Displays the entry's current text when non-empty, otherwise falls back - to the entry's ``tooltip-text`` property. + ``on_entry_query_tooltip`` — displays the entry's current text when + non-empty, otherwise falls back to the entry's ``tooltip-text`` property. + + ``on_list_query_tooltip`` — shows a tooltip with the cell value when + hovering over a TreeView row. Accepts a single *liststore* to resolve + the cell from. """ def on_entry_query_tooltip(self, widget, x, y, keyboard_mode, tooltip): @@ -135,3 +139,32 @@ class EntryTooltipMixin: else: tooltip.set_text(widget.get_tooltip_text()) return True + + def on_list_query_tooltip(self, widget, x, y, keyboard_mode, tooltip, liststore): + """Show a tooltip with the cell value when hovering over a treeview row. + + Parameters + ---------- + widget : Gtk.TreeView + The treeview that emitted the signal. + x, y : int + The cursor position inside *widget*. + keyboard_mode : bool + Whether the tooltip was triggered by the keyboard. + tooltip : Gtk.Tooltip + The tooltip widget to populate. + liststore : Gtk.ListStore + The liststore to resolve the cell from. + """ + result = widget.get_path_at_pos(x, y) + if result is not None: + path, *_ = result + try: + tree_iter = liststore.get_iter(path) + except ValueError: + return False + value = liststore.get_value(tree_iter, 0) + if value.strip(): + tooltip.set_text(value) + return True + return False diff --git a/tests/test_run_manager.py b/tests/test_run_manager.py index 60e8a8a..8face5b 100644 --- a/tests/test_run_manager.py +++ b/tests/test_run_manager.py @@ -381,7 +381,7 @@ class TestBuildBwrapCommand: assert bwrap_args[bind_idx + 1] == game_dir assert bwrap_args[bind_idx + 2] == game_dir - def test_env_from_file_merged(self, fungus_run): + def test_global_env_merged(self, fungus_run): """Environment variables from file should be in sandbox_env.""" env_data = {"FOO": "bar", "BAZ": "qux"} _, sandbox_env, _ = fungus_run.build_bwrap_command( |
