second page, timezone selection :)

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

1
.gitignore vendored

@ -1 +1,2 @@
/subprojects/blueprint-compiler
build/

@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/al/getcyrst/jadegui">
<file>window.ui</file>
<file>widgets/timezone.ui</file>
<file>gtk/help-overlay.ui</file>
<file>crystal-logo-minimal.png</file>
</gresource>

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

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

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

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

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

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

@ -82,13 +82,13 @@
<property name="vexpand">true</property>
<property name="hexpand">true</property>
<child>
<object class="GtkButton" id="quit_button">
<object class="GtkButton" id="quitButton">
<property name="label">No...</property>
<property name="margin-end">12</property>
</object>
</child>
<child>
<object class="GtkButton" id="next_button">
<object class="GtkButton" id="nextButton">
<property name="margin-start">12</property>
<property name="label">YEAH!</property>
<style>

Loading…
Cancel
Save