core, frontends: implementation of AdvancedListContainer first draft + misc:
/!\ Urwid SàText must be updated as the new TableContainer is used /!\
- fixed button value in paramsXML2XMLUI
- new Urwid SàText TabContainer is used in Primitivus for PairsContainer and AdvancedListContainer
- fixed in core's XMLUI AdvanceListContainer
This commit is contained in:
parent
b3fb68cb63
commit
9661c1c2c5
4 changed files with 77 additions and 37 deletions
|
|
@ -69,6 +69,8 @@ class Const(constants.Const):
|
|||
('show_xa_focus', 'dark red, bold', 'default'),
|
||||
('status', 'yellow', 'default'),
|
||||
('status_focus', 'yellow, bold', 'default'),
|
||||
('param_selected','default, bold', 'dark red'),
|
||||
('table_selected','default, bold', 'default'),
|
||||
]
|
||||
PRESENCE = {"unavailable": (u'⨯', "show_disconnected"),
|
||||
"": (u'✔', "show_normal"),
|
||||
|
|
|
|||
|
|
@ -103,25 +103,31 @@ class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents)
|
|||
return [option.value for option in self.getSelectedValues()]
|
||||
|
||||
|
||||
class PrimitivusPairsContainer(xmlui.PairsContainer, urwid.WidgetWrap):
|
||||
class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer):
|
||||
|
||||
def __init__(self, parent, weight_0='1', weight_1='1'):
|
||||
self.idx = 0
|
||||
self.weight_0 = weight_0
|
||||
self.weight_1 = weight_1
|
||||
columns = urwid.Columns([urwid.Text(''), urwid.Text('')])
|
||||
#XXX: empty Text hack needed because Pile doesn't support empty list
|
||||
urwid.WidgetWrap.__init__(self,columns)
|
||||
def __init__(self, parent, columns):
|
||||
options = {'ADAPT':(), 'HIGHLIGHT':()}
|
||||
sat_widgets.TableContainer.__init__(self, columns=columns, options=options)
|
||||
|
||||
def _xmluiAppend(self, widget):
|
||||
pile = self._w.widget_list[self.idx]
|
||||
if isinstance(pile, urwid.Text):
|
||||
self._w.widget_list[self.idx] = urwid.Pile([widget])
|
||||
if self.idx == 1:
|
||||
self._w.set_focus(1)
|
||||
else:
|
||||
pile.contents.append((widget,('weight',getattr(self,'weight_'+str(self.idx)))))
|
||||
self.idx = (self.idx + 1) % 2
|
||||
self.addWidget(widget)
|
||||
|
||||
def _xmluiAddRow(self):
|
||||
pass
|
||||
|
||||
class PrimitivusPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer):
|
||||
|
||||
def __init__(self, parent):
|
||||
options = {'ADAPT':(0,), 'HIGHLIGHT':(0,)}
|
||||
if self._xmlui_main.type == 'param':
|
||||
options['FOCUS_ATTR'] = 'param_selected'
|
||||
sat_widgets.TableContainer.__init__(self, columns=2, options=options)
|
||||
|
||||
def _xmluiAppend(self, widget):
|
||||
if isinstance(widget, PrimitivusEmptyWidget):
|
||||
# we don't want highlight on empty widgets
|
||||
widget = urwid.AttrMap(widget, 'default')
|
||||
self.addWidget(widget)
|
||||
|
||||
|
||||
class PrimitivusTabsContainer(xmlui.TabsContainer, sat_widgets.TabsContainer):
|
||||
|
|
@ -153,13 +159,15 @@ class WidgetFactory(object):
|
|||
|
||||
def __getattr__(self, attr):
|
||||
if attr.startswith("create"):
|
||||
return globals()["Primitivus" + attr[6:]] # XXX: we prefix with "Primitivus" to work around an Urwid bug, WidgetMeta in Urwid don't manage multiple inheritance with same names
|
||||
|
||||
cls = globals()["Primitivus" + attr[6:]] # XXX: we prefix with "Primitivus" to work around an Urwid bug, WidgetMeta in Urwid don't manage multiple inheritance with same names
|
||||
cls._xmlui_main = self._xmlui_main
|
||||
return cls
|
||||
|
||||
class XMLUI(xmlui.XMLUI, urwid.WidgetWrap):
|
||||
widget_factory = WidgetFactory()
|
||||
|
||||
def __init__(self, host, xml_data, title = None, flags = None):
|
||||
self.widget_factory._xmlui_main = self
|
||||
self._dest = "window"
|
||||
xmlui.XMLUI.__init__(self, host, xml_data, title, flags)
|
||||
urwid.WidgetWrap.__init__(self, self.main_cont)
|
||||
|
|
|
|||
|
|
@ -120,6 +120,10 @@ class VerticalContainer(Container):
|
|||
pass
|
||||
|
||||
|
||||
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
|
||||
|
|
@ -178,7 +182,7 @@ class XMLUI(object):
|
|||
"""
|
||||
for node in current_node.childNodes:
|
||||
if wanted and not node.nodeName in wanted:
|
||||
raise InvalidXMLUI
|
||||
raise InvalidXMLUI('Unexpected node: [%s]' % node.nodeName)
|
||||
|
||||
if node.nodeName == "container":
|
||||
type_ = node.getAttribute('type')
|
||||
|
|
@ -195,6 +199,13 @@ class XMLUI(object):
|
|||
elif type_ == "pairs":
|
||||
cont = self.widget_factory.createPairsContainer(parent)
|
||||
self._parseChilds(cont, node, ('widget', 'container'))
|
||||
elif type_ == "advanced_list":
|
||||
try:
|
||||
columns = int(node.getAttribute('columns'))
|
||||
except (TypeError, ValueError):
|
||||
raise DataError("Invalid columns")
|
||||
cont = self.widget_factory.createAdvancedListContainer(parent, columns)
|
||||
self._parseChilds(cont, node, ('row',))
|
||||
else:
|
||||
warning(_("Unknown container [%s], using default one") % type_)
|
||||
cont = self.widget_factory.createVerticalContainer(parent)
|
||||
|
|
@ -207,7 +218,7 @@ class XMLUI(object):
|
|||
else:
|
||||
raise Exception(_("Internal Error, container has not _xmluiAppend method"))
|
||||
|
||||
elif node.nodeName == "tab":
|
||||
elif node.nodeName == 'tab':
|
||||
name = node.getAttribute('name')
|
||||
label = node.getAttribute('label')
|
||||
if not name or not isinstance(data, TabsContainer):
|
||||
|
|
@ -218,6 +229,10 @@ class XMLUI(object):
|
|||
new_tab = tab_cont._xmluiAddTab(label or name)
|
||||
self._parseChilds(new_tab, node, ('widget', 'container'))
|
||||
|
||||
elif node.nodeName == 'row':
|
||||
parent._xmluiAddRow()
|
||||
self._parseChilds(parent, node, ('widget', 'container'))
|
||||
|
||||
elif node.nodeName == "widget":
|
||||
id_ = node.getAttribute("id")
|
||||
name = node.getAttribute("name")
|
||||
|
|
|
|||
|
|
@ -138,9 +138,20 @@ class WixContainer(object):
|
|||
self.sizer.Add(widget, self._xmlui_proportion, flag=wx.EXPAND)
|
||||
|
||||
|
||||
class AdvancedListContainer(WixContainer, xmlui.AdvancedListContainer, wx.Panel):
|
||||
|
||||
def __init__(self, parent, columns):
|
||||
wx.Panel.__init__(self, parent)
|
||||
self.sizer = wx.FlexGridSizer(cols=columns)
|
||||
self.SetSizer(self.sizer)
|
||||
|
||||
def _xmluiAddRow(self):
|
||||
pass
|
||||
|
||||
|
||||
class PairsContainer(WixContainer, xmlui.PairsContainer, wx.Panel):
|
||||
|
||||
def __init__(self, parent, weight_0='1', weight_1='1'):
|
||||
def __init__(self, parent):
|
||||
wx.Panel.__init__(self, parent)
|
||||
self.sizer = wx.FlexGridSizer(cols=2)
|
||||
self.sizer.AddGrowableCol(1) #The growable column need most of time to be the right one in pairs
|
||||
|
|
|
|||
Loading…
Reference in a new issue