From d1e7b83f5b29c05124a4fc630247fdc97e0957f7 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 6 Jun 2010 14:14:08 +1200 Subject: Implement TerminalStatus.__getitem__ --- ttystatus/status.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'ttystatus/status.py') diff --git a/ttystatus/status.py b/ttystatus/status.py index b51c5c5..6eeb55e 100644 --- a/ttystatus/status.py +++ b/ttystatus/status.py @@ -16,7 +16,16 @@ class TerminalStatus(object): - '''Show status and progress information on a terminal.''' + '''Show status and progress information on a terminal. + + All output is provided via widgets of various kinds. Many widgets + format data that TerminalStatus stores. TerminalStatus provides a + dict interface for setting and retrieving data items. Unlike a real + dict, getting a value for a key that has not been set does not + result in a KeyError exception, but in the empty string being + returned. + + ''' def __init__(self): self.clear() @@ -28,3 +37,8 @@ class TerminalStatus(object): def clear(self): '''Remove all widgets.''' self._widgets = [] + self._values = dict() + + def __getitem__(self, key): + '''Return value for key, or the empty string.''' + return self._values.get(key, '') -- cgit v1.2.1