1
- from PyQt4 import QtGui , QtCore
1
+ import os .path
2
+
2
3
from PyQt4 .QtCore import *
3
4
from PyQt4 .QtGui import *
4
- import os .path
5
- from sextante .core .SextanteConfig import SextanteConfig
6
5
6
+ from qgis .gui import *
7
+
8
+ from sextante .core .SextanteConfig import SextanteConfig
7
9
8
- class OutputSelectionPanel (QtGui . QWidget ):
10
+ class OutputSelectionPanel (QWidget ):
9
11
10
12
lastOutputFolder = None
11
13
SAVE_TO_TEMP_FILE = "[Save to temporary file]"
@@ -14,34 +16,34 @@ def __init__(self, output, alg):
14
16
self .output = output
15
17
self .alg = alg
16
18
super (OutputSelectionPanel , self ).__init__ (None )
17
- self .horizontalLayout = QtGui . QHBoxLayout (self )
19
+ self .horizontalLayout = QHBoxLayout (self )
18
20
self .horizontalLayout .setSpacing (2 )
19
21
self .horizontalLayout .setMargin (0 )
20
- self .text = QtGui . QLineEdit ()
22
+ self .text = QLineEdit ()
21
23
if hasattr (self .text , 'setPlaceholderText' ):
22
24
self .text .setPlaceholderText (OutputSelectionPanel .SAVE_TO_TEMP_FILE )
23
- self .text .setSizePolicy (QtGui . QSizePolicy .Expanding , QtGui . QSizePolicy .Expanding )
25
+ self .text .setSizePolicy (QSizePolicy .Expanding , QSizePolicy .Expanding )
24
26
self .horizontalLayout .addWidget (self .text )
25
- self .pushButton = QtGui . QPushButton ()
27
+ self .pushButton = QPushButton ()
26
28
self .pushButton .setText ("..." )
27
29
self .pushButton .clicked .connect (self .buttonPushed )
28
30
self .horizontalLayout .addWidget (self .pushButton )
29
31
self .setLayout (self .horizontalLayout )
30
32
31
33
def buttonPushed (self ):
32
34
popupmenu = QMenu ()
33
- saveToTemporaryFileAction = QtGui . QAction ("Save to a temporary file" , self .pushButton )
35
+ saveToTemporaryFileAction = QAction ("Save to a temporary file" , self .pushButton )
34
36
saveToTemporaryFileAction .triggered .connect (self .saveToTemporaryFile )
35
37
popupmenu .addAction (saveToTemporaryFileAction )
36
38
if (self .alg .provider .supportsNonFileBasedOutput ()):
37
- saveToMemoryAction = QtGui . QAction ("Save to a memory layer..." , self .pushButton )
39
+ saveToMemoryAction = QAction ("Save to a memory layer..." , self .pushButton )
38
40
saveToMemoryAction .triggered .connect (self .saveToMemory )
39
41
popupmenu .addAction (saveToMemoryAction )
40
- saveToFileAction = QtGui . QAction ("Save to file..." , self .pushButton )
42
+ saveToFileAction = QAction ("Save to file..." , self .pushButton )
41
43
saveToFileAction .triggered .connect (self .saveToFile )
42
44
popupmenu .addAction (saveToFileAction )
43
45
44
- popupmenu .exec_ (QtGui . QCursor .pos ())
46
+ popupmenu .exec_ (QCursor .pos ())
45
47
46
48
def saveToTemporaryFile (self ):
47
49
self .text .setText ("" )
@@ -51,15 +53,23 @@ def saveToMemory(self):
51
53
52
54
def saveToFile (self ):
53
55
filefilter = self .output .getFileFilter (self .alg )
54
- settings = QtCore . QSettings ()
56
+ settings = QSettings ()
55
57
if settings .contains ("/SextanteQGIS/LastOutputPath" ):
56
- path = str (settings .value ( "/SextanteQGIS/LastOutputPath" , QtCore . QVariant ( "" ) ).toString ())
58
+ path = str (settings .value ( "/SextanteQGIS/LastOutputPath" , QVariant ( "" ) ).toString ())
57
59
else :
58
60
path = SextanteConfig .getSetting (SextanteConfig .OUTPUT_FOLDER )
59
- filename = QtGui .QFileDialog .getSaveFileName (self , "Save file" , QtCore .QString (path ), filefilter )
60
- if filename :
61
+ lastEncoding = settings .value ("/SextanteQGIS/encoding" , "System" ).toString ()
62
+ fileDialog = QgsEncodingFileDialog (self , "Save file" , QString (path ), filefilter , lastEncoding )
63
+ fileDialog .setFileMode (QFileDialog .AnyFile )
64
+ fileDialog .setAcceptMode (QFileDialog .AcceptSave )
65
+ fileDialog .setConfirmOverwrite (True )
66
+ if fileDialog .exec_ () == QDialog .Accepted :
67
+ filename = fileDialog .selectedFiles ().first ()
68
+ encoding = fileDialog .encoding ()
69
+ self .output .encoding = encoding
61
70
self .text .setText (str (filename ))
62
71
settings .setValue ("/SextanteQGIS/LastOutputPath" , os .path .dirname (str (filename )))
72
+ settings .setValue ("/SextanteQGIS/encoding" , encoding )
63
73
64
74
def getValue (self ):
65
75
filename = str (self .text .text ())
0 commit comments