From 0ce2e83acd9a0f40955e2437c0cf14667cb4e7ff Mon Sep 17 00:00:00 2001 From: axtlos Date: Tue, 28 Jun 2022 21:25:01 +0200 Subject: [PATCH] second page, timezone selection :) --- .gitignore | 1 + src/jade_gui.gresource.xml | 1 + src/meson.build | 3 +++ src/widgets/__init__.py | 0 src/widgets/meson.build | 8 +++++++ src/widgets/timezone.blp | 15 +++++++++++++ src/widgets/timezone.py | 42 ++++++++++++++++++++++++++++++++++ src/window.blp | 35 +++++------------------------ src/window.py | 46 ++++++++++++++++++++++++++++++-------- src/window.ui | 4 ++-- 10 files changed, 114 insertions(+), 41 deletions(-) create mode 100644 src/widgets/__init__.py create mode 100644 src/widgets/meson.build create mode 100644 src/widgets/timezone.blp create mode 100644 src/widgets/timezone.py diff --git a/.gitignore b/.gitignore index 96901c4..41d09c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /subprojects/blueprint-compiler +build/ diff --git a/src/jade_gui.gresource.xml b/src/jade_gui.gresource.xml index ba34e2b..dfe19e4 100644 --- a/src/jade_gui.gresource.xml +++ b/src/jade_gui.gresource.xml @@ -2,6 +2,7 @@ window.ui + widgets/timezone.ui gtk/help-overlay.ui crystal-logo-minimal.png diff --git a/src/meson.build b/src/meson.build index 81252c9..056c50a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -6,6 +6,7 @@ blueprints = custom_target('blueprints', input: files( 'gtk/help-overlay.blp', 'window.blp', + 'widgets/timezone.blp', ), output: '.', command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'], @@ -37,6 +38,8 @@ configure_file( install_dir: get_option('bindir') ) +subdir('widgets') + jade_gui_sources = [ '__init__.py', 'main.py', diff --git a/src/widgets/__init__.py b/src/widgets/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/widgets/meson.build b/src/widgets/meson.build new file mode 100644 index 0000000..2308c2a --- /dev/null +++ b/src/widgets/meson.build @@ -0,0 +1,8 @@ +pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name()) +widgetsdir = join_paths(pkgdatadir, 'jade_gui/widgets') + +jade_gui_sources = [ + '__init__.py', + 'timezone.py', +] +install_data(jade_gui_sources, install_dir: widgetsdir) \ No newline at end of file diff --git a/src/widgets/timezone.blp b/src/widgets/timezone.blp new file mode 100644 index 0000000..983b4be --- /dev/null +++ b/src/widgets/timezone.blp @@ -0,0 +1,15 @@ +using Gtk 4.0; +using Adw 1; + +template TimezoneEntry : Adw.ActionRow { + title: "region/location"; + subtitle: "timezone UTC +XX:XX"; + Gtk.Box { + spacing: 6; + Gtk.Label time_label { + valign: center; + label: "Current time"; + styles ["tag", "caption"] + } + } +} \ No newline at end of file diff --git a/src/widgets/timezone.py b/src/widgets/timezone.py new file mode 100644 index 0000000..b9beda7 --- /dev/null +++ b/src/widgets/timezone.py @@ -0,0 +1,42 @@ +# timezone-entry.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 datetime import datetime +import pytz +from gi.repository import Gtk, GLib, Adw +from gettext import gettext as _ + +@Gtk.Template(resource_path='/al/getcyrst/jadegui/widgets/timezone.ui') +class TimezoneEntry(Adw.ActionRow): + __gtype_name__ = 'TimezoneEntry' + + time_label = Gtk.Template.Child() + + def __init__(self, window, location, region, locale, timezone, application, **kwargs): + super().__init__(**kwargs) + + self.set_title(region+"/"+location) + self.set_subtitle(timezone) + + self.time_label.set_text(self.calculate_time(location, region)) + + def calculate_time(widget, location, region): + timezone = pytz.timezone(location+"/"+region) + datetime_timezone = datetime.now(timezone) + return datetime_timezone.strftime('%H:%M') diff --git a/src/window.blp b/src/window.blp index 33277b8..7d3ca8c 100644 --- a/src/window.blp +++ b/src/window.blp @@ -39,7 +39,7 @@ template JadeGuiWindow : Gtk.ApplicationWindow { allow-scroll-wheel: true; allow-long-swipes: true; - Gtk.Box { + Gtk.Box welcome_page { orientation: vertical; valign: center; halign: center; @@ -69,12 +69,12 @@ template JadeGuiWindow : Gtk.ApplicationWindow { vexpand: true; hexpand: true; - Gtk.Button quitButton { + Gtk.Button quit_button { label: "No..."; margin-end: 12; } - Gtk.Button nextButton { + Gtk.Button next_button { margin-start: 12; label: "YEAH!"; styles ["suggested-action"] @@ -86,7 +86,7 @@ template JadeGuiWindow : Gtk.ApplicationWindow { description: "What's your current timezone?"; Gtk.Box { orientation: vertical; - Gtk.SearchBar timezoneSearch { + Gtk.SearchBar timezone_search { Gtk.SearchEntry entry_search { placeholder-text: "Search for a timezone..."; } @@ -94,33 +94,8 @@ template JadeGuiWindow : Gtk.ApplicationWindow { Adw.PreferencesPage { Adw.PreferencesGroup { Gtk.ListBox list_timezones { - selection-mode: none; + //selection-mode: none; styles ["boxed-list"] - Gtk.Label { - margin-top: 5; - margin-bottom: 5; - label: "test"; - } - Gtk.Label { - margin-top: 5; - margin-bottom: 5; - label: "test"; - } - Gtk.Label { - margin-top: 5; - margin-bottom: 5; - label: "test"; - } - Gtk.Label { - margin-top: 5; - margin-bottom: 5; - label: "test"; - } - Gtk.Label { - margin-top: 5; - margin-bottom: 5; - label: "test"; - } } } } diff --git a/src/window.py b/src/window.py index af9e96d..d996039 100644 --- a/src/window.py +++ b/src/window.py @@ -19,32 +19,56 @@ from gi.repository import Gtk from gi.repository import Gdk +from .widgets.timezone import TimezoneEntry import time @Gtk.Template(resource_path='/al/getcyrst/jadegui/window.ui') class JadeGuiWindow(Gtk.ApplicationWindow): __gtype_name__ = 'JadeGuiWindow' - quitButton = Gtk.Template.Child() - nextButton = Gtk.Template.Child() carousel = Gtk.Template.Child() + + ### Page and widgets on welcome screen + welcome_page = Gtk.Template.Child() + 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.quitButton.connect("clicked", self.confirmQuit) - #self.window = window - self.nextButton.connect("clicked", self.nextPage) + + + ### 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) + ### --------- + + # TODO: offload functions to seperate files/classes def nextPage(self, idk): - self.carousel.scroll_to(self.timezonePage, True) + self.carousel.scroll_to(self.timezone_page, True) def confirmQuit(self, idk): @@ -66,15 +90,19 @@ class JadeGuiWindow(Gtk.ApplicationWindow): dialog.present() def selected_timezone(self, widget, row): - print(row.timezone) + if row is not None: + print(row.get_title()) + else: + print("row is none!!") def search_timezones(self, *args): - term = self.entry_search.get_text() + 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().lower() + row.get_subtitle().lower() + text = row.get_title() + text = text.lower() + row.get_subtitle().lower() if terms.lower() in text: return True return False diff --git a/src/window.ui b/src/window.ui index da32928..616f254 100644 --- a/src/window.ui +++ b/src/window.ui @@ -82,13 +82,13 @@ true true - + No... 12 - + 12 YEAH!