simplify how form widgets get styled

This commit is contained in:
Michael Hudson-Doyle 2018-06-20 16:40:51 +12:00
parent 59da0e717b
commit ba809a9e97
1 changed files with 9 additions and 15 deletions

View File

@ -23,7 +23,6 @@ from urwid import (
MetaSignals, MetaSignals,
Text, Text,
WidgetDecoration, WidgetDecoration,
WidgetDisable,
WidgetWrap, WidgetWrap,
) )
@ -115,6 +114,7 @@ class BoundFormField(object):
self._enabled = True self._enabled = True
self.showing_extra = False self.showing_extra = False
self.widget = widget self.widget = widget
self._validator = _Validator(self, Color.string_input(widget))
if 'change' in getattr(widget, 'signals', []): if 'change' in getattr(widget, 'signals', []):
connect_signal(widget, 'change', self._change) connect_signal(widget, 'change', self._change)
if isinstance(widget, WantsToKnowFormField): if isinstance(widget, WantsToKnowFormField):
@ -211,20 +211,14 @@ class BoundFormField(object):
self.pile[0][0].set_text(val) self.pile[0][0].set_text(val)
def _cols(self): def _cols(self):
text = Text(self.caption, align="right") caption = Text(self.caption, align="right")
if self._enabled: cols = Columns([
input = Color.string_input(_Validator(self, self.widget)) (self._longest_caption, caption),
else: self._validator,
input = self.widget ], dividechars=2)
cols = [ if not self._enabled:
(self._longest_caption, text), cols = disabled(cols)
input return cols
]
cols = Columns(cols, dividechars=2)
if self._enabled:
return cols
else:
return WidgetDisable(Color.info_minor(cols))
def as_row(self, longest_caption): def as_row(self, longest_caption):
if self.pile is not None: if self.pile is not None: