Open jasperges opened 4 years ago
@jasperges Are you sure? It seems to only use directory
for __init__
but the static methods still use dir
according to this: https://doc.qt.io/qt-5/qfiledialog.html#getOpenFileName right?
Or is this old documentation?
Edit:
Also the PyQt5 documentation doesn't state that as a change from PyQt4 at all, interestingly enough. And this just points to the C++ documentation that lists the same dir
argument (same page)
Seems like someone over-refactored the code and left it undocumented? :)
@BigRoy Yes, I'm sure. :) See here.
I used to like the documentation of PyQt better then the one from PySide. But's that's now totally reversed.
@mottosso note that PySide2 and PyQt5 do it differenty as Jasper describes here
As far as I can tell PyQt5 uses directory everywhere, where PySide2 (and also PyQt4) use dir.
What's the Qt.py way to fix this one? ;)
Me and Jasper chatted about this prior to making an issue out of it, and decided it wasn't worth handling through Qt.py.
Initially we thought of making a QtCompat member.
QtCompat.getOpenFilename()
But there are quite a few of these static members that are presumably all wrong (in PyQt) that we would need to add and I'd like to avoid having too much of anyone's code being calls to QtCompat
; it should be rare.
The other option is "fixing" the original calls, like we've done by forwarding things from Qt 4's QtGui to QtWidgets for example. That would be the ideal option, as it would mean code you write with PySide also works in PyQt and vice versa. It just isn't clear how complex that would be, but a pull-request is welcome.
And for completeness, the "correct" one would be dir
, simply because that's what PySide2 does, and Qt.py is all about making PySide2's interface work with all bindings. (It's also in the corresponding C++ call)
Qt.QtCompat.QFileDialog
already provides a compatibility specifically for the PyQt4 static members getOpenFileName
, getOpenFileNames
and getSaveFileName
return not matching the other bindings. It should be possible to implement a method for PyQt5 similar to the _standardizeQFileDialog
decorator used in the PyQt4 bindings that adjusts the kwargs before passing them to PyQt5.
In all bindings you have the keyword argument
dir
for members ofQFileDialog
, but in PyQt5 it isdirectory
(personally I think it's better because it doesn't redefine a built-in). For exampleQFileDialog.getOpenFilename(dir="/home/me")
would beQFileDialog.getOpenFileName(directory="/home/me")
in PyQt5.I have no idea how difficult this would be, but personally I think the best solution would be that you can use either
dir
ordirectory
. If that would be impractical, I would suggestdir
because that is used by the majority of bindings.