Lyrics: support for loading stored lyrics.
[nephilim.git] / nephilim / plugins / __init__.py
blob577b4da1bff405275ca043e6702b4a0e0bd9e789
2 # Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
4 # Nephilim is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # Nephilim is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Nephilim. If not, see <http://www.gnu.org/licenses/>.
19 import sys
20 import logging
22 __all__ = ['AlbumCover', 'Filebrowser', 'Library', 'Lyrics', 'Notify', 'PlayControl',
23 'Playlist', 'Songinfo', 'Systray']
25 class Plugins:
26 _plugins = None
27 parent = None
28 mpclient = None
30 def __init__(self, parent, mpclient):
31 """load all modules in the plugins directory."""
32 self._plugins = {}
33 self.parent = parent
34 self.mpclient = mpclient
36 for name in __all__:
37 self.init_plugin(name)
39 def setPluginMessage(self, name, msg):
40 try:
41 self._plugins[name.lower()][PLUGIN_MSG]=msg
42 except:
43 try:
44 self._plugins["plugin%s"%(name.lower())][PLUGIN_MODULE]=msg
45 except:
46 pass
48 def plugin(self, name):
49 return self._plugins[name] if name in self._plugins else None
51 def init_plugin(self, name):
52 try:
53 if name in sys.modules:
54 reload(sys.modules[name])
55 module = sys.modules[name]
56 else:
57 module = __import__(name, globals(), locals(), [], 1)
58 except SyntaxError, e:
59 logging.error('Failed to initialize plugin %s: %s.'%(name, e))
60 return False
62 self._plugins[name] = eval('module.%s(self.parent, self.mpclient, \'%s\')'%(name, name))
63 return True
65 def load(self, name):
66 if not name in self._plugins:
67 if not self.init_plugin(name):
68 return False
70 self._plugins[name].load()
71 return True
73 def unload(self, name):
74 if name in self._plugins:
75 if self._plugins[name].is_loaded():
76 self._plugins[name].unload()
78 def plugins(self):
79 return self._plugins.values()
81 def loaded_plugins(self):
82 list = []
83 for plugin in self._plugins.values():
84 if plugin.is_loaded():
85 list.append(plugin)
86 return list