From a0219164283ac70754bf8a12197ecfe7596a3513 Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 20 Mar 2013 18:33:55 +0400 Subject: [PATCH] Make update_first configurable --- docs/source/powerline_autodoc.py | 6 +++++- powerline/lib/threaded.py | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/docs/source/powerline_autodoc.py b/docs/source/powerline_autodoc.py index a3a3d54b..084c8547 100644 --- a/docs/source/powerline_autodoc.py +++ b/docs/source/powerline_autodoc.py @@ -28,6 +28,9 @@ class ThreadedDocumenter(autodoc.FunctionDocumenter): if isinstance(self.object, ThreadedSegment): args = ['interval'] defaults = [getattr(self.object, 'interval', 1)] + if self.object.update_first: + args.append('update_first') + defaults.append(True) methods = ['render', 'set_state'] if isinstance(self.object, KwThreadedSegment): methods += ['key', 'render_one'] @@ -41,7 +44,8 @@ class ThreadedDocumenter(autodoc.FunctionDocumenter): if (arg == 'self' or (arg == 'segment_info' and getattr(self.object, 'powerline_requires_segment_info', None)) or - (method == 'render_one' and -i == len(argspec.args))): + (method == 'render_one' and -i == len(argspec.args)) or + arg in args): continue if argspec.defaults and len(argspec.defaults) >= -i: default = argspec.defaults[i] diff --git a/powerline/lib/threaded.py b/powerline/lib/threaded.py index 89c69e93..eedfc142 100644 --- a/powerline/lib/threaded.py +++ b/powerline/lib/threaded.py @@ -67,14 +67,14 @@ class ThreadedSegment(object): self.interval = interval self.has_set_interval = True - def set_state(self, interval=None, **kwargs): + def set_state(self, update_first=True, interval=None, **kwargs): if not self.did_set_interval or interval: self.set_interval(interval) # Without this we will not have to wait long until receiving bug “I # opened vim, but branch information is only shown after I move cursor”. # # If running once .update() is called in __call__. - if self.update_first and not self.run_once: + if update_first and self.update_first and not self.run_once: self.update_first = False self.update() @@ -99,7 +99,6 @@ def printed(func): class KwThreadedSegment(ThreadedSegment): drop_interval = 10 * 60 - update_missing = True update_first = False def __init__(self): @@ -115,9 +114,7 @@ class KwThreadedSegment(ThreadedSegment): try: update_state = self.queries[key][1] except KeyError: - # self.update_missing has the same reasoning as self.update_first in - # parent class - update_state = self.compute_state(key) if self.update_missing or self.run_once else None + update_state = self.compute_state(key) if self.update_first or self.run_once else None # No locks: render method is already running with write_lock acquired. self.queries[key] = (monotonic(), update_state) return self.render_one(update_state, **kwargs) @@ -135,13 +132,18 @@ class KwThreadedSegment(ThreadedSegment): for key in removes: self.queries.pop(key) - def set_state(self, interval=None, **kwargs): + def set_state(self, update_first=True, interval=None, **kwargs): if not self.did_set_interval or (interval < self.interval): self.set_interval(interval) + # Allow only to forbid to compute missing values: in either user + # configuration or in subclasses. + if self.update_first: + self.update_first = update_first + key = self.key(**kwargs) if not self.run_once and key not in self.queries: - self.queries[key] = (monotonic(), self.compute_state(key) if self.update_missing else None) + self.queries[key] = (monotonic(), self.compute_state(key) if self.update_first else None) @staticmethod def render_one(update_state, **kwargs):