Commit 0774ad55 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Wipe the widget cache at midnight

This serves two purposes:

* Relative dates and progress colors are shown correctly on the next day
* Stale cached items get wiped at least once a day (for those who continiously
  run this mode)
parent 87bfda02
...@@ -34,6 +34,7 @@ from topydo.ui.CLIApplicationBase import CLIApplicationBase ...@@ -34,6 +34,7 @@ from topydo.ui.CLIApplicationBase import CLIApplicationBase
from topydo.ui.columns.CommandLineWidget import CommandLineWidget from topydo.ui.columns.CommandLineWidget import CommandLineWidget
from topydo.ui.columns.ConsoleWidget import ConsoleWidget from topydo.ui.columns.ConsoleWidget import ConsoleWidget
from topydo.ui.columns.KeystateWidget import KeystateWidget from topydo.ui.columns.KeystateWidget import KeystateWidget
from topydo.ui.columns.TodoWidget import TodoWidget
from topydo.ui.columns.TodoListWidget import TodoListWidget from topydo.ui.columns.TodoListWidget import TodoListWidget
from topydo.ui.columns.Utils import PaletteItem, to_urwid_color from topydo.ui.columns.Utils import PaletteItem, to_urwid_color
from topydo.ui.columns.ViewWidget import ViewWidget from topydo.ui.columns.ViewWidget import ViewWidget
...@@ -220,6 +221,7 @@ class UIApplication(CLIApplicationBase): ...@@ -220,6 +221,7 @@ class UIApplication(CLIApplicationBase):
def _set_alarm_for_next_midnight_update(self): def _set_alarm_for_next_midnight_update(self):
def callback(p_loop, p_data): def callback(p_loop, p_data):
TodoWidget.wipe_cache()
self._update_all_columns() self._update_all_columns()
self._set_alarm_for_next_midnight_update() self._set_alarm_for_next_midnight_update()
......
...@@ -106,10 +106,6 @@ class TodoListWidget(urwid.LineBox): ...@@ -106,10 +106,6 @@ class TodoListWidget(urwid.LineBox):
# -2 for the same reason as in self._scroll_to_bottom() # -2 for the same reason as in self._scroll_to_bottom()
self.todolist.set_focus(len(self.todolist) - 2) self.todolist.set_focus(len(self.todolist) - 2)
# after the update there might be old stuff left in the widget cache,
# clean it
TodoWidget.clean_cache(self.view.todolist)
def _scroll_to_top(self, p_size): def _scroll_to_top(self, p_size):
self.listbox.set_focus(0) self.listbox.set_focus(0)
......
...@@ -188,19 +188,8 @@ class TodoWidget(urwid.WidgetWrap): ...@@ -188,19 +188,8 @@ class TodoWidget(urwid.WidgetWrap):
return widget return widget
cache_clean_counter = 0
@classmethod @classmethod
def clean_cache(p_class, p_todolist): def wipe_cache(p_class):
""" Cleans the widget cache once every 500 column updates. """ """ Wipes the cache """
p_class.cache = {}
if p_class.cache_clean_counter % 500 != 0:
# wait
p_class.cache_clean_counter += 1
return
sources_in_list = set([todo.source() for todo in p_todolist])
sources_in_cache = set(p_class.cache.keys())
for stale in sources_in_cache - sources_in_list:
del p_class.cache[stale]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment