diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2017-01-25 15:52:58 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2017-01-26 13:40:27 -0800 |
commit | 0511526d97cb6a74282c5f4dd334be1f5f355ea0 (patch) | |
tree | 7c150de01bc2e60c3194381475d124e2d582f765 /alot/ui.py | |
parent | a2f001df1176f14bb18d82687b4c42721bd02efd (diff) |
Implement a hook that runs periodically
This creates a deferred that runs on a user configurable timer and is
provided the ui. This deferred will re-fire after the number of seconds
specified by the timer are eclipsed. By default this is 300 seconds.
Fixes #522
Diffstat (limited to 'alot/ui.py')
-rw-r--r-- | alot/ui.py | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -7,7 +7,7 @@ import logging import os import signal -from twisted.internet import reactor, defer +from twisted.internet import reactor, defer, task import urwid from .settings import settings @@ -103,6 +103,15 @@ class UI(object): unhandled_input=self._unhandled_input, input_filter=self._input_filter) + # Create a defered that calls the loop_hook + loop_hook = settings.get_hook('loop_hook') + if loop_hook: + loop = task.LoopingCall(loop_hook, ui=self) + loop_defered = loop.start(settings.get('periodic_hook_frequency')) + loop_defered.addErrback( + lambda e: logging.error('error in loop hook %s', + e.getErrorMessage())) + # set up colours colourmode = int(settings.get('colourmode')) logging.info('setup gui in %d colours', colourmode) |