def __init__(self): QtGui.QDialog.__init__(self) # Set up the user interface from Designer. self.ui = Ui_RealCentroid() self.ui.setupUi(self) # add action to buttons self.ui.browseButton.clicked.connect(self.browse) self.ui.okButton.clicked.connect(self.ok) self.ui.cancelButton.clicked.connect(self.reject) # layer changed event self.ui.layerBox.currentIndexChanged.connect(self.sel)
class RealCentroidDialog(QtGui.QDialog): def __init__(self): QtGui.QDialog.__init__(self) # Set up the user interface from Designer. self.ui = Ui_RealCentroid() self.ui.setupUi(self) # add action to buttons self.ui.browseButton.clicked.connect(self.browse) self.ui.okButton.clicked.connect(self.ok) self.ui.cancelButton.clicked.connect(self.reject) # layer changed event self.ui.layerBox.currentIndexChanged.connect(self.sel) def showEvent(self, event): # remove previous entries from layer list self.ui.layerBox.clear() # remove previous shape path self.ui.pointEdit.clear() # add polygon layers to list names = util.getLayerNames([QGis.Polygon]) self.ui.layerBox.addItems(names) if iface.activeLayer(): # set active item in list to the active layer i = 0 for name in names: l = util.getMapLayerByName(name) if l == iface.activeLayer(): self.ui.layerBox.setCurrentIndex(i) break i += 1 def sel(self): """ enable/disable selected features only checkbox """ self.ui.selectedBox.setEnabled(False) self.ui.selectedBox.setCheckState(QtCore.Qt.Unchecked) l = util.getMapLayerByName(self.ui.layerBox.currentText()) if l is not None: sf = l.selectedFeatures() if sf is not None and len(sf): self.ui.selectedBox.setEnabled(True) self.ui.selectedBox.setCheckState(QtCore.Qt.Checked) def browse(self): self.ui.pointEdit.clear() # clear output file field # open file dialog (self.shapefileName, self.encoding) = util.saveDialog(self) if self.shapefileName is None or self.encoding is None: return self.ui.pointEdit.setText(self.shapefileName) # fill output file field def ok(self): if len(self.ui.layerBox.currentText()) == 0: QtGui.QMessageBox.information(self, "Realcentroid", \ QApplication.translate("RealCentroid", \ "No polygon layer selected", None, QApplication.UnicodeUTF8)) return if len(self.ui.pointEdit.text()) == 0: QtGui.QMessageBox.information(self, "Realcentroid", \ QApplication.translate("RealCentroid", \ "No point layer given", None, QApplication.UnicodeUTF8)) return self.accept()
class RealCentroidDialog(QtGui.QDialog): def __init__(self): QtGui.QDialog.__init__(self) # Set up the user interface from Designer. self.ui = Ui_RealCentroid() self.ui.setupUi(self) # add action to buttons self.ui.browseButton.clicked.connect(self.browse) self.ui.okButton.clicked.connect(self.ok) self.ui.cancelButton.clicked.connect(self.reject) # layer changed event self.ui.layerBox.currentIndexChanged.connect(self.sel) def showEvent(self, event): # remove previous entries from layer list self.ui.layerBox.clear() # remove previous shape path self.ui.pointEdit.clear() # add polygon layers to list names = util.getLayerNames([QGis.Polygon]) self.ui.layerBox.addItems(names) if iface.activeLayer(): # set active item in list to the active layer i = 0 for name in names: l = util.getMapLayerByName(name) if l == iface.activeLayer(): self.ui.layerBox.setCurrentIndex(i) break i += 1 def sel(self): """ enable/disable selected features only checkbox """ self.ui.selectedBox.setEnabled(False) self.ui.selectedBox.setCheckState(QtCore.Qt.Unchecked) l = util.getMapLayerByName(self.ui.layerBox.currentText()) if l is not None: sf = l.selectedFeatures() if sf is not None and len(sf): self.ui.selectedBox.setEnabled(True) self.ui.selectedBox.setCheckState(QtCore.Qt.Checked) def browse(self): self.ui.pointEdit.clear() # clear output file field # open file dialog (self.shapefileName, self.encoding) = util.saveDialog(self) if self.shapefileName is None or self.encoding is None: return self.ui.pointEdit.setText(self.shapefileName) # fill output file field def ok(self): if len(self.ui.layerBox.currentText()) == 0: QtGui.QMessageBox.information(self, "Realcentroid", \ QtGui.QApplication.translate("RealCentroid", \ "No polygon layer selected", None, QtGui.QApplication.UnicodeUTF8)) return if len(self.ui.pointEdit.text()) == 0: QtGui.QMessageBox.information(self, "Realcentroid", \ QtGui.QApplication.translate("RealCentroid", \ "No point layer given", None, QtGui.QApplication.UnicodeUTF8)) return self.accept()