From f704c56ae8a0a635db7c06e0ae12f55fe73b99ab Mon Sep 17 00:00:00 2001 From: alfrix Date: Sun, 5 May 2024 18:41:07 -0300 Subject: [PATCH] config: create a generic button type --- ks_includes/config.py | 28 +++++++++++++--------------- ks_includes/screen_panel.py | 5 +++-- panels/settings.py | 3 ++- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ks_includes/config.py b/ks_includes/config.py index 8d6e451f..aacbecaa 100644 --- a/ks_includes/config.py +++ b/ks_includes/config.py @@ -246,10 +246,6 @@ class KlipperScreenConfig: def _create_configurable_options(self, screen): self.configurable_options = [ - {"language": { - "section": "main", "name": _("Language"), "type": None, "value": "system_lang", - "callback": screen.change_language, "options": [ - {"name": _("System") + " " + _("(default)"), "value": "system_lang"}]}}, {"theme": { "section": "main", "name": _("Icon Theme"), "type": "dropdown", "tooltip": _("Changes how the interface looks"), @@ -328,22 +324,24 @@ class KlipperScreenConfig: self.configurable_options.extend(panel_options) - t_path = os.path.join(klipperscreendir, 'styles') - themes = [d for d in os.listdir(t_path) if (not os.path.isfile(os.path.join(t_path, d)) and d != "z-bolt")] - themes.sort() - theme_opt = self.configurable_options[1]['theme']['options'] - - for theme in themes: - theme_opt.append({"name": theme, "value": theme}) - - i1 = i2 = None + i0 = i1 = i2 = None for i, option in enumerate(self.configurable_options): - if list(option)[0] == "screen_blanking": + if list(option)[0] == "theme": + i0 = i + elif list(option)[0] == "screen_blanking": i1 = i elif list(option)[0] == "screen_blanking_printing": i2 = i - if i1 and i2: + if i0 and i1 and i2: break + + t_path = os.path.join(klipperscreendir, 'styles') + themes = [d for d in os.listdir(t_path) if (not os.path.isfile(os.path.join(t_path, d)) and d != "z-bolt")] + themes.sort() + + for theme in themes: + self.configurable_options[i0]['theme']['options'].append({"name": theme, "value": theme}) + for num in SCREEN_BLANKING_OPTIONS: hour = num // 3600 minute = num // 60 diff --git a/ks_includes/screen_panel.py b/ks_includes/screen_panel.py index d3be7920..b3ee9e67 100644 --- a/ks_includes/screen_panel.py +++ b/ks_includes/screen_panel.py @@ -257,9 +257,10 @@ class ScreenPanel: open_menu.set_hexpand(False) open_menu.set_halign(Gtk.Align.END) row_box.add(open_menu) - elif option['type'] == "lang": + elif option['type'] == "button": select = self._gtk.Button("load", style="color3") - select.connect("clicked", self._screen.change_language, option['name']) + if "callback" in option: + select.connect("clicked", option['callback'], option['name']) select.set_hexpand(False) select.set_halign(Gtk.Align.END) row_box.add(select) diff --git a/panels/settings.py b/panels/settings.py index b55e0b59..cae24da9 100644 --- a/panels/settings.py +++ b/panels/settings.py @@ -35,7 +35,8 @@ class Panel(ScreenPanel): for lang in self._config.lang_list: self.langs[lang] = { "name": lang, - "type": "lang", + "type": "button", + "callback": self._screen.change_language, } self.add_option("lang", self.langs, lang, self.langs[lang])