add keyboard selection and split up pages in seperate classes/files

pull/6/head
axtlos 2 years ago
parent 0ce2e83acd
commit f0faccb07f

@ -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

@ -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")

@ -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)

@ -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

@ -3,6 +3,10 @@
<gresource prefix="/al/getcyrst/jadegui"> <gresource prefix="/al/getcyrst/jadegui">
<file>window.ui</file> <file>window.ui</file>
<file>widgets/timezone.ui</file> <file>widgets/timezone.ui</file>
<file>widgets/layout.ui</file>
<file>widgets/variant.ui</file>
<file>pages/keyboard_screen.ui</file>
<file>pages/timezone_screen.ui</file>
<file>gtk/help-overlay.ui</file> <file>gtk/help-overlay.ui</file>
<file>crystal-logo-minimal.png</file> <file>crystal-logo-minimal.png</file>
</gresource> </gresource>

@ -7,6 +7,10 @@ blueprints = custom_target('blueprints',
'gtk/help-overlay.blp', 'gtk/help-overlay.blp',
'window.blp', 'window.blp',
'widgets/timezone.blp', 'widgets/timezone.blp',
'widgets/layout.blp',
'widgets/variant.blp',
'pages/keyboard_screen.blp',
'pages/timezone_screen.blp',
), ),
output: '.', output: '.',
command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'], command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'],
@ -25,7 +29,7 @@ gnome.compile_resources('jade_gui',
python = import('python') python = import('python')
conf = configuration_data() 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('VERSION', meson.project_version())
conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir'))) conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir')))
conf.set('pkgdatadir', pkgdatadir) conf.set('pkgdatadir', pkgdatadir)
@ -39,6 +43,7 @@ configure_file(
) )
subdir('widgets') subdir('widgets')
subdir('functions')
jade_gui_sources = [ jade_gui_sources = [
'__init__.py', '__init__.py',

@ -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"]
}
}
}
}
}
}
}

@ -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"]
}
}
}
}
}
}
}

@ -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";
}
}
}

@ -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 <http://www.gnu.org/licenses/>.
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)

@ -4,5 +4,7 @@ widgetsdir = join_paths(pkgdatadir, 'jade_gui/widgets')
jade_gui_sources = [ jade_gui_sources = [
'__init__.py', '__init__.py',
'timezone.py', 'timezone.py',
'layout.py',
'variant.py',
] ]
install_data(jade_gui_sources, install_dir: widgetsdir) install_data(jade_gui_sources, install_dir: widgetsdir)

@ -1,4 +1,4 @@
# timezone-entry.py # timezone.py
# #
# Copyright 2022 user # Copyright 2022 user

@ -0,0 +1,7 @@
using Gtk 4.0;
using Adw 1;
template KeyboardVariant : Adw.ActionRow {
title: "Variant";
subtitle: "Country - Country code";
}

@ -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 <http://www.gnu.org/licenses/>.
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)

@ -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"]
}
}
}
}
}
} }
} }
} }

@ -20,12 +20,16 @@
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import Gdk from gi.repository import Gdk
from .widgets.timezone import TimezoneEntry 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') @Gtk.Template(resource_path='/al/getcyrst/jadegui/window.ui')
class JadeGuiWindow(Gtk.ApplicationWindow): class JadeGuiWindow(Gtk.ApplicationWindow):
__gtype_name__ = 'JadeGuiWindow' __gtype_name__ = 'JadeGuiWindow'
event_controller = Gtk.EventControllerKey.new()
carousel = Gtk.Template.Child() carousel = Gtk.Template.Child()
### Page and widgets on welcome screen ### Page and widgets on welcome screen
@ -33,42 +37,50 @@ class JadeGuiWindow(Gtk.ApplicationWindow):
quit_button = Gtk.Template.Child() quit_button = Gtk.Template.Child()
next_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): def __init__(self, **kwargs):
super().__init__(**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) ### Widgets for first page (welcome screen)
self.quit_button.connect("clicked", self.confirmQuit) self.quit_button.connect("clicked", self.confirmQuit)
self.next_button.connect("clicked", self.nextPage) 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 ### Test timezones
timezone_test = TimezoneEntry(window=self, location="Europe", region="Berlin", timezone="CEST UTC+2", locale="en_US.UTF-8", **kwargs) 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_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) 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.timezone_screen.list_timezones.append(timezone_test)
self.list_timezones.append(timezone_test_two) self.timezone_screen.list_timezones.append(timezone_test_two)
self.list_timezones.append(timezone_test_three) 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 # TODO: offload functions to seperate files/classes
def nextPage(self, idk): def nextPage(self, idk):
self.carousel.scroll_to(self.timezone_page, True) self.carousel.scroll_to(self.timezone_screen, True)
def confirmQuit(self, idk): def confirmQuit(self, idk):
@ -89,23 +101,9 @@ class JadeGuiWindow(Gtk.ApplicationWindow):
dialog.connect("response", handle_response) dialog.connect("response", handle_response)
dialog.present() 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): class AboutDialog(Gtk.AboutDialog):

Loading…
Cancel
Save