[QGIS Commit] r13481 - trunk/qgis/python/plugins/fTools/tools

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu May 13 18:55:59 EDT 2010


Author: cfarmer
Date: 2010-05-13 18:55:59 -0400 (Thu, 13 May 2010)
New Revision: 13481

Modified:
   trunk/qgis/python/plugins/fTools/tools/doDefineProj.py
   trunk/qgis/python/plugins/fTools/tools/doGeometry.py
   trunk/qgis/python/plugins/fTools/tools/doGeoprocessing.py
   trunk/qgis/python/plugins/fTools/tools/doIntersectLines.py
   trunk/qgis/python/plugins/fTools/tools/doMeanCoords.py
   trunk/qgis/python/plugins/fTools/tools/doPointsInPolygon.py
   trunk/qgis/python/plugins/fTools/tools/doRandPoints.py
   trunk/qgis/python/plugins/fTools/tools/doRandom.py
   trunk/qgis/python/plugins/fTools/tools/doReProject.py
   trunk/qgis/python/plugins/fTools/tools/doRegPoints.py
   trunk/qgis/python/plugins/fTools/tools/doSelectByLocation.py
   trunk/qgis/python/plugins/fTools/tools/doSpatialJoin.py
   trunk/qgis/python/plugins/fTools/tools/doSubsetSelect.py
   trunk/qgis/python/plugins/fTools/tools/doSumLines.py
   trunk/qgis/python/plugins/fTools/tools/doVectorGrid.py
   trunk/qgis/python/plugins/fTools/tools/doVisual.py
Log:
New warning when creating empty multipart layer; Ok button disabled on all functions while running; General bug fixes. Fixes #2260, #2057, and #1986. Another great patch from alexbruy :-)

Modified: trunk/qgis/python/plugins/fTools/tools/doDefineProj.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doDefineProj.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doDefineProj.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -19,6 +19,7 @@
         self.label_2.setVisible(False)
         self.label_2.setEnabled(False)
         self.setWindowTitle(self.tr("Define current projection"))
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
         QObject.connect(self.btnProjection, SIGNAL("clicked()"), self.outProjFile)
         QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.updateProj1)
         QObject.connect(self.cmbLayer, SIGNAL("currentIndexChanged(QString)"), self.updateProj2)
@@ -42,6 +43,7 @@
         self.outRef.insert(unicode(crs))
 
     def accept(self):
+        self.buttonOk.setEnabled( False )
         if self.inShape.currentText() == "":
             QMessageBox.information(self, self.tr("Define current projection"), self.tr("No input shapefile specified"))
         elif self.txtProjection.text() == "" and self.rdoProjection.isChecked():
@@ -103,6 +105,7 @@
                     self.progressBar.setValue(100)
                     QMessageBox.information(self, self.tr("Define current projection"), self.tr("Defined Projection For:\n%1.shp").arg( inPath ) )
         self.progressBar.setValue(0)
+        self.buttonOk.setEnabled( True )
 
     def outProjFile(self):
         format = QString( "<h2>%1</h2>%2 <br/> %3" )

Modified: trunk/qgis/python/plugins/fTools/tools/doGeometry.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doGeometry.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doGeometry.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -14,6 +14,7 @@
     self.iface = iface
     self.setupUi(self)
     self.myFunction = function
+    self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
     QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
     if self.myFunction == 1:
       QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
@@ -126,7 +127,7 @@
     elif self.myFunction == 9:
       myList = ftools_utils.getLayerNames( "all" )
     else:
-      myList = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] )    
+      myList = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] )
     self.inShape.addItems( myList )
     return
 
@@ -151,6 +152,7 @@
       if not QgsVectorFileWriter.deleteShapeFile( self.shapefileName ):
         QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Unable to delete existing shapefile." ) )
         return
+    self.buttonOk.setEnabled( False )
     self.testThread = geometryThread( self.iface.mainWindow(), self, self.myFunction, vlayer, myParam, 
     myField, self.shapefileName, self.encoding )
     QObject.connect( self.testThread, SIGNAL( "runFinished(PyQt_PyObject)" ), self.runFinishedFromThread )
