Skip to content
Permalink
Browse files

Fix broken python save/open dialogs under PyQt5

Will break stuff under PyQt4... oh well, better stuff working on Qt5
then Qt4
  • Loading branch information
nyalldawson committed Sep 5, 2016
1 parent e54f9be commit eba61013574bff36f03f791ec4e1b4fdadce43d5
@@ -623,7 +623,7 @@ def openScriptFileExtEditor(self):
def openScriptFile(self):
lastDirPath = self.settings.value("pythonConsole/lastDirPath", QDir.homePath())
openFileTr = QCoreApplication.translate("PythonConsole", "Open File")
fileList = QFileDialog.getOpenFileNames(
fileList, selected_filter = QFileDialog.getOpenFileNames(
self, openFileTr, lastDirPath, "Script file (*.py)")
if fileList:
for pyFile in fileList:
@@ -663,9 +663,9 @@ def saveAsScriptFile(self, index=None):
pathFileName = tabWidget.path
fileNone = False
saveAsFileTr = QCoreApplication.translate("PythonConsole", "Save File As")
filename = QFileDialog.getSaveFileName(self,
saveAsFileTr,
pathFileName, "Script file (*.py)")
filename, filter = QFileDialog.getSaveFileName(self,
saveAsFileTr,
pathFileName, "Script file (*.py)")
if filename:
try:
tabWidget.save(filename)
@@ -802,10 +802,10 @@ def save(self, fileName=None):
if self.path is None:
saveTr = QCoreApplication.translate('PythonConsole',
'Python Console: Save file')
self.path = QFileDialog().getSaveFileName(self,
saveTr,
self.tw.tabText(index) + '.py',
"Script file (*.py)")
self.path, filter = QFileDialog().getSaveFileName(self,
saveTr,
self.tw.tabText(index) + '.py',
"Script file (*.py)")
# If the user didn't select a file, abort the save operation
if len(self.path) == 0:
self.path = None
@@ -73,7 +73,7 @@ def enableDisable(self, value):
def loadAPIFile(self):
settings = QSettings()
lastDirPath = settings.value("pythonConsole/lastDirAPIPath", "", type=str)
fileAPI = QFileDialog.getOpenFileName(
fileAPI, selected_filter = QFileDialog.getOpenFileName(
self, "Open API File", lastDirPath, "API file (*.api)")
if fileAPI:
self.addAPI(fileAPI)
@@ -83,10 +83,10 @@ def loadAPIFile(self):

def _prepareAPI(self):
if self.tableWidget.rowCount() != 0:
pap_file = QFileDialog().getSaveFileName(self,
"",
'*.pap',
"Prepared APIs file (*.pap)")
pap_file, filter = QFileDialog().getSaveFileName(self,
"",
'*.pap',
"Prepared APIs file (*.pap)")
else:
QMessageBox.information(self, self.tr("Warning!"),
self.tr('You need to add some APIs file in order to compile'))
@@ -447,7 +447,7 @@ def getDialog(self, parent=None, caption='', acceptMode=QFileDialog.AcceptOpen,
def getOpenFileNames(self, parent=None, caption='', filter='', selectedFilter=None, useEncoding=False):
if useEncoding:
return self.getDialog(parent, caption, QFileDialog.AcceptOpen, QFileDialog.ExistingFiles, filter, selectedFilter, useEncoding)
res = QFileDialog.getOpenFileNames(parent, caption, getLastUsedDir(), filter)
res, selected_filter = QFileDialog.getOpenFileNames(parent, caption, getLastUsedDir(), filter)
if len(res) > 0:
setLastUsedDir(res[-1])
return res
@@ -456,7 +456,7 @@ def getOpenFileNames(self, parent=None, caption='', filter='', selectedFilter=No
def getOpenFileName(self, parent=None, caption='', filter='', selectedFilter=None, useEncoding=False):
if useEncoding:
return self.getDialog(parent, caption, QFileDialog.AcceptOpen, QFileDialog.ExistingFile, filter, selectedFilter, useEncoding)
res = QFileDialog.getOpenFileName(parent, caption, getLastUsedDir(), filter)
res, selected_filter = QFileDialog.getOpenFileName(parent, caption, getLastUsedDir(), filter)
if res:
setLastUsedDir(res)
return res
@@ -465,7 +465,7 @@ def getOpenFileName(self, parent=None, caption='', filter='', selectedFilter=Non
def getSaveFileName(self, parent=None, caption='', filter='', selectedFilter=None, useEncoding=False):
if useEncoding:
return self.getDialog(parent, caption, QFileDialog.AcceptSave, QFileDialog.AnyFile, filter, selectedFilter, useEncoding)
res = QFileDialog.getSaveFileName(parent, caption, getLastUsedDir(), filter)
res, filter = QFileDialog.getSaveFileName(parent, caption, getLastUsedDir(), filter)
if res:
setLastUsedDir(res)
return res
@@ -73,12 +73,12 @@ def select_file(self):

if self.mode == 0:
slabel = self.tr('Save connections')
self.filename = QFileDialog.getSaveFileName(self, slabel,
'.', label)
self.filename, filter = QFileDialog.getSaveFileName(self, slabel,
'.', label)
else:
slabel = self.tr('Load connections')
self.filename = QFileDialog.getOpenFileName(self, slabel,
'.', label)
self.filename, selected_filter = QFileDialog.getOpenFileName(self, slabel,
'.', label)

if not self.filename:
return
@@ -89,7 +89,7 @@ def addConnection(self, conn_name, uri):
def addConnectionActionSlot(self, item, action, parent, index):
QApplication.restoreOverrideCursor()
try:
filename = QFileDialog.getOpenFileName(parent, "Choose Sqlite/Spatialite/Geopackage file")
filename, selected_filter = QFileDialog.getOpenFileName(parent, "Choose Sqlite/Spatialite/Geopackage file")
if not filename:
return
finally:
@@ -75,8 +75,8 @@ def chooseOutputFile(self):
selectedFilter = self.cboFileFormat.itemData(self.cboFileFormat.currentIndex())

# ask for a filename
filename = QFileDialog.getSaveFileName(self, self.tr("Choose where to save the file"), lastUsedDir,
selectedFilter)
filename, filter = QFileDialog.getSaveFileName(self, self.tr("Choose where to save the file"), lastUsedDir,
selectedFilter)
if filename == "":
return

@@ -130,8 +130,8 @@ def chooseInputFile(self):
lastDir = settings.value("/db_manager/lastUsedDir", "")
lastVectorFormat = settings.value("/UI/lastVectorFileFilter", "")
# ask for a filename
(filename, lastVectorFormat) = QFileDialog.getOpenFileNameAndFilter(self, self.tr("Choose the file to import"),
lastDir, vectorFormats, lastVectorFormat)
filename, lastVectorFormat = QFileDialog.getOpenFileName(self, self.tr("Choose the file to import"),
lastDir, vectorFormats, lastVectorFormat)
if filename == "":
return
# store the last used dir and format
@@ -125,8 +125,8 @@ def showFileSelectionDialog(self):
else:
path = ''

ret = QFileDialog.getOpenFileNames(self, self.tr('Open file'), path,
self.tr('All files(*.*);;') + self.param.getFileFilter())
ret, selected_filter = QFileDialog.getOpenFileNames(self, self.tr('Open file'), path,
self.tr('All files(*.*);;') + self.param.getFileFilter())
if ret:
files = list(ret)
settings.setValue('/Processing/LastInputPath',
@@ -79,8 +79,8 @@ def showSelectionDialog(self):
path = unicode(settings.value('/Processing/LastBatchOutputPath'))
else:
path = ''
filename, selectedFileFilter = QFileDialog.getSaveFileNameAndFilter(self,
self.tr('Save file'), path, filefilter)
filename, selectedFileFilter = QFileDialog.getSaveFileName(self,
self.tr('Save file'), path, filefilter)
# fix_print_with_import
print(filename, selectedFileFilter)
if filename:
@@ -179,9 +179,9 @@ def getWidgetFromParameter(self, param, row, col):
return item

def load(self):
filename = unicode(QFileDialog.getOpenFileName(self,
self.tr('Open batch'), None,
self.tr('JSON files (*.json)')))
filename, selected_filter = unicode(QFileDialog.getOpenFileName(self,
self.tr('Open batch'), None,
self.tr('JSON files (*.json)')))
if filename:
with open(filename) as f:
values = json.load(f)
@@ -283,10 +283,10 @@ def save(self):
return
toSave.append({self.PARAMETERS: algParams, self.OUTPUTS: algOutputs})

filename = unicode(QFileDialog.getSaveFileName(self,
filename, filter = QFileDialog.getSaveFileName(self,
self.tr('Save batch'),
None,
self.tr('JSON files (*.json)')))
self.tr('JSON files (*.json)'))
if filename:
if not filename.endswith('.json'):
filename += '.json'
@@ -400,9 +400,9 @@ def select(self):
self.tr('Select directory'), lastDir,
QFileDialog.ShowDirsOnly)
else:
selectedPath = QFileDialog.getOpenFileName(None,
self.tr('Select file'), lastDir, self.tr('All files (*.*)')
)
selectedPath, selected_filter = QFileDialog.getOpenFileName(None,
self.tr('Select file'), lastDir, self.tr('All files (*.*)')
)

if not selectedPath:
return
@@ -70,8 +70,8 @@ def showSelectionDialog(self):
settings.setValue('/Processing/LastInputPath',
os.path.dirname(folder))
else:
filenames = QFileDialog.getOpenFileNames(self,
self.tr('Select file'), path, '*.' + self.ext)
filenames, selected_filter = QFileDialog.getOpenFileNames(self,
self.tr('Select file'), path, '*.' + self.ext)
if filenames:
self.leText.setText(u';'.join(filenames))
settings.setValue('/Processing/LastInputPath',
@@ -84,8 +84,8 @@ def clearLog(self):
self.fillTree()

def saveLog(self):
fileName = QFileDialog.getSaveFileName(self,
self.tr('Save file'), '.', self.tr('Log files (*.log *.LOG)'))
fileName, filter = QFileDialog.getSaveFileName(self,
self.tr('Save file'), '.', self.tr('Log files (*.log *.LOG)'))

if fileName == '':
return
@@ -67,8 +67,8 @@ def showSelectionDialog(self):
else:
path = ''

filename = QFileDialog.getOpenFileName(self, self.tr('Select file'),
path, self.tr('All files (*.*);;') + self.param.getFileFilter())
filename, selected_filter = QFileDialog.getOpenFileName(self, self.tr('Select file'),
path, self.tr('All files (*.*);;') + self.param.getFileFilter())
if filename:
settings.setValue('/Processing/LastInputPath',
os.path.dirname(unicode(filename)))
@@ -92,8 +92,8 @@ def addFile(self):
else:
path = ''

files = QFileDialog.getOpenFileNames(self,
self.tr('Select file(s)'), path, self.tr('All files (*.*)'))
files, selected_filter = QFileDialog.getOpenFileNames(self,
self.tr('Select file(s)'), path, self.tr('All files (*.*)'))

if len(files) == 0:
return
@@ -46,9 +46,9 @@ def __init__(self):
self.btnSelect.clicked.connect(self.showSelectionDialog)

def showSelectionDialog(self):
filename = QFileDialog.getOpenFileName(self,
self.tr('Select style file'), '',
self.tr('QGIS Layer Style File (*.qml *.QML)'))
filename, selected_filter = QFileDialog.getOpenFileName(self,
self.tr('Select style file'), '',
self.tr('QGIS Layer Style File (*.qml *.QML)'))
if filename:
self.leText.setText(filename)

@@ -199,7 +199,7 @@ def openScript(self):
scriptDir = RUtils.RScriptsFolders()[0]
filterName = self.tr('Processing R script (*.rsx)')

self.filename = QFileDialog.getOpenFileName(
self.filename, selected_filter = QFileDialog.getOpenFileName(
self, self.tr('Open script'), scriptDir, filterName)

if self.filename == '':
@@ -230,9 +230,9 @@ def saveScript(self, saveAs):
scriptDir = RUtils.RScriptsFolders()[0]
filterName = self.tr('Processing R script (*.rsx)')

self.filename = unicode(QFileDialog.getSaveFileName(self,
self.filename, filter = QFileDialog.getSaveFileName(self,
self.tr('Save script'), scriptDir,
filterName))
filterName)

if self.filename:
if self.algType == self.SCRIPT_PYTHON and \
@@ -51,9 +51,9 @@ def getIcon(self):
def execute(self):
settings = QSettings()
lastDir = settings.value('Processing/lastModelsDir', '')
filename = QFileDialog.getOpenFileName(self.toolbox,
self.tr('Open model', 'AddModelFromFileAction'), lastDir,
self.tr('Processing model files (*.model *.MODEL)', 'AddModelFromFileAction'))
filename, selected_filter = QFileDialog.getOpenFileName(self.toolbox,
self.tr('Open model', 'AddModelFromFileAction'), lastDir,
self.tr('Processing model files (*.model *.MODEL)', 'AddModelFromFileAction'))
if filename:
try:
settings.setValue('Processing/lastModelsDir',
@@ -255,9 +255,9 @@ def saveAs(self):
self.saveModel(True)

def exportAsImage(self):
filename = unicode(QFileDialog.getSaveFileName(self,
filename, filter = QFileDialog.getSaveFileName(self,
self.tr('Save Model As Image'), '',
self.tr('PNG files (*.png *.PNG)')))
self.tr('PNG files (*.png *.PNG)'))
if not filename:
return

@@ -281,9 +281,9 @@ def exportAsImage(self):
img.save(filename)

def exportAsPython(self):
filename = unicode(QFileDialog.getSaveFileName(self,
filename, filter = QFileDialog.getSaveFileName(self,
self.tr('Save Model As Python Script'), '',
self.tr('Python files (*.py *.PY)')))
self.tr('Python files (*.py *.PY)'))
if not filename:
return

@@ -308,10 +308,10 @@ def saveModel(self, saveAs):
if self.alg.descriptionFile is not None and not saveAs:
filename = self.alg.descriptionFile
else:
filename = unicode(QFileDialog.getSaveFileName(self,
filename, filter = QFileDialog.getSaveFileName(self,
self.tr('Save Model'),
ModelerUtils.modelsFolders()[0],
self.tr('Processing models (*.model)')))
self.tr('Processing models (*.model)'))
if filename:
if not filename.endswith('.model'):
filename += '.model'
@@ -340,9 +340,9 @@ def saveModel(self, saveAs):
self.hasChanged = False

def openModel(self):
filename = unicode(QFileDialog.getOpenFileName(self,
self.tr('Open Model'), ModelerUtils.modelsFolders()[0],
self.tr('Processing models (*.model *.MODEL)')))
filename, selected_filter = unicode(QFileDialog.getOpenFileName(self,
self.tr('Open Model'), ModelerUtils.modelsFolders()[0],
self.tr('Processing models (*.model *.MODEL)')))
if filename:
try:
alg = ModelerAlgorithm.fromFile(filename)
@@ -52,9 +52,9 @@ def getIcon(self):
def execute(self):
settings = QSettings()
lastDir = settings.value('Processing/lastScriptsDir', '')
filename = QFileDialog.getOpenFileName(self.toolbox,
self.tr('Script files', 'AddScriptFromFileAction'), lastDir,
self.tr('Script files (*.py *.PY)', 'AddScriptFromFileAction'))
filename, selected_filter = QFileDialog.getOpenFileName(self.toolbox,
self.tr('Script files', 'AddScriptFromFileAction'), lastDir,
self.tr('Script files (*.py *.PY)', 'AddScriptFromFileAction'))
if filename:
try:
settings.setValue('Processing/lastScriptsDir',

6 comments on commit eba6101

@arnaud-morvan

This comment has been minimized.

Copy link
Contributor

@arnaud-morvan arnaud-morvan replied Sep 17, 2016

@volaya @nyalldawson
Seems that we are already broken with Qt4.
Does this means that I should also propose not compatible Qt4 code to fix bugs with Qt5 when needed in processing plugin ?

@nyalldawson

This comment has been minimized.

Copy link
Collaborator Author

@nyalldawson nyalldawson replied Sep 17, 2016

@arnaud-morvan I'd say yes, unless they break the Travis tests

@arnaud-morvan

This comment has been minimized.

Copy link
Contributor

@arnaud-morvan arnaud-morvan replied Sep 18, 2016

This (file, filter = QFileDialog.getOpenFileName) seems not need for me on Ubuntu 16.04 with Qt5.
Not documented in Qt5.7 API.
Do you have met some errors with another distribution ?
Is is possible to revert ? As we could keep working processing on top of master with python2, waiting for compatibility with Python3.

@nyalldawson

This comment has been minimized.

Copy link
Collaborator Author

@nyalldawson nyalldawson replied Sep 18, 2016

It's a pyqt5 change, not qt 5 itself. See http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html#qfiledialog

I hit the error using console on 16.04, so not sure why it's not triggered for you. In any case the only reason we are still keeping qt4 compatibility in master is for the handful of tests which aren't passing in qt5. I'm hoping to fix the server based tests this week, which leaves just the qvariant rounding issues. As soon as these are fixed qt5 will be mandatory.

In the meantime I'd suggest everyone using master should be on qt5 anyway, to help find and fix bugs. Use master_2 if you particularly need qt4 compatibility.

@arnaud-morvan

This comment has been minimized.

Copy link
Contributor

@arnaud-morvan arnaud-morvan replied Sep 18, 2016

I understand that qgis core plugin should be converted to python 3 ASAP. Just ?
@volaya : difficult to backport to master_2 after that.

@nyalldawson

This comment has been minimized.

Copy link
Collaborator Author

@nyalldawson nyalldawson replied Sep 18, 2016

Yeah... Backporting is a nightmare with all the changes and different branches, we're all suffering because of that. But working toward 3.0 should be our #1 priority now.

Please sign in to comment.
You can’t perform that action at this time.