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 __init_plugin(self
, name
):
41 if name
in sys
.modules
:
42 reload(sys
.modules
[name
])
43 module
= sys
.modules
[name
]
45 module
= __import__(name
, globals(), locals(), [], 1)
46 except (SyntaxError, ImportError), e
:
47 logging
.error('Failed to initialize plugin %s: %s.'%(name
, e
))
50 self
._plugins
[name
] = eval('module.%s(self.parent, self.mpclient, \'%s\')'%(name
, name
))
53 def plugin(self
, name
):
54 """Returns a plugin with the specified name. It is illegal to access
55 any functions if the plugin is unloaded."""
56 return self
._plugins
[name
] if name
in self
._plugins
else None
59 """Loads an unloaded plugin."""
60 if not name
in self
._plugins
:
61 if not self
.__init
_plugin
(name
):
64 self
._plugins
[name
].load()
67 def unload(self
, name
):
68 """Unloads a loaded plugin."""
69 if name
in self
._plugins
:
70 if self
._plugins
[name
].loaded
:
71 self
._plugins
[name
].unload()
74 """Returns all available plugins. It is illegal to access any functions
75 if the plugin is unloaded."""
76 return self
._plugins
.values()
78 def loaded_plugins(self
):
79 """Returns all loaded plugins."""
81 for plugin
in self
._plugins
.values():