diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-06-06 14:21:22 +1200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-06-06 14:21:22 +1200 |
commit | 50cc4980d6e826862c58f941f83809ec4217e996 (patch) | |
tree | 1baeee4ffde1d73727e389f2abcc6aaca9a551fe | |
parent | 92d5344bdbd445b2dd5d1f5c5a0824069911b860 (diff) | |
download | python-ttystatus-50cc4980d6e826862c58f941f83809ec4217e996.tar.gz |
Make TerminalStatus update widgets when values change.
-rw-r--r-- | ttystatus/__init__.py | 5 | ||||
-rw-r--r-- | ttystatus/status.py | 2 | ||||
-rw-r--r-- | ttystatus/status_tests.py | 7 |
3 files changed, 13 insertions, 1 deletions
diff --git a/ttystatus/__init__.py b/ttystatus/__init__.py index 95f35ac..7cb5bd7 100644 --- a/ttystatus/__init__.py +++ b/ttystatus/__init__.py @@ -15,6 +15,9 @@ from messager import Messager +from status import TerminalStatus from widget import Widget + from literal import Literal -from status import TerminalStatus +from string import String + diff --git a/ttystatus/status.py b/ttystatus/status.py index 84de7f8..6aa28a4 100644 --- a/ttystatus/status.py +++ b/ttystatus/status.py @@ -46,3 +46,5 @@ class TerminalStatus(object): def __setitem__(self, key, value): '''Set value for key.''' self._values[key] = value + for w in self._widgets: + w.update(self, 999) diff --git a/ttystatus/status_tests.py b/ttystatus/status_tests.py index 539e788..4adfeec 100644 --- a/ttystatus/status_tests.py +++ b/ttystatus/status_tests.py @@ -43,3 +43,10 @@ class TerminalStatusTests(unittest.TestCase): def test_sets_value(self): self.ts['foo'] = 'bar' self.assertEqual(self.ts['foo'], 'bar') + + def test_updates_widgets_when_value_is_set(self): + w = ttystatus.String('foo') + self.ts.add(w) + self.assertEqual(str(w), '') + self.ts['foo'] = 'bar' + self.assertEqual(str(w), 'bar') |