Skip to content

Commit

Permalink
Added separated checkbox and radio button tables. These are truly tab…
Browse files Browse the repository at this point in the history
…les, inputs separated from labels, unlike CheckBoxTable and RadioButtonTable, which are just tables with label-input pairs together in each cell.
  • Loading branch information
chbrown committed Jul 22, 2010
1 parent 0efc43d commit 633529e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 25 deletions.
20 changes: 10 additions & 10 deletions tw2/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
This package contains the basic form widgets.
"""

from widgets import (Button, CheckBox,
FieldSet, FileField, Form, HiddenField, IgnoredField, ImageButton,
Label, Spacer, ListLayout, TableLayout, PasswordField,
RadioButton, ResetButton, SubmitButton, TextField, TextArea,
SingleSelectField, MultipleSelectField, RadioButtonList, CheckBoxList,
RadioButtonTable, CheckBoxTable, GridLayout, RowLayout, TableForm, ListForm,
VerticalRadioButtonTable, VerticalCheckBoxTable,
TableFieldSet, ListFieldSet, FormPage, FileValidator,
LabelField, LinkField)
from widgets import (Button, ImageButton,
FieldSet, FileField, Form,
GridLayout, RowLayout, TableForm, ListForm, ListLayout, TableLayout,
HiddenField, IgnoredField, LabelField, LinkField, TextField, PasswordField, Label, Spacer, TextArea,
ResetButton, SubmitButton,
SingleSelectField, MultipleSelectField,
CheckBox, CheckBoxList, CheckBoxTable, SeparatedCheckBoxTable, VerticalCheckBoxTable,
RadioButton, RadioButtonList, RadioButtonTable, SeparatedRadioButtonTable, VerticalRadioButtonTable,
TableFieldSet, ListFieldSet, FormPage, FileValidator)
from mashups import PostlabeledCheckBox, PostlabeledPartialRadioButton
from calendars import CalendarDatePicker, CalendarDateTimePicker
from calendars import CalendarDatePicker, CalendarDateTimePicker
12 changes: 1 addition & 11 deletions tw2/forms/calendars.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,7 @@ def prepare(self):
self.strdate = self.value.strftime(self.date_format)
except AttributeError:
self.strdate = self.value
# print 'CalendarDatePicker.prepare: self.compound_id = ', self.compound_id
# print 'CalendarDatePicker.prepare: len(self.resources) = ', len(self.resources)
# self.setup_options.update(dict(
# inputField = self.compound_id,
# ifFormat = self.date_format,
# button = self.id + '_trigger',
# showsTime = self.picker_shows_time,
# ))
# setup_calendar = twc.JSFuncCall(function="Calendar.setup", args=self.setup_options)
# setup_calendar.src = '"Whoa-%s"' % self.compound_id
# self.resources.append(setup_calendar)

self.resources.append(self.get_calendar_lang_file_link(self.calendar_lang))


Expand Down
2 changes: 1 addition & 1 deletion tw2/forms/templates/calendar.mak
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"inputField": "${w.compound_id}", "showsTime": ${str(w.picker_shows_time).lower()}, \
"ifFormat": "${w.date_format}", "button": "${w.compound_id}_trigger",\
%for k, v in w.setup_options.items():
"${k}": ${isinstance(v, twc.JSSymbol) and v.src or '"%s"' % v}\
"${k}": ${isinstance(v, twc.JSSymbol) and (v.src + ',') or '"%s",' % v}\
%endfor
})</script>
</div>\
6 changes: 6 additions & 0 deletions tw2/forms/templates/separated_selection_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<table xmlns:py="http://genshi.edgewall.org/" py:attrs="w.attrs">
<tr py:for="attrs, desc in w.options">
<td><input py:attrs="attrs" /></td>
<td><label for="${attrs['id']}" py:content="desc" /></td>
</tr>
</table>
9 changes: 9 additions & 0 deletions tw2/forms/templates/separated_selection_table.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%namespace name="tw" module="tw2.core.mako_util"/>\
<table ${tw.attrs(attrs=w.attrs)}>
%for attrs, desc in w.options:
<tr>
<td><input ${tw.attrs(attrs=attrs)}/></td>
<td><label for="${attrs['id']}">${desc}</label></td>
</tr>
%endfor
</table>
14 changes: 11 additions & 3 deletions tw2/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def prepare(self):
super(CheckBox, self).prepare()
self.safe_modify('attrs')
self.attrs['checked'] = self.value and 'checked' or None
self.value = None
self.value = 'Voila'

class RadioButton(InputField):
type = "radio"
Expand Down Expand Up @@ -308,12 +308,13 @@ class MultipleSelectField(SelectionField):
multiple = twc.Param(default=True, attribute=True)
template = "tw2.forms.templates.select_field"


class SelectionList(SelectionField):
field_type = True
selected_verb = "checked"
template = "tw2.forms.templates.selection_list"

class SeparatedSelectionTable(SelectionList):
template = "tw2.forms.templates.separated_selection_table"

class RadioButtonList(SelectionList):
field_type = "radio"
Expand Down Expand Up @@ -350,7 +351,7 @@ def prepare(self):
super(SelectionTable, self).prepare()
self.options_rows = self._group_rows(self.options, self.cols)
self.grouped_options_rows = [(g, self._group_rows(o, self.cols)) for g, o in self.grouped_options]

class VerticalSelectionTable(SelectionField):
field_type = twc.Variable(default=True)
selected_verb = "checked"
Expand Down Expand Up @@ -408,6 +409,9 @@ def prepare(self):
class RadioButtonTable(SelectionTable):
field_type = 'radio'

class SeparatedRadioButtonTable(SeparatedSelectionTable):
field_type = 'radio'

class VerticalRadioButtonTable(VerticalSelectionTable):
field_type = 'radio'

Expand All @@ -416,6 +420,10 @@ class CheckBoxTable(SelectionTable):
field_type = 'checkbox'
multiple = True

class SeparatedCheckBoxTable(SeparatedSelectionTable):
field_type = 'checkbox'
multiple = True

class VerticalCheckBoxTable(VerticalSelectionTable):
field_type = 'checkbox'
multiple = True
Expand Down

0 comments on commit 633529e

Please sign in to comment.