Skip to content

Commit

Permalink
add some types
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Jan 10, 2024
1 parent 92b7688 commit 42c75ca
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
12 changes: 6 additions & 6 deletions errands/widgets/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
**kwargs,
):
super().__init__(**kwargs)
self.label = label
self.label: str = label
content = Adw.ButtonContent()
if icon_name:
content.set_icon_name(icon_name)
Expand Down Expand Up @@ -184,13 +184,13 @@ def _build_ui(self):

def _on_date_time_changed(self, *_args):
# Get hour
hour = str(self.hour.get_value_as_int())
hour = f"0{hour}" if len(hour) == 1 else hour
hour: str = str(self.hour.get_value_as_int())
hour: str = f"0{hour}" if len(hour) == 1 else hour
# Get min
min = str(self.minutes.get_value_as_int())
min = f"0{min}" if len(min) == 1 else min
min: str = str(self.minutes.get_value_as_int())
min: str = f"0{min}" if len(min) == 1 else min
# Get date
date = self.calendar.get_date().format("%Y%m%d")
date: str = self.calendar.get_date().format("%Y%m%d")
# Set date
self.datetime = f"{date}T{hour}{min}00"
if not self.lock_signals:
Expand Down
36 changes: 18 additions & 18 deletions errands/widgets/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, window, stack: Gtk.Stack):
self._add_actions()
self._load_lists()

def _add_actions(self):
def _add_actions(self) -> None:
group = Gio.SimpleActionGroup()
self.insert_action_group(name="lists", group=group)

Expand All @@ -33,24 +33,24 @@ def _create_action(name: str, callback: callable) -> None:
action.connect("activate", callback)
group.add_action(action)

def _add(*args):
def _add(*args) -> None:
pass

def _backup_create(*args):
def _backup_create(*args) -> None:
pass

def _backup_load(*args):
def _backup_load(*args) -> None:
pass

def _import(*args):
def _confirm(dialog: Gtk.FileDialog, res):
def _import(*args) -> None:
def _confirm(dialog: Gtk.FileDialog, res) -> None:
try:
file = dialog.open_finish(res)
file: Gio.File = dialog.open_finish(res)
except:
Log.debug("Lists: Import cancelled")
return
with open(file.get_path(), "r") as f:
calendar = Calendar.from_ical(f.read())
calendar: Calendar = Calendar.from_ical(f.read())
# List name
name = calendar.get(
"X-WR-CALNAME", file.get_basename().rstrip(".ics")
Expand All @@ -61,7 +61,7 @@ def _confirm(dialog: Gtk.FileDialog, res):
]:
name = f"{name}_{uuid4()}"
# Create list
uid = UserData.add_list(name)
uid: str = UserData.add_list(name)
# Add tasks
for todo in calendar.walk("VTODO"):
# Tags
Expand Down Expand Up @@ -122,7 +122,7 @@ def _confirm(dialog: Gtk.FileDialog, res):
_create_action("backup_load", _backup_load)
_create_action("import", _import)

