comparison frontends/src/primitivus/xmlui.py @ 803:f100fd8d279f

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
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:19:29 +0100
parents 9007bb133009
children 5174657b3378
comparison
equal deleted inserted replaced
802:9007bb133009 803:f100fd8d279f
101 101
102 def _xmluiGetSelectedValues(self): 102 def _xmluiGetSelectedValues(self):
103 return [option.value for option in self.getSelectedValues()] 103 return [option.value for option in self.getSelectedValues()]
104 104
105 105
106 class PrimitivusPairsContainer(xmlui.PairsContainer, urwid.WidgetWrap): 106 class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer):
107 107
108 def __init__(self, parent, weight_0='1', weight_1='1'): 108 def __init__(self, parent, columns):
109 self.idx = 0 109 options = {'ADAPT':(), 'HIGHLIGHT':()}
110 self.weight_0 = weight_0 110 sat_widgets.TableContainer.__init__(self, columns=columns, options=options)
111 self.weight_1 = weight_1 111
112 columns = urwid.Columns([urwid.Text(''), urwid.Text('')]) 112 def _xmluiAppend(self, widget):
113 #XXX: empty Text hack needed because Pile doesn't support empty list 113 self.addWidget(widget)
114 urwid.WidgetWrap.__init__(self,columns) 114
115 115 def _xmluiAddRow(self):
116 def _xmluiAppend(self, widget): 116 pass
117 pile = self._w.widget_list[self.idx] 117
118 if isinstance(pile, urwid.Text): 118 class PrimitivusPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer):
119 self._w.widget_list[self.idx] = urwid.Pile([widget]) 119
120 if self.idx == 1: 120 def __init__(self, parent):
121 self._w.set_focus(1) 121 options = {'ADAPT':(0,), 'HIGHLIGHT':(0,)}
122 else: 122 if self._xmlui_main.type == 'param':
123 pile.contents.append((widget,('weight',getattr(self,'weight_'+str(self.idx))))) 123 options['FOCUS_ATTR'] = 'param_selected'
124 self.idx = (self.idx + 1) % 2 124 sat_widgets.TableContainer.__init__(self, columns=2, options=options)
125
126 def _xmluiAppend(self, widget):
127 if isinstance(widget, PrimitivusEmptyWidget):
128 # we don't want highlight on empty widgets
129 widget = urwid.AttrMap(widget, 'default')
130 self.addWidget(widget)
125 131
126 132
127 class PrimitivusTabsContainer(xmlui.TabsContainer, sat_widgets.TabsContainer): 133 class PrimitivusTabsContainer(xmlui.TabsContainer, sat_widgets.TabsContainer):
128 134
129 def __init__(self, parent): 135 def __init__(self, parent):
151 157
152 class WidgetFactory(object): 158 class WidgetFactory(object):
153 159
154 def __getattr__(self, attr): 160 def __getattr__(self, attr):
155 if attr.startswith("create"): 161 if attr.startswith("create"):
156 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 162 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
157 163 cls._xmlui_main = self._xmlui_main
164 return cls
158 165
159 class XMLUI(xmlui.XMLUI, urwid.WidgetWrap): 166 class XMLUI(xmlui.XMLUI, urwid.WidgetWrap):
160 widget_factory = WidgetFactory() 167 widget_factory = WidgetFactory()
161 168
162 def __init__(self, host, xml_data, title = None, flags = None): 169 def __init__(self, host, xml_data, title = None, flags = None):
170 self.widget_factory._xmlui_main = self
163 self._dest = "window" 171 self._dest = "window"
164 xmlui.XMLUI.__init__(self, host, xml_data, title, flags) 172 xmlui.XMLUI.__init__(self, host, xml_data, title, flags)
165 urwid.WidgetWrap.__init__(self, self.main_cont) 173 urwid.WidgetWrap.__init__(self, self.main_cont)
166 174
167 def constructUI(self, xml_data): 175 def constructUI(self, xml_data):