comparison frontends/src/tools/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
117 117
118 class VerticalContainer(Container): 118 class VerticalContainer(Container):
119 """ Widgets are disposed vertically """ 119 """ Widgets are disposed vertically """
120 pass 120 pass
121 121
122
123 class AdvancedListContainer(Container):
124 """ Widgets are disposed in rows with advaned features """
125 pass
122 126
123 class XMLUI(object): 127 class XMLUI(object):
124 """ Base class to construct SàT XML User Interface 128 """ Base class to construct SàT XML User Interface
125 New frontends can inherite this class to easily implement XMLUI 129 New frontends can inherite this class to easily implement XMLUI
126 @property widget_factory: factory to create frontend-specific widgets 130 @property widget_factory: factory to create frontend-specific widgets
176 @param data: additionnal data which are needed in some cases 180 @param data: additionnal data which are needed in some cases
177 181
178 """ 182 """
179 for node in current_node.childNodes: 183 for node in current_node.childNodes:
180 if wanted and not node.nodeName in wanted: 184 if wanted and not node.nodeName in wanted:
181 raise InvalidXMLUI 185 raise InvalidXMLUI('Unexpected node: [%s]' % node.nodeName)
182 186
183 if node.nodeName == "container": 187 if node.nodeName == "container":
184 type_ = node.getAttribute('type') 188 type_ = node.getAttribute('type')
185 if parent is self and type_ != 'vertical': 189 if parent is self and type_ != 'vertical':
186 # main container is not a VerticalContainer and we want one, so we create one to wrap it 190 # main container is not a VerticalContainer and we want one, so we create one to wrap it
193 cont = self.widget_factory.createVerticalContainer(parent) 197 cont = self.widget_factory.createVerticalContainer(parent)
194 self._parseChilds(cont, node, ('widget', 'container')) 198 self._parseChilds(cont, node, ('widget', 'container'))
195 elif type_ == "pairs": 199 elif type_ == "pairs":
196 cont = self.widget_factory.createPairsContainer(parent) 200 cont = self.widget_factory.createPairsContainer(parent)
197 self._parseChilds(cont, node, ('widget', 'container')) 201 self._parseChilds(cont, node, ('widget', 'container'))
202 elif type_ == "advanced_list":
203 try:
204 columns = int(node.getAttribute('columns'))
205 except (TypeError, ValueError):
206 raise DataError("Invalid columns")
207 cont = self.widget_factory.createAdvancedListContainer(parent, columns)
208 self._parseChilds(cont, node, ('row',))
198 else: 209 else:
199 warning(_("Unknown container [%s], using default one") % type_) 210 warning(_("Unknown container [%s], using default one") % type_)
200 cont = self.widget_factory.createVerticalContainer(parent) 211 cont = self.widget_factory.createVerticalContainer(parent)
201 self._parseChilds(cont, node, ('widget', 'container')) 212 self._parseChilds(cont, node, ('widget', 'container'))
202 try: 213 try:
205 if parent is self: 216 if parent is self:
206 self.main_cont = cont 217 self.main_cont = cont
207 else: 218 else:
208 raise Exception(_("Internal Error, container has not _xmluiAppend method")) 219 raise Exception(_("Internal Error, container has not _xmluiAppend method"))
209 220
210 elif node.nodeName == "tab": 221 elif node.nodeName == 'tab':
211 name = node.getAttribute('name') 222 name = node.getAttribute('name')
212 label = node.getAttribute('label') 223 label = node.getAttribute('label')
213 if not name or not isinstance(data, TabsContainer): 224 if not name or not isinstance(data, TabsContainer):
214 raise InvalidXMLUI 225 raise InvalidXMLUI
215 if self.type == 'param': 226 if self.type == 'param':
216 self._current_category = name #XXX: awful hack because params need category and we don't keep parent 227 self._current_category = name #XXX: awful hack because params need category and we don't keep parent
217 tab_cont = data 228 tab_cont = data
218 new_tab = tab_cont._xmluiAddTab(label or name) 229 new_tab = tab_cont._xmluiAddTab(label or name)
219 self._parseChilds(new_tab, node, ('widget', 'container')) 230 self._parseChilds(new_tab, node, ('widget', 'container'))
231
232 elif node.nodeName == 'row':
233 parent._xmluiAddRow()
234 self._parseChilds(parent, node, ('widget', 'container'))
220 235
221 elif node.nodeName == "widget": 236 elif node.nodeName == "widget":
222 id_ = node.getAttribute("id") 237 id_ = node.getAttribute("id")
223 name = node.getAttribute("name") 238 name = node.getAttribute("name")
224 type_ = node.getAttribute("type") 239 type_ = node.getAttribute("type")