diff --git a/main.py b/main.py index fbd05d6..d183cc7 100644 --- a/main.py +++ b/main.py @@ -95,6 +95,15 @@ class MainWindow(Gtk.Window): ## Callbacks def on_task_list_ready(self, agenda): + # TODO: Avoid reconstructing the whole list every time + i = 0 + child = self.task_list.get_first_child() + while child is not None: + was = child + child = child.get_next_sibling() + i += 1 + self.task_list.remove(was) + for item in agenda.with_hour: self.task_list.append(self.build_agenda_task_row(item)) diff --git a/task_manager.py b/task_manager.py index 97f3501..4671408 100644 --- a/task_manager.py +++ b/task_manager.py @@ -56,6 +56,8 @@ class TaskManager: top = os.path.abspath(self.docs_path) docs = [] + if self.docs is None: + self.docs = docs for root, dirs, files in os.walk(top): # Prune dirs @@ -74,8 +76,9 @@ class TaskManager: path = os.path.join(root, name) try: - doc = org_rw.load(open(path), extra_cautious=True) + doc = org_rw.load(open(path), extra_cautious=False) docs.append(doc) + yield doc except Exception as err: import traceback @@ -91,10 +94,19 @@ class TaskManager: def get_task_list(self, callback): def aux(): if self.docs is None: - self.load() - result = self.get_agenda() - print("Result", result) - GObject.idle_add(callback, result) + last_result = None + for doc in self.load(): + result = self.get_agenda() + if ((last_result is None) + or (len(result.with_hour) != len(last_result.with_hour)) + or (len(result.no_hour) != len(last_result.no_hour))): + print("Loaded:", doc._path) + GObject.idle_add(callback, result) + print("Load completed") + else: + result = self.get_agenda() + print("Result", result) + GObject.idle_add(callback, result) thread = threading.Thread(target=aux) thread.start()