如何使用 PyQT4(快速)制作 300 张图像的缩略图?

发布于 2024-10-10 08:15:26 字数 1111 浏览 0 评论 0原文

我正在(仍在)开发书籍装订应用程序,为了使其美观,我为拖入的每个页面添加了缩略图。它工作得很好,但唯一的问题是当我拖入整个页面时书(即 400 张图像),它会完全冻结,直到完成。

这是我的简单放置代码:

  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

另外,正如您在代码中看到的那样,作为一个附带问题,f = str(file[-1])。每次调用该方法时,我都必须从删除的文件数组中选择最后一个元素,因为它会为每个删除的文件调用,即使它们一次全部删除。这有原因/解决方法吗?

谢谢你!

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 done.

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

决绝 2024-10-17 08:15:26

您可以尝试加快缩略图速度,但这只会增加书籍的大小,您可能会在注意到问题之前将其丢弃。答案是要么仅在显示页面时对其进行缩略图,要么将缩略图移交给后台线程并在每个页面完成时更新显示。

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.

英雄似剑 2024-10-17 08:15:26

我知道这非常简单,但是您是否考虑过使用 QProgressBar,以便用户可以看到程序在看起来被冻结时仍在处理?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文