Quote:
Originally Posted by jackie_w
What is the best way to deal with the change to the QFileDialog.getOpenFileName method?
PyQt4 used to return a single filepath but PyQt5 returns 2 strings ( filepath, filter). I don't need the filter part of the result so I've temporarily solved it like this:
Code:
fd = QFileDialog()
if hasattr(fd, 'getOpenFileNameAndFilter'):
# PyQt4
ans = fd.getOpenFileNameAndFilter(self, mycaption, mydir, myfilter)
else:
# PyQt5
ans = fd.getOpenFileName(self, mycaption, mydir, myfilter)
selfile = unicode(ans[0])
Is there a better calibre-way of doing this? I fully admit that this particular personal plugin started life completely external to calibre so uses less calibre special functionality than it might. I tend to only fix things if they break.
|
I have no idea if it's "better" or not, but I went with something like:
Code:
ans = QFileDialog.getOpenFileName(self, mycaption, mydir, myfilter)
selfile = ans[0] if isinstance(ans, tuple) else ans
if selfile:
do-stuff with selfile
when I ran into something similar with QFileDialog.getSaveFileName.