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/>.
22 __all__
= ['AlbumCover', 'Filebrowser', 'Library', 'Lyrics', 'Notify', 'PlayControl',
23 'Playlist', 'Songinfo', 'Systray']
30 def __init__(self
, parent
, mpclient
):
31 """load all modules in the plugins directory."""
34 self
.mpclient
= mpclient
37 self
.init_plugin(name
)
39 def plugin(self
, name
):
40 return self
._plugins
[name
] if name
in self
._plugins
else None
42 def init_plugin(self
, name
):
44 if name
in sys
.modules
:
45 reload(sys
.modules
[name
])
46 module
= sys
.modules
[name
]
48 module
= __import__(name
, globals(), locals(), [], 1)
49 except SyntaxError, e
:
50 logging
.error('Failed to initialize plugin %s: %s.'%(name
, e
))
53 self
._plugins
[name
] = eval('module.%s(self.parent, self.mpclient, \'%s\')'%(name
, name
))
57 if not name
in self
._plugins
:
58 if not self
.init_plugin(name
):
61 self
._plugins
[name
].load()
64 def unload(self
, name
):
65 if name
in self
._plugins
:
66 if self
._plugins
[name
].is_loaded():
67 self
._plugins
[name
].unload()
70 return self
._plugins
.values()
72 def loaded_plugins(self
):
74 for plugin
in self
._plugins
.values():
75 if plugin
.is_loaded():