1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
# -*- coding: utf-8 -*-
"""
***************************************************************************
doInfo.py
---------------------
Date : June 2010
Copyright : (C) 2010 by Giuseppe Sucameli
Email : brush dot tyler at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Giuseppe Sucameli'
__date__ = 'June 2010'
__copyright__ = '(C) 2010, Giuseppe Sucameli'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QWidget, QAction, QApplication, QMenu
from .ui_widgetInfo import Ui_GdalToolsWidget as Ui_Widget
from .widgetPluginBase import GdalToolsBasePluginWidget as BasePluginWidget
from . import GdalTools_utils as Utils
import platform
class GdalToolsDialog(QWidget, Ui_Widget, BasePluginWidget):
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 doCopyLine(self):
output = ''
items = self.rasterInfoList.selectedItems()
for r in items:
output += r.text() + "\n"
if output:
clipboard = QApplication.clipboard()
clipboard.setText(output)
def doCopyAll(self):
output = ''
for r in range(self.rasterInfoList.count()):
output += self.rasterInfoList.item(r).text() + "\n"
if output:
clipboard = QApplication.clipboard()
clipboard.setText(output)
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 onLayersChanged(self):
self.inSelector.setLayers(Utils.LayerRegistry.instance().getRasterLayers())
def finished(self):
self.rasterInfoList.clear()
arr = unicode(self.base.process.readAllStandardOutput()).strip()
if platform.system() == "Windows":
#info = QString.fromLocal8Bit( arr ).strip().split( "\r\n" )
# TODO test
info = arr.splitlines()
else:
info = arr.splitlines()
self.rasterInfoList.addItems(info)
def fillInputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
inputFile = Utils.FileDialog.getOpenFileName(self, self.tr("Select the file to analyse"), Utils.FileFilter.allRastersFilter(), lastUsedFilter)
if not inputFile:
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)
self.inSelector.setFilename(inputFile)
def getArguments(self):
arguments = []
if self.suppressGCPCheck.isChecked():
arguments.append("-nogcp")
if self.suppressMDCheck.isChecked():
arguments.append("-nomd")
arguments.append(self.getInputFileName())
return arguments
# def getOutputFileName( self ):
# return self.inSelector.filename()
def getInputFileName(self):
return self.inSelector.filename()
def contextMenuEvent(self, event):
menu = QMenu(self)
menu.addAction(self.copyLine)
menu.addAction(self.copyAll)
menu.exec_(event.globalPos())
|