From 5fea3e918d81a388b91dcad3367412a611cc1f74 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 25 Mar 2017 18:21:25 +0300 Subject: [PATCH] plugin reloading refactoring --- toxygen/mainscreen.py | 6 ++---- toxygen/plugin_support.py | 8 +++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/toxygen/mainscreen.py b/toxygen/mainscreen.py index f1648d3..cf52814 100644 --- a/toxygen/mainscreen.py +++ b/toxygen/mainscreen.py @@ -466,10 +466,8 @@ class MainWindow(QtGui.QMainWindow, Singleton): def reload_plugins(self): plugin_loader = plugin_support.PluginLoader.get_instance() - if plugin_loader is None: - return - plugin_loader.stop() - plugin_loader.load() + if plugin_loader is not None: + plugin_loader.reload() def import_plugin(self): import util diff --git a/toxygen/plugin_support.py b/toxygen/plugin_support.py index 19ccb8e..a7949f0 100644 --- a/toxygen/plugin_support.py +++ b/toxygen/plugin_support.py @@ -51,7 +51,8 @@ class PluginLoader(util.Singleton): continue for elem in dir(module): 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) try: # create instance of plugin class inst = obj(self._tox, self._profile, self._settings, self._encr) @@ -165,3 +166,8 @@ class PluginLoader(util.Singleton): if self._plugins[key][1]: self._plugins[key][0].close() del self._plugins[key] + + def reload(self): + print('Reloading plugins') + self.stop() + self.load()