# HG changeset patch # User souliane # Date 1425391510 -3600 # Node ID ba41a81d14c2e2bf7b00c325b2e145e84c8fbd52 # Parent 35f99c90b736b4be54b2157072e3e8cea53c09d2 frontends (QuickApp), tools (TriggerManager): frontends can also use triggers + add those for sending and receiving a message diff -r 35f99c90b736 -r ba41a81d14c2 frontends/src/quick_frontend/quick_app.py --- a/frontends/src/quick_frontend/quick_app.py Tue Mar 03 06:00:23 2015 +0100 +++ b/frontends/src/quick_frontend/quick_app.py Tue Mar 03 15:05:10 2015 +0100 @@ -22,6 +22,7 @@ from sat.core.i18n import _ from sat.core import exceptions +from sat.tools.misc import TriggerManager from sat_frontends.tools import jid from sat_frontends.quick_frontend.quick_widgets import QuickWidgetsManager @@ -219,6 +220,9 @@ # listeners self._listeners = {} # key: listener type ("avatar", "selected", etc), value: list of callbacks + # triggers + self.trigger = TriggerManager() # trigger are used to change the default behaviour + ## bridge ## try: self.bridge = create_bridge() @@ -453,6 +457,10 @@ def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile): from_jid = jid.JID(from_jid_s) to_jid = jid.JID(to_jid_s) + + if not self.trigger.point("newMessageTrigger", from_jid, msg, type_, to_jid, extra, profile=profile): + return + from_me = from_jid.bare == self.profiles[profile].whoami.bare target = to_jid if from_me else from_jid @@ -486,7 +494,11 @@ callback = lambda dummy=None: None # FIXME: optional argument is here because pyjamas doesn't support callback without arg with json proxy if errback is None: errback = lambda failure: self.showDialog(failure.fullname, failure.message, "error") - self.bridge.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) + + if not self.trigger.point("sendMessageTrigger", to_jid, message, subject, mess_type, extra, callback, errback, profile_key=profile_key): + return + + self.bridge.sendMessage(unicode(to_jid), message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) def newAlertHandler(self, msg, title, alert_type, profile): assert alert_type in ['INFO', 'ERROR'] diff -r 35f99c90b736 -r ba41a81d14c2 src/tools/misc.py --- a/src/tools/misc.py Tue Mar 03 06:00:23 2015 +0100 +++ b/src/tools/misc.py Tue Mar 03 15:05:10 2015 +0100 @@ -20,7 +20,6 @@ """Misc usefull classes""" from sat.core.i18n import _ -import sys from sat.core.log import getLogger log = getLogger(__name__) @@ -39,8 +38,13 @@ """This class manage triggers: code which interact to change the behaviour of SàT""" - MIN_PRIORITY = float('-inf') - MAX_PRIORITY = float('+inf') + try: # FIXME: to be removed when a better solution is found + MIN_PRIORITY = float('-inf') + MAX_PRIORITY = float('+inf') + except: # XXX: Pyjamas will bug if you specify ValueError here + # Pyjamas uses the JS Float class + MIN_PRIORITY = Number.NEGATIVE_INFINITY + MAX_PRIORITY = Number.POSITIVE_INFINITY def __init__(self): self.__triggers = {} @@ -81,7 +85,7 @@ if point_name not in self.__triggers: return True - for priority,trigger in self.__triggers[point_name]: + for priority, trigger in self.__triggers[point_name]: try: if not trigger(*args, **kwargs): return False