Geography Reference
In-Depth Information
Defining Resources
For our plugin, we not only need the logic to zoom the map but also a
dialog box to collect input from the user. We also need a resources file
that will contain the icon for our tool. Let's get that out of the way first
by creating our resources.qrc file that contains the definition of our icon:
<RCC>
<qresource prefix="/plugins/zoom_to_point" >
<file> icon.png </file>
</qresource>
</RCC>
This resource file uses a prefix to prevent naming clashes with other
plugins. It's good to make sure your prefix will be unique—usually
using the name of your plugin is adequate. We define one file, icon.png ,
in the resource file. This is just a PNG image that will be used in the
toolbar when we activate our plugin. You can create your own PNG or
use an existing one. The only real requirement is that it be 22-by-22
pixels so it will fit nicely on the toolbar. You can also use other formats
(XPM for one), but PNG is convenient, and there are a lot of existing
icons in that format.
Once we have the resource file built, we need to use the PyQt resource
compiler to compile it:
pyrcc4 -o resources.py resources.qrc
The -o switch is used to define the output file. If you don't include it,
the output of pyrcc4 will be written to the terminal, which is not really
what we're after here. Now that we have the resources defined, we need
to build the GUI to collect the information for ZoomToPoint.
Creating the GUI
To create the GUI, we'll use the same tool that C++ developers use: Qt
Designer. This is a visual design tool that allows you to create dialog
boxes and main windows by dragging and dropping widgets and defin-
ing their properties. Designer is installed along with Qt, so it should be
already available on your machine.
Our dialog box is pretty simple. In Figure 13.2 , on the next page, you
can see the dialog box in Designer , along with the widget palette and the
property editor. It's already complete, but let's take a look at what we
had to do to build it. It's going to be a quick tour since we won't go into
all the intricacies of Designer . If you want to get into the nitty-gritty, see
 
 
Search WWH ::




Custom Search