summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-10-17 17:47:48 +0300
committerLars Wirzenius <liw@liw.fi>2015-10-17 18:17:22 +0300
commit83e425b995e43fb21585d23d5059b9bd734b7744 (patch)
tree16edcb6e604ecf432bfc4047449d01b6ca3e4841
parentf9de5bcc0cd0df360d7ff7e13ce284a89fde02a9 (diff)
downloadttystatus-83e425b995e43fb21585d23d5059b9bd734b7744.tar.gz
Don't update widgets if they're uninterested
-rw-r--r--NEWS5
-rw-r--r--ttystatus/fmt.py12
-rw-r--r--ttystatus/status.py8
3 files changed, 20 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 3365fab..be4d334 100644
--- a/NEWS
+++ b/NEWS
@@ -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()