From 5be9954e84473f33127c24fac7b1aa37b1fb9e1b Mon Sep 17 00:00:00 2001 From: actionless Date: Wed, 25 Sep 2024 02:15:13 +0200 Subject: [PATCH] refactor(terminal: *): rename `app` arg to `window` and make it optional --- oomox_gui/main.py | 2 +- oomox_gui/multi_export_cli.py | 2 +- oomox_gui/terminal.py | 35 ++++++++++++++++++----------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/oomox_gui/main.py b/oomox_gui/main.py index 75800d9f..fb521f57 100755 --- a/oomox_gui/main.py +++ b/oomox_gui/main.py @@ -410,7 +410,7 @@ def _generate_terminal_colors(colors: "ThemeT") -> None: generate_terminal_colors_for_oomox( self.colorscheme, - app=self, + window=self, result_callback=_generate_terminal_colors, ) diff --git a/oomox_gui/multi_export_cli.py b/oomox_gui/multi_export_cli.py index b6fd9e6c..d99d8400 100644 --- a/oomox_gui/multi_export_cli.py +++ b/oomox_gui/multi_export_cli.py @@ -94,7 +94,7 @@ def do_multi_export(args: argparse.Namespace) -> None: def callback1(theme: "ThemeT") -> None: generate_terminal_colors_for_oomox( colorscheme=theme, - app=app.window, + window=app.window, result_callback=callback2, ) diff --git a/oomox_gui/terminal.py b/oomox_gui/terminal.py index 58ddd783..890248ee 100644 --- a/oomox_gui/terminal.py +++ b/oomox_gui/terminal.py @@ -391,12 +391,12 @@ def generate_theme_from_full_palette( # pylint: disable=too-many-arguments,too- theme_bg: str, theme_fg: str, template_path: str, - app: "OomoxApplicationWindow", result_callback: "Callable[[TerminalThemeT], None]", *, auto_swap_colors: bool = True, accuracy: int | None = None, extend_palette: bool = False, + window: "OomoxApplicationWindow | None" = None, **kwargs: "Any", ) -> None: @@ -437,18 +437,19 @@ def _callback(generated_colors: TerminalThemeT) -> None: ) # from time import time # before = time() - app.disable(translate("Generating terminal paletteā€¦")) - app.schedule_task( - lambda: _generate_theme_from_full_palette( - _callback, - reference_colors, - all_colors, - theme_bg, - accuracy, - extend_palette=extend_palette, - ), - ) - app.enable() + if window: + window.disable(translate("Generating terminal paletteā€¦")) + window.schedule_task( + lambda: _generate_theme_from_full_palette( + _callback, + reference_colors, + all_colors, + theme_bg, + accuracy, + extend_palette=extend_palette, + ), + ) + window.enable() # print(time() - before) @@ -471,8 +472,8 @@ def _generate_theme_from_full_palette_callback( def _generate_themes_from_oomox( original_colorscheme: "ThemeT", - app: "OomoxApplicationWindow", result_callback: "Callable[[ThemeT], None]", + window: "OomoxApplicationWindow | None" = None, ) -> None: colorscheme = {} colorscheme.update(original_colorscheme) @@ -512,7 +513,7 @@ def _callback(term_colorscheme: TerminalThemeT) -> None: auto_swap_colors=terminal_theme_auto_bgfg, extend_palette=terminal_theme_extend_palette, accuracy=255 + 8 - terminal_theme_accuracy, - app=app, + window=window, result_callback=_callback, ) return @@ -566,12 +567,12 @@ def generate_xrdb_theme_from_oomox(colorscheme: "ThemeT") -> TerminalThemeT: def generate_terminal_colors_for_oomox( colorscheme: "ThemeT", - app: "OomoxApplicationWindow", result_callback: "Callable[[ThemeT], None]", + window: "OomoxApplicationWindow | None" = None, ) -> None: _generate_themes_from_oomox( colorscheme, - app=app, + window=window, result_callback=result_callback, )