Geography Reference
In-Depth Information
class ZoomToPoint:
10
-
-
def __init__(self, iface):
# Save reference to the QGIS interface
-
self.iface = iface
-
15
-
def initGui(self):
# Create action that will start plugin configuration
-
self.action = QAction(QIcon(":/plugins/zoom_to_point/icon.png"), \
-
"Zoom To Point plugin", self.iface.getMainWindow())
-
self.action.setWhatsThis("Configuration for Zoom To Point plugin")
20
QObject.connect(self.action, SIGNAL("activated()"), self.run)
-
-
-
# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
-
self.iface.addPluginMenu("&Zoom to Point...", self.action)
25
-
-
def unload(self):
# Remove the plugin menu item and icon
-
self.iface.removePluginMenu("&Zoom to Point...",self.action)
-
self.iface.removeToolBarIcon(self.action)
30
Every Python script that uses the QGIS libraries and PyQt needs to
import the QtCore and QtGui libraries, in addition to the QGIS core
library. This gives us access to the PyQt wrappers for our Qt objects
(like our dialog box) and the QGIS core libraries. We do this in lines
2 through 8. Notice that not only did we import the PyQt and QGIS
libraries, but we also brought in our resources file and, in line 8, the
code for the dialog box.
If you noticed line 10, you probably realized that we're talking about a
Python class. The implementation of our plugin all takes place within
the ZoomToPoint class. The methods we are about to discuss are all mem-
bers of ZoomToPoint .
When the class is first instantiated, we store the reference to the iface
object using the __init__ ( ) method. This method gets called whenever we
create a ZoomToPoint object. We store iface as a class member because
we are going to use it later when we need access to the map canvas.
As far as QGIS is concerned, plugins must implement only two meth-
ods: initGui ( ) and unload ( ). These two methods are used to initialize the
user interface when the plugin is first loaded and clean up the interface
when it's unloaded. Let's take a look at what we need to initialize our
plugin GUI.
 
Search WWH ::




Custom Search