3030import os
3131
3232from qgis .PyQt import uic
33- from qgis .PyQt .QtCore import QCoreApplication
33+ from qgis .PyQt .QtCore import QCoreApplication , QDir
3434from qgis .PyQt .QtWidgets import QDialog , QMenu , QAction , QFileDialog
3535from qgis .PyQt .QtGui import QCursor
3636from qgis .gui import QgsEncodingFileDialog , QgsExpressionBuilderDialog
4040 QgsSettings ,
4141 QgsProcessingParameterFeatureSink ,
4242 QgsProcessingOutputLayerDefinition ,
43- QgsProcessingParameterDefinition )
43+ QgsProcessingParameterDefinition ,
44+ QgsProcessingParameterFolderOutput )
4445from processing .core .ProcessingConfig import ProcessingConfig
45- from processing .core .outputs import OutputVector
46- from processing .core .outputs import OutputDirectory
4746from processing .tools .dataobjects import createContext
4847from processing .gui .PostgisTableSelector import PostgisTableSelector
4948from processing .gui .ParameterGuiUtils import getFileFilter
@@ -80,7 +79,7 @@ def __init__(self, parameter, alg):
8079 and alg .provider ().supportsNonFileBasedOutput ():
8180 # use memory layers for temporary files if supported
8281 self .leText .setPlaceholderText (self .SAVE_TO_TEMP_LAYER )
83- else :
82+ elif not isinstance ( self . parameter , QgsProcessingParameterFolderOutput ) :
8483 self .leText .setPlaceholderText (self .SAVE_TO_TEMP_FILE )
8584
8685 self .btnSelect .clicked .connect (self .selectOutput )
@@ -95,7 +94,7 @@ def skipOutput(self):
9594 self .use_temporary = False
9695
9796 def selectOutput (self ):
98- if isinstance (self .parameter , OutputDirectory ):
97+ if isinstance (self .parameter , QgsProcessingParameterFolderOutput ):
9998 self .selectDirectory ()
10099 else :
101100 popupMenu = QMenu ()
@@ -253,10 +252,16 @@ def selectFile(self):
253252 settings .setValue ('/Processing/encoding' , self .encoding )
254253
255254 def selectDirectory (self ):
256- lastDir = ''
255+ lastDir = self .leText .text ()
256+ settings = QgsSettings ()
257+ if not lastDir :
258+ lastDir = settings .value ("/Processing/LastOutputPath" , QDir .homePath ())
259+
257260 dirName = QFileDialog .getExistingDirectory (self , self .tr ('Select directory' ),
258261 lastDir , QFileDialog .ShowDirsOnly )
259- self .leText .setText (dirName )
262+ if dirName :
263+ self .leText .setText (QDir .toNativeSeparators (dirName ))
264+ settings .setValue ('/Processing/LastOutputPath' , dirName )
260265
261266 def getValue (self ):
262267 key = None
@@ -268,6 +273,9 @@ def getValue(self):
268273 if not key and self .parameter .flags () & QgsProcessingParameterDefinition .FlagOptional :
269274 return None
270275
276+ if isinstance (self .parameter , QgsProcessingParameterFolderOutput ):
277+ return key
278+
271279 value = QgsProcessingOutputLayerDefinition (key )
272280 value .createOptions = {'fileEncoding' : self .encoding }
273281 return value
0 commit comments