comparison 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
comparison
equal deleted inserted replaced
803:f100fd8d279f 804:5174657b3378
47 47
48 def __init__(self, parent, value): 48 def __init__(self, parent, value):
49 urwid.Text.__init__(self, value) 49 urwid.Text.__init__(self, value)
50 50
51 51
52 class PrimitivusLabelWidget(xmlui.LabelWidget, PrimitivusTextWidget):
53
54 def __init__(self, parent, value):
55 super(PrimitivusLabelWidget, self).__init__(parent, value+": ")
56
57
58 class PrimitivusJidWidget(xmlui.JidWidget, PrimitivusTextWidget):
59 pass
60
61
62 class PrimitivusDividerWidget(xmlui.DividerWidget, urwid.Divider):
63
64 def __init__(self, parent, style='line'):
65 if style == 'line':
66 div_char = u'โ”€'
67 elif style == 'dot':
68 div_char = u'ยท'
69 elif style == 'dash':
70 div_char = u'-'
71 elif style == 'plain':
72 div_char = u'โ–ˆ'
73 elif style == 'blank':
74 div_char = ' '
75 else:
76 warning(_("Unknown div_char"))
77 div_char = u'โ”€'
78
79 urwid.Divider.__init__(self, div_char)
80
52 class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents): 81 class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents):
53 82
54 def __init__(self, parent, value): 83 def __init__(self, parent, value):
55 sat_widgets.AdvancedEdit.__init__(self, edit_text=value) 84 sat_widgets.AdvancedEdit.__init__(self, edit_text=value)
56 85
166 class XMLUI(xmlui.XMLUI, urwid.WidgetWrap): 195 class XMLUI(xmlui.XMLUI, urwid.WidgetWrap):
167 widget_factory = WidgetFactory() 196 widget_factory = WidgetFactory()
168 197
169 def __init__(self, host, xml_data, title = None, flags = None): 198 def __init__(self, host, xml_data, title = None, flags = None):
170 self.widget_factory._xmlui_main = self 199 self.widget_factory._xmlui_main = self
171 self._dest = "window" 200 self._dest = None
172 xmlui.XMLUI.__init__(self, host, xml_data, title, flags) 201 xmlui.XMLUI.__init__(self, host, xml_data, title, flags)
173 urwid.WidgetWrap.__init__(self, self.main_cont) 202 urwid.WidgetWrap.__init__(self, self.main_cont)
174 203
175 def constructUI(self, xml_data): 204 def constructUI(self, xml_data):
176 def postTreat(): 205 def postTreat():
197 self.main_cont.addFooter(grid_wid) 226 self.main_cont.addFooter(grid_wid)
198 227
199 super(XMLUI, self).constructUI(xml_data, postTreat) 228 super(XMLUI, self).constructUI(xml_data, postTreat)
200 urwid.WidgetWrap.__init__(self, self.main_cont) 229 urwid.WidgetWrap.__init__(self, self.main_cont)
201 230
202 def show(self, show_type='popup', valign='middle'): 231 def show(self, show_type=None, valign='middle'):
203 """Show the constructed UI 232 """Show the constructed UI
204 @param show_type: how to show the UI: 233 @param show_type: how to show the UI:
205 - popup 234 - None (follow XMLUI's recommendation)
206 - window 235 - 'popup'
236 - 'window'
207 @param valign: vertical alignment when show_type is 'popup'. 237 @param valign: vertical alignment when show_type is 'popup'.
208 Ignored when show_type is 'window'. 238 Ignored when show_type is 'window'.
209 239
210 """ 240 """
211 self._dest = "popup" 241 if show_type is None:
242 if self.type in ('window', 'param'):
243 show_type = 'window'
244 elif self.type in ('popup', 'form'):
245 show_type = 'popup'
246
247 if show_type not in ('popup', 'window'):
248 raise ValueError('Invalid show_type [%s]' % show_type)
249
250 self._dest = show_type
212 decorated = sat_widgets.LabelLine(self, sat_widgets.SurroundedText(self.title or '')) 251 decorated = sat_widgets.LabelLine(self, sat_widgets.SurroundedText(self.title or ''))
213 if show_type == 'popup': 252 if show_type == 'popup':
214 self.host.showPopUp(decorated, valign=valign) 253 self.host.showPopUp(decorated, valign=valign)
215 elif show_type == 'window': 254 elif show_type == 'window':
216 self.host.addWindow(decorated) 255 self.host.addWindow(decorated)
217 else: 256 else:
218 error(_('INTERNAL ERROR: Unmanaged show_type (%s)') % show_type)
219 assert(False) 257 assert(False)
220 self.host.redraw() 258 self.host.redraw()
221 259
222 260
223 def _xmluiClose(self): 261 def _xmluiClose(self):