开发者

How do I (quickly) thumbnail 300 images with PyQT4?

开发者 https://www.devze.com 2023-02-02 21:33 出处:网络
I\'m working (still) on a book binding application, and to make it aesthetically pleasing, I\'ve added a thumbnail to every page you drag in. It works just fine, but the only problem is that when I dr

I'm working (still) on a book binding application, and to make it aesthetically pleasing, I've added a thumbnail to every page you drag in. It works just fine, but the only problem is that when I drag in a whole book (i.e. 400 images), it freezes completely until it's don开发者_如何学Pythone.

Here's my simple drop code:

  def fileDropped(self, file):
    f = str(file[-1])

    if os.path.splitext(f)[1][1:] != 'tif':
      reply = QtGui.QMessageBox.question(self, 'Message', 'All files must be TIF images. Would you like me to convert a copy of your file to the TIF format?', QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)

      if reply == QtGui.QMessageBox.Yes:
        if not os.path.exists('./djvu_backup/'):  os.mkdir('./djvu_backup/')



        if f not in self.getChildren(self.ui.pageList):   # It's a custom method. It does what it looks like it does.
          icon = QtGui.QIcon(f)
          pixmap = icon.pixmap(72, 72)
          icon = QtGui.QIcon(pixmap)
          item = QtGui.QListWidgetItem(f, self.ui.pageList)
          item.setIcon(icon)
          item.setStatusTip(f)

        return True

Also, just as a side question, as you can see in the code, f = str(file[-1]). I have to select the last element from my dropped files array every time the method is called, as it is called for every file dropped, even if they are dropped all at once. Is there a reason/workaround for this?

Thank you!


You could try to make the thumbnailing faster, but that would only increase the size of the book that you could drop before you'd notice the problem. The answers are to either only thumbnail a page as it's displayed, or relegate the thumbnailing to a background thread and update the display as each is finished.


I know this is really simple but have you considered using a QProgressBar just so the users can see that the program is still processing when it appears to be frozen?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号