comparison src/tools/misc.py @ 1347:ba41a81d14c2 frontends_multi_profiles

frontends (QuickApp), tools (TriggerManager): frontends can also use triggers + add those for sending and receiving a message
author souliane <souliane@mailoo.org>
date Tue, 03 Mar 2015 15:05:10 +0100
parents 301b342c697a
children
comparison
equal deleted inserted replaced
1346:35f99c90b736 1347:ba41a81d14c2
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 """Misc usefull classes""" 20 """Misc usefull classes"""
21 21
22 from sat.core.i18n import _ 22 from sat.core.i18n import _
23 import sys
24 from sat.core.log import getLogger 23 from sat.core.log import getLogger
25 log = getLogger(__name__) 24 log = getLogger(__name__)
26 25
27 26
28 class TriggerException(Exception): 27 class TriggerException(Exception):
37 36
38 class TriggerManager(object): 37 class TriggerManager(object):
39 """This class manage triggers: code which interact to change the behaviour 38 """This class manage triggers: code which interact to change the behaviour
40 of SàT""" 39 of SàT"""
41 40
42 MIN_PRIORITY = float('-inf') 41 try: # FIXME: to be removed when a better solution is found
43 MAX_PRIORITY = float('+inf') 42 MIN_PRIORITY = float('-inf')
43 MAX_PRIORITY = float('+inf')
44 except: # XXX: Pyjamas will bug if you specify ValueError here
45 # Pyjamas uses the JS Float class
46 MIN_PRIORITY = Number.NEGATIVE_INFINITY
47 MAX_PRIORITY = Number.POSITIVE_INFINITY
44 48
45 def __init__(self): 49 def __init__(self):
46 self.__triggers = {} 50 self.__triggers = {}
47 51
48 def add(self, point_name, callback, priority=0): 52 def add(self, point_name, callback, priority=0):
79 @param point_name: name of the trigger point 83 @param point_name: name of the trigger point
80 @return: True if the action must be continued, False else""" 84 @return: True if the action must be continued, False else"""
81 if point_name not in self.__triggers: 85 if point_name not in self.__triggers:
82 return True 86 return True
83 87
84 for priority,trigger in self.__triggers[point_name]: 88 for priority, trigger in self.__triggers[point_name]:
85 try: 89 try:
86 if not trigger(*args, **kwargs): 90 if not trigger(*args, **kwargs):
87 return False 91 return False
88 except SkipOtherTriggers: 92 except SkipOtherTriggers:
89 break 93 break