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

On Tuesday, August 22, 2017 at 10:34:30 AM UTC+10, Heath Raftery wrote:
>
> In the recent past I've used PyQt to show an Open Dialog from Jupyter, 
> like so:
>
> from PyQt4 import QtGui
> app = QtGui.QApplication([dir])
> fname = QtGui.QFileDialog.getOpenFileName(None, "Select a file...", '.', 
> filter="All files (*)")
>
> This seems to work okay. On a new installation, I'm trying the equivalent 
> with PyQt5:
>
> from PyQt5.QtWidgets import QApplication, QFileDialog
> app = QApplication.instance()
> if not app:
>     app = QApplication([dir])
> fname = QFileDialog.getOpenFileName(None,  "Select a file...", '.', filter
> ="All files (*)")
> print(str(fname))
>
> This version also works okay, except if the user clicks the dialog's 
> *Cancel* button! The print statement executes but the dialog hangs and 
> the process needs to be force quit.
>
> May or may not be relevant, but oddly the fname return value is not the 
> filename as the documentation suggests 
> <http://pyqt.sourceforge.net/Docs/PyQt4/qfiledialog.html#getOpenFileName>. 
> Instead is a tuple of the filename and filter string, as if 
> QFileDialog.getOpenFileNameAndFilter had been called instead.
>
> Unfortunately I can't just install PyQt4 due to a conflict (assumedly 
> because I installed the Python3 version of Anaconda:
>
> UnsatisfiableError: The following specifications were found to be in 
> conflict:
>
>   - pyqt 4* -> python 2.6* -> openssl 1.0.1*
>
>   - python 3.6*
>
> Any ideas why the QFileDialog is hanging on cancel? Any suggestions for a 
> workaround?
>
> This is all on macOS, but I'm looking for a cross-platform solution.
>
> Regards,
> 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/78916722-73ac-4736-9900-a33245a19ca0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to