comparison frontends/src/tools/xmlui.py @ 808:d035c662b357

frontends: some modifications to ease the the use of the new sat_frontends.tools.xmlui.XMLUI class in Libervia
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:32:33 +0100
parents 7c05c39156a2
children 1fe00f0c9a91
comparison
equal deleted inserted replaced
807:be4c5e24dab9 808:d035c662b357
240 warning(_("Unknown container [%s], using default one") % type_) 240 warning(_("Unknown container [%s], using default one") % type_)
241 cont = self.widget_factory.createVerticalContainer(parent) 241 cont = self.widget_factory.createVerticalContainer(parent)
242 self._parseChilds(cont, node, ('widget', 'container')) 242 self._parseChilds(cont, node, ('widget', 'container'))
243 try: 243 try:
244 parent._xmluiAppend(cont) 244 parent._xmluiAppend(cont)
245 except AttributeError: 245 except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
246 if parent is self: 246 if parent is self:
247 self.main_cont = cont 247 self.main_cont = cont
248 else: 248 else:
249 raise Exception(_("Internal Error, container has not _xmluiAppend method")) 249 raise Exception(_("Internal Error, container has not _xmluiAppend method"))
250 250
277 ctrl = self.widget_factory.createEmptyWidget(parent) 277 ctrl = self.widget_factory.createEmptyWidget(parent)
278 elif type_=="text": 278 elif type_=="text":
279 try: 279 try:
280 value = node.childNodes[0].wholeText 280 value = node.childNodes[0].wholeText
281 except IndexError: 281 except IndexError:
282 warning (_("text node has no child !")) 282 # warning (_("text node has no child !"))
283 pass # FIXME proper warning (this one is not OK with Libervia)
283 ctrl = self.widget_factory.createTextWidget(parent, value) 284 ctrl = self.widget_factory.createTextWidget(parent, value)
284 elif type_=="label": 285 elif type_=="label":
285 ctrl = self.widget_factory.createLabelWidget(parent, value) 286 ctrl = self.widget_factory.createLabelWidget(parent, value)
286 elif type_=="jid": 287 elif type_=="jid":
287 ctrl = self.widget_factory.createJidWidget(parent, value) 288 ctrl = self.widget_factory.createJidWidget(parent, value)
316 317
317 if self.type == 'param': 318 if self.type == 'param':
318 try: 319 try:
319 ctrl._xmluiOnChange(self.onParamChange) 320 ctrl._xmluiOnChange(self.onParamChange)
320 ctrl._param_category = self._current_category 321 ctrl._param_category = self._current_category
321 except AttributeError: 322 except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
322 if not isinstance(ctrl, (EmptyWidget, TextWidget)): 323 if not isinstance(ctrl, (EmptyWidget, TextWidget, LabelWidget, JidWidget)):
323 warning(_("No change listener on [%s]" % ctrl)) 324 warning(_("No change listener on [%s]" % ctrl))
324 325
325 ctrl._xmlui_name = name 326 ctrl._xmlui_name = name
326 parent._xmluiAppend(ctrl) 327 parent._xmluiAppend(ctrl)
327 328
358 this method must be overrided 359 this method must be overrided
359 360
360 """ 361 """
361 raise NotImplementedError 362 raise NotImplementedError
362 363
364 def _xmluiLaunchAction(self, action_id, data):
365 self.host.launchAction(action_id, data, profile_key = self.host.profile)
366
367 def _xmluiSetParam(self, name, value, category):
368 self.host.bridge.setParam(name, value, category, profile_key=self.host.profile)
369
363 ##EVENTS## 370 ##EVENTS##
364 371
365 def onParamChange(self, ctrl): 372 def onParamChange(self, ctrl):
366 """ Called when type is param and a widget to save is modified 373 """ Called when type is param and a widget to save is modified
367 @param ctrl: widget modified 374 @param ctrl: widget modified
376 for wid in widgets: 383 for wid in widgets:
377 try: 384 try:
378 name = self.escape(wid._xmlui_name) 385 name = self.escape(wid._xmlui_name)
379 value = wid._xmluiGetValue() 386 value = wid._xmluiGetValue()
380 ret[name] = value 387 ret[name] = value
381 except AttributeError: 388 except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
382 pass 389 pass
383 idx = ctrl._xmluiGetSelectedIndex() 390 idx = ctrl._xmluiGetSelectedIndex()
384 if idx is not None: 391 if idx is not None:
385 data['index'] = idx 392 data['index'] = idx
386 callback_id = ctrl._xmlui_callback_id 393 callback_id = ctrl._xmlui_callback_id
387 if callback_id is None: 394 if callback_id is None:
388 warning(_("No callback_id found")) 395 warning(_("No callback_id found"))
389 return 396 return
390 self.host.launchAction(callback_id, data, profile_key = self.host.profile) 397 self._xmluiLaunchAction(callback_id, data)
391 398
392 def onButtonPress(self, button): 399 def onButtonPress(self, button):
393 """ Called when an XMLUI button is clicked 400 """ Called when an XMLUI button is clicked
394 Launch the action associated to the button 401 Launch the action associated to the button
395 @param button: the button clicked 402 @param button: the button clicked
402 ctrl = self.ctrl_list[field] 409 ctrl = self.ctrl_list[field]
403 if isinstance(ctrl['control'], ListWidget): 410 if isinstance(ctrl['control'], ListWidget):
404 data[escaped] = u'\t'.join(ctrl['control']._xmluiGetSelected()) 411 data[escaped] = u'\t'.join(ctrl['control']._xmluiGetSelected())
405 else: 412 else:
406 data[escaped] = ctrl['control']._xmluiGetValue() 413 data[escaped] = ctrl['control']._xmluiGetValue()
407 self.host.launchAction(callback_id, data, profile_key = self.host.profile) 414 self._xmluiLaunchAction(callback_id, data)
408 415
409 def onFormSubmitted(self, ignore=None): 416 def onFormSubmitted(self, ignore=None):
410 """ An XMLUI form has been submited 417 """ An XMLUI form has been submited
411 call the submit action associated with this form 418 call the submit action associated with this form
412 419
421 selected_values.append((escaped, ctrl['control']._xmluiGetValue())) 428 selected_values.append((escaped, ctrl['control']._xmluiGetValue()))
422 if self.submit_id is not None: 429 if self.submit_id is not None:
423 data = dict(selected_values) 430 data = dict(selected_values)
424 if self.session_id is not None: 431 if self.session_id is not None:
425 data["session_id"] = self.session_id 432 data["session_id"] = self.session_id
426 self.host.launchAction(self.submit_id, data, profile_key=self.host.profile) 433 self._xmluiLaunchAction(self.submit_id, data)
427 434
428 else: 435 else:
429 warning (_("The form data is not sent back, the type is not managed properly")) 436 warning (_("The form data is not sent back, the type is not managed properly"))
430 self._xmluiClose() 437 self._xmluiClose()
431 438
444 for ctrl in self.param_changed: 451 for ctrl in self.param_changed:
445 if isinstance(ctrl, ListWidget): 452 if isinstance(ctrl, ListWidget):
446 value = u'\t'.join(ctrl._xmluiGetSelectedValues()) 453 value = u'\t'.join(ctrl._xmluiGetSelectedValues())
447 else: 454 else:
448 value = ctrl._xmluiGetValue() 455 value = ctrl._xmluiGetValue()
449 param_name = ctr._xmlui_name.split(Const.SAT_PARAM_SEPARATOR)[1] 456 param_name = ctrl._xmlui_name.split(Const.SAT_PARAM_SEPARATOR)[1]
450 self.host.bridge.setParam(param_name, value, ctrl._param_category, 457 self._xmluiSetParam(param_name, value, ctrl._param_category)
451 profile_key=self.host.profile) 458
452 self._xmluiClose() 459 self._xmluiClose()