2525
2626__revision__ = '$Format:%H$'
2727
28- from qgis .core import *
29- from PyQt4 import QtGui , QtCore
3028from PyQt4 .QtCore import *
3129from PyQt4 .QtGui import *
30+
31+ from qgis .core import *
32+ from qgis .utils import iface
33+
3234from processing .gui .RectangleMapTool import RectangleMapTool
3335from processing .core .parameters import ParameterRaster
3436from processing .core .parameters import ParameterVector
3537from processing .core .parameters import ParameterMultipleInput
3638from processing .tools import dataobjects
37- from qgis .utils import iface
3839
39- class ExtentSelectionPanel (QtGui .QWidget ):
40+ from processing .ui .ui_widgetExtentSelector import Ui_Form
41+
42+ class ExtentSelectionPanel (QWidget , Ui_Form ):
4043
4144 def __init__ (self , dialog , alg , default ):
42- super (ExtentSelectionPanel , self ).__init__ (None )
45+ QWidget .__init__ (self )
46+ self .setupUi (self )
47+
4348 self .dialog = dialog
4449 self .params = alg .parameters
45- self .horizontalLayout = QtGui .QHBoxLayout (self )
46- self .horizontalLayout .setSpacing (2 )
47- self .horizontalLayout .setMargin (0 )
48- self .text = QtGui .QLineEdit ()
49- self .text .setSizePolicy (QtGui .QSizePolicy .Expanding ,
50- QtGui .QSizePolicy .Expanding )
5150 if self .canUseAutoExtent ():
52- if hasattr (self .text , 'setPlaceholderText' ):
53- self .text .setPlaceholderText (
51+ if hasattr (self .leExtent , 'setPlaceholderText' ):
52+ self .leExtent .setPlaceholderText (
5453 self .tr ('[Leave blank to use min covering extent]' ))
55- self .horizontalLayout .addWidget (self .text )
56- self .pushButton = QtGui .QPushButton ()
57- self .pushButton .setText ('...' )
58- self .pushButton .clicked .connect (self .buttonPushed )
59- self .horizontalLayout .addWidget (self .pushButton )
60- self .setLayout (self .horizontalLayout )
54+
55+ self .btnSelect .clicked .connect (self .selectExtent )
56+
6157 canvas = iface .mapCanvas ()
6258 self .prevMapTool = canvas .mapTool ()
6359 self .tool = RectangleMapTool (canvas )
64- self .connect ( self . tool , SIGNAL ( ' rectangleCreated()' ), self .fillCoords )
60+ self .tool . rectangleCreated . connect ( self .updateExtent )
6561
6662 def canUseAutoExtent (self ):
6763 for param in self .params :
@@ -72,28 +68,31 @@ def canUseAutoExtent(self):
7268
7369 return False
7470
75- def buttonPushed (self ):
71+ def selectExtent (self ):
7672 popupmenu = QMenu ()
77- useLayerExtentAction = QtGui .QAction (self .tr ('Use layer/canvas extent' ),
78- self .pushButton )
79- useLayerExtentAction .triggered .connect (self .useLayerExtent )
73+ useLayerExtentAction = QAction (
74+ self .tr ('Use layer/canvas extent' ), self .btnSelect )
75+ selectOnCanvasAction = QAction (
76+ self .tr ('Select extent on canvas' ), self .btnSelect )
77+
8078 popupmenu .addAction (useLayerExtentAction )
81- selectOnCanvasAction = QtGui .QAction (self .tr ('Select extent on canvas' ),
82- self .pushButton )
83- selectOnCanvasAction .triggered .connect (self .selectOnCanvas )
8479 popupmenu .addAction (selectOnCanvasAction )
80+
81+ selectOnCanvasAction .triggered .connect (self .selectOnCanvas )
82+ useLayerExtentAction .triggered .connect (self .useLayerExtent )
83+
8584 if self .canUseAutoExtent ():
86- useMincoveringExtentAction = \
87- QtGui . QAction ( self .tr ('Use min covering extent from input layers' ),
88- self .pushButton )
85+ useMincoveringExtentAction = QAction (
86+ self .tr ('Use min covering extent from input layers' ),
87+ self .btnSelect )
8988 useMincoveringExtentAction .triggered .connect (
9089 self .useMinCoveringExtent )
9190 popupmenu .addAction (useMincoveringExtentAction )
9291
93- popupmenu .exec_ (QtGui . QCursor .pos ())
92+ popupmenu .exec_ (QCursor .pos ())
9493
9594 def useMinCoveringExtent (self ):
96- self .text .setText ('' )
95+ self .leExtent .setText ('' )
9796
9897 def getMinCoveringExtent (self ):
9998 first = True
@@ -119,8 +118,8 @@ def getMinCoveringExtent(self):
119118 self .addToRegion (layer , first )
120119 first = False
121120 if found :
122- return str ( self . xmin ) + ',' + str ( self . xmax ) + ',' \
123- + str ( self .ymin ) + ',' + str ( self .ymax )
121+ return '{},{},{},{}' . format (
122+ self . xmin , self .xmax , self . ymin , self .ymax )
124123 else :
125124 return None
126125
@@ -148,8 +147,8 @@ def useLayerExtent(self):
148147 for layer in layers :
149148 extents .append (layer .name ())
150149 extentsDict [layer .name ()] = layer .extent ()
151- (item , ok ) = QtGui . QInputDialog .getItem (self , 'Select extent' ,
152- 'Use extent from' , extents , False )
150+ (item , ok ) = QInputDialog .getItem (self , self . tr ( 'Select extent' ) ,
151+ self . tr ( 'Use extent from' ) , extents , False )
153152 if ok :
154153 self .setValueFromRect (extentsDict [item ])
155154
@@ -158,14 +157,15 @@ def selectOnCanvas(self):
158157 canvas .setMapTool (self .tool )
159158 self .dialog .showMinimized ()
160159
161- def fillCoords (self ):
160+ def updateExtent (self ):
162161 r = self .tool .rectangle ()
163162 self .setValueFromRect (r )
164163
165164 def setValueFromRect (self , r ):
166- s = str (r .xMinimum ()) + ',' + str (r .xMaximum ()) + ',' \
167- + str (r .yMinimum ()) + ',' + str (r .yMaximum ())
168- self .text .setText (s )
165+ s = '{},{},{},{}' .format (
166+ r .xMinimum (), r .xMaximum (), r .yMinimum (), r .yMaximum ())
167+
168+ self .leExtent .setText (s )
169169 self .tool .reset ()
170170 canvas = iface .mapCanvas ()
171171 canvas .setMapTool (self .prevMapTool )
@@ -174,7 +174,7 @@ def setValueFromRect(self, r):
174174 self .dialog .activateWindow ()
175175
176176 def getValue (self ):
177- if str (self .text .text ()).strip () != '' :
178- return str (self .text .text ())
177+ if str (self .leExtent .text ()).strip () != '' :
178+ return str (self .leExtent .text ())
179179 else :
180180 return self .getMinCoveringExtent ()
0 commit comments