comparison frontends/src/tools/xmlui.py @ 1489:039d96e131be

frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present): - actionManager is used by default (no callback provided) - in XMLUI, the dialog is closed before calling actionManager - if keys are not managed in resuling data, an exceptions is raised
author Goffi <goffi@goffi.org>
date Tue, 25 Aug 2015 14:41:42 +0200
parents a77217511afd
children cb1b0fe10415
comparison
equal deleted inserted replaced
1488:66d01f29f886 1489:039d96e131be
235 @param host: %(doc_host)s 235 @param host: %(doc_host)s
236 @param parsed_dom: main parsed dom 236 @param parsed_dom: main parsed dom
237 @param title: force the title, or use XMLUI one if None 237 @param title: force the title, or use XMLUI one if None
238 @param flags: list of string which can be: 238 @param flags: list of string which can be:
239 - NO_CANCEL: the UI can't be cancelled 239 - NO_CANCEL: the UI can't be cancelled
240 @param callback: if present, will be used with launchAction 240 @param callback(callable, None): if not None, will be used with launchAction:
241 - if None is used, default behaviour will be used (closing the dialog and calling host.actionManager)
242 - if a callback is provided, it will be used instead, so you'll have to manage
243 dialog closing or new xmlui to display, or other action (you can call host.actionManager)
241 """ 244 """
242 self.host = host 245 self.host = host
243 top=parsed_dom.documentElement 246 top=parsed_dom.documentElement
244 self.session_id = top.getAttribute("session_id") or None 247 self.session_id = top.getAttribute("session_id") or None
245 self.submit_id = top.getAttribute("submit") or None 248 self.submit_id = top.getAttribute("submit") or None
246 self.xmlui_title = title or top.getAttribute("title") or u"" 249 self.xmlui_title = title or top.getAttribute("title") or u""
247 if flags is None: 250 if flags is None:
248 flags = [] 251 flags = []
249 self.flags = flags 252 self.flags = flags
250 self.callback = callback 253 self.callback = callback or self._defaultCb
251 self.profile = profile 254 self.profile = profile
255
256 def _defaultCb(self, data, cb_id, profile):
257 # TODO: when XMLUI updates will be managed, the _xmluiClose
258 # must be called only if there is not update
259 self._xmluiClose()
260 self.host.actionManager(data, profile=profile)
252 261
253 def _isAttrSet(self, name, node): 262 def _isAttrSet(self, name, node):
254 """Returnw widget boolean attribute status 263 """Returnw widget boolean attribute status
255 264
256 @param name: name of the attribute (e.g. "read_only") 265 @param name: name of the attribute (e.g. "read_only")
282 data["session_id"] = self.session_id 291 data["session_id"] = self.session_id
283 self._xmluiLaunchAction(self.submit_id, data) 292 self._xmluiLaunchAction(self.submit_id, data)
284 293
285 def _xmluiLaunchAction(self, action_id, data): 294 def _xmluiLaunchAction(self, action_id, data):
286 self.host.launchAction(action_id, data, callback=self.callback, profile=self.profile) 295 self.host.launchAction(action_id, data, callback=self.callback, profile=self.profile)
296
297 def _xmluiClose(self):
298 """Close the window/popup/... where the constructeur XMLUI is
299
300 this method must be overrided
301 """
302 raise NotImplementedError
287 303
288 304
289 class XMLUIPanel(XMLUIBase): 305 class XMLUIPanel(XMLUIBase):
290 """XMLUI Panel 306 """XMLUI Panel
291 307
491 self._parseChilds(self, parsed_dom.documentElement) 507 self._parseChilds(self, parsed_dom.documentElement)
492 508
493 if post_treat is not None: 509 if post_treat is not None:
494 post_treat() 510 post_treat()
495 511
496 def _xmluiClose(self):
497 """Close the window/popup/... where the constructeur XMLUI is
498
499 this method must be overrided
500 """
501 raise NotImplementedError
502
503 def _xmluiSetParam(self, name, value, category): 512 def _xmluiSetParam(self, name, value, category):
504 self.host.bridge.setParam(name, value, category, profile_key=self.profile) 513 self.host.bridge.setParam(name, value, category, profile_key=self.profile)
505 514
506 ##EVENTS## 515 ##EVENTS##
507 516