Sunday, 2 October 2016

qgis - plugin 'hook' when writing with Python


Just a conceptual question... when writing a plugin using Plugin Builder 1.8.3, where does the script get connected to the application instance objects?


As an example (taken from eventlayerplugin.py):


class EventLayerPlugin:

def __init__(self, iface):
self.mIface = iface
....

def run(self):
dialog = EventLayerDialog( self.mIface )
if dialog.exec_() == QDialog.Accepted:
lineLayer = QgsMapLayerRegistry.instance().mapLayers()[dialog.lineLayer()]
eventLayer = QgsMapLayerRegistry.instance().mapLayers()[dialog.eventLayer()]
....


where does iface and QgsMapLayerRegistry get assigned to the actual objects in the running instance of QGIS? From my beginner's perspective they seem to 'magically' refer to those objects already existing in the running instance, yet nowhere do I see them assigned to represent the instance objects. I.e. where in the plugin script are the QGIS objects made known to the script?


Clear as mud? If so, let me know and I'll try to figure out a better way to phrase this.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...