From 83e425b995e43fb21585d23d5059b9bd734b7744 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 17 Oct 2015 17:47:48 +0300 Subject: Don't update widgets if they're uninterested --- ttystatus/fmt.py | 12 +++++++++--- ttystatus/status.py | 8 ++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'ttystatus') diff --git a/ttystatus/fmt.py b/ttystatus/fmt.py index 5ad7994..ec5b18f 100644 --- a/ttystatus/fmt.py +++ b/ttystatus/fmt.py @@ -46,12 +46,16 @@ def parse(fmt): m = pat.match(fmt) if m: if prefix: - result.append(ttystatus.Literal(prefix)) + literal = ttystatus.Literal(prefix) + literal.interested_in = [] + result.append(literal) prefix = '' klass = getattr(ttystatus, m.group('class')) argnames = m.group('args').split(',') argnames = [x for x in argnames if x] - result.append(klass(*argnames)) + widget = klass(*argnames) + widget.interested_in = argnames + result.append(widget) fmt = fmt[m.end():] elif fmt.startswith('%%'): prefix += '%' @@ -61,5 +65,7 @@ def parse(fmt): fmt = fmt[1:] if prefix: - result.append(ttystatus.Literal(prefix)) + literal = ttystatus.Literal(prefix) + literal.interested_in = [] + result.append(literal) return result diff --git a/ttystatus/status.py b/ttystatus/status.py index df45ebc..fe90b96 100644 --- a/ttystatus/status.py +++ b/ttystatus/status.py @@ -46,6 +46,8 @@ class TerminalStatus(object): if not self._widget_rows: self._widget_rows = [[]] self._widget_rows[-1].append(widget) + if not hasattr(widget, 'interested_in'): + widget.interested_in = None def start_new_line(self): # pragma: no cover '''Start a new line of widgets.''' @@ -79,7 +81,8 @@ class TerminalStatus(object): def clear(self): '''Remove all widgets.''' self._widget_rows = [] - self._values = dict() + self._values = {} + self._interested_in = {} self._m.clear() def __getitem__(self, key): @@ -95,7 +98,8 @@ class TerminalStatus(object): self._values[key] = value for row in self._widget_rows: for w in row: - w.update(self) + if w.interested_in is None or key in w.interested_in: + w.update(self) if self._m.is_enabled() and self._m.time_to_write(): self._write() -- cgit v1.2.1