@@ -162,13 +164,19 @@
 
   def cancelThread( self ):
     self.testThread.stop()
+    self.buttonOk.setEnabled( True )
     
   def runFinishedFromThread( self, success ):
     self.testThread.stop()
+    self.buttonOk.setEnabled( True )
     if success == "math_error":
       QMessageBox.warning( self, self.tr("Geometry"), self.tr("Error processing specified tolerance!\nPlease choose larger tolerance...") )
       if not QgsVectorFileWriter.deleteShapeFile( self.shapefileName ):
         QMessageBox.warning( self, self.tr("Geometry"), self.tr( "Unable to delete incomplete shapefile." ) )
+    elif success == "attr_error":
+      QMessageBox.warning( self, self.tr("Geometry"), self.tr("At least two features must have same attribute value!\nPlease choose another field...") )
+      if not QgsVectorFileWriter.deleteShapeFile( self.shapefileName ):
+        QMessageBox.warning( self, self.tr("Geometry"), self.tr( "Unable to delete incomplete shapefile." ) )
     else: 
       self.cancel_close.setText( "Close" )
       QObject.disconnect( self.cancel_close, SIGNAL( "clicked()" ), self.cancelThread )
@@ -267,6 +275,8 @@
         outFeat.setGeometry( outGeom )
         writer.addFeature( outFeat )
       del writer
+    else:
+      return "attr_error"
     return True
 
   def multi_to_single( self ):

Modified: trunk/qgis/python/plugins/fTools/tools/doGeoprocessing.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doGeoprocessing.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doGeoprocessing.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -22,6 +22,7 @@
     self.manageGui()
     self.success = False
     self.cancel_close = self.buttonBox_2.button( QDialogButtonBox.Close )
+    self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
     self.progressBar.setValue (0 )
   
   def checkA( self ):
@@ -180,6 +181,7 @@
       if not QgsVectorFileWriter.deleteShapeFile( self.shapefileName ):
         QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Unable to delete existing shapefile." ) )
         return
+    self.buttonOk.setEnabled( False )
     self.testThread = geoprocessingThread( self.iface.mainWindow(), self, self.myFunction, myLayerA, 
     myLayerB, myParam, myMerge, mySelectionA, mySelectionB, self.shapefileName, self.encoding )
     QObject.connect( self.testThread, SIGNAL( "runFinished(PyQt_PyObject)" ), self.runFinishedFromThread )
@@ -192,9 +194,11 @@
   
   def cancelThread( self ):
     self.testThread.stop()
+    self.buttonOk.setEnabled( True )
   
   def runFinishedFromThread( self, results ):
     self.testThread.stop()
+    self.buttonOk.setEnabled( True )
     self.cancel_close.setText( self.tr("Close") )
     QObject.disconnect( self.cancel_close, SIGNAL( "clicked()" ), self.cancelThread )
     out_text = ""

Modified: trunk/qgis/python/plugins/fTools/tools/doIntersectLines.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doIntersectLines.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doIntersectLines.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -48,6 +48,7 @@
         QObject.connect(self.inLine1, SIGNAL("currentIndexChanged(QString)"), self.update1)
         QObject.connect(self.inLine2, SIGNAL("currentIndexChanged(QString)"), self.update2)
         self.setWindowTitle( self.tr("Line intersections") )
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
         # populate layer list
         self.progressBar.setValue(0)
         mapCanvas = self.iface.mapCanvas()
@@ -70,6 +71,7 @@
             self.inField2.addItem(unicode(changedField[i].name()))
 
     def accept(self):
+        self.buttonOk.setEnabled( False )
         if self.inLine1.currentText() == "":
             QMessageBox.information(self, self.tr("Locate Line Intersections"), self.tr("Please specify input line layer") )
         elif self.outShape.text() == "":
@@ -94,6 +96,7 @@
                 if not ftools_utils.addShapeToCanvas( unicode( outPath ) ):
                     QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( outPath ) ))
         self.progressBar.setValue(0)
