Merge branch 'plugins' of https://git.louiz.org/poezio into plugins

This commit is contained in:
Florent Le Coz 2011-11-07 15:15:34 +01:00
commit 953783c200
3 changed files with 8 additions and 11 deletions

View file

@ -30,23 +30,20 @@ class EventHandler(object):
'muc_msg': [], 'muc_msg': [],
} }
def add_event_handler(self, name, callback, first=True, last=False, position=None): def add_event_handler(self, name, callback, position=0):
""" """
Add a callback to a given event. Add a callback to a given event.
Note that if that event name doesnt exist, it just returns False. Note that if that event name doesnt exist, it just returns False.
If it was successfully added, it returns True If it was successfully added, it returns True
position: 0 means insert a the beginning, -1 means end
""" """
if name not in self.events: if name not in self.events:
return False return False
if first: if position >= 0:
self.events[name].insert(0, callback)
elif last:
self.events[name].append(callback)
elif position != None and isinstance(position, int):
self.events[name].insert(position, callback) self.events[name].insert(position, callback)
else: else:
self.events[name].insert(0, callback) self.events[name].append(callback)
return True return True

View file

@ -85,8 +85,8 @@ class BasePlugin(object, metaclass=SafetyMetaclass):
def del_event_handler(self, event_name, handler): def del_event_handler(self, event_name, handler):
return self.plugin_manager.del_event_handler(self.__module__, event_name, handler) return self.plugin_manager.del_event_handler(self.__module__, event_name, handler)
def add_poezio_event_handler(self, event_name, handler, first=True, last=False, position=None): def add_poezio_event_handler(self, event_name, handler, position=0):
return self.plugin_manager.add_poezio_event_handler(self.__module__, event_name, handler, first, last, position) return self.plugin_manager.add_poezio_event_handler(self.__module__, event_name, handler, position)
def del_poezio_event_handler(self, event_name, handler): def del_poezio_event_handler(self, event_name, handler):
return self.plugin_manager.del_poezio_event_handler(self.__module__, event_name, handler) return self.plugin_manager.del_poezio_event_handler(self.__module__, event_name, handler)

View file

@ -107,10 +107,10 @@ class PluginManager(object):
eh = self.event_handlers[module_name] eh = self.event_handlers[module_name]
eh = list(filter(lambda e : e != (event_name, handler), eh)) eh = list(filter(lambda e : e != (event_name, handler), eh))
def add_poezio_event_handler(self, module_name, event_name, handler, first, last, position): def add_poezio_event_handler(self, module_name, event_name, handler, position):
eh = self.poezio_event_handlers[module_name] eh = self.poezio_event_handlers[module_name]
eh.append(handler) eh.append(handler)
self.core.events.add_event_handler(event_name, handler, first, last, position) self.core.events.add_event_handler(event_name, handler, position)
def del_poezio_event_handler(self, module_name, event_name, handler): def del_poezio_event_handler(self, module_name, event_name, handler):
self.core.events.del_event_handler(None, handler) self.core.events.del_event_handler(None, handler)