diff options
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | ttystatus/fmt.py | 12 | ||||
-rw-r--r-- | ttystatus/status.py | 8 |
3 files changed, 20 insertions, 5 deletions
@@ -11,6 +11,11 @@ Version 0.30, released UNRELEASED * New method `ttystatus.TerminalStatus.get_terminal_size` returns terminal width and height. +* Speed up updates by not updating widgets if they aren't interested + in the variable that got changed. This only works for widgets added + with the `format` method, but that should be all of them for anyone + not liking verbose, tedious code. + Version 0.29, released 2015-10-10 --------------------------------- 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() |