From 555c44c5c0487ad19110cc62606a62da5779e473 Mon Sep 17 00:00:00 2001 From: Jeena Date: Sat, 17 Feb 2024 08:30:22 +0900 Subject: [PATCH] Make calendars changable --- src/main.py | 12 ++++++++---- src/notes_list.py | 6 +++--- src/sync.py | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main.py b/src/main.py index b056c5c..10a8b4b 100644 --- a/src/main.py +++ b/src/main.py @@ -36,6 +36,7 @@ class JnotesApplication(Adw.Application): calendar_set = None + def __init__(self): super().__init__(application_id='net.jeena.jnotes', flags=Gio.ApplicationFlags.DEFAULT_FLAGS) @@ -52,6 +53,7 @@ class JnotesApplication(Adw.Application): win = self.props.active_window if not win: win = JnotesWindow(application=self) + win.sidebar.calendar_set.connect('row-selected', self.on_calendar_selected) win.present() def callback(calendar_set): @@ -60,14 +62,10 @@ class JnotesApplication(Adw.Application): self.on_preferences_action(win, False) else: win.sidebar.set_calendars(self.calendar_set) - def callb(calendar): - win.notes_list.set_calendar(calendar) - Sync.get_calenndar_notes(self.calendar_set[0], callb) Sync.set_spinner(win.sidebar.spinner) Sync.get_calendar_set(callback) - def on_about_action(self, widget, _): """Callback for the app.about action.""" about = Adw.AboutWindow(transient_for=self.props.active_window, @@ -99,6 +97,12 @@ class JnotesApplication(Adw.Application): if shortcuts: self.set_accels_for_action(f"app.{name}", shortcuts) + def on_calendar_selected(self, container, row): + notes_list = self.props.active_window.notes_list + Sync.get_calenndar_notes( + self.calendar_set[row.get_index()], + lambda calendar: notes_list.set_calendar(calendar) + ) def main(version): """The application's entry point.""" diff --git a/src/notes_list.py b/src/notes_list.py index f33178e..8478eb9 100644 --- a/src/notes_list.py +++ b/src/notes_list.py @@ -16,6 +16,6 @@ class NotesList(Gtk.ScrolledWindow): self.notes_list.bind_model(calendar, self.create_item_widget) def create_item_widget(self, note): - print(note.summary) - return Gtk.Label(label=note.summary, halign="start", - hexpand=True, ellipsize=3) + return Adw.ActionRow(title=note.summary, + subtitle=note.description) + diff --git a/src/sync.py b/src/sync.py index 82fb6c8..d25a940 100644 --- a/src/sync.py +++ b/src/sync.py @@ -94,6 +94,7 @@ class Sync(): @threaded def get_calenndar_notes(self, calendar, callback): self.spinner.start() + calendar.remove_all() remote_calendar = self.principal.calendar(calendar.displayname) for journal in remote_calendar.journals(): summary = journal.icalendar_component.get("summary", "")