+        self.buttonOk.setEnabled( True )
 
     def outFile(self):
         self.outShape.clear()

Modified: trunk/qgis/python/plugins/fTools/tools/doMeanCoords.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doMeanCoords.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doMeanCoords.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -15,6 +15,7 @@
         self.updateUi()
         QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
         QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
 
         # populate layer list
         self.progressBar.setValue(0)
@@ -44,6 +45,7 @@
             self.uniqueField.addItem(unicode(changedField[i].name()))
 
     def accept(self):
+        self.buttonOk.setEnabled( False )
         if self.inShape.currentText() == "":
             QMessageBox.information(self, self.tr("Coordinate statistics"), self.tr("No input vector layer specified"))
         elif self.outShape.text() == "":
@@ -74,7 +76,8 @@
                     render.addSymbol(symbol)
                     self.vlayer.setRenderer(render)
                 QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
-            self.progressBar.setValue(0)
+        self.progressBar.setValue(0)
+        self.buttonOk.setEnabled( True )
 
     def outFile(self):
         self.outShape.clear()
@@ -137,7 +140,7 @@
                     else:
                         weight = float(feat.attributeMap()[weightIndex].toDouble()[0])
                     geom = QgsGeometry(feat.geometry())
-                    geom = self.extract(geom)
+                    geom = ftools_utils.extractPoints(geom)
                     for i in geom:
                         cx += i.x()
                         cy += i.y()
@@ -180,31 +183,3 @@
             if single:
                 break
         del writer
-
-    def extract(self, geom):
-        multi_geom = QgsGeometry()
-        temp_geom = []
-        if geom.type() == 0: # it's a point
-            if geom.isMultipart():
-                temp_geom = geom.asMultiPoint()
-            else:
-                temp_geom.append(geom.asPoint())
-        if geom.type() == 1: # it's a line
-            if geom.isMultipart():
-                multi_geom = geom.asMultiPolyline() #multi_geog is a multiline
-                for i in multi_geom: #i is a line
-                    temp_geom.extend(i)
-            else:
-                temp_geom = geom.asPolyline()
-        elif geom.type() == 2: # it's a polygon
-            if geom.isMultipart():
-                multi_geom = geom.asMultiPolygon() #multi_geom is a multipolygon
-                for i in multi_geom: #i is a polygon
-                    for j in i: #j is a line
-                        temp_geom.extend(j)
-            else:
-                multi_geom = geom.asPolygon() #multi_geom is a polygon
-                for i in multi_geom: #i is a line
-                    temp_geom.extend(i)
-        return temp_geom
-

Modified: trunk/qgis/python/plugins/fTools/tools/doPointsInPolygon.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doPointsInPolygon.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doPointsInPolygon.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -46,6 +46,7 @@
         self.setupUi(self)
         QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
         self.setWindowTitle(self.tr("Count Points in Polygon"))
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
         # populate layer list
         self.progressBar.setValue(0)
         mapCanvas = self.iface.mapCanvas()
@@ -55,6 +56,7 @@
         self.inPoint.addItems(layers)
     
     def accept(self):
+        self.buttonOk.setEnabled( False )
         if self.inPolygon.currentText() == "":
             QMessageBox.information(self, self.tr("Count Points In Polygon"), self.tr("Please specify input polygon vector layer"))
         elif self.outShape.text() == "":
@@ -81,6 +83,7 @@
                 self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
                 QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
         self.progressBar.setValue(0)
+        self.buttonOk.setEnabled( True )
 
     def outFile(self):
         self.outShape.clear()

Modified: trunk/qgis/python/plugins/fTools/tools/doRandPoints.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doRandPoints.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doRandPoints.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -48,11 +48,12 @@
         QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
         self.progressBar.setValue(0)
         self.setWindowTitle(self.tr("Random Points"))
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
         self.mapCanvas = self.iface.mapCanvas()
         layers = ftools_utils.getLayerNames([QGis.Polygon, "Raster"])
         self.inShape.addItems(layers)
 
-# If input layer is changed, update field list                
+# If input layer is changed, update field list
     def update(self, inputLayer):
         self.cmbField.clear()
         changedLayer = ftools_utils.getMapLayerByName(unicode(inputLayer))
