From 4b02b1a8123505607de90db7a82b485d302f0267 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 13 Nov 2011 00:25:30 +0100 Subject: Fix add_tab_command (and remove) --- src/plugin_manager.py | 5 ++++- src/tabs.py | 9 +-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/plugin_manager.py b/src/plugin_manager.py index fe4d2b7e..437d8ee2 100644 --- a/src/plugin_manager.py +++ b/src/plugin_manager.py @@ -99,12 +99,15 @@ class PluginManager(object): def add_tab_command(self, module_name, tab_type, name, handler, help, completion=None): commands = self.tab_commands[module_name] t = tab_type.__name__ + if name in tab_type.plugin_commands: + return if not t in commands: commands[t] = [] commands[t].append((name, handler, help, completion)) + tab_type.plugin_commands[name] = (handler, help, completion) for tab in self.core.tabs: if isinstance(tab, tab_type): - tab.add_plugin_command(name, handler, help, completion) + tab.update_commands() def del_tab_command(self, module_name, tab_type, name): commands = self.tab_commands[module_name] diff --git a/src/tabs.py b/src/tabs.py index 472a15fa..28bb90d2 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -222,17 +222,10 @@ class Tab(object): def on_input(self, key): pass - def add_plugin_command(self, name, handler, help, completion=None): - if name in self.plugin_commands or name in self.commands: - return - self.plugin_commands[name] = (handler, help, completion) - self.commands[name] = (handler, help, completion) - self.update_commands() - def update_commands(self): for c in self.plugin_commands: if not c in self.commands: - self.commands[name] = self.plugin_commands[c] + self.commands[c] = self.plugin_commands[c] def on_lose_focus(self): """ -- cgit v1.2.3 From 572cc678a079aa24fffebda5c76f4e5cb35893c5 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 13 Nov 2011 00:26:14 +0100 Subject: Example for add_tab_command in the test plugin --- plugins/test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/test.py b/plugins/test.py index 13ba1e9c..dcb2f7f5 100644 --- a/plugins/test.py +++ b/plugins/test.py @@ -1,8 +1,10 @@ from plugin import BasePlugin +import tabs class Plugin(BasePlugin): def init(self): self.add_command('plugintest', self.command_plugintest, 'Test command') + self.add_tab_command(tabs.MucTab, 'plugintest', self.command_tab_plugintest, 'Test command') self.add_event_handler('message', self.on_message) self.core.information("Plugin loaded") @@ -12,5 +14,9 @@ class Plugin(BasePlugin): def on_message(self, message): self.core.information("Test plugin received message: {}".format(message)) + def command_tab_plugintest(self, args): + self.core.information("Command for MucTabs! With args {}".format(args)) + self.del_tab_command(tabs.MucTab, 'plugintest') + def command_plugintest(self, args): self.core.information("Command! With args {}".format(args)) -- cgit v1.2.3 From aac980cd4c55c5e49ee2f571f808a48ed349550a Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 13 Nov 2011 00:57:54 +0100 Subject: Add a /set_plugin command --- src/core.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/core.py b/src/core.py index 1f93324d..dd2690f4 100644 --- a/src/core.py +++ b/src/core.py @@ -135,6 +135,7 @@ class Core(object): 'plugins': (self.command_plugins, _('Usage: /plugins\nPlugins: Show the plugins in use.'), None), 'presence': (self.command_presence, _('Usage: /presence [type] [status]\nPresence: Send a directed presence to and using [type] and [status] if provided.'), None), 'rawxml': (self.command_rawxml, _('Usage: /rawxml\nRawXML: Send a custom xml stanza.'), None), + 'set_plugin': (self.command_set_plugin, _("Usage: /set_plugin