Skip to content

Commit

Permalink
Fix broken python save/open dialogs under PyQt5
Browse files Browse the repository at this point in the history
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 eba6101
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 66 deletions.
8 changes: 4 additions & 4 deletions python/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions python/console/console_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions python/console/console_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'))
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/GdalTools/tools/GdalTools_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/MetaSearch/dialogs/manageconnectionsdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/db_manager/db_plugins/spatialite/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/db_manager/dlg_export_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions python/plugins/db_manager/dlg_import_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/BatchInputSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/BatchOutputSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions python/plugins/processing/gui/BatchPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/gui/ConfigDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/FileSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/HistoryDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/InputLayerSelectorPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/MultipleFileInputDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/gui/RenderingStyleFilePanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/gui/ScriptEditorDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == '':
Expand Down Expand Up @@ -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 \
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/modeler/AddModelFromFileAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 9 additions & 9 deletions python/plugins/processing/modeler/ModelerDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/script/AddScriptFromFileAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

6 comments on commit eba6101

@arnaud-morvan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@arnaud-morvan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@nyalldawson
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.