diff options
| author | bwarsaw | 2001-08-14 06:22:43 +0000 |
|---|---|---|
| committer | bwarsaw | 2001-08-14 06:22:43 +0000 |
| commit | 300187223fc3c46254e83fbdb505785dc9df3567 (patch) | |
| tree | 1f30651d3d719e50446ef9cbfc8f446edfc970e2 | |
| parent | 39b0306d99c40a8bb1498f6aa438af8edf4af05a (diff) | |
| download | mailman-300187223fc3c46254e83fbdb505785dc9df3567.tar.gz mailman-300187223fc3c46254e83fbdb505785dc9df3567.tar.zst mailman-300187223fc3c46254e83fbdb505785dc9df3567.zip | |
Add CheckBoxArray, a new class which implements an array of check
boxes (i.e. multiple selections). Refactor RadioButtonArray class
into new base class WidgetArray which contains most of the logic.
RadioButtonArray and CheckBoxArray inherit from WidgetArray.
map(None, ...) => zip(...)
| -rw-r--r-- | Mailman/htmlformat.py | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/Mailman/htmlformat.py b/Mailman/htmlformat.py index e732c1a05..65b72df27 100644 --- a/Mailman/htmlformat.py +++ b/Mailman/htmlformat.py @@ -473,8 +473,6 @@ class CheckBox(InputObj): def __init__(self, name, value, checked=0, **kws): apply(InputObj.__init__, (self, name, "CHECKBOX", value, checked), kws) - - class VerticalSpacer: def __init__(self, size=10): self.size = size @@ -482,29 +480,30 @@ class VerticalSpacer: output = '<spacer type="vertical" height="%d">' % self.size return output -class RadioButtonArray: - def __init__(self, name, button_names, checked=None, horizontal=1, - values=None): - self.button_names = button_names - self.horizontal = horizontal +class WidgetArray: + Widget = None + + def __init__(self, name, button_names, checked, horizontal, values): self.name = name + self.button_names = button_names self.checked = checked self.horizontal = horizontal - if values is not None: - assert len(values) == len(button_names) - self.values = values - else: - self.values = range(len(button_names)) + self.values = values + assert len(values) == len(button_names) + # Don't assert `checked' because for RadioButtons it is a scalar while + # for CheckedBoxes it is a vector. Subclasses will assert length. + + def ischecked(self, i): + raise NotImplemented def Format(self, indent=0): t = Table(cellspacing=5) items = [] - for i, name, value in map(None, - range(len(self.button_names)), + for i, name, value in zip(range(len(self.button_names)), self.button_names, self.values): - ischecked = (self.checked == i) - item = RadioButton(self.name, value, ischecked).Format() + name + ischecked = (self.ischecked(i)) + item = self.Widget(self.name, value, ischecked).Format() + name items.append(item) if not self.horizontal: t.AddRow(items) @@ -513,6 +512,37 @@ class RadioButtonArray: t.AddRow(items) return t.Format(indent) +class RadioButtonArray(WidgetArray): + Widget = RadioButton + + def __init__(self, name, button_names, checked=None, horizontal=1, + values=None): + if values is None: + values = range(len(button_names)) + # BAW: assert checked is a scalar... + WidgetArray.__init__(self, name, button_names, checked, horizontal, + values) + + def ischecked(self, i): + return self.checked == i + +class CheckBoxArray(WidgetArray): + Widget = CheckBox + + def __init__(self, name, button_names, checked=None, horizontal=0, + values=None): + if checked is None: + checked = [0] * len(button_names) + else: + assert len(checked) == len(button_names) + if values is None: + values = range(len(button_names)) + WidgetArray.__init__(self, name, button_names, checked, horizontal, + values) + + def ischecked(self, i): + return self.checked[i] + class UnorderedList(Container): def Format(self, indent=0): spaces = ' ' * indent |