@@ -75,8 +76,9 @@
             self.cmbField.setEnabled(False)
             self.label_4.setEnabled(False)
 
-# when 'OK' button is pressed, gather required inputs, and initiate random points generation            
+# when 'OK' button is pressed, gather required inputs, and initiate random points generation
     def accept(self):
+        self.buttonOk.setEnabled( False )
         if self.inShape.currentText() == "":
             QMessageBox.information(self, self.tr("Random Points"), self.tr("No input layer specified"))
         elif self.outShape.text() == "":
@@ -127,7 +129,8 @@
             if addToTOC == QMessageBox.Yes:
                 self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
                 QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
-            self.progressBar.setValue(0)
+        self.progressBar.setValue(0)
+        self.buttonOk.setEnabled( True )
 
     def outFile(self):
         self.outShape.clear()
@@ -136,7 +139,7 @@
             return
         self.outShape.setText( QString( self.shapefileName ) )
     
-# combine all polygons in layer to create single polygon (slow for complex polygons)     
+# combine all polygons in layer to create single polygon (slow for complex polygons)
     def createSinglePolygon(self, vlayer):
         provider = vlayer.dataProvider()
         allAttrs = provider.attributeIndexes()
@@ -157,7 +160,7 @@
             self.progressBar.setValue(count)
         return geom
     
-# Generate list of random points     
+# Generate list of random points
     def simpleRandom(self, n, bound, xmin, xmax, ymin, ymax):
         seed()
         points = []

Modified: trunk/qgis/python/plugins/fTools/tools/doRandom.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doRandom.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doRandom.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -17,36 +17,39 @@
         # populate layer list
         self.progressBar.setValue(0)
         mapCanvas = self.iface.mapCanvas()
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
         layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon])
         self.inShape.addItems(layers)
         
     def changed(self, inputLayer):
-	changedLayer = ftools_utils.getVectorLayerByName(inputLayer)
-	changedProvider = changedLayer.dataProvider()
-	upperVal = changedProvider.featureCount()
-	self.spnNumber.setMaximum(upperVal)
+        changedLayer = ftools_utils.getVectorLayerByName(inputLayer)
+        changedProvider = changedLayer.dataProvider()
+        upperVal = changedProvider.featureCount()
+        self.spnNumber.setMaximum(upperVal)
 
     def accept(self):
-	if self.inShape.currentText() == "":
-	    QMessageBox.information(self, self.tr("Random Selection Tool"), self.tr("No input shapefile specified"))
-	else:
+        self.buttonOk.setEnabled( False )
+        if self.inShape.currentText() == "":
+            QMessageBox.information(self, self.tr("Random Selection Tool"), self.tr("No input shapefile specified"))
+        else:
             self.progressBar.setValue(10)
             inName = self.inShape.currentText()
-	    self.progressBar.setValue(20)
-    	    layer = ftools_utils.getVectorLayerByName(inName)
-    	    self.progressBar.setValue(30)
-	    if self.rdoNumber.isChecked():
-		value = self.spnNumber.value()
-		self.progressBar.setValue(60)
-	    else:
-		value = self.spnPercent.value()
-		self.progressBar.setValue(50)
-		value = int(round((value / 100.0000), 4) * layer.featureCount())
-		self.progressBar.setValue(60)
-	    selran = random.sample(xrange(0, layer.featureCount()), value)
-	    self.progressBar.setValue(70)
-	    self.progressBar.setValue(80)
-	    self.progressBar.setValue(90)
-	    self.progressBar.setValue(100)
-	    layer.setSelectedFeatures(selran)
-	    self.progressBar.setValue(0)
+            self.progressBar.setValue(20)
+            layer = ftools_utils.getVectorLayerByName(inName)
+            self.progressBar.setValue(30)
+            if self.rdoNumber.isChecked():
+                value = self.spnNumber.value()
+                self.progressBar.setValue(60)
+            else:
+                value = self.spnPercent.value()
+                self.progressBar.setValue(50)
+                value = int(round((value / 100.0000), 4) * layer.featureCount())
+                self.progressBar.setValue(60)
+                selran = random.sample(xrange(0, layer.featureCount()), value)
+                self.progressBar.setValue(70)
+                self.progressBar.setValue(80)
+                self.progressBar.setValue(90)
+                self.progressBar.setValue(100)
+                layer.setSelectedFeatures(selran)
+        self.progressBar.setValue(0)
+        self.buttonOk.setEnabled( True )

