diff --git a/frontends/src/primitivus/primitivus b/frontends/src/primitivus/primitivus index 13580c89..2ea908b7 100755 --- a/frontends/src/primitivus/primitivus +++ b/frontends/src/primitivus/primitivus @@ -455,7 +455,7 @@ class PrimitivusApp(QuickApp, InputHistory): pass elif "xmlui" in data: ui = XMLUI(self, xml_data = data['xmlui']) - ui.show('popup') + ui.show() else: self.showPopUp(sat_widgets.Alert(_("Error"), _(u"Unmanaged action result"), ok_cb=self.removePopUp)) def action_eb(failure): diff --git a/frontends/src/primitivus/xmlui.py b/frontends/src/primitivus/xmlui.py index fb45f4de..7e4278cd 100644 --- a/frontends/src/primitivus/xmlui.py +++ b/frontends/src/primitivus/xmlui.py @@ -49,6 +49,35 @@ class PrimitivusTextWidget(xmlui.TextWidget, urwid.Text): 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 @@ class XMLUI(xmlui.XMLUI, urwid.WidgetWrap): 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 @@ class XMLUI(xmlui.XMLUI, urwid.WidgetWrap): 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() diff --git a/frontends/src/tools/xmlui.py b/frontends/src/tools/xmlui.py index c8db68c9..12144e96 100644 --- a/frontends/src/tools/xmlui.py +++ b/frontends/src/tools/xmlui.py @@ -54,6 +54,21 @@ class TextWidget(Widget): pass +class LabelWidget(Widget): + """ Non interactive text """ + pass + + +class JidWidget(Widget): + """ Jabber ID """ + pass + + +class DividerWidget(Widget): + """ Separator """ + pass + + class StringWidget(Widget): """ Input widget with require a string often called Edit in toolkits @@ -124,6 +139,7 @@ class AdvancedListContainer(Container): """ Widgets are disposed in rows with advaned features """ pass + class XMLUI(object): """ Base class to construct SàT XML User Interface New frontends can inherite this class to easily implement XMLUI @@ -247,7 +263,12 @@ class XMLUI(object): warning (_("text node has no child !")) ctrl = self.widget_factory.createTextWidget(parent, value) elif type_=="label": - ctrl = self.widget_factory.createTextWidget(parent, value+": ") + ctrl = self.widget_factory.createLabelWidget(parent, value) + elif type_=="jid": + ctrl = self.widget_factory.createJidWidget(parent, value) + elif type_=="divider": + style = node.getAttribute("style") or 'line' + ctrl = self.widget_factory.createDividerWidget(parent, style) elif type_=="string": ctrl = self.widget_factory.createStringWidget(parent, value) self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) @@ -300,7 +321,7 @@ class XMLUI(object): self.title = self.title or top.getAttribute("title") or u"" self.session_id = top.getAttribute("session_id") or None self.submit_id = top.getAttribute("submit") or None - if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: + if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window', 'popup']: raise InvalidXMLUI if self.type == 'param': diff --git a/frontends/src/wix/xmlui.py b/frontends/src/wix/xmlui.py index e04d7355..89191d11 100644 --- a/frontends/src/wix/xmlui.py +++ b/frontends/src/wix/xmlui.py @@ -57,6 +57,22 @@ class TextWidget(WixWidget, xmlui.TextWidget, wx.StaticText): wx.StaticText.__init__(self, parent, -1, value) +class LabelWidget(xmlui.LabelWidget, TextWidget): + + def __init__(self, parent, value): + super(LabelWidget, self).__init__(parent, value+": ") + + +class JidWidget(xmlui.JidWidget, TextWidget): + pass + + +class DividerWidget(WixWidget, xmlui.DividerWidget, wx.StaticLine): + + def __init__(self, parent, style='line'): + wx.StaticLine.__init__(self, parent, -1) + + class StringWidget(EventWidget, ValueWidget, xmlui.StringWidget, wx.TextCtrl): _xmlui_change_event = wx.EVT_TEXT diff --git a/src/tools/xml_tools.py b/src/tools/xml_tools.py index 012ba6cb..1cf1eae6 100644 --- a/src/tools/xml_tools.py +++ b/src/tools/xml_tools.py @@ -424,6 +424,7 @@ class AdvancedListContainer(Container): self.addHeader(header) def addHeader(self, header): + pass # TODO def addItems(self, items): @@ -443,7 +444,7 @@ class AdvancedListContainer(Container): change current container to first container parent """ - if self._current_colum % self._columns != 0: + if self._item_idx % self._columns != 0: raise exceptions.DataError(_("Incorrect number of items in list")) parent_container = self.getParentContainer() self.xmlui.changeContainer(parent_container) @@ -490,6 +491,37 @@ class LabelWidget(Widget): self.elem.setAttribute('value', label) +class JidWidget(Widget): + type='jid' + + def __init__(self, xmlui, jid, name=None, parent=None): + super(JidWidget, self).__init__(xmlui, name, parent) + try: + self.elem.setAttribute('value', jid.full()) + except AttributeError: + self.elem.setAttribute('value', unicode(jid)) + + +class DividerWidget(Widget): + type = 'divider' + + def __init__(self, xmlui, style='line', name=None, parent=None): + """ Create a divider + @param xmlui: XMLUI instance + @param style: one of: + - line: a simple line + - dot: a line of dots + - dash: a line of dashes + - plain: a full thick line + - blank: a blank line/space + @param name: name of the widget + @param parent: parent container + + """ + super(DividerWidget, self).__init__(xmlui, name, parent) + self.elem.setAttribute('style', style) + + class StringWidget(InputWidget): type = 'string' @@ -521,7 +553,7 @@ class BoolWidget(InputWidget): self.elem.setAttribute('value', value) -class ButtonWidget(InputWidget): +class ButtonWidget(Widget): type = 'button' def __init__(self, xmlui, callback_id, value=None, fields_back=None, name=None, parent=None): @@ -571,10 +603,11 @@ class ListWidget(InputWidget): class XMLUI(object): """This class is used to create a user interface (form/window/parameters/etc) using SàT XML""" - def __init__(self, panel_type, container="vertical", title=None, submit_id=None, session_id=None): + def __init__(self, panel_type="window", container="vertical", title=None, submit_id=None, session_id=None): """Init SàT XML Panel @param panel_type: one of - window (new window) + - popup - form (formulaire, depend of the frontend, usually a panel with cancel/submit buttons) - param (parameters, presentation depend of the frontend) @param container: disposition of elements, one of: @@ -587,7 +620,7 @@ class XMLUI(object): @param submit_id: callback id to call for panel_type we can submit (form, param) """ self._introspect() - if panel_type not in ['window', 'form', 'param']: + if panel_type not in ['window', 'form', 'param', 'popup']: raise exceptions.DataError(_("Unknown panel type [%s]") % panel_type) if panel_type == 'form' and submit_id is None: raise exceptions.DataError(_("form XMLUI need a submit_id")) @@ -686,7 +719,7 @@ class XMLUI(object): if container not in self._containers: raise exceptions.DataError(_("Unknown container type [%s]") % container) cls = self._containers[container] - new_container = cls(self, parent, **kwargs) + new_container = cls(self, parent=parent, **kwargs) return new_container def changeContainer(self, container, **kwargs):