def initGui(self): # Create action that will start plugin configuration self.dlg = CoarsityDefinerDialog() self.action = QAction(QIcon(":/plugins/CoarsityDefiner/icon.png"), "Define Points", self.iface.mainWindow()) self.action.setWhatsThis("Define Points") self.export = QAction(QIcon(":/plugins/CoarsityDefiner/icon2.png"), "Export...", self.iface.mainWindow()) self.export.setWhatsThis("Export...") # connect the action to the run method QObject.connect(self.action, SIGNAL("activated()"), self.run) QObject.connect(self.export, SIGNAL("activated()"), self.exportFile) QObject.connect(self.layerRegistry.instance(), SIGNAL("layerWillBeRemoved(QString)"), self.deleteLayer) # Add menu item self.iface.addPluginToMenu("&CDF", self.action) self.iface.addPluginToMenu("&CDF", self.export) result = QObject.connect( self.pinTool, SIGNAL("canvasClicked(const QgsPoint &, Qt::MouseButton)"), self.markMap)
def run(self): # create and show the dialog self.dlg = CoarsityDefinerDialog() # show the dialog al = self.iface.activeLayer() if al: self.dlg.ui.label_layer.setText('Select the number of points') else: self.dlg.ui.label_layer.setText('Select a layer first') self.dlg.show() result = self.dlg.exec_() # See if OK was pressed if result == 1: if self.dlg.ui.radioButton.isChecked(): numOfPoints = 1 elif self.dlg.ui.radioButton_2.isChecked(): numOfPoints = 2 elif self.dlg.ui.radioButton_3.isChecked(): numOfPoints = 3 elif self.dlg.ui.radioButton_4.isChecked(): numOfPoints = 4 else: numOfPoints = 0 self.newPinLayer() self.layerPoints.append(numOfPoints) self.canvas.setMapTool(self.pinTool)