Modified: trunk/qgis/python/plugins/fTools/tools/doReProject.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doReProject.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doReProject.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -18,6 +18,7 @@
         QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.updateProj1)
         QObject.connect(self.cmbLayer, SIGNAL("currentIndexChanged(QString)"), self.updateProj2)
         self.setWindowTitle( self.tr("Export to new projection") )
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
         self.progressBar.setValue(0)
         mapCanvas = self.iface.mapCanvas()
         layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon])
@@ -37,6 +38,7 @@
         self.outRef.insert(unicode(crs))
 
     def accept(self):
+        self.buttonOk.setEnabled( False )
         if self.inShape.currentText() == "":
             QMessageBox.information(self, self.tr("Export to new projection"), self.tr("No input layer specified"))
         elif self.outShape.text() == "":
@@ -64,6 +66,7 @@
                     self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
                     QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
         self.progressBar.setValue(0)
+        self.buttonOk.setEnabled( True )
 
     def outProjFile(self):
         format = QString( "<h2>%1</h2>%2 <br/> %3" )

Modified: trunk/qgis/python/plugins/fTools/tools/doRegPoints.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doRegPoints.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doRegPoints.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -50,12 +50,14 @@
         self.yMax.setValidator(QDoubleValidator(self.yMax))
         QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
         self.setWindowTitle( self.tr("Regular points") )
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
         self.progressBar.setValue(0)
         self.mapCanvas = self.iface.mapCanvas()
         layers = ftools_utils.getLayerNames("all")
         self.inShape.addItems(layers)
 
     def accept(self):
+        self.buttonOk.setEnabled( False )
         if not self.rdoCoordinates.isChecked() and self.inShape.currentText() == "":
             QMessageBox.information(self, self.tr("Generate Regular Points"), self.tr("Please specify input layer"))
         elif self.rdoCoordinates.isChecked() and (self.xMin.text() == "" or self.xMax.text() == "" or self.yMin.text() == "" or self.yMax.text() == ""):
@@ -90,7 +92,8 @@
             if addToTOC == QMessageBox.Yes:
                 self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
                 QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
-            self.progressBar.setValue(0)
+        self.progressBar.setValue(0)
+        self.buttonOk.setEnabled( True )
 
     def outFile(self):
         self.outShape.clear()
@@ -99,7 +102,7 @@
             return
         self.outShape.setText( QString( self.shapefileName ) )
     
-# Generate list of random points     
+# Generate list of random points
     def simpleRandom(self, n, bound, xmin, xmax, ymin, ymax):
         seed()
         points = []

Modified: trunk/qgis/python/plugins/fTools/tools/doSelectByLocation.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doSelectByLocation.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doSelectByLocation.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -12,6 +12,7 @@
         self.iface = iface
         # Set up the user interface from Designer.
         self.setupUi(self)
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
 
         # populate layer list
         self.progressBar.setValue(0)
@@ -41,6 +42,7 @@
         self.resize(381, 100)
 
     def accept(self):
+        self.buttonOk.setEnabled( False )
         if self.inPolygon.currentText() == "":
             QMessageBox.information(self, self.tr("Select by location"), self.tr( "Please specify input layer"))
         elif self.inPoint.currentText() == "":
@@ -50,6 +52,7 @@
             inPts = self.inPoint.currentText()
             self.compute(inPoly, inPts, self.cmbModify.currentText())
         self.progressBar.setValue(0)
+        self.buttonOk.setEnabled( True )
 
     def compute(self, inPoly, inPts, modify):
         inputLayer = ftools_utils.getVectorLayerByName(inPoly)

