summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-11-07 15:15:34 +0100
committerFlorent Le Coz <louiz@louiz.org>2011-11-07 15:15:34 +0100
commit953783c2001c55da7aa42077f7e109306adb1ef9 (patch)
tree5ec4276788185a9672065d1527350416f0b2caff /src
parent41b54973309d49932e4a5459bd76b0ef671e4545 (diff)
parentd6b8ca50f2c046aa1248173f453b3804f40c479a (diff)
downloadpoezio-953783c2001c55da7aa42077f7e109306adb1ef9.tar.gz
poezio-953783c2001c55da7aa42077f7e109306adb1ef9.tar.bz2
poezio-953783c2001c55da7aa42077f7e109306adb1ef9.tar.xz
poezio-953783c2001c55da7aa42077f7e109306adb1ef9.zip
Merge branch 'plugins' of https://git.louiz.org/poezio into plugins
Diffstat (limited to 'src')
-rw-r--r--src/events.py11
-rw-r--r--src/plugin.py4
-rw-r--r--src/plugin_manager.py4
3 files changed, 8 insertions, 11 deletions
diff --git a/src/events.py b/src/events.py
index d4fc8fc6..22d60ddf 100644
--- a/src/events.py
+++ b/src/events.py
@@ -30,23 +30,20 @@ class EventHandler(object):
'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.
Note that if that event name doesn’t exist, it just returns False.
If it was successfully added, it returns True
+ position: 0 means insert a the beginning, -1 means end
"""
if name not in self.events:
return False
- if first:
- self.events[name].insert(0, callback)
- elif last:
- self.events[name].append(callback)
- elif position != None and isinstance(position, int):
+ if position >= 0:
self.events[name].insert(position, callback)
else:
- self.events[name].insert(0, callback)
+ self.events[name].append(callback)
return True
diff --git a/src/plugin.py b/src/plugin.py
index 0b4f3f3a..80bc4dfc 100644
--- a/src/plugin.py
+++ b/src/plugin.py
@@ -85,8 +85,8 @@ class BasePlugin(object, metaclass=SafetyMetaclass):
def del_event_handler(self, 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):
- return self.plugin_manager.add_poezio_event_handler(self.__module__, event_name, handler, first, last, position)
+ def add_poezio_event_handler(self, event_name, handler, position=0):
+ return self.plugin_manager.add_poezio_event_handler(self.__module__, event_name, handler, position)
def del_poezio_event_handler(self, event_name, handler):
return self.plugin_manager.del_poezio_event_handler(self.__module__, event_name, handler)
diff --git a/src/plugin_manager.py b/src/plugin_manager.py
index 37db3d13..bdf94a5b 100644
--- a/src/plugin_manager.py
+++ b/src/plugin_manager.py
@@ -107,10 +107,10 @@ class PluginManager(object):
eh = self.event_handlers[module_name]
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.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):
self.core.events.del_event_handler(None, handler)