comparison tools/xml_tools.py @ 107:5ae370c71803

CS: message sending is now working - xmltools/xmlui: buttons can now send fields of the ui when used - xmltools/xmlui: new textbox element, to write a large text (used for messages in CS plugin) - xmltools/xmlui: list have now an attribute multi for selecting several options - xmltools/xmlui: window title can now be specified in the xml (attribute title) - CS_plugin: message sending interface & management
author Goffi <goffi@goffi.org>
date Mon, 28 Jun 2010 15:18:59 +0800
parents 138d82f64b6f
children 7c00c4b0a5c2
comparison
equal deleted inserted replaced
106:138d82f64b6f 107:5ae370c71803
101 101
102 102
103 class XMLUI: 103 class XMLUI:
104 """This class is used to create a user interface (form/window/parameters/etc) using SàT XML""" 104 """This class is used to create a user interface (form/window/parameters/etc) using SàT XML"""
105 105
106 def __init__(self, panel_type, layout="vertical"): 106 def __init__(self, panel_type, layout="vertical", title=None):
107 """Init SàT XML Panel 107 """Init SàT XML Panel
108 @param panel_type: one of 108 @param panel_type: one of
109 - window (new window) 109 - window (new window)
110 - form (formulaire, depend of the frontend, usually a panel with cancel/submit buttons) 110 - form (formulaire, depend of the frontend, usually a panel with cancel/submit buttons)
111 - param (parameters, presentatio depend of the frontend) 111 - param (parameters, presentatio depend of the frontend)
112 @param layout: disposition of elements, one of: 112 @param layout: disposition of elements, one of:
113 - VERTICAL: elements are disposed up to bottom 113 - vertical: elements are disposed up to bottom
114 - HORIZONTAL: elements are disposed left to right 114 - horizontal: elements are disposed left to right
115 - PAIRS: elements come on two aligned columns 115 - pairs: elements come on two aligned columns
116 (usually one for a label, the next for the element) 116 (usually one for a label, the next for the element)
117 - tabs: elemens are in categories with tabs (notebook)
118 @param title: title or default if None
117 """ 119 """
118 if not panel_type in ['window', 'form', 'param']: 120 if not panel_type in ['window', 'form', 'param']:
119 error(_("Unknown panel type [%s]") % panel_type) 121 error(_("Unknown panel type [%s]") % panel_type)
120 assert(False) 122 assert(False)
121 self.type = panel_type 123 self.type = panel_type
122 impl = minidom.getDOMImplementation() 124 impl = minidom.getDOMImplementation()
123 125
124 self.doc = impl.createDocument(None, "sat_xmlui", None) 126 self.doc = impl.createDocument(None, "sat_xmlui", None)
125 top_element = self.doc.documentElement 127 top_element = self.doc.documentElement
126 top_element.setAttribute("type", panel_type) 128 top_element.setAttribute("type", panel_type)
129 if title:
130 top_element.setAttribute("title", title)
127 self.parentTabsLayout = None #used only we have 'tabs' layout 131 self.parentTabsLayout = None #used only we have 'tabs' layout
128 self.currentCategory = None #used only we have 'tabs' layout 132 self.currentCategory = None #used only we have 'tabs' layout
129 self.changeLayout(layout) 133 self.changeLayout(layout)
130 134
131 def __del__(self): 135 def __del__(self):
193 """Add a password box""" 197 """Add a password box"""
194 elem = self.__createElem('password', name, self.currentLayout) 198 elem = self.__createElem('password', name, self.currentLayout)
195 if value: 199 if value:
196 elem.setAttribute('value', value) 200 elem.setAttribute('value', value)
197 201
198 def addList(self, options, name=None, value=None): 202 def addTextBox(self, name=None, value=None):
203 """Add a string box"""
204 elem = self.__createElem('textbox', name, self.currentLayout)
205 if value:
206 elem.setAttribute('value', value)
207
208 def addList(self, options, name=None, value=None, style=set()):
199 """Add a list of choices""" 209 """Add a list of choices"""
210 styles = set(style)
200 assert (options) 211 assert (options)
212 assert (styles.issubset(['multi']))
201 elem = self.__createElem('list', name, self.currentLayout) 213 elem = self.__createElem('list', name, self.currentLayout)
202 self.addOptions(options, elem) 214 self.addOptions(options, elem)
203 if value: 215 if value:
204 elem.setAttribute('value', value) 216 elem.setAttribute('value', value)
205 217 for style in styles:
206 def addButton(self, callback_id, name, value): 218 elem.setAttribute(style, 'yes')
219
220 def addButton(self, callback_id, name, value, fields_back=[]):
207 """Add a button 221 """Add a button
208 @param callback: callback which will be called if button is pressed 222 @param callback: callback which will be called if button is pressed
209 @param name: name 223 @param name: name
210 @param value: label of the button""" 224 @param value: label of the button
225 @fields_back: list of names of field to give back when pushing the button"""
211 elem = self.__createElem('button', name, self.currentLayout) 226 elem = self.__createElem('button', name, self.currentLayout)
212 elem.setAttribute('callback_id', callback_id) 227 elem.setAttribute('callback_id', callback_id)
213 if value: 228 elem.setAttribute('value', value)
214 elem.setAttribute('value', value) 229 for field in fields_back:
230 fback_el = self.doc.createElement('field_back')
231 fback_el.setAttribute('name', field)
232 elem.appendChild(fback_el)
233
215 234
216 235
217 def addElement(self, type, name = None, content = None, value = None, options = None, callback_id = None): 236 def addElement(self, type, name = None, content = None, value = None, options = None, callback_id = None):
218 """Convenience method to add element, the params correspond to the ones in addSomething methods""" 237 """Convenience method to add element, the params correspond to the ones in addSomething methods"""
219 if type == 'empty': 238 if type == 'empty':
225 assert(value) 244 assert(value)
226 elif type == 'string': 245 elif type == 'string':
227 self.addString(name, value) 246 self.addString(name, value)
228 elif type == 'password': 247 elif type == 'password':
229 self.addPassword(name, value) 248 self.addPassword(name, value)
249 elif type == 'textbox':
250 self.addTextBox(name, value)
230 elif type == 'list': 251 elif type == 'list':
231 self.addList(options, name, value) 252 self.addList(options, name, value)
232 elif type == 'button': 253 elif type == 'button':
233 assert(callback_id and value) 254 assert(callback_id and value)
234 self.addButton(callback_id, name, value) 255 self.addButton(callback_id, name, value)