Graphics Reference
In-Depth Information
def unload(self):
...
def run(self):
...
If you open the
__init__.py
module, you'll see how this class is used to define the
plugin's behavior:
def classFactory(iface):
from zoomtopoint import ZoomToPoint
return ZoomToPoint(iface)
When the plugin is loaded, a parameter named
iface
is passed to the
ClassFactory
function. This parameter is an instance of
QgsInterface
, and provides access to the
various parts of the running QGIS application. As you can see, the class factory creates a
ZoomToPoint
object, and passes the
iface
parameter to the initializer so that
ZoomToPoint
can make use of it.
Notice how
ZoomToPoint.__init__()
, in the
Zoomtopoint.py
module, stores
a reference to the
iface
parameter in an instance variable, so that the other methods can
refer to the QGIS interface using
self.iface
. For example:
def __init__(self, iface):
self.iface = iface
def initGui(self):
...
self.iface.addPluginToMenu("&Zoom to point...",
self.action)
This allows the plugin to interact with and manipulate the QGIS user interface.
The four methods defined by the
ZoomToPoint
class are all quite straightforward:
•
__init__()
: This method initializes a new
ZoomToPoint
object.
•
initGui()
: This method initializes the plugin's user interface, preparing it to
be used.
•
unload()
: This method removes the plugin from the QGIS user interface.