How to make PyMT Plugin

Create directory structure

You will need few things to make it work. Go to pymt/examples/ directory, and :

  • create a directory with your plugin name
  • add an empty __init__.py file in plugin directory
  • put your plugin.py in your plugin directory

You will have :

  • pymt/examples/plugin
  • pymt/examples/plugin/__init__.py (empty file)
  • pymt/examples/plugin/plugin.py

Add plugin informations

You must add some informations at start of plugin.py. Here is an example from paint/paint.py :

# PYMT Plugin integration
 IS_PYMT_PLUGIN = True
 PLUGIN_TITLE = 'GL Paint'
 PLUGIN_AUTHOR = 'Thomas Hansen'
 PLUGIN_EMAIL = 'thomas.hansen@gmail.com'
 PLUGIN_DESCRIPTION = 'This is a simple paint canvas.'

Add hook for plugin activate/deactivate

2 hooks are needed to create instance of plugin. It's pymt_plugin_activate() and pymt_plugin_deactivate() functions. These fonction are offer you 2 variables:

  • root: this is the container widget of your application
  • ctx: a generic object to store your plugin instance

Here is an example from paint/paint.py :

def pymt_plugin_activate(root, ctx):
    ctx.canvas = Canvas(pos=(40,40),size=(root.width,root.height))
    root.add_widget(ctx.canvas)
    ctx.slider = MTColorPicker(size=(130,290), target=[ctx.canvas])
    root.add_widget(ctx.slider)

def pymt_plugin_deactivate(root, ctx):
    root.remove_widget(ctx.canvas)
    root.remove_widget(ctx.slider)

Make your plugin running as standalone application

Just add the code at the end of your plugin to make it work :

if __name__ == '__main__':
    w = MTWindow()
    w.set_fullscreen()
    ctx = MTContext()
    pymt_plugin_activate(w, ctx)
    runTouchApp()
    pymt_plugin_deactivate(w, ctx)