def _build_ui(self):
def _build_ui(self) -> None:
hb = Adw.HeaderBar(
title_widget=Gtk.Label(
label=_("Errands"),
Expand Down Expand Up @@ -226,7 +226,7 @@ def add_list(self, name, uid) -> Gtk.ListBoxRow:
self.lists.append(row)
return row

def on_add_btn_clicked(self, btn):
def on_add_btn_clicked(self, btn) -> None:
def _entry_activated(_, dialog):
if dialog.get_response_enabled("add"):
dialog.response("add")
Expand Down Expand Up @@ -265,13 +265,13 @@ def _confirm(_, res, entry):
entry.connect("notify::text", _entry_changed, dialog)
dialog.present()

def on_trash_btn_clicked(self, _btn):
def on_trash_btn_clicked(self, _btn) -> None:
self.lists.unselect_all()
self.stack.set_visible_child_name("trash")
self.window.split_view.set_show_content(True)
self.window.split_view_inner.set_show_sidebar(False)

def on_list_swiched(self, _, row: Gtk.ListBoxRow):
def on_list_swiched(self, _, row: Gtk.ListBoxRow) -> None:
Log.debug("Lists: Switch list")
if row:
name = row.label.get_label()
Expand All @@ -290,7 +290,7 @@ def get_lists(self) -> list[TaskList]:
lists.append(child)
return lists

def _load_lists(self):
def _load_lists(self) -> None:
# Add lists
lists = [i for i in UserData.get_lists_as_dicts() if not i["deleted"]]
for list in lists:
Expand All @@ -299,7 +299,7 @@ def _load_lists(self):
self.lists.select_row(row)
self.status_page.set_visible(len(lists) == 0)

def update_ui(self):
def update_ui(self) -> None:
Log.debug("Lists: Update UI...")

# Delete lists
Expand Down Expand Up @@ -360,7 +360,7 @@ def __init__(self, task_list, list_box, lists, window) -> None:
self._build_ui()
self._add_actions()

def _add_actions(self):
def _add_actions(self) -> None:
group = Gio.SimpleActionGroup()
self.insert_action_group(name="list_item", group=group)

Expand Down Expand Up @@ -517,7 +517,7 @@ def _confirm(dialog, res):
_create_action("rename", _rename)
_create_action("export", _export)

def _build_ui(self):
def _build_ui(self) -> None:
# Label
self.label = Gtk.Label(
halign="start",
Expand Down Expand Up @@ -553,6 +553,6 @@ def _build_ui(self):
)
)

def _on_click(self, *args):
def _on_click(self, *args) -> None:
self.window.stack.set_visible_child_name(self.label.get_label())
self.window.split_view.set_show_content(True)
4 changes: 2 additions & 2 deletions errands/widgets/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,14 @@ def set_text():
self.task_list.update_status()
Sync.sync()

def on_row_clicked(self, *args):
def on_row_clicked(self, *args) -> None:
# 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())
else:
self.on_details_clicked()

def on_details_clicked(self, *args):
def on_details_clicked(self, *args) -> None:
# Close details on second click
if (
self.details.parent == self
Expand Down
6 changes: 3 additions & 3 deletions errands/widgets/task_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, window, list_uid: str, parent):
self._build_ui()
self._load_tasks()

def _build_ui(self):
def _build_ui(self) -> None:
# Title
self.title = Adw.WindowTitle(
title=UserData.run_sql(
Expand Down Expand Up @@ -317,7 +317,7 @@ def update_ui(self) -> None:
)

# Remove deleted tasks
ids = UserData.get_tasks_uids(self.list_uid)
ids: list[str] = UserData.get_tasks_uids(self.list_uid)
for task in self.get_all_tasks():
if task.uid not in ids:
task.purge()
Expand Down Expand Up @@ -379,7 +379,7 @@ def _auto_scroll(scroll_up: bool) -> bool:
"""Scroll while drag is near the edge"""
if not self.scrolling or not self.dnd_ctrl.contains_pointer():
return False
adj = self.scrl.get_vadjustment()
adj: Gtk.Adjustment = self.scrl.get_vadjustment()
adj.set_value(adj.get_value() - (2 if scroll_up else -2))
return True

Expand Down
12 changes: 6 additions & 6 deletions errands/widgets/trash.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def __init__(self, window):
super().__init__()
self.window = window
self.stack: Adw.ViewStack = window.stack
self.build_ui()
self._build_ui()
self.update_status()

def build_ui(self):
def _build_ui(self) -> None:
# Headerbar
hb = Adw.HeaderBar(title_widget=Adw.WindowTitle(title=_("Trash")))
# Clear button
Expand Down Expand Up @@ -88,7 +88,7 @@ def trash_add(self, task_widget) -> None:
self.trash_list.append(TrashItem(task_widget, self))
self.status.set_visible(False)

def update_status(self):
def update_status(self) -> None:
deleted_uids = [
i[0]
for i in UserData.run_sql(
Expand All @@ -98,7 +98,7 @@ def update_status(self):
self.status.set_visible(len(deleted_uids) == 0)

def on_trash_clear(self, btn) -> None:
def _confirm(_, res):
def _confirm(_, res) -> None:
if res == "cancel":
Log.debug("Clear Trash cancelled")
return
Expand Down Expand Up @@ -194,9 +194,9 @@ def __init__(self, task_widget, trash) -> None:
self.uid = task_widget.uid
self.trash = trash
self.trash_list = trash.trash_list
self.build_ui()
self._build_ui()

def build_ui(self):
def _build_ui(self) -> None:
self.add_css_class("card")
row = Adw.ActionRow(
title=self.task_widget.get_prop("text"),
Expand Down

0 comments on commit 42c75ca

Please sign in to comment.