Modified: trunk/qgis/python/plugins/fTools/tools/doSpatialJoin.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doSpatialJoin.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doSpatialJoin.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -48,6 +48,7 @@
         self.setupUi(self)
         QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
         self.setWindowTitle( self.tr("Join attributes by location") )
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
         # populate layer list
         self.progressBar.setValue(0)
         mapCanvas = self.iface.mapCanvas()
@@ -56,6 +57,7 @@
         self.joinShape.addItems(layers)
     
     def accept(self):
+        self.buttonOk.setEnabled( False )
         if self.inShape.currentText() == "":
             QMessageBox.information(self, self.tr("Spatial Join"), self.tr("Please specify target vector layer") )
         elif self.outShape.text() == "":
@@ -96,6 +98,7 @@
                 self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
                 QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
         self.progressBar.setValue(0)
+        self.buttonOk.setEnabled( True )
 
     def outFile(self):
         self.outShape.clear()

Modified: trunk/qgis/python/plugins/fTools/tools/doSubsetSelect.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doSubsetSelect.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doSubsetSelect.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -45,6 +45,7 @@
         self.setupUi(self)
         QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
         self.setWindowTitle(self.tr("Random selection within subsets"))
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
         # populate layer list
         self.progressBar.setValue(0)
         mapCanvas = self.iface.mapCanvas()
@@ -61,6 +62,7 @@
         self.spnNumber.setMaximum( maxFeatures )
 
     def accept(self):
+        self.buttonOk.setEnabled( False )
         if self.inShape.currentText() == "":
             QMessageBox.information(self, self.tr("Random selection within subsets"), self.tr("Please specify input vector layer"))
         elif self.inField.currentText() == "":
@@ -77,26 +79,12 @@
             self.compute(inVect, uidField, value, perc, self.progressBar)
             self.progressBar.setValue(100)
         self.progressBar.setValue(0)
+        self.buttonOk.setEnabled( True )
 
-    def outFile(self):
-        self.outShape.clear()
-        fileDialog = QFileDialog()
-        fileDialog.setConfirmOverwrite(False)
-        outName = fileDialog.getSaveFileName(self, self.tr("Output Shapefile"),".", self.tr("Shapefiles (*.shp)"))
-        fileCheck = QFile(outName)
-        if fileCheck.exists():
-            QMessageBox.warning(self, self.tr("Random selection within subsets"), self.tr("Cannot overwrite existing shapefile..."))
-        else:
-            filePath = QFileInfo(outName).absoluteFilePath()
-            if filePath.right(4) != ".shp": filePath = filePath + ".shp"
-            if not outName.isEmpty():
-                self.outShape.clear()
-                self.outShape.insert(filePath)
-
     def compute(self, inVect, inField, value, perc, progressBar):
         vlayer = ftools_utils.getVectorLayerByName(inVect)
         vprovider = vlayer.dataProvider()
-        mlayer = self.getMapLayerByName(inVect)
+        mlayer = ftools_utils.getMapLayerByName(inVect)
         allAttrs = vprovider.attributeIndexes()
         vprovider.select(allAttrs)
         index = vprovider.fieldNameIndex(inField)
@@ -129,11 +117,3 @@
                 mlayer.setSelectedFeatures(selran)
         else:
             mlayer.setSelectedFeatures(range(0, mlayer.featureCount()))
-
-    def getMapLayerByName(self, myName):
-        mc = self.iface.mapCanvas()
-        nLayers = mc.layerCount()
-        for l in range(nLayers):
-            layer = mc.layer(l)
-            if layer.name() == unicode(myName,'latin1'):
-                return layer

Modified: trunk/qgis/python/plugins/fTools/tools/doSumLines.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doSumLines.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doSumLines.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -46,6 +46,7 @@
         self.setupUi(self)
         QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
         self.setWindowTitle(self.tr("Sum line lengths"))
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
         # populate layer list
         self.progressBar.setValue(0)
         mapCanvas = self.iface.mapCanvas()
@@ -55,6 +56,7 @@
         self.inPolygon.addItems(layers)
     
     def accept(self):
