Allow to register callback after the pluginned classes got generated

This commit is contained in:
shortcutme 2017-10-03 14:57:44 +02:00
parent fcfd428b54
commit 7153982981
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 9 additions and 0 deletions

View File

@ -15,6 +15,7 @@ class PluginManager:
self.subclass_order = {} # Record the load order of the plugins, to keep it after reload
self.pluggable = {}
self.plugin_names = [] # Loaded plugin names
self.after_load = [] # Execute functions after loaded plugins
sys.path.append(self.plugin_path)
@ -42,6 +43,9 @@ class PluginManager:
if dir_name not in self.plugin_names:
self.plugin_names.append(dir_name)
for func in self.after_load:
func()
# Reload all plugins
def reloadPlugins(self):
self.plugins_before = self.plugins
@ -141,6 +145,11 @@ def registerTo(class_name):
return classDecorator
def afterLoad(func):
plugin_manager.after_load.append(func)
return func
# - Example usage -
if __name__ == "__main__":