jp (xmlui): JidWidget + small improvments:

- JidWidget is now handled basically using TextWidget.
- EmptyWidget display an empty line.
- BoolWidget display current value with an asterisk when write is allowed.
- fixed an bug in LabelContainer when for_name was not specified.
This commit is contained in:
Goffi 2019-01-02 18:50:47 +01:00
commit bd9cec8b47

View file

@ -174,8 +174,12 @@ class OptionsWidget(Widget):
class EmptyWidget(xmlui_base.EmptyWidget, Widget):
def __init__(self, _xmlui_parent):
Widget.__init__(self)
def __init__(self, xmlui_parent):
Widget.__init__(self, xmlui_parent)
def show(self):
self.host.disp(u'')
class TextWidget(xmlui_base.TextWidget, ValueWidget):
@ -204,6 +208,9 @@ class LabelWidget(xmlui_base.LabelWidget, ValueWidget):
self.disp(A.color(ansi, self.value), no_lf=no_lf)
class JidWidget(xmlui_base.JidWidget, TextWidget):
type = u"jid"
class StringWidget(xmlui_base.StringWidget, InputWidget):
type = u"string"
@ -286,8 +293,12 @@ class BoolWidget(xmlui_base.BoolWidget, InputWidget):
if self.read_only:
self.disp(disp_true if self.value else disp_false)
else:
self.disp(A.color(C.A_HEADER, u"0: ", disp_false))
self.disp(A.color(C.A_HEADER, u"1: ", disp_true))
self.disp(A.color(C.A_HEADER, u"0: ",
disp_false, A.RESET,
u" *" if not self.value else u""))
self.disp(A.color(C.A_HEADER, u"1: ",
disp_true, A.RESET,
u" *" if self.value else u""))
choice = None
while choice not in ("0", "1"):
elems = [C.A_HEADER, _(u"your choice (0,1): ")]
@ -342,7 +353,7 @@ class LabelContainer(xmlui_base.PairsContainer, Container):
# to see if we want the label on the same line or not
if child.type == u"label":
for_name = child.for_name
if for_name is not None:
if for_name:
for_widget = self.root.widgets[for_name]
wid_type = for_widget.type
if self.root.values_only or wid_type in (
@ -382,9 +393,9 @@ class NoteDialog(xmlui_base.NoteDialog, Dialog):
# TODO: handle title and level
self.disp(self.message)
def __init__(self, _xmlui_parent, title, message, level):
Dialog.__init__(self, _xmlui_parent)
xmlui_base.NoteDialog.__init__(self, _xmlui_parent)
def __init__(self, xmlui_parent, title, message, level):
Dialog.__init__(self, xmlui_parent)
xmlui_base.NoteDialog.__init__(self, xmlui_parent)
self.title, self.message, self.level = title, message, level