summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2010-07-07 08:34:16 +1200
committerLars Wirzenius <liw@liw.fi>2010-07-07 08:34:16 +1200
commitb15fcce5b6d2046e3419b3201e38667554de53fd (patch)
treeafc2afd601ae8cadcb843e6d78761f81fa3fbfe5
parent56f628bb3d49a52c6e5ee1360b520c6381ebd510 (diff)
downloadpython-ttystatus-b15fcce5b6d2046e3419b3201e38667554de53fd.tar.gz
Speed things up by only updating widgets interested in the updated value.
-rw-r--r--ttystatus/bytesize.py1
-rw-r--r--ttystatus/counter.py1
-rw-r--r--ttystatus/elapsed.py1
-rw-r--r--ttystatus/index.py1
-rw-r--r--ttystatus/literal.py2
-rw-r--r--ttystatus/pathname.py1
-rw-r--r--ttystatus/percent.py1
-rw-r--r--ttystatus/progressbar.py1
-rw-r--r--ttystatus/remtime.py1
-rw-r--r--ttystatus/status.py7
-rw-r--r--ttystatus/string.py1
-rw-r--r--ttystatus/widget.py4
12 files changed, 19 insertions, 3 deletions
diff --git a/ttystatus/bytesize.py b/ttystatus/bytesize.py
index 0652b2f..3a2e88f 100644
--- a/ttystatus/bytesize.py
+++ b/ttystatus/bytesize.py
@@ -24,6 +24,7 @@ class ByteSize(ttystatus.Widget):
def __init__(self, name):
self.name = name
self.value = self.format(0)
+ self.interesting_keys = set([name])
def format(self, bytes):
units = (
diff --git a/ttystatus/counter.py b/ttystatus/counter.py
index b409114..a401d8d 100644
--- a/ttystatus/counter.py
+++ b/ttystatus/counter.py
@@ -26,6 +26,7 @@ class Counter(ttystatus.Widget):
self.prev = None
self.count = 0
self.value = '0'
+ self.interesting_keys = set([name])
def update(self, master, width):
if master[self.name] != self.prev:
diff --git a/ttystatus/elapsed.py b/ttystatus/elapsed.py
index bcea7df..1e14ecf 100644
--- a/ttystatus/elapsed.py
+++ b/ttystatus/elapsed.py
@@ -26,6 +26,7 @@ class ElapsedTime(ttystatus.Widget):
def __init__(self):
self.started = None
self.value = self.format(0)
+ self.interesting_keys = set()
def get_time(self): # pragma: no cover
'''Wrapper around time.time() for unit tests to override.'''
diff --git a/ttystatus/index.py b/ttystatus/index.py
index 2d51189..f402bea 100644
--- a/ttystatus/index.py
+++ b/ttystatus/index.py
@@ -25,6 +25,7 @@ class Index(ttystatus.Widget):
self.name = name
self.listname = listname
self.value = self.format(0, 0)
+ self.interesting_keys = set([name, listname])
def format(self, index, listlen):
return '%d/%d' % (index, listlen)
diff --git a/ttystatus/literal.py b/ttystatus/literal.py
index 7d8eb19..5ccfdf2 100644
--- a/ttystatus/literal.py
+++ b/ttystatus/literal.py
@@ -23,3 +23,5 @@ class Literal(ttystatus.Widget):
def __init__(self, string):
self.value = string
+ self.interesting_keys = set()
+
diff --git a/ttystatus/pathname.py b/ttystatus/pathname.py
index ac51a31..6933d03 100644
--- a/ttystatus/pathname.py
+++ b/ttystatus/pathname.py
@@ -27,6 +27,7 @@ class Pathname(ttystatus.Widget):
def __init__(self, key):
self._key = key
+ self.interesting_keys = set([key])
def update(self, master, width):
v = master.get(self._key, '')
diff --git a/ttystatus/percent.py b/ttystatus/percent.py
index 9750cac..b06d070 100644
--- a/ttystatus/percent.py
+++ b/ttystatus/percent.py
@@ -26,6 +26,7 @@ class PercentDone(ttystatus.Widget):
self.total_name = total_name
self.decimals = decimals
self.value = self.format(0, 1)
+ self.interesting_keys = set([done_name, total_name])
def format(self, done, total):
try:
diff --git a/ttystatus/progressbar.py b/ttystatus/progressbar.py
index aca8ea3..52a2b11 100644
--- a/ttystatus/progressbar.py
+++ b/ttystatus/progressbar.py
@@ -24,6 +24,7 @@ class ProgressBar(ttystatus.Widget):
def __init__(self, done_name, total_name):
self.done_name = done_name
self.total_name = total_name
+ self.interesting_keys = set([done_name, total_name])
def update(self, master, width):
done = float(master.get(self.done_name, 0))
diff --git a/ttystatus/remtime.py b/ttystatus/remtime.py
index b1cffe5..7602e54 100644
--- a/ttystatus/remtime.py
+++ b/ttystatus/remtime.py
@@ -29,6 +29,7 @@ class RemainingTime(ttystatus.Widget):
self.started = None
self.default = '--h--m--s'
self.value = self.default
+ self.interesting_keys = set([done_name, total_name])
def get_time(self): # pragma: no cover
'''Return current time.
diff --git a/ttystatus/status.py b/ttystatus/status.py
index f810525..012014a 100644
--- a/ttystatus/status.py
+++ b/ttystatus/status.py
@@ -43,7 +43,7 @@ class TerminalStatus(object):
self._widgets = []
self._values = dict()
self._m.clear()
-
+
def __getitem__(self, key):
'''Return value for key, or the empty string.'''
return self._values.get(key, '')
@@ -57,8 +57,9 @@ class TerminalStatus(object):
self._values[key] = value
width = self._m.width
for w in self._widgets:
- w.update(self, width)
- width -= len(str(w))
+ if w.interested_in(key):
+ w.update(self, width)
+ width -= len(str(w))
self._m.write(''.join(str(w) for w in self._widgets))
def increase(self, key, delta):
diff --git a/ttystatus/string.py b/ttystatus/string.py
index 34b2638..6806b01 100644
--- a/ttystatus/string.py
+++ b/ttystatus/string.py
@@ -23,6 +23,7 @@ class String(ttystatus.Widget):
def __init__(self, key):
self._key = key
+ self.interesting_keys = set([key])
def update(self, master, width):
self.value = master[self._key]
diff --git a/ttystatus/widget.py b/ttystatus/widget.py
index 34d0787..c498e96 100644
--- a/ttystatus/widget.py
+++ b/ttystatus/widget.py
@@ -32,6 +32,10 @@ class Widget(object):
else:
return ''
+ def interested_in(self, key):
+ '''Are we interested in this specific value?'''
+ return key in self.interesting_keys
+
def update(self, master, width):
'''Update displayed value for widget, from values in master.