+        self.buttonOk.setEnabled( False )
         if self.inPolygon.currentText() == "":
             QMessageBox.information(self, self.tr("Sum Line Lengths In Polyons"), self.tr("Please specify input polygon vector layer"))
         elif self.outShape.text() == "":
@@ -81,6 +83,7 @@
                 self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
                 QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
         self.progressBar.setValue(0)
+        self.buttonOk.setEnabled( True )
 
     def outFile(self):
         self.outShape.clear()

Modified: trunk/qgis/python/plugins/fTools/tools/doVectorGrid.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doVectorGrid.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doVectorGrid.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -46,6 +46,7 @@
         #QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.updateInput)
         QObject.connect(self.btnUpdate, SIGNAL("clicked()"), self.updateLayer)
         QObject.connect(self.btnCanvas, SIGNAL("clicked()"), self.updateCanvas)
+        self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
         self.setWindowTitle(self.tr("Vector grid"))
         self.xMin.setValidator(QDoubleValidator(self.xMin))
         self.xMax.setValidator(QDoubleValidator(self.xMax))
@@ -78,6 +79,7 @@
         self.yMax.setText( unicode( boundBox.yMaximum() ) )
 
     def accept(self):
+        self.buttonOk.setEnabled( False )
         if self.xMin.text() == "" or self.xMax.text() == "" or self.yMin.text() == "" or self.yMax.text() == "":
             QMessageBox.information(self, self.tr("Vector grid"), self.tr("Please specify valid extent coordinates"))
         elif self.outShape.text() == "":
@@ -100,7 +102,8 @@
             addToTOC = QMessageBox.question(self, self.tr("Generate Vector Grid"), self.tr("Created output shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg(unicode(self.shapefileName)), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
             if addToTOC == QMessageBox.Yes:
                 ftools_utils.addShapeToCanvas( self.shapefileName )
-            self.progressBar.setValue( 0 )
+        self.progressBar.setValue( 0 )
+        self.buttonOk.setEnabled( True )
 
     def compute( self, bound, xOffset, yOffset, polygon ):
         crs = self.iface.mapCanvas().mapRenderer().destinationSrs()

Modified: trunk/qgis/python/plugins/fTools/tools/doVisual.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doVisual.py	2010-05-13 22:52:11 UTC (rev 13480)
+++ trunk/qgis/python/plugins/fTools/tools/doVisual.py	2010-05-13 22:55:59 UTC (rev 13481)
@@ -16,6 +16,7 @@
       QObject.connect( self.inShape, SIGNAL( "currentIndexChanged(QString)" ), self.update )
     self.manageGui()
     self.cancel_close = self.buttonBox_2.button( QDialogButtonBox.Close )
+    self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
     self.progressBar.setValue( 0 )
     self.partProgressBar.setValue( 0 )
     self.partProgressBar.setVisible( False )
@@ -110,6 +111,7 @@
     self.tblUnique.clearContents()
     self.tblUnique.setRowCount( 0 )
     self.lstCount.clear()
+    self.buttonOk.setEnabled( False )
     self.testThread = visualThread( self.iface.mainWindow(), self, self.myFunction, vlayer, myField, mySelection )
     QObject.connect( self.testThread, SIGNAL( "runFinished(PyQt_PyObject)" ), self.runFinishedFromThread )
     QObject.connect( self.testThread, SIGNAL( "runStatus(PyQt_PyObject)" ), self.runStatusFromThread )
@@ -123,9 +125,11 @@
 
   def cancelThread( self ):
     self.testThread.stop()
+    self.buttonOk.setEnabled( True )
     
   def runFinishedFromThread( self, output ):
     self.testThread.stop()
+    self.buttonOk.setEnabled( True )
     result = output[ 0 ]
     numRows = len( result )
     self.tblUnique.setRowCount( numRows )
@@ -195,7 +199,7 @@
     self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
 
   def stop(self):
-    self.running = False        
+    self.running = False
 
   def list_unique_values( self, vlayer, myField ):
     vprovider = vlayer.dataProvider()



More information about the QGIS-commit mailing list