Merge pull request #599 from mwhudson/radiobuttonfield

add a RadioButtonField for forms
This commit is contained in:
Dimitri John Ledkov 2019-12-14 16:47:29 +00:00 committed by GitHub
commit b4ff1bde70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 0 deletions

View File

@ -24,6 +24,7 @@ from urwid import (
emit_signal,
MetaSignals,
Padding as UrwidPadding,
RadioButton,
Text,
WidgetDecoration,
)
@ -307,6 +308,41 @@ IntegerField = simple_field(IntegerEditor)
EmailField = simple_field(EmailEditor)
class RadioButtonEditor(RadioButton):
reserve_columns = 3
@property
def value(self):
return self.state
@value.setter
def value(self, val):
self.state = val
class RadioButtonField(FormField):
caption_first = False
takes_default_style = False
def __init__(self, group, caption=None, help=None):
if group is None:
group = []
group.append(self)
self.group = group
super().__init__(caption, help)
def _make_widget(self, form):
for bf in form._fields:
if bf.field in self.group:
group = bf.widget.group
break
else:
group = []
return RadioButtonEditor(group, "")
class URLEditor(StringEditor, WantsToKnowFormField):
def __init__(self, allowed_schemes=frozenset(['http', 'https'])):
self.allowed_schemes = allowed_schemes