Recently, I had a need to write a plugin framework for the markerlight project, so I could rapidly write and deploy various “templates” (similar concept to 010 Editor’s templates) to find things in memory.
I suspect this is something I’ll need to do again in future, so I’ve shifted this functionality to a clean class. To use this, just drop the “plugins.py” file into your project, create an instance of the pluginLoader class (which will automatically scan for Python files in the “plugins/” folder), and then load modules with pluginLoader.loadModule(moduleName).
It’s that easy – source code doesn’t even break 50 lines.
Edit: do you want to add your plugins to a menu with Tkinter? Here’s how!
self.pluginList = plugins.pluginLoader() for pluginName in self.pluginList.listModules(): extractMenu.add_command(label=pluginName,command=lambda pluginName=pluginName: self.pluginList.loadModule(pluginName))