comparison frontends/src/tools/xmlui.py @ 1087:b3b7a2863060

frontends (XMLUI): use of logging system instead of print
author Goffi <goffi@goffi.org>
date Wed, 25 Jun 2014 14:01:58 +0200
parents 2cb30f46e560
children e2e1e27a3680
comparison
equal deleted inserted replaced
1086:2cb30f46e560 1087:b3b7a2863060
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core.log import getLogger
22 log = getLogger(__name__)
21 from sat_frontends.constants import Const 23 from sat_frontends.constants import Const
22 from sat.core.exceptions import DataError 24 from sat.core.exceptions import DataError
23 25
24 26
25 class InvalidXMLUI(Exception): 27 class InvalidXMLUI(Exception):
257 cont._xmlui_callback_id = callback_id 259 cont._xmlui_callback_id = callback_id
258 cont._xmluiOnSelect(self.onAdvListSelect) 260 cont._xmluiOnSelect(self.onAdvListSelect)
259 261
260 self._parseChilds(cont, node, ('row',), data) 262 self._parseChilds(cont, node, ('row',), data)
261 else: 263 else:
262 print(_("Unknown container [%s], using default one") % type_) 264 log.warning(_("Unknown container [%s], using default one") % type_)
263 cont = self.widget_factory.createVerticalContainer(parent) 265 cont = self.widget_factory.createVerticalContainer(parent)
264 self._parseChilds(cont, node, ('widget', 'container')) 266 self._parseChilds(cont, node, ('widget', 'container'))
265 try: 267 try:
266 parent._xmluiAppend(cont) 268 parent._xmluiAppend(cont)
267 except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError 269 except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
331 elif type_=="button": 333 elif type_=="button":
332 callback_id = node.getAttribute("callback") 334 callback_id = node.getAttribute("callback")
333 ctrl = self.widget_factory.createButtonWidget(parent, value, self.onButtonPress) 335 ctrl = self.widget_factory.createButtonWidget(parent, value, self.onButtonPress)
334 ctrl._xmlui_param_id = (callback_id, [field.getAttribute('name') for field in node.getElementsByTagName("field_back")]) 336 ctrl._xmlui_param_id = (callback_id, [field.getAttribute('name') for field in node.getElementsByTagName("field_back")])
335 else: 337 else:
336 print(_("FIXME FIXME FIXME: widget type [%s] is not implemented") % type_) 338 log.error(_("FIXME FIXME FIXME: widget type [%s] is not implemented") % type_)
337 raise NotImplementedError(_("FIXME FIXME FIXME: type [%s] is not implemented") % type_) 339 raise NotImplementedError(_("FIXME FIXME FIXME: type [%s] is not implemented") % type_)
338 340
339 if self.type == 'param' and type_ not in ('text', 'button'): 341 if self.type == 'param' and type_ not in ('text', 'button'):
340 try: 342 try:
341 ctrl._xmluiOnChange(self.onParamChange) 343 ctrl._xmluiOnChange(self.onParamChange)
342 ctrl._param_category = self._current_category 344 ctrl._param_category = self._current_category
343 except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError 345 except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
344 if not isinstance(ctrl, (EmptyWidget, TextWidget, LabelWidget, JidWidget)): 346 if not isinstance(ctrl, (EmptyWidget, TextWidget, LabelWidget, JidWidget)):
345 print(_("No change listener on [%s]") % ctrl) 347 log.warning(_("No change listener on [%s]") % ctrl)
346 348
347 if type_ != 'text': 349 if type_ != 'text':
348 callback = node.getAttribute("internal_callback") or None 350 callback = node.getAttribute("internal_callback") or None
349 if callback: 351 if callback:
350 fields = [field.getAttribute('name') for field in node.getElementsByTagName("internal_field")] 352 fields = [field.getAttribute('name') for field in node.getElementsByTagName("internal_field")]
422 idx = ctrl._xmluiGetSelectedIndex() 424 idx = ctrl._xmluiGetSelectedIndex()
423 if idx is not None: 425 if idx is not None:
424 data['index'] = idx 426 data['index'] = idx
425 callback_id = ctrl._xmlui_callback_id 427 callback_id = ctrl._xmlui_callback_id
426 if callback_id is None: 428 if callback_id is None:
427 print(_("No callback_id found")) 429 log.info(_("No callback_id found"))
428 return 430 return
429 self._xmluiLaunchAction(callback_id, data) 431 self._xmluiLaunchAction(callback_id, data)
430 432
431 def onButtonPress(self, button): 433 def onButtonPress(self, button):
432 """ Called when an XMLUI button is clicked 434 """ Called when an XMLUI button is clicked
544 if self.session_id is not None: 546 if self.session_id is not None:
545 data["session_id"] = self.session_id 547 data["session_id"] = self.session_id
546 self._xmluiLaunchAction(self.submit_id, data) 548 self._xmluiLaunchAction(self.submit_id, data)
547 549
548 else: 550 else:
549 print(_("The form data is not sent back, the type is not managed properly")) 551 log.warning(_("The form data is not sent back, the type is not managed properly"))
550 self._xmluiClose() 552 self._xmluiClose()
551 553
552 def onFormCancelled(self, ignore=None): 554 def onFormCancelled(self, ignore=None):
553 """ Called when a form is cancelled """ 555 """ Called when a form is cancelled """
554 print(_("Cancelling form")) 556 log.debug(_("Cancelling form"))
555 self._xmluiClose() 557 self._xmluiClose()
556 558
557 def onSaveParams(self, ignore=None): 559 def onSaveParams(self, ignore=None):
558 """ Params are saved, we send them to backend 560 """ Params are saved, we send them to backend
559 self.type must be param 561 self.type must be param