Graphics Reference
In-Depth Information
Creating a simple plugin
Now that we've seen how plugins are structured and used, let's create a very simple "Hello
World" style plugin to see what's involved in making one. While there are various tools
such as the Plugin Builder plugin, which will create the various files for you, we're going
to eschew them in favor of creating our plugin manually. This will make the process clearer
and avoid the situation where your code just magically works without knowing why or
how.
Go to the ~/.qgis2/python/plugins directory and create a subdirectory named
testPlugin . In this directory, create a file named metadata.txt and enter the fol-
lowing values into it:
[general]
name=Test Plugin
email=test@example.com
author=My Name Here
qgisMinimumVersion=2.0
description=Simple test plugin.
about=A very simple test plugin.
version=version 0.1
This is the minimum metadata you need to enter for a plugin. Obviously, you can change
these values if you want. Now, create a package initialization file, __init__.py , and
enter the following into that file:
def classFactory(iface):
from testPlugin import TestPlugin
return TestPlugin(iface)
As you can see, we're going to define a class named TestPlugin that represents our plu-
gin object, and implement it in a module named testPlugin.py . Let's create this mod-
ule now:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class TestPlugin:
Search WWH ::




Custom Search