Python Drop-in Plugin Framework

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.

plugins.py

plugins/elf.py

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))

About Norman

Sometimes, I write code. Occasionally, it even works.
This entry was posted in Computers, Jesting. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s