2010-06-04 00:31:48 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-10-06 13:10:25 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
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$'
|
|
|
|
|
2010-06-04 00:31:48 +00:00
|
|
|
from PyQt4.QtCore import *
|
|
|
|
from PyQt4.QtGui import *
|
|
|
|
from qgis.core import *
|
|
|
|
from qgis.gui import *
|
|
|
|
|
|
|
|
from ui_widgetInfo import Ui_GdalToolsWidget as Ui_Widget
|
|
|
|
from widgetPluginBase import GdalToolsBasePluginWidget as BasePluginWidget
|
|
|
|
import GdalTools_utils as Utils
|
|
|
|
|
|
|
|
import platform
|
2013-06-03 23:42:12 -03:00
|
|
|
import string
|
2010-06-04 00:31:48 +00:00
|
|
|
|
|
|
|
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(
|
|
|
|
[
|
2011-04-15 18:30:10 +00:00
|
|
|
(self.inSelector, SIGNAL("filenameChanged()") ),
|
2010-06-04 00:31:48 +00:00
|
|
|
( self.suppressGCPCheck, SIGNAL( "stateChanged( int )" ) ),
|
|
|
|
( self.suppressMDCheck, SIGNAL( "stateChanged( int )" ) )
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2011-04-15 18:30:10 +00:00
|
|
|
self.connect( self.inSelector, SIGNAL( "selectClicked()" ), self.fillInputFileEdit )
|
2010-06-04 00:31:48 +00:00
|
|
|
|
|
|
|
# helper actions for copying info output
|
|
|
|
self.copyLine = QAction( self.tr( "Copy" ), self )
|
|
|
|
QObject.connect( self.copyLine, SIGNAL( "triggered()" ), self.doCopyLine )
|
|
|
|
self.copyAll = QAction( self.tr( "Copy all" ), self )
|
|
|
|
QObject.connect( self.copyAll, SIGNAL( "triggered()" ), self.doCopyAll )
|
|
|
|
|
|
|
|
|
|
|
|
def doCopyLine( self ):
|
2013-06-04 09:28:43 +10:00
|
|
|
output = ''
|
2010-06-04 00:31:48 +00:00
|
|
|
items = self.rasterInfoList.selectedItems()
|
|
|
|
for r in items:
|
|
|
|
output.append( r.text() + "\n" )
|
2013-06-14 14:58:19 -03:00
|
|
|
if output:
|
2010-06-04 00:31:48 +00:00
|
|
|
clipboard = QApplication.clipboard()
|
|
|
|
clipboard.setText( output )
|
|
|
|
|
|
|
|
def doCopyAll( self ):
|
2013-06-04 09:28:43 +10:00
|
|
|
output = ''
|
2010-06-04 00:31:48 +00:00
|
|
|
for r in range( self.rasterInfoList.count() ):
|
|
|
|
output.append( self.rasterInfoList.item( r ).text() + "\n" )
|
2013-06-14 14:58:19 -03:00
|
|
|
if output:
|
2010-06-04 00:31:48 +00:00
|
|
|
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:
|
2013-06-04 09:28:43 +10:00
|
|
|
items = ''
|
2010-06-04 00:31:48 +00:00
|
|
|
for r in range( self.rasterInfoList.count() ):
|
|
|
|
items.append( self.rasterInfoList.item( r ).text() + "\n" )
|
2013-06-14 14:58:19 -03:00
|
|
|
if items:
|
2010-06-04 00:31:48 +00:00
|
|
|
clipboard = QApplication.clipboard()
|
|
|
|
clipboard.setText( items )
|
|
|
|
else:
|
|
|
|
QWidget.keyPressEvent( self, e )
|
|
|
|
|
2011-03-14 16:01:10 +00:00
|
|
|
def onLayersChanged(self):
|
2011-04-15 18:30:10 +00:00
|
|
|
self.inSelector.setLayers( Utils.LayerRegistry.instance().getRasterLayers() )
|
2010-06-04 00:31:48 +00:00
|
|
|
|
|
|
|
def finished( self ):
|
|
|
|
self.rasterInfoList.clear()
|
2013-06-03 23:42:12 -03:00
|
|
|
arr = str(self.base.process.readAllStandardOutput()).strip()
|
2010-06-04 00:31:48 +00:00
|
|
|
if platform.system() == "Windows":
|
2013-06-19 18:26:37 +02:00
|
|
|
#info = QString.fromLocal8Bit( arr ).strip().split( "\r\n" )
|
2013-06-03 23:42:12 -03:00
|
|
|
# TODO test
|
2013-06-27 22:52:46 +02:00
|
|
|
info = arr.splitlines()
|
2010-06-04 00:31:48 +00:00
|
|
|
else:
|
2013-06-27 22:52:46 +02:00
|
|
|
info = arr.splitlines()
|
2010-06-04 00:31:48 +00:00
|
|
|
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 )
|
2013-06-14 14:58:19 -03:00
|
|
|
if not inputFile:
|
2010-06-04 00:31:48 +00:00
|
|
|
return
|
|
|
|
Utils.FileFilter.setLastUsedRasterFilter( lastUsedFilter )
|
|
|
|
|
2011-04-15 18:30:10 +00:00
|
|
|
self.inSelector.setFilename( inputFile )
|
2010-06-04 00:31:48 +00:00
|
|
|
|
|
|
|
def getArguments( self ):
|
2013-06-03 23:42:12 -03:00
|
|
|
arguments = []
|
2010-06-04 00:31:48 +00:00
|
|
|
if self.suppressGCPCheck.isChecked():
|
2013-06-03 23:42:12 -03:00
|
|
|
arguments.append("-nogcp")
|
2010-06-04 00:31:48 +00:00
|
|
|
if self.suppressMDCheck.isChecked():
|
2013-06-03 23:42:12 -03:00
|
|
|
arguments.append("-nomd")
|
|
|
|
arguments.append(self.getInputFileName())
|
2010-06-04 00:31:48 +00:00
|
|
|
return arguments
|
|
|
|
|
|
|
|
# def getOutputFileName( self ):
|
2011-04-15 18:30:10 +00:00
|
|
|
# return self.inSelector.filename()
|
|
|
|
|
|
|
|
def getInputFileName( self ):
|
|
|
|
return self.inSelector.filename()
|
|
|
|
|
2010-06-04 00:31:48 +00:00
|
|
|
|
|
|
|
def contextMenuEvent( self, event ):
|
|
|
|
menu = QMenu( self )
|
|
|
|
menu.addAction( self.copyLine )
|
|
|
|
menu.addAction( self.copyAll )
|
|
|
|
menu.exec_( event.globalPos() )
|
2011-04-15 18:30:10 +00:00
|
|
|
|