Mercurial > libervia-backend
diff frontends/src/primitivus/xmlui.py @ 804:5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
- JidWidget is a text container a Jabber ID, this can be used by frontends for special treatment (e.g.: possibility to click on it)
- DividerWidget is a separator, like a blank or dashed line
- popup type is similar to normal window, but designed for a smaller popping window
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 04 Feb 2014 18:19:32 +0100 |
parents | f100fd8d279f |
children | 7c05c39156a2 |
line wrap: on
line diff
--- a/frontends/src/primitivus/xmlui.py Tue Feb 04 18:19:29 2014 +0100 +++ b/frontends/src/primitivus/xmlui.py Tue Feb 04 18:19:32 2014 +0100 @@ -49,6 +49,35 @@ urwid.Text.__init__(self, value) +class PrimitivusLabelWidget(xmlui.LabelWidget, PrimitivusTextWidget): + + def __init__(self, parent, value): + super(PrimitivusLabelWidget, self).__init__(parent, value+": ") + + +class PrimitivusJidWidget(xmlui.JidWidget, PrimitivusTextWidget): + pass + + +class PrimitivusDividerWidget(xmlui.DividerWidget, urwid.Divider): + + def __init__(self, parent, style='line'): + if style == 'line': + div_char = u'โ' + elif style == 'dot': + div_char = u'ยท' + elif style == 'dash': + div_char = u'-' + elif style == 'plain': + div_char = u'โ' + elif style == 'blank': + div_char = ' ' + else: + warning(_("Unknown div_char")) + div_char = u'โ' + + urwid.Divider.__init__(self, div_char) + class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents): def __init__(self, parent, value): @@ -168,7 +197,7 @@ def __init__(self, host, xml_data, title = None, flags = None): self.widget_factory._xmlui_main = self - self._dest = "window" + self._dest = None xmlui.XMLUI.__init__(self, host, xml_data, title, flags) urwid.WidgetWrap.__init__(self, self.main_cont) @@ -199,23 +228,32 @@ super(XMLUI, self).constructUI(xml_data, postTreat) urwid.WidgetWrap.__init__(self, self.main_cont) - def show(self, show_type='popup', valign='middle'): + def show(self, show_type=None, valign='middle'): """Show the constructed UI @param show_type: how to show the UI: - - popup - - window + - None (follow XMLUI's recommendation) + - 'popup' + - 'window' @param valign: vertical alignment when show_type is 'popup'. Ignored when show_type is 'window'. """ - self._dest = "popup" + if show_type is None: + if self.type in ('window', 'param'): + show_type = 'window' + elif self.type in ('popup', 'form'): + show_type = 'popup' + + if show_type not in ('popup', 'window'): + raise ValueError('Invalid show_type [%s]' % show_type) + + self._dest = show_type decorated = sat_widgets.LabelLine(self, sat_widgets.SurroundedText(self.title or '')) if show_type == 'popup': self.host.showPopUp(decorated, valign=valign) elif show_type == 'window': self.host.addWindow(decorated) else: - error(_('INTERNAL ERROR: Unmanaged show_type (%s)') % show_type) assert(False) self.host.redraw()