def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdal_merge.py") self.inSelector.setType(self.inSelector.FILE) self.outSelector.setType(self.outSelector.FILE) self.recurseCheck.hide() # use this for approx. previous UI #self.creationOptionsWidget.setType(QgsRasterFormatSaveOptionsWidget.Table) self.outputFormat = Utils.fillRasterOutputFormat() self.extent = None self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.noDataSpin, "valueChanged", self.noDataCheck), (self.inputDirCheck, "stateChanged"), (self.recurseCheck, "stateChanged", self.inputDirCheck), (self.separateCheck, "stateChanged"), (self.pctCheck, "stateChanged"), (self.intersectCheck, "stateChanged"), (self.creationOptionsWidget, "optionsChanged"), (self.creationOptionsGroupBox, "toggled") ]) self.inSelector.selectClicked.connect(self.fillInputFilesEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.intersectCheck.toggled.connect(self.refreshExtent) self.inputDirCheck.stateChanged.connect(self.switchToolMode) self.inSelector.filenameChanged.connect(self.refreshExtent)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.resolutions = ("highest", "average", "lowest") self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdalbuildvrt") self.inSelector.setType(self.inSelector.FILE) self.outSelector.setType(self.outSelector.FILE) self.recurseCheck.hide() self.visibleRasterLayers = [] self.setParamsStatus( [ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.resolutionComboBox, "currentIndexChanged", self.resolutionCheck), (self.noDataEdit, "textChanged", self.srcNoDataCheck, 1700), (self.inputDirCheck, "stateChanged"), (self.separateCheck, "stateChanged", None, 1700), (self.targetSRSEdit, "textChanged", self.targetSRSCheck), (self.allowProjDiffCheck, "stateChanged", None, 1700), (self.recurseCheck, "stateChanged", self.inputDirCheck), (self.inputSelLayersCheck, "stateChanged") ] ) self.inSelector.selectClicked.connect(self.fillInputFilesEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.inputDirCheck.stateChanged.connect(self.switchToolMode) self.inputSelLayersCheck.stateChanged.connect(self.switchLayerMode) self.iface.mapCanvas().layersChanged.connect(self.switchLayerMode) self.selectTargetSRSButton.clicked.connect(self.fillTargetSRSEdit)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BaseBatchWidget.__init__(self, self.iface, "rgb2pct.py") self.outSelector.setType(self.outSelector.FILE) # set the default QSpinBoxes and QProgressBar value self.colorsSpin.setValue(2) self.progressBar.setValue(0) self.progressBar.hide() self.outputFormat = Utils.fillRasterOutputFormat() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.colorsSpin, "valueChanged", self.colorsCheck), (self.bandSpin, "valueChanged", self.bandCheck, "-1") # hide this option ]) self.inSelector.selectClicked.connect(self.fillInputFile) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.batchCheck.stateChanged.connect(self.switchToolMode)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdal_rasterize") self.outSelector.setType(self.outSelector.FILE) # set the default QSpinBoxes and QProgressBar value self.widthSpin.setValue(3000) self.heightSpin.setValue(3000) self.horizresSpin.setValue(1) self.vertresSpin.setValue(1) self.lastEncoding = Utils.getLastUsedEncoding() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.attributeComboBox, "currentIndexChanged"), ([self.widthSpin, self.heightSpin], "valueChanged"), ([self.horizresSpin, self.vertresSpin], "valueChanged") ]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.inSelector.layerChanged.connect(self.fillFieldsCombo) self.radioSetSize.toggled.connect(self.someValueChanged) self.radioSetResolution.toggled.connect(self.someValueChanged)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BaseBatchWidget.__init__(self, self.iface, "pct2rgb.py") # we use one widget for two tools self.base.setWindowTitle(self.tr("Convert paletted image to RGB")) self.outSelector.setType(self.outSelector.FILE) # set the default QSpinBoxes and QProgressBar value self.bandSpin.setValue(1) self.progressBar.setValue(0) self.progressBar.hide() self.outputFormat = Utils.fillRasterOutputFormat() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.colorsSpin, "valueChanged", self.colorsCheck, "-1"), # hide this option (self.bandSpin, "valueChanged", self.bandCheck) ]) self.inSelector.selectClicked.connect(self.fillInputFile) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.batchCheck.stateChanged.connect(self.switchToolMode)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdal_contour") gdalVersion = Utils.GdalConfig.versionNum() self.useDirAsOutput = gdalVersion < 1700 if self.useDirAsOutput: self.label_2.setText( QApplication.translate( "GdalToolsWidget", "&Output directory for contour lines (shapefile)")) self.outSelector.setType(self.outSelector.FILE) # set the default QSpinBoxes value self.intervalDSpinBox.setValue(10.0) self.setParamsStatus([(self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.intervalDSpinBox, "valueChanged"), (self.attributeEdit, "textChanged", self.attributeCheck)]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BaseBatchWidget.__init__(self, self.iface, "rgb2pct.py") self.outSelector.setType(self.outSelector.FILE) # set the default QSpinBoxes and QProgressBar value self.colorsSpin.setValue(2) self.progressBar.setValue(0) self.progressBar.hide() self.outputFormat = Utils.fillRasterOutputFormat() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.colorsSpin, "valueChanged", self.colorsCheck), (self.bandSpin, "valueChanged", self.bandCheck, "-1" ) # hide this option ]) self.inSelector.selectClicked.connect(self.fillInputFile) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.batchCheck.stateChanged.connect(self.switchToolMode)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdalinfo") # we don't need load to canvas functionality self.base.loadCheckBox.hide() # make window large self.base.resize(400, 360) self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.suppressGCPCheck, "stateChanged"), (self.suppressMDCheck, "stateChanged") ]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) # helper actions for copying info output self.copyLine = QAction(self.tr("Copy"), self) self.copyLine.triggered.connect(self.doCopyLine) self.copyAll = QAction(self.tr("Copy all"), self) self.copyAll.triggered.connect(self.doCopyAll)
def init_ui(self): #Builds GUI self.setGeometry(200, 200, 500, 500) b1 = QWidget() self.load_button = QPushButton(b1) self.load_button.setText('Load Data') self.load_button.clicked.connect(self.load_data) b2 = QWidget() self.stats_button = QPushButton(b1) self.stats_button.setText('Compute Statistics') self.stats_button.clicked.connect(self.compute_stats) self.mean_label = QLabel("Mean: Not Computed Yet", self) #Set up a Table to display data self.data_table = QTableWidget() self.data_table.itemSelectionChanged.connect(self.compute_stats) #Define where the widgets go in the window v_layout = QVBoxLayout() v_layout.addWidget(self.load_button) v_layout.addWidget(self.stats_button) v_layout.addWidget(self.data_table) v_layout.addWidget(self.mean_label) self.setLayout(v_layout) self.setWindowTitle('Introduction to Descriptive Statistics') self.activateWindow() self.raise_() self.show()
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.resampling_method = ('nearest', 'average', 'gauss', 'cubic', 'average_mp', 'average_magphase', 'mode') self.setupUi(self) BaseBatchWidget.__init__(self, self.iface, "gdaladdo") # set the default QSpinBoxes and QProgressBar value self.progressBar.setValue(0) self.progressBar.hide() # we don't need load to canvas functionality self.base.loadCheckBox.hide() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.cleanCheck, "stateChanged", None, 1700), (self.mPyramidOptionsWidget, "overviewListChanged"), (self.mPyramidOptionsWidget, "someValueChanged") ]) self.inSelector.selectClicked.connect(self.fillInputFile) self.batchCheck.stateChanged.connect(self.switchToolMode) self.init = False # workaround bug that pyramid options widgets are not initialized at first
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdal_contour") gdalVersion = Utils.GdalConfig.versionNum() self.useDirAsOutput = gdalVersion < 1700 if self.useDirAsOutput: self.label_2.setText(QApplication.translate("GdalToolsWidget", "&Output directory for contour lines (shapefile)")) self.outSelector.setType(self.outSelector.FILE) # set the default QSpinBoxes value self.intervalDSpinBox.setValue(10.0) self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.intervalDSpinBox, "valueChanged"), (self.attributeEdit, "textChanged", self.attributeCheck) ]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BaseBatchWidget.__init__(self, self.iface, "gdal_fillnodata.py") self.inSelector.setType(self.inSelector.FILE_LAYER) self.outSelector.setType(self.outSelector.FILE) self.maskSelector.setType(self.maskSelector.FILE) self.progressBar.setValue(0) self.progressBar.hide() self.formatLabel.hide() self.formatCombo.hide() self.outputFormat = Utils.fillRasterOutputFormat() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.maskSelector, "filenameChanged", self.maskCheck), (self.distanceSpin, "valueChanged", self.distanceCheck), (self.smoothSpin, "valueChanged", self.smoothCheck), (self.bandSpin, "valueChanged", self.bandCheck), (self.nomaskCheck, "stateChanged") ]) self.inSelector.selectClicked.connect(self.fillInputFile) self.outSelector.selectClicked.connect(self.fillOutputFile) self.maskSelector.selectClicked.connect(self.fillMaskFile) self.batchCheck.stateChanged.connect(self.switchToolMode) # add raster filters to combo self.formatCombo.addItems(Utils.FileFilter.allRastersFilter().split(";;"))
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.canvas = self.iface.mapCanvas() self.algorithm = ('invdist', 'average', 'nearest', 'datametrics') self.datametrics = ('minimum', 'maximum', 'range') self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdal_grid") self.outSelector.setType(self.outSelector.FILE) self.extentSelector.setCanvas(self.canvas) #self.extentSelector.stop() # set the default QSpinBoxes and QProgressBar value self.widthSpin.setValue(3000) self.heightSpin.setValue(3000) self.invdistPowerSpin.setValue(2.0) self.outputFormat = Utils.fillRasterOutputFormat() self.lastEncoding = Utils.getLastUsedEncoding() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.zfieldCombo, "currentIndexChanged", self.zfieldCheck), (self.algorithmCombo, "currentIndexChanged", self.algorithmCheck), (self.stackedWidget, None, self.algorithmCheck), ([ self.invdistPowerSpin, self.invdistSmothingSpin, self.invdistRadius1Spin, self.invdistRadius2Spin, self.invdistAngleSpin, self.invdistNoDataSpin ], "valueChanged"), ([self.invdistMaxPointsSpin, self.invdistMinPointsSpin], "valueChanged"), ([ self.averageRadius1Spin, self.averageRadius2Spin, self.averageAngleSpin, self.averageNoDataSpin ], "valueChanged"), (self.averageMinPointsSpin, "valueChanged"), ([ self.nearestRadius1Spin, self.nearestRadius2Spin, self.nearestAngleSpin, self.nearestNoDataSpin ], "valueChanged"), (self.datametricsCombo, "currentIndexChanged"), ([ self.datametricsRadius1Spin, self.datametricsRadius2Spin, self.datametricsAngleSpin, self.datametricsNoDataSpin ], "valueChanged"), (self.datametricsMinPointsSpin, "valueChanged"), (self.extentSelector, ["selectionStarted", "newExtentDefined"], self.extentGroup), ([self.widthSpin, self.heightSpin], "valueChanged", self.resizeGroupBox) ]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.inSelector.layerChanged.connect(self.fillFieldsCombo) self.extentGroup.toggled.connect(self.onExtentCheckedChanged)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.modes = ("hillshade", "slope", "aspect", "color-relief", "TRI", "TPI", "roughness") self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdaldem") self.outSelector.setType(self.outSelector.FILE) self.configSelector.setType(self.configSelector.FILE) # set the default QSpinBoxes and QProgressBar value self.bandSpin.setValue(1) self.hillshadeZFactorSpin.setValue(1) self.hillshadeScaleSpin.setValue(1) self.hillshadeAltitudeSpin.setValue(45.0) self.hillshadeAzimuthSpin.setValue(315.0) self.slopeScaleSpin.setValue(1) # set the default color configuration file to terrain import os.path colorConfigFile = os.path.join(os.path.dirname(__file__), "terrain.txt") self.configSelector.setFilename(colorConfigFile) self.outputFormat = Utils.fillRasterOutputFormat() self.creationOptionsWidget.setFormat(self.outputFormat) self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.computeEdgesCheck, "stateChanged", None, 1800), (self.bandSpin, "valueChanged", self.bandCheck), (self.algorithmCheck, "stateChanged", None, 1800), (self.creationOptionsWidget, "optionsChanged"), (self.creationOptionsGroupBox, "toggled"), (self.modeCombo, "currentIndexChanged"), ([ self.hillshadeZFactorSpin, self.hillshadeScaleSpin, self.hillshadeAltitudeSpin, self.hillshadeAzimuthSpin ], "valueChanged"), (self.slopeScaleSpin, "valueChanged"), (self.slopePercentCheck, "stateChanged"), ([self.aspectTrigonometricCheck, self.aspectZeroForFlatCheck], "stateChanged"), (self.configSelector, "filenameChanged"), ([self.colorExactRadio, self.colorNearestRadio], "toggled", self.colorMatchGroupBox), (self.colorAlphaCheck, "stateChanged") ]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.configSelector.selectClicked.connect(self.fillColorConfigFileEdit) self.modeCombo.currentIndexChanged.connect(self.showModeParams)
def keyPressEvent(self, e): if (e.modifiers() == Qt.ControlModifier or e.modifiers() == Qt.MetaModifier) and e.key() == Qt.Key_C: items = '' for r in range(self.rasterInfoList.count()): items.append(self.rasterInfoList.item(r).text() + "\n") if items: clipboard = QApplication.clipboard() clipboard.setText(items) else: QWidget.keyPressEvent(self, e)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setupUi(self) self.table.cellChanged.connect(self.cellValueChanged) self.table.itemSelectionChanged.connect(self.enableDeleteButton) self.btnAdd.clicked.connect(self.addNewRow) self.btnDel.clicked.connect(self.deleteRow) self.btnDel.setEnabled(False)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.canvas = None self.tool = None self.previousMapTool = None self.isStarted = False self.setupUi(self) self.x1CoordEdit.textChanged.connect(self.coordsChanged) self.x2CoordEdit.textChanged.connect(self.coordsChanged) self.y1CoordEdit.textChanged.connect(self.coordsChanged) self.y2CoordEdit.textChanged.connect(self.coordsChanged) self.btnEnable.clicked.connect(self.start)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.modes = ("hillshade", "slope", "aspect", "color-relief", "TRI", "TPI", "roughness") self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdaldem") self.outSelector.setType(self.outSelector.FILE) self.configSelector.setType(self.configSelector.FILE) # set the default QSpinBoxes and QProgressBar value self.bandSpin.setValue(1) self.hillshadeZFactorSpin.setValue(1) self.hillshadeScaleSpin.setValue(1) self.hillshadeAltitudeSpin.setValue(45.0) self.hillshadeAzimuthSpin.setValue(315.0) self.slopeScaleSpin.setValue(1) # set the default color configuration file to terrain import os.path colorConfigFile = os.path.join(os.path.dirname(__file__), "terrain.txt") self.configSelector.setFilename(colorConfigFile) self.outputFormat = Utils.fillRasterOutputFormat() self.creationOptionsWidget.setFormat(self.outputFormat) self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.computeEdgesCheck, "stateChanged", None, 1800), (self.bandSpin, "valueChanged", self.bandCheck), (self.algorithmCheck, "stateChanged", None, 1800), (self.creationOptionsWidget, "optionsChanged"), (self.creationOptionsGroupBox, "toggled"), (self.modeCombo, "currentIndexChanged"), ([self.hillshadeZFactorSpin, self.hillshadeScaleSpin, self.hillshadeAltitudeSpin, self.hillshadeAzimuthSpin], "valueChanged"), (self.slopeScaleSpin, "valueChanged"), (self.slopePercentCheck, "stateChanged"), ([self.aspectTrigonometricCheck, self.aspectZeroForFlatCheck], "stateChanged"), (self.configSelector, "filenameChanged"), ([self.colorExactRadio, self.colorNearestRadio], "toggled", self.colorMatchGroupBox), (self.colorAlphaCheck, "stateChanged") ]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.configSelector.selectClicked.connect(self.fillColorConfigFileEdit) self.modeCombo.currentIndexChanged.connect(self.showModeParams)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.canvas = self.iface.mapCanvas() self.expand_method = ('gray', 'rgb', 'rgba') self.setupUi(self) BaseBatchWidget.__init__(self, self.iface, "gdal_translate") self.outSelector.setType(self.outSelector.FILE) # set the default QSpinBoxes and QProgressBar value self.outsizeSpin.setValue(25) self.progressBar.setValue(0) self.progressBar.hide() self.formatLabel.hide() self.formatCombo.hide() if Utils.GdalConfig.versionNum() < 1700: index = self.expandCombo.findText('gray', Qt.MatchFixedString) if index >= 0: self.expandCombo.removeItem(index) self.outputFormat = Utils.fillRasterOutputFormat() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.targetSRSEdit, "textChanged", self.targetSRSCheck), (self.selectTargetSRSButton, None, self.targetSRSCheck), (self.creationOptionsWidget, "optionsChanged"), (self.outsizeSpin, "valueChanged", self.outsizeCheck), (self.nodataSpin, "valueChanged", self.nodataCheck), (self.expandCombo, "currentIndexChanged", self.expandCheck, 1600), (self.sdsCheck, "stateChanged"), (self.srcwinEdit, "textChanged", self.srcwinCheck), (self.prjwinEdit, "textChanged", self.prjwinCheck) ]) #self.canvas.layersChanged.connect(self.fillInputLayerCombo) self.inSelector.layerChanged.connect(self.fillTargetSRSEditDefault) self.inSelector.selectClicked.connect(self.fillInputFile) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.selectTargetSRSButton.clicked.connect(self.fillTargetSRSEdit) self.batchCheck.stateChanged.connect(self.switchToolMode) # add raster filters to combo self.formatCombo.addItems(Utils.FileFilter.allRastersFilter().split(";;"))
def __init__(self, parent, alg): ParametersPanel.__init__(self, parent, alg) w = QWidget() layout = QVBoxLayout() layout.setMargin(0) layout.setSpacing(6) label = QLabel() label.setText(self.tr("GDAL/OGR console call")) layout.addWidget(label) self.text = QPlainTextEdit() self.text.setReadOnly(True) layout.addWidget(self.text) w.setLayout(layout) self.layoutMain.addWidget(w) self.connectParameterSignals() self.parametersHaveChanged()
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.canvas = self.iface.mapCanvas() self.algorithm = ('invdist', 'average', 'nearest', 'datametrics') self.datametrics = ('minimum', 'maximum', 'range') self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdal_grid") self.outSelector.setType(self.outSelector.FILE) self.extentSelector.setCanvas(self.canvas) #self.extentSelector.stop() # set the default QSpinBoxes and QProgressBar value self.widthSpin.setValue(3000) self.heightSpin.setValue(3000) self.invdistPowerSpin.setValue(2.0) self.outputFormat = Utils.fillRasterOutputFormat() self.lastEncoding = Utils.getLastUsedEncoding() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.zfieldCombo, "currentIndexChanged", self.zfieldCheck), (self.algorithmCombo, "currentIndexChanged", self.algorithmCheck), (self.stackedWidget, None, self.algorithmCheck), ([self.invdistPowerSpin, self.invdistSmothingSpin, self.invdistRadius1Spin, self.invdistRadius2Spin, self.invdistAngleSpin, self.invdistNoDataSpin], "valueChanged"), ([self.invdistMaxPointsSpin, self.invdistMinPointsSpin], "valueChanged"), ([self.averageRadius1Spin, self.averageRadius2Spin, self.averageAngleSpin, self.averageNoDataSpin], "valueChanged"), (self.averageMinPointsSpin, "valueChanged"), ([self.nearestRadius1Spin, self.nearestRadius2Spin, self.nearestAngleSpin, self.nearestNoDataSpin], "valueChanged"), (self.datametricsCombo, "currentIndexChanged"), ([self.datametricsRadius1Spin, self.datametricsRadius2Spin, self.datametricsAngleSpin, self.datametricsNoDataSpin], "valueChanged"), (self.datametricsMinPointsSpin, "valueChanged"), (self.extentSelector, ["selectionStarted", "newExtentDefined"], self.extentGroup), ([self.widthSpin, self.heightSpin], "valueChanged", self.resizeGroupBox) ]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.inSelector.layerChanged.connect(self.fillFieldsCombo) self.extentGroup.toggled.connect(self.onExtentCheckedChanged)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.resampling_method = ('near', 'bilinear', 'cubic', 'cubicspline', 'lanczos') self.setupUi(self) BaseBatchWidget.__init__(self, self.iface, "gdalwarp") self.outSelector.setType(self.outSelector.FILE) # set the default QSpinBoxes and QProgressBar value self.widthSpin.setValue(3000) self.heightSpin.setValue(3000) self.progressBar.setValue(0) self.progressBar.hide() self.outputFormat = Utils.fillRasterOutputFormat() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.sourceSRSEdit, "textChanged", self.sourceSRSCheck), (self.selectSourceSRSButton, None, self.sourceSRSCheck), (self.targetSRSEdit, "textChanged", self.targetSRSCheck), (self.selectTargetSRSButton, None, self.targetSRSCheck), (self.resamplingCombo, "currentIndexChanged", self.resamplingCheck), (self.cacheSpin, "valueChanged", self.cacheCheck), ([self.widthSpin, self.heightSpin], "valueChanged", self.resizeGroupBox), (self.multithreadCheck, "stateChanged"), (self.noDataEdit, "textChanged", self.noDataCheck), (self.maskSelector, "filenameChanged", self.maskCheck, 1600), ]) self.inSelector.layerChanged.connect(self.fillSourceSRSEditDefault) self.inSelector.selectClicked.connect(self.fillInputFile) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.selectSourceSRSButton.clicked.connect(self.fillSourceSRSEdit) self.selectTargetSRSButton.clicked.connect(self.fillTargetSRSEdit) self.maskSelector.selectClicked.connect(self.fillMaskFile) self.batchCheck.stateChanged.connect(self.switchToolMode)
def __init__(self, parent=None, type=None): QWidget.__init__(self, parent) self.setupUi(self) self.setFocusPolicy(Qt.StrongFocus) self.combo.setInsertPolicy(QComboBox.NoInsert) self.clear() self.typ = None if type is None: self.resetType() else: self.setType(type) self.selectBtn.clicked.connect(self.selectClicked) self.fileEdit.textChanged.connect(self.textChanged) self.combo.editTextChanged.connect(self.textChanged) self.combo.currentIndexChanged.connect(self.indexChanged)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdal_sieve.py") self.outSelector.setType(self.outSelector.FILE) self.outputFormat = Utils.fillRasterOutputFormat() self.setParamsStatus([(self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.thresholdSpin, "valueChanged", self.thresholdCheck), (self.connectionsCombo, "currentIndexChanged", self.connectionsCheck)]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit)
def __init__(self, parent=None, selectFile=False): QWidget.__init__(self, parent) # create gui self.btnSelect = QToolButton() self.btnSelect.setText(self.tr('...')) self.lineEdit = QLineEdit() self.hbl = QHBoxLayout() self.hbl.setMargin(0) self.hbl.setSpacing(0) self.hbl.addWidget(self.lineEdit) self.hbl.addWidget(self.btnSelect) self.setLayout(self.hbl) self.canFocusOut = False self.selectFile = selectFile self.setFocusPolicy(Qt.StrongFocus) self.btnSelect.clicked.connect(self.select)
def __init__(self, alg): AlgorithmDialogBase.__init__(self, alg) self.alg = alg self.mainWidget = ParametersPanel(self, alg) self.setMainWidget() self.cornerWidget = QWidget() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 5) self.tabWidget.setStyleSheet("QTabBar::tab { height: 30px; }") self.runAsBatchButton = QPushButton(self.tr("Run as batch process...")) self.runAsBatchButton.clicked.connect(self.runAsBatch) layout.addWidget(self.runAsBatchButton) self.cornerWidget.setLayout(layout) self.tabWidget.setCornerWidget(self.cornerWidget) QgsMapLayerRegistry.instance().layerWasAdded.connect(self.mainWidget.layerAdded) QgsMapLayerRegistry.instance().layersWillBeRemoved.connect(self.mainWidget.layersWillBeRemoved)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdaltindex") self.inSelector.setType(self.inSelector.FILE) self.outSelector.setType(self.outSelector.FILE) self.setParamsStatus([ (self.inSelector, "filenameChanged"), #( self.recurseCheck, "stateChanged" ), (self.outSelector, "filenameChanged"), (self.indexFieldEdit, "textChanged", self.indexFieldCheck), (self.skipDifferentProjCheck, "stateChanged", None, 1500) ]) self.inSelector.selectClicked.connect(self.fillInputDirEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit)
def __init__(self, alg): AlgorithmDialogBase.__init__(self, alg) self.alg = alg self.mainWidget = ParametersPanel(self, alg) self.setMainWidget() cornerWidget = QWidget() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 5) self.tabWidget.setStyleSheet("QTabBar::tab { height: 30px; }") runAsBatchButton = QPushButton(self.tr("Run as batch process...")) runAsBatchButton.clicked.connect(self.runAsBatch) layout.addWidget(runAsBatchButton) cornerWidget.setLayout(layout) self.tabWidget.setCornerWidget(cornerWidget) QgsMapLayerRegistry.instance().layerWasAdded.connect(self.mainWidget.layerAdded) QgsMapLayerRegistry.instance().layersWillBeRemoved.connect(self.mainWidget.layersWillBeRemoved)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "nearblack") self.outSelector.setType(self.outSelector.FILE) # set the default QSpinBoxes value self.nearSpin.setValue(15) self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.nearSpin, "valueChanged", self.nearCheck), (self.whiteCheckBox, "stateChanged") ]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.resolutions = ("highest", "average", "lowest") self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdal_polygonize.py") self.outSelector.setType(self.outSelector.FILE) self.outputFormat = Utils.fillVectorOutputFormat() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.maskSelector, "filenameChanged", self.maskCheck), (self.fieldEdit, "textChanged", self.fieldCheck) ]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.maskSelector.selectClicked.connect(self.fillMaskFileEdit)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdal_sieve.py") self.outSelector.setType(self.outSelector.FILE) self.outputFormat = Utils.fillRasterOutputFormat() self.setParamsStatus( [ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.thresholdSpin, "valueChanged", self.thresholdCheck), (self.connectionsCombo, "currentIndexChanged", self.connectionsCheck), ] ) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdal_proximity.py") self.outSelector.setType(self.outSelector.FILE) self.outputFormat = Utils.fillRasterOutputFormat() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.valuesEdit, "textChanged", self.valuesCheck), (self.distUnitsCombo, "currentIndexChanged", self.distUnitsCheck), (self.maxDistSpin, "valueChanged", self.maxDistCheck), (self.noDataSpin, "valueChanged", self.noDataCheck), (self.fixedBufValSpin, "valueChanged", self.fixedBufValCheck) ]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdal_proximity.py") self.outSelector.setType(self.outSelector.FILE) self.outputFormat = Utils.fillRasterOutputFormat() self.setParamsStatus( [ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.valuesEdit, "textChanged", self.valuesCheck), (self.distUnitsCombo, "currentIndexChanged", self.distUnitsCheck), (self.maxDistSpin, "valueChanged", self.maxDistCheck), (self.noDataSpin, "valueChanged", self.noDataCheck), (self.fixedBufValSpin, "valueChanged", self.fixedBufValCheck), ] ) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BaseBatchWidget.__init__(self, self.iface, "gdal_fillnodata.py") self.inSelector.setType(self.inSelector.FILE_LAYER) self.outSelector.setType(self.outSelector.FILE) self.maskSelector.setType(self.maskSelector.FILE) self.progressBar.setValue(0) self.progressBar.hide() self.formatLabel.hide() self.formatCombo.hide() self.outputFormat = Utils.fillRasterOutputFormat() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.maskSelector, "filenameChanged", self.maskCheck), (self.distanceSpin, "valueChanged", self.distanceCheck), (self.smoothSpin, "valueChanged", self.smoothCheck), (self.bandSpin, "valueChanged", self.bandCheck), (self.nomaskCheck, "stateChanged") ]) self.inSelector.selectClicked.connect(self.fillInputFile) self.outSelector.selectClicked.connect(self.fillOutputFile) self.maskSelector.selectClicked.connect(self.fillMaskFile) self.batchCheck.stateChanged.connect(self.switchToolMode) # add raster filters to combo self.formatCombo.addItems( Utils.FileFilter.allRastersFilter().split(";;"))
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.setupUi(self) BaseBatchWidget.__init__(self, self.iface, "gdalwarp") self.inSelector.setType(self.inSelector.FILE) # set the default QSpinBoxes and QProgressBar value self.progressBar.setValue(0) self.progressBar.hide() self.recurseCheck.hide() self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.desiredSRSEdit, "textChanged") ]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.selectDesiredSRSButton.clicked.connect(self.fillDesiredSRSEdit) self.batchCheck.stateChanged.connect(self.switchToolMode) self.recurseCheck.stateChanged.connect(self.enableRecurse)
def __init__(self, iface): QWidget.__init__(self) self.iface = iface self.canvas = self.iface.mapCanvas() self.setupUi(self) BasePluginWidget.__init__(self, self.iface, "gdal_translate") self.outSelector.setType(self.outSelector.FILE) self.extentSelector.setCanvas(self.canvas) self.outputFormat = Utils.fillRasterOutputFormat() # set the default QDoubleSpinBoxes self.xRes.setValue(12.5) self.yRes.setValue(12.5) self.setParamsStatus([ (self.inSelector, "filenameChanged"), (self.outSelector, "filenameChanged"), (self.noDataSpin, "valueChanged", self.noDataCheck, 1700), (self.maskSelector, "filenameChanged", self.maskModeRadio, 1600), (self.alphaBandCheck, "stateChanged"), (self.cropToCutlineCheck, "stateChanged"), ([self.xRes, self.yRes], "valueChanged", self.setResolutionRadio), (self.extentSelector, ["selectionStarted", "newExtentDefined"], self.extentModeRadio), (self.modeStackedWidget, "currentChanged") ]) self.inSelector.selectClicked.connect(self.fillInputFileEdit) self.outSelector.selectClicked.connect(self.fillOutputFileEdit) self.maskSelector.selectClicked.connect(self.fillMaskFileEdit) self.extentSelector.newExtentDefined.connect(self.extentChanged) self.extentSelector.selectionStarted.connect(self.checkRun) self.extentModeRadio.toggled.connect(self.switchClippingMode) self.keepResolutionRadio.toggled.connect(self.switchResolutionMode)
def getQgisTestApp(): """ Start one QGis application to test agaist Input NIL Output handle to qgis app If QGis is already running the handle to that app will be returned """ global QGISAPP # pylint: disable=W0603 if QGISAPP is None: myGuiFlag = True # All test will run qgis in gui mode # In python3 we need to conver to a bytes object (or should # QgsApplication accept a QString instead of const char* ?) try: argvb = list(map(os.fsencode, sys.argv)) except AttributeError: argvb = sys.argv # Note: QGIS_PREFIX_PATH is evaluated in QgsApplication - # no need to mess with it here. QGISAPP = QgsApplication(argvb, myGuiFlag) QGISAPP.initQgis() s = QGISAPP.showSettings() print(s) global PARENT # pylint: disable=W0603 if PARENT is None: PARENT = QWidget() global CANVAS # pylint: disable=W0603 if CANVAS is None: CANVAS = QgsMapCanvas(PARENT) CANVAS.resize(QSize(400, 400)) global IFACE # pylint: disable=W0603 if IFACE is None: # QgisInterface is a stub implementation of the QGIS plugin interface IFACE = QgisInterface(CANVAS) return QGISAPP, CANVAS, IFACE, PARENT
def createWrapper(self, layer, filter=None): """ Basic setup of a relation widget wrapper. Will create a new wrapper and set its feature to the one and only book in the table. It will also assign some instance variables to help * self.widget The created widget * self.table_view The table view of the widget :return: The created wrapper """ if layer == self.vl_b: relation = self.rel_b nmrel = self.rel_a else: relation = self.rel_a nmrel = self.rel_b parent = QWidget() self.wrapper = QgsRelationWidgetWrapper(layer, relation) self.wrapper.setConfig({'nm-rel': nmrel.id()}) context = QgsAttributeEditorContext() context.setVectorLayerTools(self.vltools) self.wrapper.setContext(context) self.widget = self.wrapper.widget() self.widget.show() request = QgsFeatureRequest() if filter: request.setFilterExpression(filter) book = layer.getFeatures(request).next() self.wrapper.setFeature(book) self.table_view = self.widget.findChild(QTableView) return self.wrapper
def initWidgets(self): #tooltips = self.alg.getParameterDescriptions() # If there are advanced parameters — show corresponding groupbox for param in self.alg.parameters: if param.isAdvanced: self.grpAdvanced.show() break # Create widgets and put them in layouts for param in self.alg.parameters: if param.hidden: continue desc = param.description if isinstance(param, ParameterExtent): desc += self.tr(' (xmin, xmax, ymin, ymax)') if isinstance(param, ParameterPoint): desc += self.tr(' (x, y)') try: if param.optional: desc += self.tr(' [optional]') except: pass widget = self.getWidgetFromParameter(param) self.valueItems[param.name] = widget if isinstance(param, ParameterVector) and \ not self.alg.allowOnlyOpenedLayers: layout = QHBoxLayout() layout.setSpacing(2) layout.setMargin(0) layout.addWidget(widget) button = QToolButton() icon = QIcon(os.path.join(pluginPath, 'images', 'iterate.png')) button.setIcon(icon) button.setToolTip(self.tr('Iterate over this layer')) button.setCheckable(True) layout.addWidget(button) self.iterateButtons[param.name] = button button.toggled.connect(self.buttonToggled) widget = QWidget() widget.setLayout(layout) #~ if param.name in tooltips.keys(): #~ tooltip = tooltips[param.name] #~ else: #~ tooltip = param.description #~ widget.setToolTip(tooltip) if isinstance(param, ParameterBoolean): widget.setText(desc) if param.isAdvanced: self.layoutAdvanced.addWidget(widget) else: self.layoutMain.insertWidget( self.layoutMain.count() - 2, widget) else: label = QLabel(desc) #label.setToolTip(tooltip) self.labels[param.name] = label if param.isAdvanced: self.layoutAdvanced.addWidget(label) self.layoutAdvanced.addWidget(widget) else: self.layoutMain.insertWidget( self.layoutMain.count() - 2, label) self.layoutMain.insertWidget( self.layoutMain.count() - 2, widget) self.widgets[param.name] = widget for output in self.alg.outputs: if output.hidden: continue label = QLabel(output.description) widget = OutputSelectionPanel(output, self.alg) self.layoutMain.insertWidget(self.layoutMain.count() - 1, label) self.layoutMain.insertWidget(self.layoutMain.count() - 1, widget) if isinstance(output, (OutputRaster, OutputVector, OutputTable)): check = QCheckBox() check.setText(self.tr('Open output file after running algorithm')) check.setChecked(True) self.layoutMain.insertWidget(self.layoutMain.count() - 1, check) self.checkBoxes[output.name] = check self.valueItems[output.name] = widget
def setupUi(self): self.labels = {} self.widgets = {} self.checkBoxes = {} self.showAdvanced = False self.valueItems = {} self.dependentItems = {} self.resize(650, 450) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) tooltips = self._alg.getParameterDescriptions() self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.verticalLayout = QVBoxLayout() self.verticalLayout.setSpacing(5) self.verticalLayout.setMargin(20) hLayout = QHBoxLayout() hLayout.setSpacing(5) hLayout.setMargin(0) descriptionLabel = QLabel(self.tr("Description")) self.descriptionBox = QLineEdit() self.descriptionBox.setText(self._alg.name) hLayout.addWidget(descriptionLabel) hLayout.addWidget(self.descriptionBox) self.verticalLayout.addLayout(hLayout) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) self.verticalLayout.addWidget(line) for param in self._alg.parameters: if param.isAdvanced: self.advancedButton = QPushButton() self.advancedButton.setText( self.tr('Show advanced parameters')) self.advancedButton.clicked.connect( self.showAdvancedParametersClicked) advancedButtonHLayout = QHBoxLayout() advancedButtonHLayout.addWidget(self.advancedButton) advancedButtonHLayout.addStretch() self.verticalLayout.addLayout(advancedButtonHLayout) break for param in self._alg.parameters: if param.hidden: continue desc = param.description if isinstance(param, ParameterExtent): desc += self.tr('(xmin, xmax, ymin, ymax)') if isinstance(param, ParameterPoint): desc += self.tr('(x, y)') label = QLabel(desc) self.labels[param.name] = label widget = self.getWidgetFromParameter(param) self.valueItems[param.name] = widget if param.name in tooltips.keys(): tooltip = tooltips[param.name] else: tooltip = param.description label.setToolTip(tooltip) widget.setToolTip(tooltip) if param.isAdvanced: label.setVisible(self.showAdvanced) widget.setVisible(self.showAdvanced) self.widgets[param.name] = widget self.verticalLayout.addWidget(label) self.verticalLayout.addWidget(widget) for output in self._alg.outputs: if output.hidden: continue if isinstance(output, (OutputRaster, OutputVector, OutputTable, OutputHTML, OutputFile, OutputDirectory)): label = QLabel(output.description + '<' + output.__class__.__name__ + '>') item = QLineEdit() if hasattr(item, 'setPlaceholderText'): item.setPlaceholderText(ModelerParametersDialog.ENTER_NAME) self.verticalLayout.addWidget(label) self.verticalLayout.addWidget(item) self.valueItems[output.name] = item label = QLabel(' ') self.verticalLayout.addWidget(label) label = QLabel(self.tr('Parent algorithms')) self.dependenciesPanel = self.getDependenciesPanel() self.verticalLayout.addWidget(label) self.verticalLayout.addWidget(self.dependenciesPanel) self.verticalLayout.addStretch(1000) self.setLayout(self.verticalLayout) self.setPreviousValues() self.setWindowTitle(self._alg.name) self.verticalLayout2 = QVBoxLayout() self.verticalLayout2.setSpacing(2) self.verticalLayout2.setMargin(0) self.tabWidget = QTabWidget() self.tabWidget.setMinimumWidth(300) self.paramPanel = QWidget() self.paramPanel.setLayout(self.verticalLayout) self.scrollArea = QScrollArea() self.scrollArea.setWidget(self.paramPanel) self.scrollArea.setWidgetResizable(True) self.tabWidget.addTab(self.scrollArea, self.tr('Parameters')) self.webView = QWebView() html = None url = None isText, help = self._alg.help() if help is not None: if isText: html = help else: url = QUrl(help) else: html = self.tr('<h2>Sorry, no help is available for this ' 'algorithm.</h2>') try: if html: self.webView.setHtml(html) elif url: self.webView.load(url) except: self.webView.setHtml( self.tr('<h2>Could not open help file :-( </h2>')) self.tabWidget.addTab(self.webView, 'Help') self.verticalLayout2.addWidget(self.tabWidget) self.verticalLayout2.addWidget(self.buttonBox) self.setLayout(self.verticalLayout2) self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) QMetaObject.connectSlotsByName(self)
class PythonConsoleWidget(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console")) self.settings = QSettings() self.shell = ShellScintilla(self) self.setFocusProxy(self.shell) self.shellOut = ShellOutputScintilla(self) self.tabEditorWidget = EditorTabWidget(self) ##------------ UI ------------------------------- self.splitterEditor = QSplitter(self) self.splitterEditor.setOrientation(Qt.Horizontal) self.splitterEditor.setHandleWidth(6) self.splitterEditor.setChildrenCollapsible(True) self.shellOutWidget = QWidget(self) self.shellOutWidget.setLayout(QVBoxLayout()) self.shellOutWidget.layout().setContentsMargins(0, 0, 0, 0) self.shellOutWidget.layout().addWidget(self.shellOut) self.splitter = QSplitter(self.splitterEditor) self.splitter.setOrientation(Qt.Vertical) self.splitter.setHandleWidth(3) self.splitter.setChildrenCollapsible(False) self.splitter.addWidget(self.shellOutWidget) self.splitter.addWidget(self.shell) #self.splitterEditor.addWidget(self.tabEditorWidget) self.splitterObj = QSplitter(self.splitterEditor) self.splitterObj.setHandleWidth(3) self.splitterObj.setOrientation(Qt.Horizontal) #self.splitterObj.setSizes([0, 0]) #self.splitterObj.setStretchFactor(0, 1) self.widgetEditor = QWidget(self.splitterObj) self.widgetFind = QWidget(self) self.listClassMethod = QTreeWidget(self.splitterObj) self.listClassMethod.setColumnCount(2) objInspLabel = QCoreApplication.translate("PythonConsole", "Object Inspector") self.listClassMethod.setHeaderLabels([objInspLabel, '']) self.listClassMethod.setColumnHidden(1, True) self.listClassMethod.setAlternatingRowColors(True) #self.splitterEditor.addWidget(self.widgetEditor) #self.splitterObj.addWidget(self.listClassMethod) #self.splitterObj.addWidget(self.widgetEditor) # Hide side editor on start up self.splitterObj.hide() self.listClassMethod.hide() # Hide search widget on start up self.widgetFind.hide() sizes = self.splitter.sizes() self.splitter.setSizes(sizes) ##----------------Restore Settings------------------------------------ self.restoreSettingsConsole() ##------------------Toolbar Editor------------------------------------- ## Action for Open File openFileBt = QCoreApplication.translate("PythonConsole", "Open Script...") self.openFileButton = QAction(self) self.openFileButton.setCheckable(False) self.openFileButton.setEnabled(True) self.openFileButton.setIcon(QgsApplication.getThemeIcon("console/iconOpenConsole.png")) self.openFileButton.setMenuRole(QAction.PreferencesRole) self.openFileButton.setIconVisibleInMenu(True) self.openFileButton.setToolTip(openFileBt) self.openFileButton.setText(openFileBt) openExtEditorBt = QCoreApplication.translate("PythonConsole", "Open in External Editor") self.openInEditorButton = QAction(self) self.openInEditorButton.setCheckable(False) self.openInEditorButton.setEnabled(True) self.openInEditorButton.setIcon(QgsApplication.getThemeIcon("console/iconShowEditorConsole.png")) self.openInEditorButton.setMenuRole(QAction.PreferencesRole) self.openInEditorButton.setIconVisibleInMenu(True) self.openInEditorButton.setToolTip(openExtEditorBt) self.openInEditorButton.setText(openExtEditorBt) ## Action for Save File saveFileBt = QCoreApplication.translate("PythonConsole", "Save") self.saveFileButton = QAction(self) self.saveFileButton.setCheckable(False) self.saveFileButton.setEnabled(False) self.saveFileButton.setIcon(QgsApplication.getThemeIcon("console/iconSaveConsole.png")) self.saveFileButton.setMenuRole(QAction.PreferencesRole) self.saveFileButton.setIconVisibleInMenu(True) self.saveFileButton.setToolTip(saveFileBt) self.saveFileButton.setText(saveFileBt) ## Action for Save File As saveAsFileBt = QCoreApplication.translate("PythonConsole", "Save As...") self.saveAsFileButton = QAction(self) self.saveAsFileButton.setCheckable(False) self.saveAsFileButton.setEnabled(True) self.saveAsFileButton.setIcon(QgsApplication.getThemeIcon("console/iconSaveAsConsole.png")) self.saveAsFileButton.setMenuRole(QAction.PreferencesRole) self.saveAsFileButton.setIconVisibleInMenu(True) self.saveAsFileButton.setToolTip(saveAsFileBt) self.saveAsFileButton.setText(saveAsFileBt) ## Action Cut cutEditorBt = QCoreApplication.translate("PythonConsole", "Cut") self.cutEditorButton = QAction(self) self.cutEditorButton.setCheckable(False) self.cutEditorButton.setEnabled(True) self.cutEditorButton.setIcon(QgsApplication.getThemeIcon("mActionEditCut.png")) self.cutEditorButton.setMenuRole(QAction.PreferencesRole) self.cutEditorButton.setIconVisibleInMenu(True) self.cutEditorButton.setToolTip(cutEditorBt) self.cutEditorButton.setText(cutEditorBt) ## Action Copy copyEditorBt = QCoreApplication.translate("PythonConsole", "Copy") self.copyEditorButton = QAction(self) self.copyEditorButton.setCheckable(False) self.copyEditorButton.setEnabled(True) self.copyEditorButton.setIcon(QgsApplication.getThemeIcon("mActionEditCopy.png")) self.copyEditorButton.setMenuRole(QAction.PreferencesRole) self.copyEditorButton.setIconVisibleInMenu(True) self.copyEditorButton.setToolTip(copyEditorBt) self.copyEditorButton.setText(copyEditorBt) ## Action Paste pasteEditorBt = QCoreApplication.translate("PythonConsole", "Paste") self.pasteEditorButton = QAction(self) self.pasteEditorButton.setCheckable(False) self.pasteEditorButton.setEnabled(True) self.pasteEditorButton.setIcon(QgsApplication.getThemeIcon("mActionEditPaste.png")) self.pasteEditorButton.setMenuRole(QAction.PreferencesRole) self.pasteEditorButton.setIconVisibleInMenu(True) self.pasteEditorButton.setToolTip(pasteEditorBt) self.pasteEditorButton.setText(pasteEditorBt) ## Action Run Script (subprocess) runScriptEditorBt = QCoreApplication.translate("PythonConsole", "Run script") self.runScriptEditorButton = QAction(self) self.runScriptEditorButton.setCheckable(False) self.runScriptEditorButton.setEnabled(True) self.runScriptEditorButton.setIcon(QgsApplication.getThemeIcon("console/iconRunScriptConsole.png")) self.runScriptEditorButton.setMenuRole(QAction.PreferencesRole) self.runScriptEditorButton.setIconVisibleInMenu(True) self.runScriptEditorButton.setToolTip(runScriptEditorBt) self.runScriptEditorButton.setText(runScriptEditorBt) ## Action Run Script (subprocess) commentEditorBt = QCoreApplication.translate("PythonConsole", "Comment") self.commentEditorButton = QAction(self) self.commentEditorButton.setCheckable(False) self.commentEditorButton.setEnabled(True) self.commentEditorButton.setIcon(QgsApplication.getThemeIcon("console/iconCommentEditorConsole.png")) self.commentEditorButton.setMenuRole(QAction.PreferencesRole) self.commentEditorButton.setIconVisibleInMenu(True) self.commentEditorButton.setToolTip(commentEditorBt) self.commentEditorButton.setText(commentEditorBt) ## Action Run Script (subprocess) uncommentEditorBt = QCoreApplication.translate("PythonConsole", "Uncomment") self.uncommentEditorButton = QAction(self) self.uncommentEditorButton.setCheckable(False) self.uncommentEditorButton.setEnabled(True) self.uncommentEditorButton.setIcon(QgsApplication.getThemeIcon("console/iconUncommentEditorConsole.png")) self.uncommentEditorButton.setMenuRole(QAction.PreferencesRole) self.uncommentEditorButton.setIconVisibleInMenu(True) self.uncommentEditorButton.setToolTip(uncommentEditorBt) self.uncommentEditorButton.setText(uncommentEditorBt) ## Action for Object browser objList = QCoreApplication.translate("PythonConsole", "Object Inspector...") self.objectListButton = QAction(self) self.objectListButton.setCheckable(True) self.objectListButton.setEnabled(self.settings.value("pythonConsole/enableObjectInsp", False, type=bool)) self.objectListButton.setIcon(QgsApplication.getThemeIcon("console/iconClassBrowserConsole.png")) self.objectListButton.setMenuRole(QAction.PreferencesRole) self.objectListButton.setIconVisibleInMenu(True) self.objectListButton.setToolTip(objList) self.objectListButton.setText(objList) ## Action for Find text findText = QCoreApplication.translate("PythonConsole", "Find Text") self.findTextButton = QAction(self) self.findTextButton.setCheckable(True) self.findTextButton.setEnabled(True) self.findTextButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchEditorConsole.png")) self.findTextButton.setMenuRole(QAction.PreferencesRole) self.findTextButton.setIconVisibleInMenu(True) self.findTextButton.setToolTip(findText) self.findTextButton.setText(findText) ##----------------Toolbar Console------------------------------------- ## Action Show Editor showEditor = QCoreApplication.translate("PythonConsole", "Show Editor") self.showEditorButton = QAction(self) self.showEditorButton.setEnabled(True) self.showEditorButton.setCheckable(True) self.showEditorButton.setIcon(QgsApplication.getThemeIcon("console/iconShowEditorConsole.png")) self.showEditorButton.setMenuRole(QAction.PreferencesRole) self.showEditorButton.setIconVisibleInMenu(True) self.showEditorButton.setToolTip(showEditor) self.showEditorButton.setText(showEditor) ## Action for Clear button clearBt = QCoreApplication.translate("PythonConsole", "Clear Console") self.clearButton = QAction(self) self.clearButton.setCheckable(False) self.clearButton.setEnabled(True) self.clearButton.setIcon(QgsApplication.getThemeIcon("console/iconClearConsole.png")) self.clearButton.setMenuRole(QAction.PreferencesRole) self.clearButton.setIconVisibleInMenu(True) self.clearButton.setToolTip(clearBt) self.clearButton.setText(clearBt) ## Action for settings optionsBt = QCoreApplication.translate("PythonConsole", "Options...") self.optionsButton = QAction(self) self.optionsButton.setCheckable(False) self.optionsButton.setEnabled(True) self.optionsButton.setIcon(QgsApplication.getThemeIcon("console/iconSettingsConsole.png")) self.optionsButton.setMenuRole(QAction.PreferencesRole) self.optionsButton.setIconVisibleInMenu(True) self.optionsButton.setToolTip(optionsBt) self.optionsButton.setText(optionsBt) ## Action menu for class actionClassBt = QCoreApplication.translate("PythonConsole", "Import Class") self.actionClass = QAction(self) self.actionClass.setCheckable(False) self.actionClass.setEnabled(True) self.actionClass.setIcon(QgsApplication.getThemeIcon("console/iconClassConsole.png")) self.actionClass.setMenuRole(QAction.PreferencesRole) self.actionClass.setIconVisibleInMenu(True) self.actionClass.setToolTip(actionClassBt) self.actionClass.setText(actionClassBt) ## Import Processing class loadProcessingBt = QCoreApplication.translate("PythonConsole", "Import Processing Class") self.loadProcessingButton = QAction(self) self.loadProcessingButton.setCheckable(False) self.loadProcessingButton.setEnabled(True) self.loadProcessingButton.setIcon(QgsApplication.getThemeIcon("console/iconProcessingConsole.png")) self.loadProcessingButton.setMenuRole(QAction.PreferencesRole) self.loadProcessingButton.setIconVisibleInMenu(True) self.loadProcessingButton.setToolTip(loadProcessingBt) self.loadProcessingButton.setText(loadProcessingBt) ## Import QtCore class loadQtCoreBt = QCoreApplication.translate("PythonConsole", "Import PyQt.QtCore Class") self.loadQtCoreButton = QAction(self) self.loadQtCoreButton.setCheckable(False) self.loadQtCoreButton.setEnabled(True) self.loadQtCoreButton.setIcon(QgsApplication.getThemeIcon("console/iconQtCoreConsole.png")) self.loadQtCoreButton.setMenuRole(QAction.PreferencesRole) self.loadQtCoreButton.setIconVisibleInMenu(True) self.loadQtCoreButton.setToolTip(loadQtCoreBt) self.loadQtCoreButton.setText(loadQtCoreBt) ## Import QtGui class loadQtGuiBt = QCoreApplication.translate("PythonConsole", "Import PyQt.QtGui Class") self.loadQtGuiButton = QAction(self) self.loadQtGuiButton.setCheckable(False) self.loadQtGuiButton.setEnabled(True) self.loadQtGuiButton.setIcon(QgsApplication.getThemeIcon("console/iconQtGuiConsole.png")) self.loadQtGuiButton.setMenuRole(QAction.PreferencesRole) self.loadQtGuiButton.setIconVisibleInMenu(True) self.loadQtGuiButton.setToolTip(loadQtGuiBt) self.loadQtGuiButton.setText(loadQtGuiBt) ## Action for Run script runBt = QCoreApplication.translate("PythonConsole", "Run Command") self.runButton = QAction(self) self.runButton.setCheckable(False) self.runButton.setEnabled(True) self.runButton.setIcon(QgsApplication.getThemeIcon("console/iconRunConsole.png")) self.runButton.setMenuRole(QAction.PreferencesRole) self.runButton.setIconVisibleInMenu(True) self.runButton.setToolTip(runBt) self.runButton.setText(runBt) ## Help action helpBt = QCoreApplication.translate("PythonConsole", "Help...") self.helpButton = QAction(self) self.helpButton.setCheckable(False) self.helpButton.setEnabled(True) self.helpButton.setIcon(QgsApplication.getThemeIcon("console/iconHelpConsole.png")) self.helpButton.setMenuRole(QAction.PreferencesRole) self.helpButton.setIconVisibleInMenu(True) self.helpButton.setToolTip(helpBt) self.helpButton.setText(helpBt) self.toolBar = QToolBar() self.toolBar.setEnabled(True) self.toolBar.setFocusPolicy(Qt.NoFocus) self.toolBar.setContextMenuPolicy(Qt.DefaultContextMenu) self.toolBar.setLayoutDirection(Qt.LeftToRight) self.toolBar.setIconSize(QSize(16, 16)) self.toolBar.setMovable(False) self.toolBar.setFloatable(False) self.toolBar.addAction(self.clearButton) self.toolBar.addAction(self.actionClass) self.toolBar.addAction(self.runButton) self.toolBar.addSeparator() self.toolBar.addAction(self.showEditorButton) self.toolBar.addSeparator() self.toolBar.addAction(self.optionsButton) self.toolBar.addAction(self.helpButton) self.toolBarEditor = QToolBar() self.toolBarEditor.setEnabled(False) self.toolBarEditor.setFocusPolicy(Qt.NoFocus) self.toolBarEditor.setContextMenuPolicy(Qt.DefaultContextMenu) self.toolBarEditor.setLayoutDirection(Qt.LeftToRight) self.toolBarEditor.setIconSize(QSize(16, 16)) self.toolBarEditor.setMovable(False) self.toolBarEditor.setFloatable(False) self.toolBarEditor.addAction(self.openFileButton) self.toolBarEditor.addAction(self.openInEditorButton) self.toolBarEditor.addSeparator() self.toolBarEditor.addAction(self.saveFileButton) self.toolBarEditor.addAction(self.saveAsFileButton) self.toolBarEditor.addSeparator() self.toolBarEditor.addAction(self.runScriptEditorButton) self.toolBarEditor.addSeparator() self.toolBarEditor.addAction(self.findTextButton) self.toolBarEditor.addSeparator() self.toolBarEditor.addAction(self.cutEditorButton) self.toolBarEditor.addAction(self.copyEditorButton) self.toolBarEditor.addAction(self.pasteEditorButton) self.toolBarEditor.addSeparator() self.toolBarEditor.addAction(self.commentEditorButton) self.toolBarEditor.addAction(self.uncommentEditorButton) self.toolBarEditor.addSeparator() self.toolBarEditor.addAction(self.objectListButton) ## Menu Import Class self.classMenu = QMenu() self.classMenu.addAction(self.loadProcessingButton) self.classMenu.addAction(self.loadQtCoreButton) self.classMenu.addAction(self.loadQtGuiButton) cM = self.toolBar.widgetForAction(self.actionClass) cM.setMenu(self.classMenu) cM.setPopupMode(QToolButton.InstantPopup) self.widgetButton = QWidget() sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.widgetButton.sizePolicy().hasHeightForWidth()) self.widgetButton.setSizePolicy(sizePolicy) self.widgetButtonEditor = QWidget(self.widgetEditor) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.widgetButtonEditor.sizePolicy().hasHeightForWidth()) self.widgetButtonEditor.setSizePolicy(sizePolicy) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.shellOut.sizePolicy().hasHeightForWidth()) self.shellOut.setSizePolicy(sizePolicy) self.shellOut.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.shell.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) ##------------ Layout ------------------------------- self.mainLayout = QGridLayout(self) self.mainLayout.setMargin(0) self.mainLayout.setSpacing(0) self.mainLayout.addWidget(self.widgetButton, 0, 0, 1, 1) self.mainLayout.addWidget(self.splitterEditor, 0, 1, 1, 1) self.shellOutWidget.layout().insertWidget(0, self.toolBar) self.layoutEditor = QGridLayout(self.widgetEditor) self.layoutEditor.setMargin(0) self.layoutEditor.setSpacing(0) self.layoutEditor.addWidget(self.toolBarEditor, 0, 1, 1, 1) self.layoutEditor.addWidget(self.widgetButtonEditor, 1, 0, 2, 1) self.layoutEditor.addWidget(self.tabEditorWidget, 1, 1, 1, 1) self.layoutEditor.addWidget(self.widgetFind, 2, 1, 1, 1) ## Layout for the find widget self.layoutFind = QGridLayout(self.widgetFind) self.layoutFind.setContentsMargins(0, 0, 0, 0) self.lineEditFind = QgsFilterLineEdit() placeHolderTxt = QCoreApplication.translate("PythonConsole", "Enter text to find...") self.lineEditFind.setPlaceholderText(placeHolderTxt) self.findNextButton = QToolButton() self.findNextButton.setEnabled(False) toolTipfindNext = QCoreApplication.translate("PythonConsole", "Find Next") self.findNextButton.setToolTip(toolTipfindNext) self.findNextButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchNextEditorConsole.png")) self.findNextButton.setIconSize(QSize(24, 24)) self.findNextButton.setAutoRaise(True) self.findPrevButton = QToolButton() self.findPrevButton.setEnabled(False) toolTipfindPrev = QCoreApplication.translate("PythonConsole", "Find Previous") self.findPrevButton.setToolTip(toolTipfindPrev) self.findPrevButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchPrevEditorConsole.png")) self.findPrevButton.setIconSize(QSize(24, 24)) self.findPrevButton.setAutoRaise(True) self.caseSensitive = QCheckBox() caseSensTr = QCoreApplication.translate("PythonConsole", "Case Sensitive") self.caseSensitive.setText(caseSensTr) self.wholeWord = QCheckBox() wholeWordTr = QCoreApplication.translate("PythonConsole", "Whole Word") self.wholeWord.setText(wholeWordTr) self.wrapAround = QCheckBox() self.wrapAround.setChecked(True) wrapAroundTr = QCoreApplication.translate("PythonConsole", "Wrap Around") self.wrapAround.setText(wrapAroundTr) self.layoutFind.addWidget(self.lineEditFind, 0, 1, 1, 1) self.layoutFind.addWidget(self.findPrevButton, 0, 2, 1, 1) self.layoutFind.addWidget(self.findNextButton, 0, 3, 1, 1) self.layoutFind.addWidget(self.caseSensitive, 0, 4, 1, 1) self.layoutFind.addWidget(self.wholeWord, 0, 5, 1, 1) self.layoutFind.addWidget(self.wrapAround, 0, 6, 1, 1) ##------------ Add first Tab in Editor ------------------------------- #self.tabEditorWidget.newTabEditor(tabName='first', filename=None) ##------------ Signal ------------------------------- self.findTextButton.toggled.connect(self.findTextEditor) self.objectListButton.toggled.connect(self.toggleObjectListWidget) self.commentEditorButton.triggered.connect(self.commentCode) self.uncommentEditorButton.triggered.connect(self.uncommentCode) self.runScriptEditorButton.triggered.connect(self.runScriptEditor) self.cutEditorButton.triggered.connect(self.cutEditor) self.copyEditorButton.triggered.connect(self.copyEditor) self.pasteEditorButton.triggered.connect(self.pasteEditor) self.showEditorButton.toggled.connect(self.toggleEditor) self.clearButton.triggered.connect(self.shellOut.clearConsole) self.optionsButton.triggered.connect(self.openSettings) self.loadProcessingButton.triggered.connect(self.processing) self.loadQtCoreButton.triggered.connect(self.qtCore) self.loadQtGuiButton.triggered.connect(self.qtGui) self.runButton.triggered.connect(self.shell.entered) self.openFileButton.triggered.connect(self.openScriptFile) self.openInEditorButton.triggered.connect(self.openScriptFileExtEditor) self.saveFileButton.triggered.connect(self.saveScriptFile) self.saveAsFileButton.triggered.connect(self.saveAsScriptFile) self.helpButton.triggered.connect(self.openHelp) self.listClassMethod.itemClicked.connect(self.onClickGoToLine) self.lineEditFind.returnPressed.connect(self._findText) self.findNextButton.clicked.connect(self._findNext) self.findPrevButton.clicked.connect(self._findPrev) self.lineEditFind.textChanged.connect(self._textFindChanged) def _findText(self): self.tabEditorWidget.currentWidget().newEditor.findText(True) def _findNext(self): self.tabEditorWidget.currentWidget().newEditor.findText(True) def _findPrev(self): self.tabEditorWidget.currentWidget().newEditor.findText(False) def _textFindChanged(self): if self.lineEditFind.text(): self.findNextButton.setEnabled(True) self.findPrevButton.setEnabled(True) else: self.lineEditFind.setStyleSheet('') self.findNextButton.setEnabled(False) self.findPrevButton.setEnabled(False) def onClickGoToLine(self, item, column): tabEditor = self.tabEditorWidget.currentWidget().newEditor if item.text(1) == 'syntaxError': check = tabEditor.syntaxCheck(fromContextMenu=False) if check and not tabEditor.isReadOnly(): self.tabEditorWidget.currentWidget().save() return linenr = int(item.text(1)) itemName = str(item.text(0)) charPos = itemName.find(' ') if charPos != -1: objName = itemName[0:charPos] else: objName = itemName tabEditor.goToLine(objName, linenr) def processing(self): self.shell.commandConsole('processing') def qtCore(self): self.shell.commandConsole('qtCore') def qtGui(self): self.shell.commandConsole('qtGui') def toggleEditor(self, checked): self.splitterObj.show() if checked else self.splitterObj.hide() if not self.tabEditorWidget: self.tabEditorWidget.enableToolBarEditor(checked) self.tabEditorWidget.restoreTabsOrAddNew() def toggleObjectListWidget(self, checked): self.listClassMethod.show() if checked else self.listClassMethod.hide() def findTextEditor(self, checked): self.widgetFind.show() if checked else self.widgetFind.hide() def pasteEditor(self): self.tabEditorWidget.currentWidget().newEditor.paste() def cutEditor(self): self.tabEditorWidget.currentWidget().newEditor.cut() def copyEditor(self): self.tabEditorWidget.currentWidget().newEditor.copy() def runScriptEditor(self): self.tabEditorWidget.currentWidget().newEditor.runScriptCode() def commentCode(self): self.tabEditorWidget.currentWidget().newEditor.commentEditorCode(True) def uncommentCode(self): self.tabEditorWidget.currentWidget().newEditor.commentEditorCode(False) def openScriptFileExtEditor(self): tabWidget = self.tabEditorWidget.currentWidget() path = tabWidget.path import subprocess try: subprocess.Popen([os.environ['EDITOR'], path]) except KeyError: QDesktopServices.openUrl(QUrl.fromLocalFile(path)) def openScriptFile(self): lastDirPath = self.settings.value("pythonConsole/lastDirPath", QDir.homePath()) openFileTr = QCoreApplication.translate("PythonConsole", "Open File") fileList = QFileDialog.getOpenFileNames( self, openFileTr, lastDirPath, "Script file (*.py)") if fileList: for pyFile in fileList: for i in range(self.tabEditorWidget.count()): tabWidget = self.tabEditorWidget.widget(i) if tabWidget.path == pyFile: self.tabEditorWidget.setCurrentWidget(tabWidget) break else: tabName = QFileInfo(pyFile).fileName() self.tabEditorWidget.newTabEditor(tabName, pyFile) lastDirPath = QFileInfo(pyFile).path() self.settings.setValue("pythonConsole/lastDirPath", pyFile) self.updateTabListScript(pyFile, action='append') def saveScriptFile(self): tabWidget = self.tabEditorWidget.currentWidget() try: tabWidget.save() except (IOError, OSError) as error: msgText = QCoreApplication.translate('PythonConsole', 'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path, error.strerror) self.callWidgetMessageBarEditor(msgText, 2, False) def saveAsScriptFile(self, index=None): tabWidget = self.tabEditorWidget.currentWidget() if not index: index = self.tabEditorWidget.currentIndex() if not tabWidget.path: fileName = self.tabEditorWidget.tabText(index) + '.py' folder = self.settings.value("pythonConsole/lastDirPath", QDir.home()) pathFileName = os.path.join(folder, fileName) fileNone = True else: pathFileName = tabWidget.path fileNone = False saveAsFileTr = QCoreApplication.translate("PythonConsole", "Save File As") filename = QFileDialog.getSaveFileName(self, saveAsFileTr, pathFileName, "Script file (*.py)") if filename: try: tabWidget.save(filename) except (IOError, OSError) as error: msgText = QCoreApplication.translate('PythonConsole', 'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path, error.strerror) self.callWidgetMessageBarEditor(msgText, 2, False) if fileNone: tabWidget.path = None else: tabWidget.path = pathFileName return if not fileNone: self.updateTabListScript(pathFileName, action='remove') def openHelp(self): QgsContextHelp.run("PythonConsole") def openSettings(self): if optionsDialog(self).exec_(): self.shell.refreshSettingsShell() self.shellOut.refreshSettingsOutput() self.tabEditorWidget.refreshSettingsEditor() def callWidgetMessageBar(self, text): self.shellOut.widgetMessageBar(iface, text) def callWidgetMessageBarEditor(self, text, level, timed): self.tabEditorWidget.widgetMessageBar(iface, text, level, timed) def updateTabListScript(self, script, action=None): if action == 'remove': self.tabListScript.remove(script) elif action == 'append': if not self.tabListScript: self.tabListScript = [] if script not in self.tabListScript: self.tabListScript.append(script) else: self.tabListScript = [] self.settings.setValue("pythonConsole/tabScripts", self.tabListScript) def saveSettingsConsole(self): self.settings.setValue("pythonConsole/splitterConsole", self.splitter.saveState()) self.settings.setValue("pythonConsole/splitterObj", self.splitterObj.saveState()) self.settings.setValue("pythonConsole/splitterEditor", self.splitterEditor.saveState()) self.shell.writeHistoryFile(True) def restoreSettingsConsole(self): storedTabScripts = self.settings.value("pythonConsole/tabScripts", []) self.tabListScript = storedTabScripts self.splitter.restoreState(self.settings.value("pythonConsole/splitterConsole", QByteArray())) self.splitterEditor.restoreState(self.settings.value("pythonConsole/splitterEditor", QByteArray())) self.splitterObj.restoreState(self.settings.value("pythonConsole/splitterObj", QByteArray()))
def closeEvent(self, event): self.console.saveSettingsConsole() QWidget.closeEvent(self, event)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console")) self.settings = QSettings() self.shell = ShellScintilla(self) self.setFocusProxy(self.shell) self.shellOut = ShellOutputScintilla(self) self.tabEditorWidget = EditorTabWidget(self) ##------------ UI ------------------------------- self.splitterEditor = QSplitter(self) self.splitterEditor.setOrientation(Qt.Horizontal) self.splitterEditor.setHandleWidth(6) self.splitterEditor.setChildrenCollapsible(True) self.shellOutWidget = QWidget(self) self.shellOutWidget.setLayout(QVBoxLayout()) self.shellOutWidget.layout().setContentsMargins(0, 0, 0, 0) self.shellOutWidget.layout().addWidget(self.shellOut) self.splitter = QSplitter(self.splitterEditor) self.splitter.setOrientation(Qt.Vertical) self.splitter.setHandleWidth(3) self.splitter.setChildrenCollapsible(False) self.splitter.addWidget(self.shellOutWidget) self.splitter.addWidget(self.shell) #self.splitterEditor.addWidget(self.tabEditorWidget) self.splitterObj = QSplitter(self.splitterEditor) self.splitterObj.setHandleWidth(3) self.splitterObj.setOrientation(Qt.Horizontal) #self.splitterObj.setSizes([0, 0]) #self.splitterObj.setStretchFactor(0, 1) self.widgetEditor = QWidget(self.splitterObj) self.widgetFind = QWidget(self) self.listClassMethod = QTreeWidget(self.splitterObj) self.listClassMethod.setColumnCount(2) objInspLabel = QCoreApplication.translate("PythonConsole", "Object Inspector") self.listClassMethod.setHeaderLabels([objInspLabel, '']) self.listClassMethod.setColumnHidden(1, True) self.listClassMethod.setAlternatingRowColors(True) #self.splitterEditor.addWidget(self.widgetEditor) #self.splitterObj.addWidget(self.listClassMethod) #self.splitterObj.addWidget(self.widgetEditor) # Hide side editor on start up self.splitterObj.hide() self.listClassMethod.hide() # Hide search widget on start up self.widgetFind.hide() sizes = self.splitter.sizes() self.splitter.setSizes(sizes) ##----------------Restore Settings------------------------------------ self.restoreSettingsConsole() ##------------------Toolbar Editor------------------------------------- ## Action for Open File openFileBt = QCoreApplication.translate("PythonConsole", "Open Script...") self.openFileButton = QAction(self) self.openFileButton.setCheckable(False) self.openFileButton.setEnabled(True) self.openFileButton.setIcon(QgsApplication.getThemeIcon("console/iconOpenConsole.png")) self.openFileButton.setMenuRole(QAction.PreferencesRole) self.openFileButton.setIconVisibleInMenu(True) self.openFileButton.setToolTip(openFileBt) self.openFileButton.setText(openFileBt) openExtEditorBt = QCoreApplication.translate("PythonConsole", "Open in External Editor") self.openInEditorButton = QAction(self) self.openInEditorButton.setCheckable(False) self.openInEditorButton.setEnabled(True) self.openInEditorButton.setIcon(QgsApplication.getThemeIcon("console/iconShowEditorConsole.png")) self.openInEditorButton.setMenuRole(QAction.PreferencesRole) self.openInEditorButton.setIconVisibleInMenu(True) self.openInEditorButton.setToolTip(openExtEditorBt) self.openInEditorButton.setText(openExtEditorBt) ## Action for Save File saveFileBt = QCoreApplication.translate("PythonConsole", "Save") self.saveFileButton = QAction(self) self.saveFileButton.setCheckable(False) self.saveFileButton.setEnabled(False) self.saveFileButton.setIcon(QgsApplication.getThemeIcon("console/iconSaveConsole.png")) self.saveFileButton.setMenuRole(QAction.PreferencesRole) self.saveFileButton.setIconVisibleInMenu(True) self.saveFileButton.setToolTip(saveFileBt) self.saveFileButton.setText(saveFileBt) ## Action for Save File As saveAsFileBt = QCoreApplication.translate("PythonConsole", "Save As...") self.saveAsFileButton = QAction(self) self.saveAsFileButton.setCheckable(False) self.saveAsFileButton.setEnabled(True) self.saveAsFileButton.setIcon(QgsApplication.getThemeIcon("console/iconSaveAsConsole.png")) self.saveAsFileButton.setMenuRole(QAction.PreferencesRole) self.saveAsFileButton.setIconVisibleInMenu(True) self.saveAsFileButton.setToolTip(saveAsFileBt) self.saveAsFileButton.setText(saveAsFileBt) ## Action Cut cutEditorBt = QCoreApplication.translate("PythonConsole", "Cut") self.cutEditorButton = QAction(self) self.cutEditorButton.setCheckable(False) self.cutEditorButton.setEnabled(True) self.cutEditorButton.setIcon(QgsApplication.getThemeIcon("mActionEditCut.png")) self.cutEditorButton.setMenuRole(QAction.PreferencesRole) self.cutEditorButton.setIconVisibleInMenu(True) self.cutEditorButton.setToolTip(cutEditorBt) self.cutEditorButton.setText(cutEditorBt) ## Action Copy copyEditorBt = QCoreApplication.translate("PythonConsole", "Copy") self.copyEditorButton = QAction(self) self.copyEditorButton.setCheckable(False) self.copyEditorButton.setEnabled(True) self.copyEditorButton.setIcon(QgsApplication.getThemeIcon("mActionEditCopy.png")) self.copyEditorButton.setMenuRole(QAction.PreferencesRole) self.copyEditorButton.setIconVisibleInMenu(True) self.copyEditorButton.setToolTip(copyEditorBt) self.copyEditorButton.setText(copyEditorBt) ## Action Paste pasteEditorBt = QCoreApplication.translate("PythonConsole", "Paste") self.pasteEditorButton = QAction(self) self.pasteEditorButton.setCheckable(False) self.pasteEditorButton.setEnabled(True) self.pasteEditorButton.setIcon(QgsApplication.getThemeIcon("mActionEditPaste.png")) self.pasteEditorButton.setMenuRole(QAction.PreferencesRole) self.pasteEditorButton.setIconVisibleInMenu(True) self.pasteEditorButton.setToolTip(pasteEditorBt) self.pasteEditorButton.setText(pasteEditorBt) ## Action Run Script (subprocess) runScriptEditorBt = QCoreApplication.translate("PythonConsole", "Run script") self.runScriptEditorButton = QAction(self) self.runScriptEditorButton.setCheckable(False) self.runScriptEditorButton.setEnabled(True) self.runScriptEditorButton.setIcon(QgsApplication.getThemeIcon("console/iconRunScriptConsole.png")) self.runScriptEditorButton.setMenuRole(QAction.PreferencesRole) self.runScriptEditorButton.setIconVisibleInMenu(True) self.runScriptEditorButton.setToolTip(runScriptEditorBt) self.runScriptEditorButton.setText(runScriptEditorBt) ## Action Run Script (subprocess) commentEditorBt = QCoreApplication.translate("PythonConsole", "Comment") self.commentEditorButton = QAction(self) self.commentEditorButton.setCheckable(False) self.commentEditorButton.setEnabled(True) self.commentEditorButton.setIcon(QgsApplication.getThemeIcon("console/iconCommentEditorConsole.png")) self.commentEditorButton.setMenuRole(QAction.PreferencesRole) self.commentEditorButton.setIconVisibleInMenu(True) self.commentEditorButton.setToolTip(commentEditorBt) self.commentEditorButton.setText(commentEditorBt) ## Action Run Script (subprocess) uncommentEditorBt = QCoreApplication.translate("PythonConsole", "Uncomment") self.uncommentEditorButton = QAction(self) self.uncommentEditorButton.setCheckable(False) self.uncommentEditorButton.setEnabled(True) self.uncommentEditorButton.setIcon(QgsApplication.getThemeIcon("console/iconUncommentEditorConsole.png")) self.uncommentEditorButton.setMenuRole(QAction.PreferencesRole) self.uncommentEditorButton.setIconVisibleInMenu(True) self.uncommentEditorButton.setToolTip(uncommentEditorBt) self.uncommentEditorButton.setText(uncommentEditorBt) ## Action for Object browser objList = QCoreApplication.translate("PythonConsole", "Object Inspector...") self.objectListButton = QAction(self) self.objectListButton.setCheckable(True) self.objectListButton.setEnabled(self.settings.value("pythonConsole/enableObjectInsp", False, type=bool)) self.objectListButton.setIcon(QgsApplication.getThemeIcon("console/iconClassBrowserConsole.png")) self.objectListButton.setMenuRole(QAction.PreferencesRole) self.objectListButton.setIconVisibleInMenu(True) self.objectListButton.setToolTip(objList) self.objectListButton.setText(objList) ## Action for Find text findText = QCoreApplication.translate("PythonConsole", "Find Text") self.findTextButton = QAction(self) self.findTextButton.setCheckable(True) self.findTextButton.setEnabled(True) self.findTextButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchEditorConsole.png")) self.findTextButton.setMenuRole(QAction.PreferencesRole) self.findTextButton.setIconVisibleInMenu(True) self.findTextButton.setToolTip(findText) self.findTextButton.setText(findText) ##----------------Toolbar Console------------------------------------- ## Action Show Editor showEditor = QCoreApplication.translate("PythonConsole", "Show Editor") self.showEditorButton = QAction(self) self.showEditorButton.setEnabled(True) self.showEditorButton.setCheckable(True) self.showEditorButton.setIcon(QgsApplication.getThemeIcon("console/iconShowEditorConsole.png")) self.showEditorButton.setMenuRole(QAction.PreferencesRole) self.showEditorButton.setIconVisibleInMenu(True) self.showEditorButton.setToolTip(showEditor) self.showEditorButton.setText(showEditor) ## Action for Clear button clearBt = QCoreApplication.translate("PythonConsole", "Clear Console") self.clearButton = QAction(self) self.clearButton.setCheckable(False) self.clearButton.setEnabled(True) self.clearButton.setIcon(QgsApplication.getThemeIcon("console/iconClearConsole.png")) self.clearButton.setMenuRole(QAction.PreferencesRole) self.clearButton.setIconVisibleInMenu(True) self.clearButton.setToolTip(clearBt) self.clearButton.setText(clearBt) ## Action for settings optionsBt = QCoreApplication.translate("PythonConsole", "Options...") self.optionsButton = QAction(self) self.optionsButton.setCheckable(False) self.optionsButton.setEnabled(True) self.optionsButton.setIcon(QgsApplication.getThemeIcon("console/iconSettingsConsole.png")) self.optionsButton.setMenuRole(QAction.PreferencesRole) self.optionsButton.setIconVisibleInMenu(True) self.optionsButton.setToolTip(optionsBt) self.optionsButton.setText(optionsBt) ## Action menu for class actionClassBt = QCoreApplication.translate("PythonConsole", "Import Class") self.actionClass = QAction(self) self.actionClass.setCheckable(False) self.actionClass.setEnabled(True) self.actionClass.setIcon(QgsApplication.getThemeIcon("console/iconClassConsole.png")) self.actionClass.setMenuRole(QAction.PreferencesRole) self.actionClass.setIconVisibleInMenu(True) self.actionClass.setToolTip(actionClassBt) self.actionClass.setText(actionClassBt) ## Import Processing class loadProcessingBt = QCoreApplication.translate("PythonConsole", "Import Processing Class") self.loadProcessingButton = QAction(self) self.loadProcessingButton.setCheckable(False) self.loadProcessingButton.setEnabled(True) self.loadProcessingButton.setIcon(QgsApplication.getThemeIcon("console/iconProcessingConsole.png")) self.loadProcessingButton.setMenuRole(QAction.PreferencesRole) self.loadProcessingButton.setIconVisibleInMenu(True) self.loadProcessingButton.setToolTip(loadProcessingBt) self.loadProcessingButton.setText(loadProcessingBt) ## Import QtCore class loadQtCoreBt = QCoreApplication.translate("PythonConsole", "Import PyQt.QtCore Class") self.loadQtCoreButton = QAction(self) self.loadQtCoreButton.setCheckable(False) self.loadQtCoreButton.setEnabled(True) self.loadQtCoreButton.setIcon(QgsApplication.getThemeIcon("console/iconQtCoreConsole.png")) self.loadQtCoreButton.setMenuRole(QAction.PreferencesRole) self.loadQtCoreButton.setIconVisibleInMenu(True) self.loadQtCoreButton.setToolTip(loadQtCoreBt) self.loadQtCoreButton.setText(loadQtCoreBt) ## Import QtGui class loadQtGuiBt = QCoreApplication.translate("PythonConsole", "Import PyQt.QtGui Class") self.loadQtGuiButton = QAction(self) self.loadQtGuiButton.setCheckable(False) self.loadQtGuiButton.setEnabled(True) self.loadQtGuiButton.setIcon(QgsApplication.getThemeIcon("console/iconQtGuiConsole.png")) self.loadQtGuiButton.setMenuRole(QAction.PreferencesRole) self.loadQtGuiButton.setIconVisibleInMenu(True) self.loadQtGuiButton.setToolTip(loadQtGuiBt) self.loadQtGuiButton.setText(loadQtGuiBt) ## Action for Run script runBt = QCoreApplication.translate("PythonConsole", "Run Command") self.runButton = QAction(self) self.runButton.setCheckable(False) self.runButton.setEnabled(True) self.runButton.setIcon(QgsApplication.getThemeIcon("console/iconRunConsole.png")) self.runButton.setMenuRole(QAction.PreferencesRole) self.runButton.setIconVisibleInMenu(True) self.runButton.setToolTip(runBt) self.runButton.setText(runBt) ## Help action helpBt = QCoreApplication.translate("PythonConsole", "Help...") self.helpButton = QAction(self) self.helpButton.setCheckable(False) self.helpButton.setEnabled(True) self.helpButton.setIcon(QgsApplication.getThemeIcon("console/iconHelpConsole.png")) self.helpButton.setMenuRole(QAction.PreferencesRole) self.helpButton.setIconVisibleInMenu(True) self.helpButton.setToolTip(helpBt) self.helpButton.setText(helpBt) self.toolBar = QToolBar() self.toolBar.setEnabled(True) self.toolBar.setFocusPolicy(Qt.NoFocus) self.toolBar.setContextMenuPolicy(Qt.DefaultContextMenu) self.toolBar.setLayoutDirection(Qt.LeftToRight) self.toolBar.setIconSize(QSize(16, 16)) self.toolBar.setMovable(False) self.toolBar.setFloatable(False) self.toolBar.addAction(self.clearButton) self.toolBar.addAction(self.actionClass) self.toolBar.addAction(self.runButton) self.toolBar.addSeparator() self.toolBar.addAction(self.showEditorButton) self.toolBar.addSeparator() self.toolBar.addAction(self.optionsButton) self.toolBar.addAction(self.helpButton) self.toolBarEditor = QToolBar() self.toolBarEditor.setEnabled(False) self.toolBarEditor.setFocusPolicy(Qt.NoFocus) self.toolBarEditor.setContextMenuPolicy(Qt.DefaultContextMenu) self.toolBarEditor.setLayoutDirection(Qt.LeftToRight) self.toolBarEditor.setIconSize(QSize(16, 16)) self.toolBarEditor.setMovable(False) self.toolBarEditor.setFloatable(False) self.toolBarEditor.addAction(self.openFileButton) self.toolBarEditor.addAction(self.openInEditorButton) self.toolBarEditor.addSeparator() self.toolBarEditor.addAction(self.saveFileButton) self.toolBarEditor.addAction(self.saveAsFileButton) self.toolBarEditor.addSeparator() self.toolBarEditor.addAction(self.runScriptEditorButton) self.toolBarEditor.addSeparator() self.toolBarEditor.addAction(self.findTextButton) self.toolBarEditor.addSeparator() self.toolBarEditor.addAction(self.cutEditorButton) self.toolBarEditor.addAction(self.copyEditorButton) self.toolBarEditor.addAction(self.pasteEditorButton) self.toolBarEditor.addSeparator() self.toolBarEditor.addAction(self.commentEditorButton) self.toolBarEditor.addAction(self.uncommentEditorButton) self.toolBarEditor.addSeparator() self.toolBarEditor.addAction(self.objectListButton) ## Menu Import Class self.classMenu = QMenu() self.classMenu.addAction(self.loadProcessingButton) self.classMenu.addAction(self.loadQtCoreButton) self.classMenu.addAction(self.loadQtGuiButton) cM = self.toolBar.widgetForAction(self.actionClass) cM.setMenu(self.classMenu) cM.setPopupMode(QToolButton.InstantPopup) self.widgetButton = QWidget() sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.widgetButton.sizePolicy().hasHeightForWidth()) self.widgetButton.setSizePolicy(sizePolicy) self.widgetButtonEditor = QWidget(self.widgetEditor) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.widgetButtonEditor.sizePolicy().hasHeightForWidth()) self.widgetButtonEditor.setSizePolicy(sizePolicy) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.shellOut.sizePolicy().hasHeightForWidth()) self.shellOut.setSizePolicy(sizePolicy) self.shellOut.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.shell.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) ##------------ Layout ------------------------------- self.mainLayout = QGridLayout(self) self.mainLayout.setMargin(0) self.mainLayout.setSpacing(0) self.mainLayout.addWidget(self.widgetButton, 0, 0, 1, 1) self.mainLayout.addWidget(self.splitterEditor, 0, 1, 1, 1) self.shellOutWidget.layout().insertWidget(0, self.toolBar) self.layoutEditor = QGridLayout(self.widgetEditor) self.layoutEditor.setMargin(0) self.layoutEditor.setSpacing(0) self.layoutEditor.addWidget(self.toolBarEditor, 0, 1, 1, 1) self.layoutEditor.addWidget(self.widgetButtonEditor, 1, 0, 2, 1) self.layoutEditor.addWidget(self.tabEditorWidget, 1, 1, 1, 1) self.layoutEditor.addWidget(self.widgetFind, 2, 1, 1, 1) ## Layout for the find widget self.layoutFind = QGridLayout(self.widgetFind) self.layoutFind.setContentsMargins(0, 0, 0, 0) self.lineEditFind = QgsFilterLineEdit() placeHolderTxt = QCoreApplication.translate("PythonConsole", "Enter text to find...") self.lineEditFind.setPlaceholderText(placeHolderTxt) self.findNextButton = QToolButton() self.findNextButton.setEnabled(False) toolTipfindNext = QCoreApplication.translate("PythonConsole", "Find Next") self.findNextButton.setToolTip(toolTipfindNext) self.findNextButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchNextEditorConsole.png")) self.findNextButton.setIconSize(QSize(24, 24)) self.findNextButton.setAutoRaise(True) self.findPrevButton = QToolButton() self.findPrevButton.setEnabled(False) toolTipfindPrev = QCoreApplication.translate("PythonConsole", "Find Previous") self.findPrevButton.setToolTip(toolTipfindPrev) self.findPrevButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchPrevEditorConsole.png")) self.findPrevButton.setIconSize(QSize(24, 24)) self.findPrevButton.setAutoRaise(True) self.caseSensitive = QCheckBox() caseSensTr = QCoreApplication.translate("PythonConsole", "Case Sensitive") self.caseSensitive.setText(caseSensTr) self.wholeWord = QCheckBox() wholeWordTr = QCoreApplication.translate("PythonConsole", "Whole Word") self.wholeWord.setText(wholeWordTr) self.wrapAround = QCheckBox() self.wrapAround.setChecked(True) wrapAroundTr = QCoreApplication.translate("PythonConsole", "Wrap Around") self.wrapAround.setText(wrapAroundTr) self.layoutFind.addWidget(self.lineEditFind, 0, 1, 1, 1) self.layoutFind.addWidget(self.findPrevButton, 0, 2, 1, 1) self.layoutFind.addWidget(self.findNextButton, 0, 3, 1, 1) self.layoutFind.addWidget(self.caseSensitive, 0, 4, 1, 1) self.layoutFind.addWidget(self.wholeWord, 0, 5, 1, 1) self.layoutFind.addWidget(self.wrapAround, 0, 6, 1, 1) ##------------ Add first Tab in Editor ------------------------------- #self.tabEditorWidget.newTabEditor(tabName='first', filename=None) ##------------ Signal ------------------------------- self.findTextButton.toggled.connect(self.findTextEditor) self.objectListButton.toggled.connect(self.toggleObjectListWidget) self.commentEditorButton.triggered.connect(self.commentCode) self.uncommentEditorButton.triggered.connect(self.uncommentCode) self.runScriptEditorButton.triggered.connect(self.runScriptEditor) self.cutEditorButton.triggered.connect(self.cutEditor) self.copyEditorButton.triggered.connect(self.copyEditor) self.pasteEditorButton.triggered.connect(self.pasteEditor) self.showEditorButton.toggled.connect(self.toggleEditor) self.clearButton.triggered.connect(self.shellOut.clearConsole) self.optionsButton.triggered.connect(self.openSettings) self.loadProcessingButton.triggered.connect(self.processing) self.loadQtCoreButton.triggered.connect(self.qtCore) self.loadQtGuiButton.triggered.connect(self.qtGui) self.runButton.triggered.connect(self.shell.entered) self.openFileButton.triggered.connect(self.openScriptFile) self.openInEditorButton.triggered.connect(self.openScriptFileExtEditor) self.saveFileButton.triggered.connect(self.saveScriptFile) self.saveAsFileButton.triggered.connect(self.saveAsScriptFile) self.helpButton.triggered.connect(self.openHelp) self.listClassMethod.itemClicked.connect(self.onClickGoToLine) self.lineEditFind.returnPressed.connect(self._findText) self.findNextButton.clicked.connect(self._findNext) self.findPrevButton.clicked.connect(self._findPrev) self.lineEditFind.textChanged.connect(self._textFindChanged)
def __init__(self, iface, db, parent=None): QWidget.__init__(self, parent) self.iface = iface self.db = db self.filter = "" self.allowMultiColumnPk = isinstance(db, PGDatabase) # at the moment only PostgreSQL allows a primary key to span multiple columns, spatialite doesn't self.aliasSubQuery = isinstance(db, PGDatabase) # only PostgreSQL requires subqueries to be aliases self.setupUi(self) self.setWindowTitle( u"%s - %s [%s]" % (self.windowTitle(), db.connection().connectionName(), db.connection().typeNameString())) self.defaultLayerName = 'QueryLayer' if self.allowMultiColumnPk: self.uniqueColumnCheck.setText(self.trUtf8("Column(s) with unique values")) else: self.uniqueColumnCheck.setText(self.trUtf8("Column with unique values")) self.editSql.setFocus() self.editSql.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.initCompleter() # allow copying results copyAction = QAction("copy", self) self.viewResult.addAction(copyAction) copyAction.setShortcuts(QKeySequence.Copy) copyAction.triggered.connect(self.copySelectedResults) self.btnExecute.clicked.connect(self.executeSql) self.btnSetFilter.clicked.connect(self.setFilter) self.btnClear.clicked.connect(self.clearSql) self.presetStore.clicked.connect(self.storePreset) self.presetDelete.clicked.connect(self.deletePreset) self.presetCombo.activated[str].connect(self.loadPreset) self.presetCombo.activated[str].connect(self.presetName.setText) self.updatePresetsCombobox() self.geomCombo.setEditable(True) self.geomCombo.lineEdit().setReadOnly(True) self.uniqueCombo.setEditable(True) self.uniqueCombo.lineEdit().setReadOnly(True) self.uniqueModel = QStandardItemModel(self.uniqueCombo) self.uniqueCombo.setModel(self.uniqueModel) if self.allowMultiColumnPk: self.uniqueCombo.setItemDelegate(QStyledItemDelegate()) self.uniqueModel.itemChanged.connect(self.uniqueChanged) # react to the (un)checking of an item self.uniqueCombo.lineEdit().textChanged.connect(self.uniqueTextChanged) # there are other events that change the displayed text and some of them can not be caught directly # hide the load query as layer if feature is not supported self._loadAsLayerAvailable = self.db.connector.hasCustomQuerySupport() self.loadAsLayerGroup.setVisible(self._loadAsLayerAvailable) if self._loadAsLayerAvailable: self.layerTypeWidget.hide() # show if load as raster is supported self.loadLayerBtn.clicked.connect(self.loadSqlLayer) self.getColumnsBtn.clicked.connect(self.fillColumnCombos) self.loadAsLayerGroup.toggled.connect(self.loadAsLayerToggled) self.loadAsLayerToggled(False) self._createViewAvailable = self.db.connector.hasCreateSpatialViewSupport() self.btnCreateView.setVisible(self._createViewAvailable) if self._createViewAvailable: self.btnCreateView.clicked.connect(self.createView) self.queryBuilderFirst = True self.queryBuilderBtn.setIcon(QIcon(":/db_manager/icons/sql.gif")) self.queryBuilderBtn.clicked.connect(self.displayQueryBuilder) self.presetName.textChanged.connect(self.nameChanged)
class AlgorithmDialog(AlgorithmDialogBase): def __init__(self, alg): AlgorithmDialogBase.__init__(self, alg) self.alg = alg self.mainWidget = ParametersPanel(self, alg) self.setMainWidget() self.cornerWidget = QWidget() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 5) self.tabWidget.setStyleSheet("QTabBar::tab { height: 30px; }") self.runAsBatchButton = QPushButton(self.tr("Run as batch process...")) self.runAsBatchButton.clicked.connect(self.runAsBatch) layout.addWidget(self.runAsBatchButton) self.cornerWidget.setLayout(layout) self.tabWidget.setCornerWidget(self.cornerWidget) QgsMapLayerRegistry.instance().layerWasAdded.connect(self.mainWidget.layerAdded) QgsMapLayerRegistry.instance().layersWillBeRemoved.connect(self.mainWidget.layersWillBeRemoved) def runAsBatch(self): dlg = BatchAlgorithmDialog(self.alg) dlg.exec_() def setParamValues(self): params = self.alg.parameters outputs = self.alg.outputs for param in params: if param.hidden: continue if isinstance(param, ParameterExtent): continue if not self.setParamValue( param, self.mainWidget.valueItems[param.name]): raise AlgorithmDialogBase.InvalidParameterValue(param, self.mainWidget.valueItems[param.name]) for param in params: if isinstance(param, ParameterExtent): if not self.setParamValue( param, self.mainWidget.valueItems[param.name]): raise AlgorithmDialogBase.InvalidParameterValue( param, self.mainWidget.valueItems[param.name]) for output in outputs: if output.hidden: continue output.value = self.mainWidget.valueItems[output.name].getValue() if isinstance(output, (OutputRaster, OutputVector, OutputTable)): output.open = self.mainWidget.checkBoxes[output.name].isChecked() return True def setParamValue(self, param, widget, alg=None): if isinstance(param, ParameterRaster): return param.setValue(widget.getValue()) elif isinstance(param, (ParameterVector, ParameterTable)): try: return param.setValue(widget.itemData(widget.currentIndex())) except: return param.setValue(widget.getValue()) elif isinstance(param, ParameterBoolean): return param.setValue(widget.isChecked()) elif isinstance(param, ParameterSelection): return param.setValue(widget.currentIndex()) elif isinstance(param, ParameterFixedTable): return param.setValue(widget.table) elif isinstance(param, ParameterRange): return param.setValue(widget.getValue()) if isinstance(param, ParameterTableField): if param.optional and widget.currentIndex() == 0: return param.setValue(None) return param.setValue(widget.currentText()) elif isinstance(param, ParameterMultipleInput): if param.datatype == ParameterMultipleInput.TYPE_FILE: return param.setValue(widget.selectedoptions) else: if param.datatype == ParameterMultipleInput.TYPE_RASTER: options = dataobjects.getRasterLayers(sorting=False) elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY: options = dataobjects.getVectorLayers(sorting=False) else: options = dataobjects.getVectorLayers([param.datatype], sorting=False) return param.setValue([options[i] for i in widget.selectedoptions]) elif isinstance(param, (ParameterNumber, ParameterFile, ParameterCrs, ParameterExtent, ParameterPoint)): return param.setValue(widget.getValue()) elif isinstance(param, ParameterString): if param.multiline: return param.setValue(unicode(widget.toPlainText())) else: return param.setValue(unicode(widget.text())) elif isinstance(param, ParameterGeometryPredicate): return param.setValue(widget.value()) else: return param.setValue(unicode(widget.text())) def accept(self): self.settings.setValue("/Processing/dialogBase", self.saveGeometry()) checkCRS = ProcessingConfig.getSetting(ProcessingConfig.WARN_UNMATCHING_CRS) try: self.setParamValues() if checkCRS and not self.alg.checkInputCRS(): reply = QMessageBox.question(self, self.tr("Unmatching CRS's"), self.tr('Layers do not all use the same CRS. This can ' 'cause unexpected results.\nDo you want to ' 'continue?'), QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.No: return msg = self.alg._checkParameterValuesBeforeExecuting() if msg: QMessageBox.warning( self, self.tr('Unable to execute algorithm'), msg) return self.btnRun.setEnabled(False) self.btnClose.setEnabled(False) buttons = self.mainWidget.iterateButtons self.iterateParam = None for i in range(len(buttons.values())): button = buttons.values()[i] if button.isChecked(): self.iterateParam = buttons.keys()[i] break self.progressBar.setMaximum(0) self.lblProgress.setText(self.tr('Processing algorithm...')) # Make sure the Log tab is visible before executing the algorithm try: self.tabWidget.setCurrentIndex(1) self.repaint() except: pass QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) self.setInfo( self.tr('<b>Algorithm %s starting...</b>') % self.alg.name) if self.iterateParam: if runalgIterating(self.alg, self.iterateParam, self): self.finish() else: QApplication.restoreOverrideCursor() self.resetGUI() else: command = self.alg.getAsCommand() if command: ProcessingLog.addToLog( ProcessingLog.LOG_ALGORITHM, command) if runalg(self.alg, self): self.finish() else: QApplication.restoreOverrideCursor() self.resetGUI() except AlgorithmDialogBase.InvalidParameterValue as e: try: self.buttonBox.accepted.connect(lambda: e.widget.setPalette(QPalette())) palette = e.widget.palette() palette.setColor(QPalette.Base, QColor(255, 255, 0)) e.widget.setPalette(palette) self.lblProgress.setText( self.tr('<b>Missing parameter value: %s</b>') % e.parameter.description) return except: QMessageBox.critical(self, self.tr('Unable to execute algorithm'), self.tr('Wrong or missing parameter values')) def finish(self): keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN) if self.iterateParam is None: if not handleAlgorithmResults(self.alg, self, not keepOpen): self.resetGUI() return self.executed = True self.setInfo('Algorithm %s finished' % self.alg.name) QApplication.restoreOverrideCursor() if not keepOpen: self.close() else: self.resetGUI() if self.alg.getHTMLOutputsCount() > 0: self.setInfo( self.tr('HTML output has been generated by this algorithm.' '\nOpen the results dialog to check it.')) def closeEvent(self, evt): QgsMapLayerRegistry.instance().layerWasAdded.disconnect(self.mainWidget.layerAdded) QgsMapLayerRegistry.instance().layersWillBeRemoved.disconnect(self.mainWidget.layersWillBeRemoved) super(AlgorithmDialog, self).closeEvent(evt)