View Single Post
Old 07-12-2014, 06:30 PM   #74
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,774
Karma: 206758686
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by jackie_w View Post
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.

Last edited by DiapDealer; 07-12-2014 at 06:34 PM.
DiapDealer is offline   Reply With Quote