Graphics Reference
In-Depth Information
def unload(self):
self.iface.removePluginMenu("Test Plugin", self.action)
self.iface.removeToolBarIcon(self.action)
There's one last thing we need to do before our toolbar icon will work; we need to tell
QGIS that the icon.png file is a resource used by our plugin. This is done through the
resources.qrc file. Create this file now, placing it into your plugin's directory, and
edit it using your favorite text editor, so that it contains the following XML format text:
<RCC>
<qresource prefix="/plugins/testPlugin">
<file>icon.png</file>
</qresource>
</RCC>
QGIS can't use this file directly; it has to be compiled into a resources.py module us-
ing the pyrcc4 command-line tool. This tool is installed as part of PyQt; once you've cre-
ated your resources.qrc file, use the following command to compile it:
pyrcc4 resources.qrc -o resources.py
Tip
Depending on where PyQt installed it, you might need to include the path to the pyrcc4
command. If you run this command from a directory other than the plugin directory, you
will also need to include the path to the resources.qrc and resource.py files.
Finally, we need to add the following to the top of our testPlugin.py module:
import resources
This makes the compiled resources available for our plugin to use. When you reload your
plugin, an icon should appear in the QGIS toolbar, and if you click on that icon, the "Run-
ning" message box should be displayed.
While this plugin is very basic, we've actually learned a lot: how to create and install a
plugin, how a plugin can add itself to the QGIS user interface, how plugins interact with
the user, how errors in a plugin are handled, and how to deal with images and other plugin
resources. Let's take a closer look now at the processes typically used to develop and dis-
tribute plugins, before going on to create a plugin that actually does something useful.
Search WWH ::




Custom Search