Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Sep 7, 2023
1 parent a742052 commit 91d32bc
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 19 deletions.
6 changes: 3 additions & 3 deletions io.github.mrvladus.List.Devel.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"sdk": "org.gnome.Sdk",
"command": "errands",
"finish-args": [
"--share=ipc",
"--socket=fallback-x11",
"--device=dri",
"--filesystem=home",
"--socket=wayland",
"--filesystem=home"
"--socket=fallback-x11",
"--share=ipc"
],
"modules": [
{
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project(
'errands',
version: '44.7.1',
version: '44.7.2',
meson_version: '>= 0.62.0',
)

Expand Down
5 changes: 3 additions & 2 deletions src/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ def add_action(name: str, callback):

def add_sub_tasks(self) -> None:
sub_count: int = 0
for task in UserData.get()["tasks"]:
tasks: list[dict] = UserData.get()["tasks"]
for task in tasks:
if task["parent"] == self.task["id"]:
sub_task = SubTask(task, self, self.window)
self.sub_tasks.append(sub_task)
if not task["deleted"]:
sub_task.toggle_visibility()
sub_count += 1
self.expand(sub_count > 0)
self.expand(len(tasks) > 0)
self.update_statusbar()
self.window.update_status()

Expand Down
89 changes: 76 additions & 13 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def add_toast(self, toast: Adw.Toast) -> None:
self.toast_overlay.add_toast(toast)

def create_actions(self) -> None:
"""Create actions for main menu"""
"""
Create actions for main menu
"""

def create_action(name: str, callback: callable, shortcuts=None) -> None:
action = Gio.SimpleAction.new(name, None)
Expand All @@ -105,6 +107,10 @@ def create_action(name: str, callback: callable, shortcuts=None) -> None:
create_action("open_log", self.open_log)

def load_tasks(self) -> None:
"""
Load tasks and sub-tasks
"""

Log.debug("Loading tasks")
data: dict = UserData.get()
for task in data["tasks"]:
Expand All @@ -118,13 +124,18 @@ def load_tasks(self) -> None:
self.trash_add_items()

def about(self, *args) -> None:
"""Show about window"""
"""
Show about window
"""

self.about_window.props.version = VERSION
self.about_window.props.application_icon = APP_ID
self.about_window.show()

def export_tasks(self, *_) -> None:
"""Show export dialog"""
"""
Show export dialog
"""

def finish_export(_dial, res, _data):
try:
Expand All @@ -141,7 +152,9 @@ def finish_export(_dial, res, _data):
self.export_dialog.save(self, None, finish_export, None)

def import_tasks(self, *_) -> None:
"""Show import dialog"""
"""
Show import dialog
"""

def finish_import(_dial, res, _data):
Log.info("Importing tasks")
Expand Down Expand Up @@ -182,20 +195,34 @@ def finish_import(_dial, res, _data):
self.import_dialog.open(self, None, finish_import, None)

def open_log(self, *_) -> None:
"""
Open log file with default text editor
"""

GLib.spawn_command_line_async(
f"xdg-open {GLib.get_user_data_dir()}/list/log.txt"
)

def shortcuts(self, *_) -> None:
"""
Show shortcuts window
"""

self.shortcuts_window.set_transient_for(self)
self.shortcuts_window.show()

def trash_add(self, task: dict) -> None:
"""
Add item to trash
"""

self.trash_list.append(TrashItem(task, self))
self.trash_list_scrl.set_visible(True)

def trash_add_items(self) -> None:
"""Populate trash on startup"""
"""
Populate trash on startup
"""

tasks: list[dict] = UserData.get()["tasks"]
deleted_count: int = 0
Expand All @@ -206,7 +233,9 @@ def trash_add_items(self) -> None:
self.trash_list_scrl.set_visible(deleted_count > 0)

def trash_clear(self) -> None:
"""Clear unneeded items from trash"""
"""
Clear unneeded items from trash
"""

tasks: list[dict] = UserData.get()["tasks"]
children = self.trash_list.observe_children()
Expand All @@ -222,14 +251,21 @@ def trash_clear(self) -> None:
self.trash_list_scrl.set_visible(deleted_count > 0)

def trash_update(self, tasks: list[dict] = UserData.get()["tasks"]) -> None:
"""
Update trash visibility
"""

deleted_count: int = 0
for task in tasks:
if task["deleted"]:
deleted_count += 1
self.trash_list_scrl.set_visible(deleted_count > 0)

def update_status(self) -> None:
"""Update progress bar on the top"""
"""
Update progress bar on the top
"""

n_total = 0
n_completed = 0
for task in UserData.get()["tasks"]:
Expand All @@ -253,7 +289,9 @@ def update_status(self) -> None:

@Gtk.Template.Callback()
def on_dnd_scroll(self, _motion, _x, y) -> bool:
"""Autoscroll while dragging task"""
"""
Autoscroll while dragging task
"""

def auto_scroll(scroll_up: bool) -> bool:
"""Scroll while drag is near the edge"""
Expand All @@ -280,7 +318,9 @@ def auto_scroll(scroll_up: bool) -> bool:

@Gtk.Template.Callback()
def on_scroll(self, adj) -> None:
"""Show scroll up button"""
"""
Show scroll up button
"""

self.scroll_up_btn_rev.set_reveal_child(adj.get_value() > 0)
if adj.get_value() > 0:
Expand All @@ -290,13 +330,17 @@ def on_scroll(self, adj) -> None:

@Gtk.Template.Callback()
def on_scroll_up_btn_clicked(self, _) -> None:
"""Scroll up"""
"""
Scroll up
"""

Animate.scroll(self.scrolled_window, False)

@Gtk.Template.Callback()
def on_task_added(self, entry: Gtk.Entry) -> None:
"""Add new task"""
"""
Add new task
"""

text: str = entry.props.text
# Check for empty string or task exists
Expand All @@ -319,14 +363,19 @@ def on_task_added(self, entry: Gtk.Entry) -> None:

@Gtk.Template.Callback()
def on_toggle_trash_btn(self, btn: Gtk.ToggleButton) -> None:
"""
Move focus to sidebar
"""
if btn.props.active:
self.clear_trash_btn.grab_focus()
else:
btn.grab_focus()

@Gtk.Template.Callback()
def on_trash_scroll(self, adj) -> None:
"""Show scroll up button"""
"""
Show scroll up button
"""

if adj.get_value() > 0:
self.trash_scroll_separator.add_css_class("separator")
Expand All @@ -335,7 +384,9 @@ def on_trash_scroll(self, adj) -> None:

@Gtk.Template.Callback()
def on_delete_completed_tasks_btn_clicked(self, _) -> None:
"""Hide completed tasks"""
"""
Hide completed tasks
"""

tasks = self.tasks_list.observe_children()
for i in range(tasks.get_n_items()):
Expand All @@ -346,6 +397,10 @@ def on_delete_completed_tasks_btn_clicked(self, _) -> None:

@Gtk.Template.Callback()
def on_trash_clear(self, _) -> None:
"""
Remove all trash items and tasks
"""

Log.info("Clear Trash")
children = self.tasks_list.observe_children()
to_remove = [
Expand All @@ -372,6 +427,10 @@ def on_trash_clear(self, _) -> None:

@Gtk.Template.Callback()
def on_trash_restore(self, _) -> None:
"""
Remove trash items and restore all tasks
"""

Log.info("Restore Trash")

data: dict = UserData.get()
Expand Down Expand Up @@ -404,6 +463,10 @@ def restore_tasks(list: Gtk.Box) -> None:

@Gtk.Template.Callback()
def on_trash_drop(self, _drop, task: Task | SubTask, _x, _y) -> None:
"""
Move task to trash via dnd
"""

task.toggle_visibility()
task.task["deleted"] = True
task.update_data()
Expand Down

0 comments on commit 91d32bc

Please sign in to comment.