Skip to content

Commit

Permalink
fixes to complete button
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Dec 26, 2023
1 parent 7e178f0 commit 6dd1a54
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
18 changes: 9 additions & 9 deletions errands/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ def update_props(

@classmethod
def run_sql(cls, *cmds: list[str], fetch: bool = False) -> list[tuple] | None:
try:
with cls.connection:
cur = cls.connection.cursor()
for cmd in cmds:
cur.execute(cmd)
cls.connection.commit()
return cur.fetchall() if fetch else None
except Exception as e:
Log.error(f"Data: {e}")
# try:
with cls.connection:
cur = cls.connection.cursor()
for cmd in cmds:
cur.execute(cmd)
cls.connection.commit()
return cur.fetchall() if fetch else None
# except Exception as e:
# Log.error(f"Data: {e}")

@classmethod
def get_tasks_uids(cls, list_uid: str) -> list[str]:
Expand Down
7 changes: 1 addition & 6 deletions errands/utils/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ def init(self, window, testing: bool = False) -> None:
match GSettings.get("sync-provider"):
case 0:
Log.info("Sync: Sync disabled")
# Clear deleted tasks and lists
if GSettings.get("sync-provider") == 0:
UserData.run_sql(
"DELETE FROM lists WHERE deleted = 1",
"DELETE FROM tasks WHERE deleted = 1",
)
UserData.clean_deleted()
case 1:
self.provider = SyncProviderCalDAV("Nextcloud", self.window, testing)
case 2:
Expand Down
20 changes: 12 additions & 8 deletions errands/widgets/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,11 @@ def update_status(self) -> None:
else ""
)

def on_completed_btn_toggled(self, btn: Gtk.Button) -> None:
def on_completed_btn_toggled(self, btn: Gtk.ToggleButton) -> None:
"""
Toggle check button and add style to the text
"""

Log.info(f"Task: Set completed to '{btn.get_active()}'")

def set_text():
Expand All @@ -249,7 +250,7 @@ def set_text():
self.remove_css_class("task-completed")
self.task_row.set_title(text)

# If task is just added set text and return to avoid useless sync
# If task is just added set text and return to avoid sync loop
if self.just_added:
set_text()
return
Expand All @@ -259,23 +260,26 @@ def set_text():
["completed", "synced", "percent_complete"],
[btn.get_active(), False, 100 if btn.get_active() else 0],
)
self.task_list.details.update_info(self)

if isinstance(self.parent, Task):
self.parent.update_status()

# Update children
children: list[Task] = get_children(self.tasks_list)
for task in children:
task.can_sync = False
if btn.get_active():
task.completed_btn.set_active(True)
# Update status
self.parent.update_status()
self.task_list.details.update_info(self)
task.can_sync = True

# Set text
set_text()

# Sync
if self.can_sync:
Sync.sync()
self.task_list.update_status()
for task in children:
task.can_sync = True
Sync.sync()

def on_details_clicked(self, *args):
self.task_list.details.update_info(self)
Expand Down
3 changes: 1 addition & 2 deletions errands/widgets/trash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

from errands.utils.data import UserData
from errands.utils.functions import get_children
from errands.widgets.components.box import Box
from errands.widgets.components.button import Button
from errands.widgets.components import Box, Button
from gi.repository import Adw, Gtk, GObject
from errands.widgets.task import Task
from errands.utils.sync import Sync
Expand Down

0 comments on commit 6dd1a54

Please sign in to comment.