1 # vim: set expandtab tabstop=4 shiftwidth=4:
4 """Base widget class."""
6 def __init__(self, attrs = None):
12 return 'widget(attrs=' + str(self.attrs) + ')'
14 def render(self, userdata = None):
18 class container(widget):
19 """Base container widget class."""
21 def __init__(self, attrs = None, content = None):
22 widget.__init__(self, attrs)
25 self.content.append(content)
28 return 'container(attrs=' + str(self.attrs) + ', content=' \
29 + str(self.content) + ')'
32 return len(self.content)
34 def __getitem__(self, item):
35 return self.content[item]
37 def __setitem__(self, item, value):
38 self.content[item] = value
40 def __delitem__(self, item):
41 del self.content[item]
43 def __contains__(self, item):
44 return item in self.content
47 for i in self.content: yield i
49 def append(self, content):
50 self.content.append(content)
52 def extend(self, content):
53 self.content.extend(content)
55 def renderContent(self, userdata = None):
57 for content in self.content:
58 if isinstance(content, widget):
59 out += content.render(userdata)
65 class fallback(container):
66 """Fallback widget to use when no specific widget is implemented."""
68 def __init__(self, name, attrs = None, content = None):
69 container.__init__(self, attrs, content)
73 return 'fallback(name=\'' + str(self.name) + '\', attrs=' \
74 + str(self.attrs) + ', content=' + str(self.content) + ')'