Graphics Reference
In-Depth Information
• A plugin is simply a directory that contains a Python package initialization file
( __init__.py ), some Python modules, and other files created using Qt
Designer.
• The __init__.py module must define a top-level function named
ClassFactory that accepts an iface parameter and returns an object that
represents the plugin.
• The plugin object must define an initGui() method, which is called to initial-
ize the plugin's user interface, and an unload() method, which is called to re-
move the plugin from the QGIS application.
• The plugin can interact with and manipulate the QGIS application via the iface
object passed to the class factory.
• The resources.qrc file lists various resources such as images, which are
used by the plugin.
• The resources.qrc file is compiled into a resources.py file using the
PyQt command-line tools.
• Dialog boxes and other windows are created using a Qt Designer template, which
are typically stored in a file with a name of the form ui_Foo.ui .
• The UI template files are then compiled into Python code using the PyQt
command-line tools. If the template is named ui_foo.ui , then the associated
Python module will be named ui_foo.py .
• Once the user interface for a dialog box has been defined, you create a subclass of
QtGui.QDialog , and load that user interface module into it. This defines the
contents of the dialog box based on your template.
• Your plugin can then display the dialog box as required, extracting the entered
values and using the results to interact with QGIS via the iface variable.
Plugins are a useful way of extending and customizing QGIS. We will return to the topic
of QGIS plugins in Chapter 4 , Creating QGIS Plugins , where we will create our own plu-
gin from scratch.
Search WWH ::




Custom Search