Skip to content

Writing Plugins

Damien Farrell edited this page Jan 10, 2016 · 2 revisions

Plugins are for adding custom functionality that is not present in the main application. They are implemented by sub-classing the Plugin class in the plugin module. This is a python script that can generally contain any code you wish. Usually the idea will be to implement a dialog that the user interacts with. But this could also be a single method that runs on the current table or all sheets at once.

Implementing a plugin

Plugins should inherit from the Plugin class. Though this is not strictly necessary for the plugin to function.

from pandastable.plugin import Plugin

You can simply copy the example plugin to get started. All plugins need to have a main() method which is called by the application to launch them. By default this method contains the _doFrame() method which constructs a main frame as part of the current table frame. Usually you override main() and call _doFrame then add your own custom code with your widgets.

_doFrame method has the following lines which are always needed unless it is a non GUI plugin.

self.table = self.parent.getCurrentTable() #get the current table
#add the plugin frame to the table parent
self.mainwin = Frame(self.table.parentframe) 
#pluginrow is 6 to make the frame appear below other widgets
self.mainwin.grid(row=pluginrow,column=0,columnspan=2,sticky='news')

You can also override the quit() and about() methods.

Non-table based plugins

Plugins that don't rely on using the table directly do not need to use the above method and can have essentially anything in them as long as there is a main() method present. The Batch File Rename plugin is an example. This is a standalone utility launched in a separate toplevel window. see https://github.com/dmnfarrell/pandastable/blob/master/pandastable/plugins/rename.py