Move the base plugin classes to plugin.py for cleaner importing in additional plugins

This commit is contained in:
Chris Jones 2010-01-05 22:22:13 +00:00
parent 710b8a4834
commit 0b5cf876ba
3 changed files with 29 additions and 22 deletions

View File

@ -105,6 +105,31 @@ for %s' % (len(self.instances), capability))
"""Return all plugins"""
return(self.instances)
# This is where we should define a base class for each type of plugin we
# support
# URLHandler - This adds a regex match to the Terminal widget and provides a
# callback to turn that into a URL.
class URLHandler(Plugin):
"""Base class for URL handlers"""
capabilities = ['url_handler']
handler_name = None
match = None
def callback(self, url):
"""Callback to transform the enclosed URL"""
raise NotImplementedError
# MenuItem - This is able to execute code during the construction of the
# context menu of a Terminal.
class MenuItem(Plugin):
"""Base class for menu items"""
capabilities = ['terminal_menu']
def callback(self, menuitems, menu, terminal):
"""Callback to transform the enclosed URL"""
raise NotImplementedError
if __name__ == '__main__':
import sys
import doctest

View File

@ -10,15 +10,7 @@ import terminatorlib.plugin as plugin
#available = ['MyFirstMenuItem']
available = []
class MenuItem(plugin.Plugin):
"""Base class for menu items"""
capabilities = ['terminal_menu']
def callback(self, menuitems, menu, terminal):
"""Callback to transform the enclosed URL"""
raise NotImplementedError
class MyFirstMenuItem(MenuItem):
class MyFirstMenuItem(plugin.MenuItem):
"""Simple proof of concept"""
capabilities = ['terminal_menu']

View File

@ -7,17 +7,7 @@ import terminatorlib.plugin as plugin
# Every plugin you want Terminator to load *must* be listed in 'available'
available = ['LaunchpadBugURLHandler', 'LaunchpadCodeURLHandler', 'APTURLHandler']
class URLHandler(plugin.Plugin):
"""Base class for URL handlers"""
capabilities = ['url_handler']
handler_name = None
match = None
def callback(self, url):
"""Callback to transform the enclosed URL"""
raise NotImplementedError
class LaunchpadBugURLHandler(URLHandler):
class LaunchpadBugURLHandler(plugin.URLHandler):
"""Launchpad Bug URL handler. If the URL looks like a Launchpad changelog
closure entry... 'LP: #12345' then it should be transformed into a
Launchpad Bug URL"""
@ -31,7 +21,7 @@ class LaunchpadBugURLHandler(URLHandler):
url = 'https://bugs.launchpad.net/bugs/%s' % item
return(url)
class LaunchpadCodeURLHandler(URLHandler):
class LaunchpadCodeURLHandler(plugin.URLHandler):
"""Launchpad Code URL handler. If the URL looks like a Launchpad project or
branch entry then it should be transformed into a code.launchpad.net URL"""
capabilities = ['url_handler']
@ -50,7 +40,7 @@ class LaunchpadCodeURLHandler(URLHandler):
url = url[3:]
return('https://code.launchpad.net/+branch/%s' % url)
class APTURLHandler(URLHandler):
class APTURLHandler(plugin.URLHandler):
"""APT URL handler. If there is a URL that looks like an apturl, handle
it appropriately"""
capabilities = ['url_handler']