From 975ac373b66813f0b26700f451f15f3e0614ad39 Mon Sep 17 00:00:00 2001 From: axtloss Date: Thu, 21 Jul 2022 18:24:15 +0200 Subject: [PATCH] Populate keyboard screen --- src/functions/keyboard_screen.py | 18 ++++++++++++++++-- src/widgets/layout.py | 8 +++++++- src/widgets/variant.py | 2 +- src/window.py | 9 ++------- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/functions/keyboard_screen.py b/src/functions/keyboard_screen.py index 2009b75..d0e3098 100644 --- a/src/functions/keyboard_screen.py +++ b/src/functions/keyboard_screen.py @@ -18,6 +18,8 @@ # along with this program. If not, see . +from jade_gui.locales.locales_list import locations +from jade_gui.widgets.variant import KeyboardVariant from gi.repository import Gtk, Adw from gettext import gettext as _ @@ -38,6 +40,9 @@ class KeyboardScreen(Adw.Bin): variant_search = Gtk.Template.Child() variant_entry_search = Gtk.Template.Child() + layout = None + variant = "" + def __init__(self, window, main_carousel, next_page, application, **kwargs): super().__init__(**kwargs) self.window = window @@ -59,15 +64,24 @@ class KeyboardScreen(Adw.Bin): terms = self.variant_entry_search.get_text() self.list_keyboard_variants.set_filter_func(self.filter_text, terms) - def selected_layout(self, widget, row): + def selected_layout(self, widget, row, *args): if row is not None or row is not self.layout_entry_search: + if self.layout is not None: + for n in range(len(self.layout.variants)): + print(n) + print(self.list_keyboard_variants.get_row_at_index(n)) + if self.list_keyboard_variants.get_row_at_index(n) is not None: + self.list_keyboard_variants.remove(self.list_keyboard_variants.get_row_at_index(n)) + self.layout = row + for variant in row.variants: + self.list_keyboard_variants.append(KeyboardVariant(window=self.window, country=row.country, country_shorthand=row.country_shorthand, variant=variant, *args)) self.keyboard_carousel.scroll_to(self.keyboard_variants, True) else: print("row is none!! layout") def selected_variant(self, widget, row): if row is not None or row is not self.variant_entry_search: - print("variant selected") + self.variant = row self.carousel.scroll_to(self.next_page, True) else: print("row is none!! variant") diff --git a/src/widgets/layout.py b/src/widgets/layout.py index b4264a4..5b5709a 100644 --- a/src/widgets/layout.py +++ b/src/widgets/layout.py @@ -24,9 +24,15 @@ from gettext import gettext as _ class KeyboardLayout(Adw.ActionRow): __gtype_name__ = 'KeyboardLayout' - def __init__(self, window, country, country_shorthand, application, **kwargs): + variants=[] + + def __init__(self, window, country, country_shorthand, variants, application, **kwargs): super().__init__(**kwargs) + self.country = country + self.country_shorthand = country_shorthand + self.set_title(country) self.set_subtitle(country_shorthand) + self.variants = variants diff --git a/src/widgets/variant.py b/src/widgets/variant.py index 8b0eddc..bdcb78c 100644 --- a/src/widgets/variant.py +++ b/src/widgets/variant.py @@ -24,7 +24,7 @@ from gettext import gettext as _ class KeyboardVariant(Adw.ActionRow): __gtype_name__ = 'KeyboardVariant' - def __init__(self, window, variant, country, country_shorthand, application, **kwargs): + def __init__(self, window, variant, country, country_shorthand, **kwargs): super().__init__(**kwargs) self.set_title(variant) diff --git a/src/window.py b/src/window.py index 521f78e..39e557e 100644 --- a/src/window.py +++ b/src/window.py @@ -88,16 +88,11 @@ class JadeGuiWindow(Gtk.ApplicationWindow): for keymap in keymaps: print(keymap.layout) print(keymap.backend_layout) - self.keyboard_screen.list_keyboard_layouts.append(KeyboardLayout(window=self, country=keymap.layout, country_shorthand=keymap.backend_layout, **kwargs)) + self.keyboard_screen.list_keyboard_layouts.append(KeyboardLayout(window=self, country=keymap.layout, country_shorthand=keymap.backend_layout, variants=keymap.variant, **kwargs)) ### --------- ### Test variants - variant_test = KeyboardVariant(window=self, variant="Colemak", country="United Kingdom", country_shorthand="GB", **kwargs) - variant_test_two = KeyboardVariant(window=self, variant="QWERTY", country="Germany", country_shorthand="DE", **kwargs) - variant_test_three = KeyboardVariant(window=self, variant="QWERTZ", country="United States", country_shorthand="US", **kwargs) - self.keyboard_screen.list_keyboard_variants.append(variant_test) - self.keyboard_screen.list_keyboard_variants.append(variant_test_two) - self.keyboard_screen.list_keyboard_variants.append(variant_test_three) + ### --------- ### Test desktops