diff --git a/pythonrewrite/bin/CryptoBoxPlugin.py b/pythonrewrite/bin/CryptoBoxPlugin.py index cffb2c2..28f2210 100644 --- a/pythonrewrite/bin/CryptoBoxPlugin.py +++ b/pythonrewrite/bin/CryptoBoxPlugin.py @@ -4,6 +4,7 @@ # import os +import cherrypy class CryptoBoxPlugin: @@ -22,7 +23,7 @@ class CryptoBoxPlugin: ## default icon of this plugin (relative path) - iconFile = "plugin_icon.png" + defaultIconFileName = "plugin_icon.png" def __init__(self, cbox, pluginDir): @@ -47,10 +48,14 @@ class CryptoBoxPlugin: return self.__module__ + @cherrypy.expose def getIcon(self): """return the image data of the icon of the plugin""" import cherrypy - return cherrypy.lib.cptools.serveFile(os.path.join(self.pluginDir, self.iconFile)) + plugin_icon_file = os.path.join(self.pluginDir, self.defaultIconFileName) + if not os.access(plugin_icon_file, os.R_OK): + plugin_icon_file = os.path.join(self.cbox.prefs["Locations"]["PluginDir"], "plugin_icon_unknown.png") + return cherrypy.lib.cptools.serveFile(plugin_icon_file) def getTemplateFileName(self, template_name): diff --git a/pythonrewrite/bin/WebInterfaceSites.py b/pythonrewrite/bin/WebInterfaceSites.py index 9ddf3bb..79df20b 100755 --- a/pythonrewrite/bin/WebInterfaceSites.py +++ b/pythonrewrite/bin/WebInterfaceSites.py @@ -20,6 +20,29 @@ class WebInterfacePlugins: #setattr(getattr(self, plname), "stream_respones", True) +class IconHandler: + + def __init__(self, plugins): + self.plugins = PluginIconHandler(plugins) + self.plugins.exposed = True + + +class PluginIconHandler: + + def __init__(self, plugins): + for plugin in plugins.getPlugins(): + if not plugin: continue + plname = plugin.getName() + ## this should be the "easiest" way to expose all plugins as URLs + x = lambda: plugin.getIcon() + print x + print plugin.getIcon + def getIcon(p): + return p.getIcon() + setattr(self, plname, plugin.getIcon) + ## the function is exposed in the CryptoBoxPlugin class - it did not work here + + class WebInterfaceSites: ''' @@ -46,6 +69,8 @@ class WebInterfaceSites: ## publish the url "/system" as an alias for "/plugins" self.plugins.index = self.system self.dataset = WebInterfaceDataset.WebInterfaceDataset(self.cbox, self.prefs, self.pluginList.getPlugins()) + ## publish plugin icons + self.icons = IconHandler(self.pluginList) def __check_config(self): diff --git a/pythonrewrite/plugins/plugin_icon_unknown.png b/pythonrewrite/plugins/plugin_icon_unknown.png new file mode 100644 index 0000000..d6e9b3a Binary files /dev/null and b/pythonrewrite/plugins/plugin_icon_unknown.png differ diff --git a/pythonrewrite/templates/macros.cs b/pythonrewrite/templates/macros.cs index bfa4036..d4fcef0 100644 --- a/pythonrewrite/templates/macros.cs +++ b/pythonrewrite/templates/macros.cs @@ -88,6 +88,6 @@ def:print_form_header(form_name, action) ?>