~ubuntu-branches/ubuntu/utopic/qgis/utopic

« back to all changes in this revision

Viewing changes to python/plugins/GdalTools/tools/doNearBlack.py

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-04-24 15:12:20 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20120424151220-r88g00af5fpn5fc3
Tags: 1.7.4+1.7.5~20120320-1
The "Sometimes they come back" release.

* Branching from Qgis tree and adapting to current Debian Policy and
  standards. The target tree is currently set to release-1.7.
  (closes: #661491, #606304, #615683, #616182, #600308)
* Policy bumped to 3.9.3.
* Moving to debhelper compatibility level 9.
* Source format is now 3.0 with quilt support.
* Merged with 2bf42287 upstream git snapshot.
* Migrated to dh_python2 instead of python-central.
  (closes: #617048)
* Snapshot in qgis.org release-1.7: c936d031
* Added an automagic creation of a lintian override for sqlite embedding.
  This is required for uploading currently.
* Added missing ${misc:Depends} to make lintian happy.
* Copyright notes updated and debian/copyright moved to format 1.0.
* More licenses notices now reported in debian/copyright. Thanks ftpmasters.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
from PyQt4.QtCore import *
 
3
from PyQt4.QtGui import *
 
4
from qgis.core import *
 
5
from qgis.gui import *
 
6
from osgeo import ogr
 
7
 
 
8
from ui_widgetNearBlack import Ui_GdalToolsWidget as Ui_Widget
 
9
from widgetPluginBase import GdalToolsBasePluginWidget as BasePluginWidget
 
10
import GdalTools_utils as Utils
 
11
 
 
12
class GdalToolsDialog(QWidget, Ui_Widget, BasePluginWidget):
 
13
 
 
14
  def __init__(self, iface):
 
15
      QWidget.__init__(self)
 
16
      self.iface = iface
 
17
 
 
18
      self.setupUi(self)
 
19
      BasePluginWidget.__init__(self, self.iface, "nearblack")
 
20
 
 
21
      self.outSelector.setType( self.outSelector.FILE )
 
22
 
 
23
      # set the default QSpinBoxes value
 
24
      self.nearSpin.setValue(15)
 
25
 
 
26
      self.setParamsStatus(
 
27
        [
 
28
          (self.inSelector, SIGNAL("filenameChanged()")),
 
29
          (self.outSelector, SIGNAL("filenameChanged()")),
 
30
          (self.nearSpin, SIGNAL("valueChanged(int)"), self.nearCheck),
 
31
          (self.whiteCheckBox, SIGNAL("stateChanged(int)"))
 
32
        ]
 
33
      )
 
34
 
 
35
      self.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFileEdit)
 
36
      self.connect(self.outSelector, SIGNAL("selectClicked()"), self.fillOutputFileEdit)
 
37
 
 
38
  def onLayersChanged(self):
 
39
      self.inSelector.setLayers( Utils.LayerRegistry.instance().getRasterLayers() )
 
40
 
 
41
  def fillInputFileEdit(self):
 
42
      lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
 
43
      inputFile = Utils.FileDialog.getOpenFileName(self, self.tr( "Select the input file for Near Black" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
 
44
      if inputFile.isEmpty():
 
45
        return
 
46
      Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)
 
47
 
 
48
      self.inSelector.setFilename(inputFile)
 
49
 
 
50
  def fillOutputFileEdit(self):
 
51
      lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
 
52
      outputFile = Utils.FileDialog.getSaveFileName(self, self.tr( "Select the raster file to save the results to" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter)
 
53
      if outputFile.isEmpty():
 
54
        return
 
55
      Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)
 
56
 
 
57
      self.outSelector.setFilename(outputFile)
 
58
 
 
59
  def getArguments(self):
 
60
      arguments = QStringList()
 
61
      if self.whiteCheckBox.isChecked():
 
62
        arguments << "-white"
 
63
      if self.nearCheck.isChecked():
 
64
        arguments << "-near"
 
65
        arguments << str(self.nearSpin.value())
 
66
      arguments << "-o"
 
67
      arguments << self.getOutputFileName()
 
68
      arguments << self.getInputFileName()
 
69
      return arguments
 
70
 
 
71
  def getOutputFileName(self):
 
72
      return self.outSelector.filename()
 
73
 
 
74
  def getInputFileName(self):
 
75
      return self.inSelector.filename()
 
76
 
 
77
  def addLayerIntoCanvas(self, fileInfo):
 
78
      self.iface.addRasterLayer(fileInfo.filePath())
 
79