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
This commit is contained in:
Goffi 2014-02-04 18:19:32 +01:00
commit edf3e1bc87
4 changed files with 122 additions and 14 deletions

View file

@ -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):

View file

@ -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()

View file

@ -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':

View file

@ -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