diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-07-07 09:20:10 +1200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-07-07 09:20:10 +1200 |
commit | dc830c6e3bdaa9f2caf766a541a33767c14eacc3 (patch) | |
tree | 97e1be607f431c0ab791c022b98d606720bceee9 /ttystatus/index.py | |
parent | 3a1ecab53b935e6c794d1080939884286a119320 (diff) | |
download | python-ttystatus-dc830c6e3bdaa9f2caf766a541a33767c14eacc3.tar.gz |
Change update methods to only cache information and compute minimal things.
Add a format() method that actually do the heavy duty lifting,
such as string formatting, which is only needed during actual
output.
Diffstat (limited to 'ttystatus/index.py')
-rw-r--r-- | ttystatus/index.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/ttystatus/index.py b/ttystatus/index.py index a9e1541..941165a 100644 --- a/ttystatus/index.py +++ b/ttystatus/index.py @@ -24,18 +24,18 @@ class Index(ttystatus.Widget): def __init__(self, name, listname): self.name = name self.listname = listname - self.value = self.format(0, 0) self.interesting_keys = [name, listname] + self.value = None + self.listvalue = [] - def format(self, index, listlen): - return '%d/%d' % (index, listlen) - - def update(self, master, width): - value = master[self.name] - listvalue = master[self.listname] + def format(self): try: - index = listvalue.index(value) + 1 + index = self.listvalue.index(self.value) + 1 except ValueError: - pass - else: - self.value = self.format(index, len(listvalue)) + index = 0 + return '%d/%d' % (index, len(self.listvalue)) + + def update(self, master, width): + self.value = master[self.name] + self.listvalue = master[self.listname] + |