comparison frontends/src/jp/base.py @ 1840:9eabf7fadfdd

frontends (jp): onActionNew displays xmlui message if no meta_type is defined and xmlui is defined
author souliane <souliane@mailoo.org>
date Thu, 04 Feb 2016 11:48:37 +0100
parents 39545dc527a1
children afc7f6328394
comparison
equal deleted inserted replaced
1839:cdecf553e051 1840:9eabf7fadfdd
35 from sat_frontends.tools.jid import JID 35 from sat_frontends.tools.jid import JID
36 from sat_frontends.bridge.DBus import DBusBridgeFrontend 36 from sat_frontends.bridge.DBus import DBusBridgeFrontend
37 from sat.core import exceptions 37 from sat.core import exceptions
38 import sat_frontends.jp 38 import sat_frontends.jp
39 from sat_frontends.jp.constants import Const as C 39 from sat_frontends.jp.constants import Const as C
40 import xml.etree.ElementTree as ET # FIXME: used temporarily to manage XMLUI
41
40 try: 42 try:
41 import progressbar 43 import progressbar
42 except ImportError: 44 except ImportError:
43 log.info (_('ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar')) 45 log.info (_('ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar'))
44 log.info (_('Progress bar deactivated\n--\n')) 46 log.info (_('Progress bar deactivated\n--\n'))
619 if profile != self.profile: 621 if profile != self.profile:
620 return 622 return
621 try: 623 try:
622 action_type = action_data['meta_type'] 624 action_type = action_data['meta_type']
623 except KeyError: 625 except KeyError:
624 pass 626 try:
627 xml_ui = action_data["xmlui"]
628 except KeyError:
629 pass
630 else:
631 self.onXMLUI(xml_ui)
625 else: 632 else:
626 try: 633 try:
627 callback = self.action_callbacks[action_type] 634 callback = self.action_callbacks[action_type]
628 except KeyError: 635 except KeyError:
629 pass 636 pass
630 else: 637 else:
631 callback(action_data, action_id, security_limit, profile) 638 callback(action_data, action_id, security_limit, profile)
639
640 def onXMLUI(self, xml_ui):
641 """Display a dialog received from the backend.
642
643 @param xml_ui (unicode): dialog XML representation
644 """
645 # FIXME: we temporarily use ElementTree, but a real XMLUI managing module
646 # should be available in the future
647 # TODO: XMLUI module
648 ui = ET.fromstring(xml_ui.encode('utf-8'))
649 dialog = ui.find("dialog")
650 if dialog is not None:
651 self.disp(dialog.findtext("message"), error=dialog.get("level") == "error")
632 652
633 def connected(self): 653 def connected(self):
634 """Auto reply to confirmations requests""" 654 """Auto reply to confirmations requests"""
635 self.need_loop = True 655 self.need_loop = True
636 super(CommandAnswering, self).connected() 656 super(CommandAnswering, self).connected()