From f0faccb07ffb273d568925911735f2c101a6732d Mon Sep 17 00:00:00 2001 From: axtlos Date: Wed, 29 Jun 2022 14:07:59 +0200 Subject: [PATCH] add keyboard selection and split up pages in seperate classes/files --- build.sh | 27 ++++++++++++ src/functions/__init__.py | 0 src/functions/keyboard_screen.py | 45 ++++++++++++++++++++ src/functions/meson.build | 9 ++++ src/functions/timezone_screen.py | 48 +++++++++++++++++++++ src/jade_gui.gresource.xml | 4 ++ src/meson.build | 7 +++- src/pages/keyboard_screen.blp | 57 +++++++++++++++++++++++++ src/pages/timezone_screen.blp | 34 +++++++++++++++ src/widgets/layout.blp | 13 ++++++ src/widgets/layout.py | 32 ++++++++++++++ src/widgets/meson.build | 2 + src/widgets/timezone.py | 2 +- src/widgets/variant.blp | 7 ++++ src/widgets/variant.py | 32 ++++++++++++++ src/window.blp | 21 ---------- src/window.py | 72 ++++++++++++++++---------------- 17 files changed, 352 insertions(+), 60 deletions(-) create mode 100755 build.sh create mode 100644 src/functions/__init__.py create mode 100644 src/functions/keyboard_screen.py create mode 100644 src/functions/meson.build create mode 100644 src/functions/timezone_screen.py create mode 100644 src/pages/keyboard_screen.blp create mode 100644 src/pages/timezone_screen.blp create mode 100644 src/widgets/layout.blp create mode 100644 src/widgets/layout.py create mode 100644 src/widgets/variant.blp create mode 100644 src/widgets/variant.py diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..9703fd1 --- /dev/null +++ b/build.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +if [[ $1 == "build" ]]; then + if [[ ! -d "build" ]]; then + meson build + else + meson --reconfigure build + fi + ninja -C build +elif [[ $1 == "install" ]]; then + pushd build + sudo ninja install +elif [[ $1 == "build-install" ]]; then + if [[ ! -d "build" ]]; then + meson build + else + meson --reconfigure build + fi + ninja -C build + pushd build + sudo ninja install +else + echo "Unkown command $1" + echo "usage:" + echo "build build jade gui" + echo "install install jade gui" + echo "build-install build and install jade_gui" +fi diff --git a/src/functions/__init__.py b/src/functions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/functions/keyboard_screen.py b/src/functions/keyboard_screen.py new file mode 100644 index 0000000..2b62c0e --- /dev/null +++ b/src/functions/keyboard_screen.py @@ -0,0 +1,45 @@ +from gi.repository import Gtk, Adw +from gettext import gettext as _ + +@Gtk.Template(resource_path='/al/getcyrst/jadegui/pages/keyboard_screen.ui') +class KeyboardScreen(Adw.Bin): + __gtype_name__ = 'KeyboardScreen' + + event_controller = Gtk.EventControllerKey.new() + #carousel = Gtk.Template.Child() + + ### Page and widgets for keyboard screen + # keyboard_page = Gtk.Template.Child() + keyboard_entry_search = Gtk.Template.Child() + keyboard_search = Gtk.Template.Child() + keyboard_carousel = Gtk.Template.Child() + list_keyboard_layouts = Gtk.Template.Child() + list_keyboard_variants = Gtk.Template.Child() + keyboard_layouts = Gtk.Template.Child() + keyboard_variants = Gtk.Template.Child() + + def __init__(self, window, main_carousel, next_page, application, **kwargs): + super().__init__(**kwargs) + self.window = window + self.carousel = main_carousel + self.next_page = next_page + ### Widgets for third page (keyboard layout) + self.keyboard_search.set_key_capture_widget(self) + self.list_keyboard_layouts.connect("row-selected", self.selected_layout) + self.list_keyboard_variants.connect("row-selected", self.selected_variant) + + def search_keyboards(self, *args): + pass + + def selected_layout(self, widget, row): + if row is not None: + 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: + print("variant selected") + else: + print("row is none!! variant") + diff --git a/src/functions/meson.build b/src/functions/meson.build new file mode 100644 index 0000000..c6c2267 --- /dev/null +++ b/src/functions/meson.build @@ -0,0 +1,9 @@ +pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name()) +functionsdir = join_paths(pkgdatadir, 'jade_gui/functions') + +jade_gui_sources = [ + '__init__.py', + 'keyboard_screen.py', + 'timezone_screen.py', +] +install_data(jade_gui_sources, install_dir: functionsdir) \ No newline at end of file diff --git a/src/functions/timezone_screen.py b/src/functions/timezone_screen.py new file mode 100644 index 0000000..abb8972 --- /dev/null +++ b/src/functions/timezone_screen.py @@ -0,0 +1,48 @@ +from gi.repository import Gtk, Adw +from gettext import gettext as _ + +@Gtk.Template(resource_path='/al/getcyrst/jadegui/pages/timezone_screen.ui') +class TimezoneScreen(Adw.Bin): + __gtype_name__ = 'TimezoneScreen' + + event_controller = Gtk.EventControllerKey.new() + #carousel = Gtk.Template.Child() + + ### Page and widgets on timezone screen + #timezone_page = Gtk.Template.Child() + list_timezones = Gtk.Template.Child() + timezone_entry_search = Gtk.Template.Child() + timezone_search = Gtk.Template.Child() + + def __init__(self, window, main_carousel, next_page, application, **kwargs): + super().__init__(**kwargs) + self.window = window + self.carousel = main_carousel + self.next_page = next_page + + + ### Widgets for second page (timezone selection) + self.event_controller.connect("key-released", self.search_timezones) + self.timezone_entry_search.add_controller(self.event_controller) + self.timezone_search.set_key_capture_widget(self) + self.list_timezones.connect("row-selected", self.selected_timezone) + ### --------- + + def selected_timezone(self, widget, row): + if row is not None: + print(row.get_title()) + self.carousel.scroll_to(self.next_page, True) + else: + print("row is none!!") + + def search_timezones(self, *args): + terms = self.entry_search.get_text() + self.list_timezones.set_filter_func(self.filter_timezones, terms) + + @staticmethod + def filter_timezones(row, terms=None): + text = row.get_title() + text = text.lower() + row.get_subtitle().lower() + if terms.lower() in text: + return True + return False diff --git a/src/jade_gui.gresource.xml b/src/jade_gui.gresource.xml index dfe19e4..e1d78a9 100644 --- a/src/jade_gui.gresource.xml +++ b/src/jade_gui.gresource.xml @@ -3,6 +3,10 @@ window.ui widgets/timezone.ui + widgets/layout.ui + widgets/variant.ui + pages/keyboard_screen.ui + pages/timezone_screen.ui gtk/help-overlay.ui crystal-logo-minimal.png diff --git a/src/meson.build b/src/meson.build index 056c50a..e7a2c54 100644 --- a/src/meson.build +++ b/src/meson.build @@ -7,6 +7,10 @@ blueprints = custom_target('blueprints', 'gtk/help-overlay.blp', 'window.blp', 'widgets/timezone.blp', + 'widgets/layout.blp', + 'widgets/variant.blp', + 'pages/keyboard_screen.blp', + 'pages/timezone_screen.blp', ), output: '.', command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'], @@ -25,7 +29,7 @@ gnome.compile_resources('jade_gui', python = import('python') conf = configuration_data() -conf.set('PYTHON', python.find_installation('python3').path()) +conf.set('PYTHON', python.find_installation('python3').full_path()) conf.set('VERSION', meson.project_version()) conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir'))) conf.set('pkgdatadir', pkgdatadir) @@ -39,6 +43,7 @@ configure_file( ) subdir('widgets') +subdir('functions') jade_gui_sources = [ '__init__.py', diff --git a/src/pages/keyboard_screen.blp b/src/pages/keyboard_screen.blp new file mode 100644 index 0000000..707b80a --- /dev/null +++ b/src/pages/keyboard_screen.blp @@ -0,0 +1,57 @@ +using Gtk 4.0; +using Adw 1; + +template KeyboardScreen : Adw.Bin { + hexpand: true; + vexpand: true; + Gtk.Box { + vexpand: true; + hexpand: true; + //halign: center; + //valign: center; + Adw.StatusPage { + hexpand: true; + vexpand: true; + title: "Next question: keyboard layout?"; + description: "What is it? Huh?"; + Gtk.Box { + orientation: vertical; + Gtk.SearchBar keyboard_search { + Gtk.SearchEntry keyboard_entry_search { + placeholder-text: "Search for a timezone..."; + } + } + } + Adw.PreferencesPage { + Adw.Carousel keyboard_carousel { + orientation: horizontal; + vexpand: true; + hexpand: true; + Adw.PreferencesGroup keyboard_layouts { + hexpand: true; + vexpand: true; + margin-end: 5; + Gtk.ListBox list_keyboard_layouts { + //selection-mode: none; + hexpand: true; + vexpand: true; + // margin-end: 5; + styles ["boxed-list"] + } + } + Adw.PreferencesGroup keyboard_variants { + hexpand: true; + vexpand: true; + margin-start: 5; + Gtk.ListBox list_keyboard_variants { + hexpand: true; + vexpand: true; + // margin-start: 5; + styles ["boxed-list"] + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/pages/timezone_screen.blp b/src/pages/timezone_screen.blp new file mode 100644 index 0000000..ebfc331 --- /dev/null +++ b/src/pages/timezone_screen.blp @@ -0,0 +1,34 @@ +using Gtk 4.0; +using Adw 1; + +template TimezoneScreen : Adw.Bin { + hexpand: true; + vexpand: true; + Gtk.Box { + vexpand: true; + hexpand: true; + //valign: center; + //halign: center; + Adw.StatusPage { + hexpand: true; + vexpand: true; + title: "Let's get started, shall we?"; + description: "What's your curent timezone?"; + Gtk.Box { + orientation: vertical; + Gtk.SearchBar timezone_search { + Gtk.SearchEntry timezone_entry_search { + placeholder-text: "Search for a timezone..."; + } + } + Adw.PreferencesPage { + Adw.PreferencesGroup { + Gtk.ListBox list_timezones { + styles ["boxed-list"] + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/widgets/layout.blp b/src/widgets/layout.blp new file mode 100644 index 0000000..2017e8d --- /dev/null +++ b/src/widgets/layout.blp @@ -0,0 +1,13 @@ +using Gtk 4.0; +using Adw 1; + +template KeyboardLayout : Adw.ActionRow { + title: "Country"; + subtitle: "Country Code"; + Gtk.Box { + spacing: 6; + Gtk.Image { + icon-name: "go-next-symbolic"; + } + } +} \ No newline at end of file diff --git a/src/widgets/layout.py b/src/widgets/layout.py new file mode 100644 index 0000000..49731cf --- /dev/null +++ b/src/widgets/layout.py @@ -0,0 +1,32 @@ +# layout.py + +# +# Copyright 2022 user + +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from gi.repository import Gtk, GLib, Adw +from gettext import gettext as _ + +@Gtk.Template(resource_path='/al/getcyrst/jadegui/widgets/layout.ui') +class KeyboardLayout(Adw.ActionRow): + __gtype_name__ = 'KeyboardLayout' + + def __init__(self, window, country, country_shorthand, application, **kwargs): + super().__init__(**kwargs) + + self.set_title(country) + self.set_subtitle(country_shorthand) + diff --git a/src/widgets/meson.build b/src/widgets/meson.build index 2308c2a..f494968 100644 --- a/src/widgets/meson.build +++ b/src/widgets/meson.build @@ -4,5 +4,7 @@ widgetsdir = join_paths(pkgdatadir, 'jade_gui/widgets') jade_gui_sources = [ '__init__.py', 'timezone.py', + 'layout.py', + 'variant.py', ] install_data(jade_gui_sources, install_dir: widgetsdir) \ No newline at end of file diff --git a/src/widgets/timezone.py b/src/widgets/timezone.py index b9beda7..b0ea3cf 100644 --- a/src/widgets/timezone.py +++ b/src/widgets/timezone.py @@ -1,4 +1,4 @@ -# timezone-entry.py +# timezone.py # # Copyright 2022 user diff --git a/src/widgets/variant.blp b/src/widgets/variant.blp new file mode 100644 index 0000000..c18d3a1 --- /dev/null +++ b/src/widgets/variant.blp @@ -0,0 +1,7 @@ +using Gtk 4.0; +using Adw 1; + +template KeyboardVariant : Adw.ActionRow { + title: "Variant"; + subtitle: "Country - Country code"; +} \ No newline at end of file diff --git a/src/widgets/variant.py b/src/widgets/variant.py new file mode 100644 index 0000000..8ffaa89 --- /dev/null +++ b/src/widgets/variant.py @@ -0,0 +1,32 @@ +# variant.py + +# +# Copyright 2022 user + +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from gi.repository import Gtk, GLib, Adw +from gettext import gettext as _ + +@Gtk.Template(resource_path='/al/getcyrst/jadegui/widgets/variant.ui') +class KeyboardVariant(Adw.ActionRow): + __gtype_name__ = 'KeyboardVariant' + + def __init__(self, window, variant, country, country_shorthand, application, **kwargs): + super().__init__(**kwargs) + + self.set_title(variant) + self.set_subtitle(country+" - "+country_shorthand) + diff --git a/src/window.blp b/src/window.blp index 7d3ca8c..ccc5882 100644 --- a/src/window.blp +++ b/src/window.blp @@ -81,27 +81,6 @@ template JadeGuiWindow : Gtk.ApplicationWindow { } } } - Adw.StatusPage timezone_page { - title: "Let's get started, shall we?"; - description: "What's your current timezone?"; - Gtk.Box { - orientation: vertical; - Gtk.SearchBar timezone_search { - Gtk.SearchEntry entry_search { - placeholder-text: "Search for a timezone..."; - } - } - Adw.PreferencesPage { - Adw.PreferencesGroup { - Gtk.ListBox list_timezones { - //selection-mode: none; - styles ["boxed-list"] - } - } - } - } - } } } } - diff --git a/src/window.py b/src/window.py index d996039..c87f0c9 100644 --- a/src/window.py +++ b/src/window.py @@ -20,12 +20,16 @@ from gi.repository import Gtk from gi.repository import Gdk from .widgets.timezone import TimezoneEntry -import time +from .widgets.layout import KeyboardLayout +from .widgets.variant import KeyboardVariant +from .functions.keyboard_screen import KeyboardScreen +from .functions.timezone_screen import TimezoneScreen @Gtk.Template(resource_path='/al/getcyrst/jadegui/window.ui') class JadeGuiWindow(Gtk.ApplicationWindow): __gtype_name__ = 'JadeGuiWindow' + event_controller = Gtk.EventControllerKey.new() carousel = Gtk.Template.Child() ### Page and widgets on welcome screen @@ -33,42 +37,50 @@ class JadeGuiWindow(Gtk.ApplicationWindow): quit_button = Gtk.Template.Child() next_button = Gtk.Template.Child() - ### Page and widgets on timezone screen - timezone_page = Gtk.Template.Child() - list_timezones = Gtk.Template.Child() - entry_search = Gtk.Template.Child() - timezone_search = Gtk.Template.Child() - event_controller = Gtk.EventControllerKey.new() + def __init__(self, **kwargs): super().__init__(**kwargs) - - + self.keyboard_screen = KeyboardScreen(window=self, main_carousel=self.carousel, next_page=None, **kwargs) + self.timezone_screen = TimezoneScreen(window=self, main_carousel=self.carousel, next_page=self.keyboard_screen, **kwargs) + self.carousel.append(self.timezone_screen) + self.carousel.append(self.keyboard_screen) ### Widgets for first page (welcome screen) self.quit_button.connect("clicked", self.confirmQuit) self.next_button.connect("clicked", self.nextPage) ### --------- - ### Widgets for second page (timezone selection) - self.event_controller.connect("key-released", self.search_timezones) - self.entry_search.add_controller(self.event_controller) - self.timezone_search.set_key_capture_widget(self) - self.list_timezones.connect("row-selected", self.selected_timezone) - ### --------- - ### Test timezones timezone_test = TimezoneEntry(window=self, location="Europe", region="Berlin", timezone="CEST UTC+2", locale="en_US.UTF-8", **kwargs) timezone_test_two = TimezoneEntry(window=self, location="Europe", region="London", timezone="BST UTC+1", locale="en_US.UTF-8", **kwargs) timezone_test_three = TimezoneEntry(window=self, location="America", region="Chihuahua", timezone="MDT UTC-6", locale="en_MX.UTF-8", **kwargs) - self.list_timezones.append(timezone_test) - self.list_timezones.append(timezone_test_two) - self.list_timezones.append(timezone_test_three) + self.timezone_screen.list_timezones.append(timezone_test) + self.timezone_screen.list_timezones.append(timezone_test_two) + self.timezone_screen.list_timezones.append(timezone_test_three) + ### --------- + + ### Test layouts + layout_test = KeyboardLayout(window=self, country="Germany", country_shorthand="DE", **kwargs) + layout_test_two = KeyboardLayout(window=self, country="United Kingdom", country_shorthand="GB", **kwargs) + layout_test_three = KeyboardLayout(window=self, country="United States", country_shorthand="US", **kwargs) + self.keyboard_screen.list_keyboard_layouts.append(layout_test) + self.keyboard_screen.list_keyboard_layouts.append(layout_test_two) + self.keyboard_screen.list_keyboard_layouts.append(layout_test_three) + ### --------- + + ### 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) ### --------- # TODO: offload functions to seperate files/classes def nextPage(self, idk): - self.carousel.scroll_to(self.timezone_page, True) + self.carousel.scroll_to(self.timezone_screen, True) def confirmQuit(self, idk): @@ -89,23 +101,9 @@ class JadeGuiWindow(Gtk.ApplicationWindow): dialog.connect("response", handle_response) dialog.present() - def selected_timezone(self, widget, row): - if row is not None: - print(row.get_title()) - else: - print("row is none!!") - - def search_timezones(self, *args): - terms = self.entry_search.get_text() - self.list_timezones.set_filter_func(self.filter_timezones, terms) - - @staticmethod - def filter_timezones(row, terms=None): - text = row.get_title() - text = text.lower() + row.get_subtitle().lower() - if terms.lower() in text: - return True - return False + + + class AboutDialog(Gtk.AboutDialog):