Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_app.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 | 621b045cd284 |
children | 955221487a3e |
comparison
equal
deleted
inserted
replaced
1488:66d01f29f886 | 1489:039d96e131be |
---|---|
463 log.debug(_("Disconnected")) | 463 log.debug(_("Disconnected")) |
464 self.contact_lists[profile].clearContacts() | 464 self.contact_lists[profile].clearContacts() |
465 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile) | 465 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile) |
466 | 466 |
467 def actionNewHandler(self, action_data, id_, profile): | 467 def actionNewHandler(self, action_data, id_, profile): |
468 self._actionManager(action_data, profile=profile) | 468 self.actionManager(action_data, profile=profile) |
469 | 469 |
470 def newContactHandler(self, jid_s, attributes, groups, profile): | 470 def newContactHandler(self, jid_s, attributes, groups, profile): |
471 entity = jid.JID(jid_s) | 471 entity = jid.JID(jid_s) |
472 _groups = list(groups) | 472 _groups = list(groups) |
473 self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True) | 473 self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True) |
712 raise NotImplementedError | 712 raise NotImplementedError |
713 | 713 |
714 def actionResultHandler(self, type, id, data, profile): | 714 def actionResultHandler(self, type, id, data, profile): |
715 raise NotImplementedError | 715 raise NotImplementedError |
716 | 716 |
717 def _actionManagerUnknownError(self): | 717 def actionManager(self, action_data, callback=None, profile=C.PROF_KEY_NONE): |
718 raise NotImplementedError | 718 try: |
719 | 719 xmlui = action_data.pop('xmlui') |
720 | 720 except KeyError: |
721 def _actionManager(self, action_data, callback=None, profile=C.PROF_KEY_NONE): | 721 pass |
722 if "xmlui" in action_data: | 722 else: |
723 ui = self.xmlui.create(self, xml_data=action_data['xmlui'], callback=callback, profile=profile) | 723 ui = self.xmlui.create(self, xml_data=xmlui, callback=callback, profile=profile) |
724 ui.show() | 724 ui.show() |
725 else: | 725 if action_data: |
726 self._actionManagerUnknownError() | 726 raise exceptions.DataError(u"Not all keys in action_data are managed ({keys})".format(keys=', '.join(action_data.keys()))) |
727 | 727 |
728 def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE): | 728 def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE): |
729 """ Launch a dynamic action | 729 """ Launch a dynamic action |
730 | 730 |
731 @param callback_id: id of the action to launch | 731 @param callback_id: id of the action to launch |
732 @param data: data needed only for certain actions | 732 @param data: data needed only for certain actions |
733 @param callback: if not None and 'validated' key is present, it will be called with the following parameters: | 733 @param callback(callable, None): will be called with the resut |
734 - callback_id | 734 if None, self.actionManager will be called |
735 - data | 735 else the callable will be called with the following kw parameters: |
736 - profile | 736 - data: action_data |
737 - cb_id: callback id | |
738 - profile: %(doc_profile)s | |
737 @param profile: %(doc_profile)s | 739 @param profile: %(doc_profile)s |
738 | 740 |
739 """ | 741 """ |
740 if data is None: | 742 if data is None: |
741 data = dict() | 743 data = dict() |
742 | 744 |
743 def action_cb(data): | 745 def action_cb(data): |
744 if not data: | 746 if callback is None: |
745 # action was a one shot, nothing to do | 747 self.actionManager(data, profile=profile) |
746 pass | |
747 elif 'validated' in data: | |
748 if callback: | |
749 callback(callback_id, data, profile) | |
750 else: | 748 else: |
751 self._actionManager(data, profile=profile) | 749 callback(data=data, cb_id=callback_id, profile=profile) |
752 | 750 |
753 self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure) | 751 self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure) |
754 | 752 |
755 def disconnect(self, profile): | 753 def disconnect(self, profile): |
756 log.info("disconnecting") | 754 log.info("disconnecting") |