plugin reloading refactoring

This commit is contained in:
ingvar1995 2017-03-25 18:21:25 +03:00
parent 7cc404ce52
commit 5fea3e918d
2 changed files with 9 additions and 5 deletions

View File

@ -466,10 +466,8 @@ class MainWindow(QtGui.QMainWindow, Singleton):
def reload_plugins(self): def reload_plugins(self):
plugin_loader = plugin_support.PluginLoader.get_instance() plugin_loader = plugin_support.PluginLoader.get_instance()
if plugin_loader is None: if plugin_loader is not None:
return plugin_loader.reload()
plugin_loader.stop()
plugin_loader.load()
def import_plugin(self): def import_plugin(self):
import util import util

View File

@ -51,7 +51,8 @@ class PluginLoader(util.Singleton):
continue continue
for elem in dir(module): for elem in dir(module):
obj = getattr(module, elem) obj = getattr(module, elem)
if inspect.isclass(obj) and hasattr(obj, 'is_plugin') and obj.is_plugin: # looking for plugin class in module # looking for plugin class in module
if inspect.isclass(obj) and hasattr(obj, 'is_plugin') and obj.is_plugin:
print('Plugin', elem) print('Plugin', elem)
try: # create instance of plugin class try: # create instance of plugin class
inst = obj(self._tox, self._profile, self._settings, self._encr) inst = obj(self._tox, self._profile, self._settings, self._encr)
@ -165,3 +166,8 @@ class PluginLoader(util.Singleton):
if self._plugins[key][1]: if self._plugins[key][1]:
self._plugins[key][0].close() self._plugins[key][0].close()
del self._plugins[key] del self._plugins[key]
def reload(self):
print('Reloading plugins')
self.stop()
self.load()