comparison tools/xml_tools.py @ 104:5458ac1380cc

XMLUI: added tabs layout xmltools: tabs layout are added, and a new addCategory method is used to add tabs wix: tabs layout are managed with notebook
author Goffi <goffi@goffi.org>
date Wed, 23 Jun 2010 14:55:04 +0800
parents 6be927a465ed
children d2630fba8dfd
comparison
equal deleted inserted replaced
103:6be927a465ed 104:5458ac1380cc
30 def dataForm2xml(form): 30 def dataForm2xml(form):
31 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml""" 31 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml"""
32 32
33 form_panel = XMLUI("form", "vertical") 33 form_panel = XMLUI("form", "vertical")
34 34
35
35 if form.instructions: 36 if form.instructions:
36 form_panel.addText('\n'.join(form.instructions), 'instructions') 37 form_panel.addText('\n'.join(form.instructions), 'instructions')
37 38
38 form_panel.changeLayout("pairs") 39 form_panel.changeLayout("pairs")
39 40
89 impl = minidom.getDOMImplementation() 90 impl = minidom.getDOMImplementation()
90 91
91 self.doc = impl.createDocument(None, "sat_xmlui", None) 92 self.doc = impl.createDocument(None, "sat_xmlui", None)
92 top_element = self.doc.documentElement 93 top_element = self.doc.documentElement
93 top_element.setAttribute("type", panel_type) 94 top_element.setAttribute("type", panel_type)
94 self.currentLayout = self.__createLayout(layout, top_element) 95 self.parentTabsLayout = None #used only we have 'tabs' layout
96 self.currentCategory = None #used only we have 'tabs' layout
97 self.changeLayout(layout)
95 98
96 def __del__(self): 99 def __del__(self):
97 self.doc.unlink() 100 self.doc.unlink()
98 101
99 def __createLayout(self, layout, parent=None): 102 def __createLayout(self, layout, parent=None):
100 """Create a layout element 103 """Create a layout element
101 @param type: layout type (cf init doc) 104 @param type: layout type (cf init doc)
102 @parent: parent element or None 105 @parent: parent element or None
103 """ 106 """
104 if not layout in ['vertical', 'horizontal', 'pairs']: 107 if not layout in ['vertical', 'horizontal', 'pairs', 'tabs']:
105 error (_("Unknown layout type [%s]") % layout) 108 error (_("Unknown layout type [%s]") % layout)
106 assert (False) 109 assert (False)
107 layout_elt = self.doc.createElement('layout') 110 layout_elt = self.doc.createElement('layout')
108 layout_elt.setAttribute('type',layout) 111 layout_elt.setAttribute('type',layout)
109 if parent != None: 112 if parent != None:
126 parent.appendChild(elem) 129 parent.appendChild(elem)
127 return elem 130 return elem
128 131
129 def changeLayout(self, layout): 132 def changeLayout(self, layout):
130 """Change the current layout""" 133 """Change the current layout"""
131 self.currentLayout = self.__createLayout(layout, self.doc.documentElement) 134 self.currentLayout = self.__createLayout(layout, self.currentCategory if self.currentCategory else self.doc.documentElement)
135 if layout == "tabs":
136 self.parentTabsLayout = self.currentLayout
132 137
133 138
134 def addEmpty(self, name=None): 139 def addEmpty(self, name=None):
135 """Add a multi-lines text""" 140 """Add a multi-lines text"""
136 elem = self.__createElem('empty', name, self.currentLayout) 141 elem = self.__createElem('empty', name, self.currentLayout)
188 for option in options: 193 for option in options:
189 opt = self.doc.createElement('option') 194 opt = self.doc.createElement('option')
190 opt.setAttribute('value', option) 195 opt.setAttribute('value', option)
191 parent.appendChild(opt) 196 parent.appendChild(opt)
192 197
198 def addCategory(self, name, layout):
199 """Add a category to current layout (must be a tabs layout)"""
200 assert(layout != 'tabs')
201 if not self.parentTabsLayout:
202 error(_("Trying to add a category without parent tabs layout"))
203 assert(False)
204 if self.parentTabsLayout.getAttribute('type') != 'tabs':
205 error(_("parent layout of a category is not tabs"))
206 assert(False)
207 self.currentCategory = cat = self.doc.createElement('category')
208 cat.setAttribute('name', name)
209 self.changeLayout(layout)
210 self.parentTabsLayout.appendChild(cat)
211
193 def toXml(self): 212 def toXml(self):
194 """return the XML representation of the panel""" 213 """return the XML representation of the panel"""
195 return self.doc.toxml() 214 return self.doc.toxml()