Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Jan 10, 2024
1 parent 8f46465 commit c009cd2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
24 changes: 14 additions & 10 deletions errands/widgets/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, win: Adw.ApplicationWindow) -> None:
self._build_ui()
self._setup_sync()

def _build_ui(self):
def _build_ui(self) -> None:
self.set_transient_for(self.window)
self.set_search_enabled(False)

Expand Down Expand Up @@ -140,7 +140,10 @@ def _build_ui(self):
self.open_details_panel_btn = Gtk.CheckButton(
active=not GSettings.get("primary-action-show-sub-tasks")
)
self.open_details_panel_btn.connect("toggled", self.on_primary_action_change, False)
self.open_details_panel_btn.connect(
"toggled",
lambda *_: GSettings.set("primary-action-show-sub-tasks", "b", False),
)
open_details_panel_row = Adw.ActionRow(
title=_("Open Details Panel"),
icon_name="errands-info-symbolic",
Expand All @@ -150,9 +153,13 @@ def _build_ui(self):
primary_action_group.add(open_details_panel_row)
# Show Sub-Tasks Row
self.show_sub_tasks_btn = Gtk.CheckButton(
group=self.open_details_panel_btn, active=GSettings.get("primary-action-show-sub-tasks")
group=self.open_details_panel_btn,
active=GSettings.get("primary-action-show-sub-tasks"),
)
self.show_sub_tasks_btn.connect(
"toggled",
lambda *_: GSettings.set("primary-action-show-sub-tasks", "b", True),
)
self.show_sub_tasks_btn.connect("toggled", self.on_primary_action_change, True)
show_sub_tasks_row = Adw.ActionRow(
title=_("Show Sub-Tasks"),
icon_name="view-list-bullet-symbolic",
Expand All @@ -169,7 +176,7 @@ def _build_ui(self):
page.add(primary_action_group)
self.add(page)

def _setup_sync(self):
def _setup_sync(self) -> None:
selected = self.sync_providers.props.selected
self.sync_url.set_visible(0 < selected < 3)
self.sync_username.set_visible(0 < selected < 3)
Expand All @@ -185,12 +192,12 @@ def _setup_sync(self):
def on_sync_provider_selected(self, *_) -> None:
self._setup_sync()

def on_sync_pass_changed(self, _entry):
def on_sync_pass_changed(self, _entry) -> None:
if 0 < self.sync_providers.props.selected < 3:
account = self.sync_providers.props.selected_item.props.string
GSettings.set_secret(account, self.sync_password.props.text)

def on_test_connection_btn_clicked(self, _btn):
def on_test_connection_btn_clicked(self, _btn) -> None:
res: bool = Sync.test_connection()
msg: str = _("Connected") if res else _("Can't connect")
toast: Adw.Toast = Adw.Toast(title=msg, timeout=2)
Expand All @@ -203,6 +210,3 @@ def on_theme_change(self, btn: Gtk.Button, theme: int) -> None:
def on_details_change(self, btn: Gtk.Button, right: bool) -> None:
self.window.update_details(right)
GSettings.set("right-sidebar", "b", right)

def on_primary_action_change(self, btn: Gtk.Button, show_subtasks: bool) -> None:
GSettings.set("primary-action-show-sub-tasks", "b", show_subtasks)
34 changes: 19 additions & 15 deletions errands/widgets/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def build_ui(self):
GObject.BindingFlags.SYNC_CREATE,
)
self.add_controller(drop_ctrl)

# Task row
self.task_row = Adw.ActionRow(
title=Markup.find_url(Markup.escape(self.get_prop("text"))),
Expand All @@ -84,6 +85,7 @@ def build_ui(self):
cursor=Gdk.Cursor.new_from_name("pointer"),
use_markup=True,
)

# Mark as completed button
self.completed_btn = Gtk.CheckButton(
valign="center",
Expand All @@ -92,6 +94,7 @@ def build_ui(self):
self.completed_btn.connect("toggled", self.on_completed_btn_toggled)
self.completed_btn.set_active(self.get_prop("completed"))
self.task_row.add_prefix(self.completed_btn)

# Expand button
self.expand_btn = Button(
icon_name="errands-up-symbolic",
Expand All @@ -109,6 +112,7 @@ def build_ui(self):
accessible_role=Gtk.AccessibleRole.PRESENTATION,
)
task_row_box.append(self.task_row)

# Task row controllers
task_row_drag_source = Gtk.DragSource.new()
task_row_drag_source.set_actions(Gdk.DragAction.MOVE)
Expand All @@ -125,45 +129,47 @@ def build_ui(self):
task_row_click_ctrl = Gtk.GestureClick.new()
task_row_click_ctrl.connect("released", self.on_row_clicked)
self.task_row.add_controller(task_row_click_ctrl)

# Sub-tasks entry
sub_tasks_entry = Gtk.Entry(
hexpand=True,
placeholder_text=_("Add new Sub-Task"),
)
sub_tasks_entry.connect("activate", self.on_sub_task_added)

# Details panel button
details_btn = Gtk.Button(
details_btn = Button(
icon_name="errands-info-symbolic",
on_click=self.on_details_clicked,
tooltip_text=_("Details"),
margin_start=12
)
details_btn.connect("clicked", self.on_details_clicked)
GSettings.bind("primary-action-show-sub-tasks", details_btn, "visible")
sub_tasks_entry_box = Gtk.Box(
sub_tasks_entry_box = Box(
children=[sub_tasks_entry, details_btn],
orientation="horizontal",
margin_bottom=6,
margin_start=12,
margin_end=12,
margin_bottom=6,
margin_start=12,
margin_end=12,
spacing=6,
)
sub_tasks_entry_box.append(sub_tasks_entry)
sub_tasks_entry_box.append(details_btn)

# Sub-tasks
self.tasks_list = Box(orientation="vertical", css_classes=["sub-tasks"])

# Sub-tasks revealer
self.sub_tasks_revealer = Gtk.Revealer(
child=Box(
children=[sub_tasks_entry_box, self.tasks_list], orientation="vertical"
)
)

# Task card
self.main_box = Box(
children=[task_row_box, self.sub_tasks_revealer],
orientation="vertical",
hexpand=True,
css_classes=["fade", "card"],
css_classes=["fade", "card", f'task-{self.get_prop("color")}'],
)
if self.get_prop("color") != "":
self.main_box.add_css_class(f'task-{self.get_prop("color")}')

self.set_child(
Box(
Expand Down Expand Up @@ -297,9 +303,7 @@ def set_text():
def on_row_clicked(self, *args):
# Show sub-tasks if this is primary action
if GSettings.get("primary-action-show-sub-tasks"):
self.expand(
not self.sub_tasks_revealer.get_child_revealed()
)
self.expand(not self.sub_tasks_revealer.get_child_revealed())
else:
self.on_details_clicked()

Expand Down

0 comments on commit c009cd2

Please sign in to comment.