The docs you are looking at are for qt4 not qt5 thats probably why the api
is different. This information
http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html#qfiledialog may
be relevant to you, In brief it looks like qt4's getOpenFileNameAndFilter
has been renamed getOpenFileName and the qt4 version of getOpenFileName has
been removed. I don't think thats directly relevant to your other issue.

Is this specific to running from Jupyter? I can't reproduce the issue on
OSX 10.12 and Python 3.6, neither with Anaconda and pyqt5.6 or the pip
installed pyqt5.9 running a script with your code. If I add a
sys.exit(app.exec_()) to the bottom to run the event loop such as here
http://zetcode.com/gui/pyqt5/firstprograms/ it does indeed hang but that is
independent of if you press cancel or not. That is probably because there
is no main widget.

If I add the File dialog to a widget such as in the following, everything
works as expected.

import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtWidgets import QApplication, QFileDialog

app = QApplication(sys.argv)

w = QWidget()
w.show()
fname = QFileDialog.getOpenFileName(w,  "Select a file...", '.',
filter="All files (*)")
print(str(fname))
sys.exit(app.exec_())





On Tue, 22 Aug 2017 at 03:09 Heath Raftery <[email protected]> wrote:

> Two updates:
>
>
>    1. Reading the source code I see that sure enough, getOpenFileName
>    returns a tuple of the name and the filter, contrary to the docs.
>    2. Inspired by this
>    <http://www.qtcentre.org/threads/60874-QFileDialog-freezes>, I found a
>    crappy workaround:
>
> fname = QFileDialog.getOpenFileName(None, "Select a file...", '.', filter="All
> files (*),
>
> options=QFileDialog.DontUseNativeDialog)
>
> Adding the DontUseNativeDialog option shows the ugly Qt dialog, but it
> doesn't hang!
>
> Heath
>
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/ebc23011-0ae6-40c8-8a9a-05ef48b4c44d%40googlegroups.com
> <https://groups.google.com/d/msgid/jupyter/ebc23011-0ae6-40c8-8a9a-05ef48b4c44d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/CAM-Pw02NW1u-45kEcBt-6R4MCTB%3DpzVfQBxwjXzBgGJ2apW47w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to