Merge pull request #599 from mwhudson/radiobuttonfield
add a RadioButtonField for forms
This commit is contained in:
commit
b4ff1bde70
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue