Mercurial > libervia-web
comparison browser_side/xmlui.py @ 247:fe83837d3491
browser_side: removed some trailing spaces
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 09 Nov 2013 17:08:45 +0100 |
parents | e632f77c4219 |
children | e4f586fc6101 |
comparison
equal
deleted
inserted
replaced
246:d7c41c84d062 | 247:fe83837d3491 |
---|---|
39 pass | 39 pass |
40 | 40 |
41 class Pairs(Grid): | 41 class Pairs(Grid): |
42 | 42 |
43 def __init__(self): | 43 def __init__(self): |
44 Grid.__init__(self, 0, 0) | 44 Grid.__init__(self, 0, 0) |
45 self.row = 0 | 45 self.row = 0 |
46 self.col = 0 | 46 self.col = 0 |
47 | 47 |
48 def append(self, widget): | 48 def append(self, widget): |
49 if self.col == 0: | 49 if self.col == 0: |
51 self.setWidget(self.row, self.col, widget) | 51 self.setWidget(self.row, self.col, widget) |
52 self.col += 1 | 52 self.col += 1 |
53 if self.col == 2: | 53 if self.col == 2: |
54 self.row +=1 | 54 self.row +=1 |
55 self.col = 0 | 55 self.col = 0 |
56 | 56 |
57 class XMLUI(VerticalPanel): | 57 class XMLUI(VerticalPanel): |
58 | 58 |
59 def __init__(self, host, xml_data, title = None, options = None, misc = None, close_cb = None): | 59 def __init__(self, host, xml_data, title = None, options = None, misc = None, close_cb = None): |
60 print "XMLUI init" | 60 print "XMLUI init" |
61 VerticalPanel.__init__(self) | 61 VerticalPanel.__init__(self) |
62 self.dom = NativeDOM() | 62 self.dom = NativeDOM() |
63 self.host = host | 63 self.host = host |
87 node_id = elem.getAttribute("node_id") | 87 node_id = elem.getAttribute("node_id") |
88 name = elem.getAttribute("name") | 88 name = elem.getAttribute("name") |
89 node_type = elem.getAttribute("type") | 89 node_type = elem.getAttribute("type") |
90 value = elem.getAttribute("value") if elem.hasAttribute('value') else u'' | 90 value = elem.getAttribute("value") if elem.hasAttribute('value') else u'' |
91 if node_type=="empty": | 91 if node_type=="empty": |
92 ctrl = Label('') | 92 ctrl = Label('') |
93 elif node_type=="text": | 93 elif node_type=="text": |
94 try: | 94 try: |
95 value = elem.childNodes[0].wholeText | 95 value = elem.childNodes[0].wholeText |
96 except IndexError: | 96 except IndexError: |
97 print ("WARNING: text node has no child !") | 97 print ("WARNING: text node has no child !") |
167 current.append(pairs) | 167 current.append(pairs) |
168 else: | 168 else: |
169 print("WARNING: Unknown layout [%s], using default one" % (node_type,)) | 169 print("WARNING: Unknown layout [%s], using default one" % (node_type,)) |
170 self.__parseElems(node, current) | 170 self.__parseElems(node, current) |
171 elif node.nodeName == "category": | 171 elif node.nodeName == "category": |
172 name = node.getAttribute('name') | 172 name = node.getAttribute('name') |
173 label = node.getAttribute('label') | 173 label = node.getAttribute('label') |
174 if not name or not isinstance(data,TabPanel): | 174 if not name or not isinstance(data,TabPanel): |
175 raise InvalidXMLUI | 175 raise InvalidXMLUI |
176 if self.node_type == 'param': | 176 if self.node_type == 'param': |
177 self._current_category = name #XXX: awful hack because params need category and we don't keep parent | 177 self._current_category = name #XXX: awful hack because params need category and we don't keep parent |
178 tab_cont = data | 178 tab_cont = data |
179 tab_body = VerticalPanel() | 179 tab_body = VerticalPanel() |
180 tab_cont.add(tab_body, label or name) | 180 tab_cont.add(tab_body, label or name) |
182 else: | 182 else: |
183 message=_("Unknown tag") | 183 message=_("Unknown tag") |
184 raise NotImplementedError(message) | 184 raise NotImplementedError(message) |
185 | 185 |
186 def constructUI(self, xml_data): | 186 def constructUI(self, xml_data): |
187 | 187 |
188 cat_dom = self.dom.parseString(xml_data) | 188 cat_dom = self.dom.parseString(xml_data) |
189 | 189 |
190 top=cat_dom.documentElement | 190 top=cat_dom.documentElement |
191 self.node_type = top.getAttribute("type") | 191 self.node_type = top.getAttribute("type") |
192 self.title = top.getAttribute("title") or self.title | 192 self.title = top.getAttribute("title") or self.title |
193 if top.nodeName != "sat_xmlui" or not self.node_type in ['form', 'param', 'window']: | 193 if top.nodeName != "sat_xmlui" or not self.node_type in ['form', 'param', 'window']: |
194 raise InvalidXMLUI | 194 raise InvalidXMLUI |
195 | 195 |
196 if self.node_type == 'param': | 196 if self.node_type == 'param': |
197 self.param_changed = set() | 197 self.param_changed = set() |
198 | 198 |
199 self.__parseChilds(self, cat_dom.documentElement) | 199 self.__parseChilds(self, cat_dom.documentElement) |
200 | 200 |
201 if self.node_type == 'form': | 201 if self.node_type == 'form': |
202 hpanel = HorizontalPanel() | 202 hpanel = HorizontalPanel() |
203 hpanel.add(Button('Submit',self.onFormSubmitted)) | 203 hpanel.add(Button('Submit',self.onFormSubmitted)) |
204 if not 'NO_CANCEL' in self.options: | 204 if not 'NO_CANCEL' in self.options: |
205 hpanel.add(Button('Cancel',self.onFormCancelled)) | 205 hpanel.add(Button('Cancel',self.onFormCancelled)) |
206 self.add(hpanel) | 206 self.add(hpanel) |
207 elif self.node_type == 'param': | 207 elif self.node_type == 'param': |
208 assert(isinstance(self.children[0],TabPanel)) | 208 assert(isinstance(self.children[0],TabPanel)) |
209 hpanel = HorizontalPanel() | 209 hpanel = HorizontalPanel() |
210 hpanel.add(Button('Cancel', lambda ignore: self.close())) | 210 hpanel.add(Button('Cancel', lambda ignore: self.close())) |
211 hpanel.add(Button('Save', self.onSaveParams)) | 211 hpanel.add(Button('Save', self.onSaveParams)) |
212 self.add(hpanel) | 212 self.add(hpanel) |
213 | 213 |
214 ##EVENTS## | 214 ##EVENTS## |
215 | 215 |
216 def onButtonPress(self, button): | 216 def onButtonPress(self, button): |
235 print "onParamChange:", widget | 235 print "onParamChange:", widget |
236 self.param_changed.add(widget) | 236 self.param_changed.add(widget) |
237 | 237 |
238 def onFormSubmitted(self, button): | 238 def onFormSubmitted(self, button): |
239 print "onFormSubmitted" | 239 print "onFormSubmitted" |
240 # FIXME: untested | 240 # FIXME: untested |
241 print "FIXME FIXME FIXME: Form submitting not managed yet" | 241 print "FIXME FIXME FIXME: Form submitting not managed yet" |
242 data = [] | 242 data = [] |
243 for ctrl_name in self.ctrl_list: | 243 for ctrl_name in self.ctrl_list: |
244 ctrl = self.ctrl_list[ctrl_name] | 244 ctrl = self.ctrl_list[ctrl_name] |
245 if isinstance(ctrl['control'], ListBox): | 245 if isinstance(ctrl['control'], ListBox): |
254 self.misc['callback'](data) | 254 self.misc['callback'](data) |
255 else: | 255 else: |
256 print ("WARNING: The form data is not sent back, the type is not managed properly") | 256 print ("WARNING: The form data is not sent back, the type is not managed properly") |
257 | 257 |
258 self.close() | 258 self.close() |
259 | 259 |
260 def onFormCancelled(self, button): | 260 def onFormCancelled(self, button): |
261 self.close() | 261 self.close() |
262 | 262 |
263 def onSaveParams(self, button): | 263 def onSaveParams(self, button): |
264 print "onSaveParams" | 264 print "onSaveParams" |