Skip to content

Commit

Permalink
add time presets
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Jan 6, 2024
1 parent e2a3e5f commit ad9776b
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 36 deletions.
3 changes: 2 additions & 1 deletion errands/resources/errands.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
<file preprocess="xml-stripblanks" alias="errands-calendar-symbolic.svg">resources/icons/errands-calendar-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="errands-copy-symbolic.svg">resources/icons/errands-copy-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="errands-share-symbolic.svg">resources/icons/errands-share-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="errands-today-symbolic.svg">resources/icons/errands-today-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="errands-theme-system-symbolic.svg">resources/icons/errands-theme-system-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="errands-theme-light-symbolic.svg">resources/icons/errands-theme-light-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="errands-theme-dark-symbolic.svg">resources/icons/errands-theme-dark-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="errands-sync-symbolic.svg">resources/icons/errands-sync-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="errands-info-symbolic.svg">resources/icons/errands-info-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="errands-trash-symbolic.svg">resources/icons/errands-trash-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="errands-lists-symbolic.svg">resources/icons/errands-lists-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="errands-daytime-morning-symbolic.svg">resources/icons/errands-daytime-morning-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="errands-daytime-sunset-symbolic.svg">resources/icons/errands-daytime-sunset-symbolic.svg</file>
</gresource>
</gresources>
2 changes: 2 additions & 0 deletions errands/resources/icons/errands-daytime-morning-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions errands/resources/icons/errands-daytime-sunset-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions errands/resources/icons/errands-today-symbolic.svg

This file was deleted.

110 changes: 77 additions & 33 deletions errands/widgets/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(
**kwargs,
):
super().__init__(**kwargs)
self.label = label
content = Adw.ButtonContent()
if icon_name:
content.set_icon_name(icon_name)
Expand Down Expand Up @@ -93,12 +94,49 @@ def _build_ui(self):
self.append(
Box(
children=[
self.hour,
Gtk.Label(label=":"),
self.minutes,
Box(
children=[
self.hour,
Gtk.Label(label=":"),
self.minutes,
],
css_classes=["toolbar"],
halign="center",
),
Box(
children=[
Button(
"09:00",
"errands-daytime-morning-symbolic",
on_click=self._on_time_preset_clicked,
),
Button(
"13:00",
"errands-theme-light-symbolic",
on_click=self._on_time_preset_clicked,
),
],
css_classes=["toolbar"],
homogeneous=True,
),
Box(
children=[
Button(
"17:00",
"errands-daytime-sunset-symbolic",
on_click=self._on_time_preset_clicked,
),
Button(
"20:00",
"errands-theme-dark-symbolic",
on_click=self._on_time_preset_clicked,
),
],
css_classes=["toolbar"],
homogeneous=True,
),
],
css_classes=["toolbar"],
halign="center",
orientation="vertical",
)
)
# Calendar
Expand All @@ -109,37 +147,38 @@ def _build_ui(self):
self.append(
Box(
children=[
Button(
label=_("Today"),
on_click=self._on_today_btn_clicked,
hexpand=True,
),
Button(
label=_("Tomorrow"),
on_click=self._on_tomorrow_btn_clicked,
hexpand=True,
),
],
css_classes=["toolbar"],
homogeneous=True,
)
)
self.append(
Box(
children=[
Button(
label=_("Now"),
on_click=self._on_now_btn_clicked,
hexpand=True,
Box(
children=[
Button(
label=_("Today"),
on_click=self._on_today_btn_clicked,
),
Button(
label=_("Tomorrow"),
on_click=self._on_tomorrow_btn_clicked,
),
],
css_classes=["toolbar"],
homogeneous=True,
),
Button(
label=_("Clear"),
on_click=self._on_clear_btn_clicked,
hexpand=True,
Box(
children=[
Button(
label=_("Now"),
on_click=self._on_now_btn_clicked,
hexpand=True,
),
Button(
label=_("Clear"),
on_click=self._on_clear_btn_clicked,
hexpand=True,
),
],
css_classes=["toolbar"],
homogeneous=True,
),
],
css_classes=["toolbar"],
homogeneous=True,
orientation="vertical",
)
)

Expand All @@ -157,6 +196,11 @@ def _on_date_time_changed(self, *_args):
if not self.lock_signals:
self.emit("changed")

def _on_time_preset_clicked(self, btn: Button):
hour, min = btn.label.split(":")
self.hour.set_value(int(hour))
self.minutes.set_value(int(min))

def _on_now_btn_clicked(self, _btn):
self.set_datetime(datetime.datetime.now().strftime("%Y%m%dT%H%M00"))
self.emit("changed")
Expand Down

0 comments on commit ad9776b

Please sign in to comment.