frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated

This commit is contained in:
Goffi 2015-08-20 18:36:53 +02:00
commit 9df7cd6d33
2 changed files with 38 additions and 7 deletions

View file

@ -217,6 +217,27 @@ class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents)
selected.append(value) selected.append(value)
self._xmluiSelectValues(selected) self._xmluiSelectValues(selected)
class PrimitivusJidsListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents):
def __init__(self, _xmlui_parent, jids, styles):
sat_widgets.List.__init__(self, options=jids+[''], # the empty field is here to add new jids if needed
option_type=lambda txt, align: sat_widgets.AdvancedEdit(edit_text=txt, align=align),
on_change=self._onChange)
self.delete=0
def _onChange(self, list_widget, jid_widget=None, text=None):
if jid_widget is not None:
if jid_widget != list_widget.contents[-1] and not text:
# if a field is empty, we delete the line (except for the last line)
list_widget.contents.remove(jid_widget)
elif jid_widget == list_widget.contents[-1] and text:
# we always want an empty field as last value to be able to add jids
list_widget.contents.append(sat_widgets.AdvancedEdit())
def _xmluiGetSelectedValues(self):
# XXX: there is not selection in this list, so we return all non empty values
return [jid_ for jid_ in self.getAllValues() if jid_]
class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents): class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents):
@ -386,7 +407,7 @@ class XMLUIPanel(xmlui.XMLUIPanel, PrimitivusWidget):
self.main_cont.body.append(grid_wid) self.main_cont.body.append(grid_wid)
elif self.type == 'param': elif self.type == 'param':
tabs_cont = self.main_cont.body[0].base_widget tabs_cont = self.main_cont.body[0].base_widget
assert(isinstance(tabs_cont,sat_widgets.TabsContainer)) assert isinstance(tabs_cont,sat_widgets.TabsContainer)
buttons = [] buttons = []
buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams)) buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams))
buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow())) buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow()))
@ -422,7 +443,7 @@ class XMLUIPanel(xmlui.XMLUIPanel, PrimitivusWidget):
elif show_type == 'window': elif show_type == 'window':
self.host.newWidget(self) self.host.newWidget(self)
else: else:
assert(False) assert False
self.host.redraw() self.host.redraw()
def _xmluiClose(self): def _xmluiClose(self):

View file

@ -128,6 +128,11 @@ class ListWidget(Widget):
pass pass
class JidsListWidget(Widget):
"""A widget able to show/choose one or several strings in a list"""
pass
class Container(Widget): class Container(Widget):
"""Widget which can contain other ones with a specific layout""" """Widget which can contain other ones with a specific layout"""
@ -429,6 +434,11 @@ class XMLUIPanel(XMLUIBase):
_selected = [option.getAttribute("value") for option in node.getElementsByTagName("option") if option.getAttribute('selected') == C.BOOL_TRUE] _selected = [option.getAttribute("value") for option in node.getElementsByTagName("option") if option.getAttribute('selected') == C.BOOL_TRUE]
ctrl = self.widget_factory.createListWidget(_xmlui_parent, _options, _selected, style) ctrl = self.widget_factory.createListWidget(_xmlui_parent, _options, _selected, style)
self.ctrl_list[name] = ({'type': type_, 'control': ctrl}) self.ctrl_list[name] = ({'type': type_, 'control': ctrl})
elif type_ == "jids_list":
style = []
jids = [getText(jid_) for jid_ in node.getElementsByTagName("jid")]
ctrl = self.widget_factory.createJidsListWidget(_xmlui_parent, jids, style)
self.ctrl_list[name] = ({'type': type_, 'control': ctrl})
elif type_=="button": elif type_=="button":
callback_id = node.getAttribute("callback") callback_id = node.getAttribute("callback")
ctrl = self.widget_factory.createButtonWidget(_xmlui_parent, value, self.onButtonPress) ctrl = self.widget_factory.createButtonWidget(_xmlui_parent, value, self.onButtonPress)
@ -445,7 +455,7 @@ class XMLUIPanel(XMLUIBase):
if not isinstance(ctrl, (EmptyWidget, TextWidget, LabelWidget, JidWidget)): if not isinstance(ctrl, (EmptyWidget, TextWidget, LabelWidget, JidWidget)):
log.warning(_("No change listener on [%s]") % ctrl) log.warning(_("No change listener on [%s]") % ctrl)
if type_ != 'text': elif type_ != 'text':
callback = node.getAttribute("internal_callback") or None callback = node.getAttribute("internal_callback") or None
if callback: if callback:
fields = [field.getAttribute('name') for field in node.getElementsByTagName("internal_field")] fields = [field.getAttribute('name') for field in node.getElementsByTagName("internal_field")]
@ -499,7 +509,7 @@ class XMLUIPanel(XMLUIBase):
@param ctrl: widget modified @param ctrl: widget modified
""" """
assert(self.type == "param") assert self.type == "param"
self.param_changed.add(ctrl) self.param_changed.add(ctrl)
def onAdvListSelect(self, ctrl): def onAdvListSelect(self, ctrl):
@ -574,8 +584,8 @@ class XMLUIPanel(XMLUIBase):
def groups_of_contact(source, target): def groups_of_contact(source, target):
"""Select in target the groups of the contact which is selected in source.""" """Select in target the groups of the contact which is selected in source."""
assert(isinstance(source, ListWidget)) assert isinstance(source, ListWidget)
assert(isinstance(target, ListWidget)) assert isinstance(target, ListWidget)
try: try:
contact_jid_s = source._xmluiGetSelectedValues()[0] contact_jid_s = source._xmluiGetSelectedValues()[0]
except IndexError: except IndexError:
@ -649,7 +659,7 @@ class XMLUIPanel(XMLUIBase):
self.type must be param self.type must be param
""" """
assert(self.type == 'param') assert self.type == 'param'
for ctrl in self.param_changed: for ctrl in self.param_changed:
if isinstance(ctrl, ListWidget): if isinstance(ctrl, ListWidget):
value = u'\t'.join(ctrl._xmluiGetSelectedValues()) value = u'\t'.join(ctrl._xmluiGetSelectedValues())