diff options
author | Florent Le Coz <louiz@louiz.org> | 2011-11-14 00:56:15 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2011-11-14 00:56:15 +0100 |
commit | f0f9f670b9084761023ba9c594b97a0ad37581ed (patch) | |
tree | a6a3b72d68f0f5783875cd721ce5e6686009078a /src/plugin_manager.py | |
parent | 3ea5eb6163181ba016cfddcc616a171d7f309e76 (diff) | |
parent | 920c43dae25b06fd843dc8f8cbbf5e6bc5bf91c0 (diff) | |
download | poezio-f0f9f670b9084761023ba9c594b97a0ad37581ed.tar.gz poezio-f0f9f670b9084761023ba9c594b97a0ad37581ed.tar.bz2 poezio-f0f9f670b9084761023ba9c594b97a0ad37581ed.tar.xz poezio-f0f9f670b9084761023ba9c594b97a0ad37581ed.zip |
Merge branch 'master' of http://git.louiz.org/poezio
Diffstat (limited to 'src/plugin_manager.py')
-rw-r--r-- | src/plugin_manager.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/plugin_manager.py b/src/plugin_manager.py index 437d8ee2..e3b786cb 100644 --- a/src/plugin_manager.py +++ b/src/plugin_manager.py @@ -36,6 +36,8 @@ class PluginManager(object): self.commands = {} # module name -> dict of commands loaded for the module self.event_handlers = {} # module name -> list of event_name/handler pairs loaded for the module self.tab_commands = {} #module name -> dict of tab types; tab type -> commands loaded by the module + self.keys = {} # module name → dict of keys/handlers loaded for the module + self.tab_keys = {} #module name → dict of tab types; tab type → list of keybinds (tuples) def load(self, name, notify=True): if name in self.plugins: @@ -61,6 +63,8 @@ class PluginManager(object): self.modules[name] = module self.commands[name] = {} + self.keys[name] = {} + self.tab_keys[name] = {} self.tab_commands[name] = {} self.event_handlers[name] = [] self.plugins[name] = module.Plugin(self, self.core, plugins_conf_dir) @@ -72,16 +76,23 @@ class PluginManager(object): try: for command in self.commands[name].keys(): del self.core.commands[command] + for key in self.keys[name].keys(): + del self.core.key_func[key] for tab in list(self.tab_commands[name].keys()): for command in self.tab_commands[name][tab]: self.del_tab_command(name, getattr(tabs, tab), command[0]) del self.tab_commands[name][tab] + for tab in list(self.tab_keys[name].keys()): + for key in self.tab_keys[name][tab]: + self.del_tab_key(name, getattr(tabs, tab), key[0]) + del self.tab_keys[name][tab] for event_name, handler in self.event_handlers[name]: self.del_event_handler(name, event_name, handler) self.plugins[name].unload() del self.plugins[name] del self.commands[name] + del self.keys[name] del self.tab_commands[name] del self.event_handlers[name] if notify: @@ -122,6 +133,45 @@ class PluginManager(object): if isinstance(tab, tab_type) and name in tab.commands: del tab.commands[name] + def add_tab_key(self, module_name, tab_type, key, handler): + keys = self.tab_keys[module_name] + t = tab_type.__name__ + if key in tab_type.plugin_keys: + return + if not t in keys: + keys[t] = [] + keys[t].append((key, handler)) + tab_type.plugin_keys[key] = handler + for tab in self.core.tabs: + if isinstance(tab, tab_type): + tab.update_keys() + + def del_tab_key(self, module_name, tab_type, key): + keys = self.tab_keys[module_name] + t = tab_type.__name__ + if not t in keys: + return + for _key in keys[t]: + if _key[0] == key: + keys[t].remove(_key) + del tab_type.plugin_keys[key] + for tab in self.core.tabs: + if isinstance(tab, tab_type) and key in tab.key_func: + del tab.key_func[key] + + def add_key(self, module_name, key, handler): + if key in self.core.key_func: + raise Exception(_("Key '%s' already exists") % (key,)) + keys = self.keys[module_name] + keys[key] = handler + self.core.key_func[key] = handler + + def del_key(self, module_name, key): + if key in self.keys[module_name]: + del self.keys[module_name][key] + if key in self.core.key_func: + del self.core.commands[key] + def add_command(self, module_name, name, handler, help, completion=None): if name in self.core.commands: raise Exception(_("Command '%s' already exists") % (name,)) |