summaryrefslogtreecommitdiff
path: root/ttystatus
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 /ttystatus
parentf9de5bcc0cd0df360d7ff7e13ce284a89fde02a9 (diff)
downloadttystatus-83e425b995e43fb21585d23d5059b9bd734b7744.tar.gz
Don't update widgets if they're uninterested
Diffstat (limited to 'ttystatus')
-rw-r--r--ttystatus/fmt.py12
-rw-r--r--ttystatus/status.py8
2 files changed, 15 insertions, 5 deletions
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()