Qt.py icon indicating copy to clipboard operation
Qt.py copied to clipboard

PyQt5 uses `directory` instead of `dir` for members of QFileDialog

Open jasperges opened this issue 6 years ago • 5 comments

In all bindings you have the keyword argument dir for members of QFileDialog, but in PyQt5 it is directory (personally I think it's better because it doesn't redefine a built-in). For example QFileDialog.getOpenFilename(dir="/home/me") would be QFileDialog.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 or directory. If that would be impractical, I would suggest dir because that is used by the majority of bindings.

jasperges avatar Aug 02 '19 09:08 jasperges

@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 avatar Aug 02 '19 09:08 BigRoy

@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.

jasperges avatar Aug 02 '19 10:08 jasperges

@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? ;)

BigRoy avatar Aug 02 '19 12:08 BigRoy

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)

mottosso avatar Aug 04 '19 10:08 mottosso

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.

MHendricks avatar Aug 05 '19 17:08 MHendricks