mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use a progress spinner in the PDF covers dialog
This commit is contained in:
parent
57f712d1b6
commit
5346902c6f
@ -13,14 +13,15 @@ from glob import glob
|
||||
|
||||
import sip
|
||||
from PyQt5.Qt import (
|
||||
QDialog, QApplication, QLabel, QStackedLayout, QVBoxLayout, QDialogButtonBox, Qt,
|
||||
pyqtSignal, QListWidget, QListWidgetItem, QSize, QPixmap, QStyledItemDelegate, QWidget
|
||||
QDialog, QApplication, QLabel, QVBoxLayout, QDialogButtonBox, Qt,
|
||||
pyqtSignal, QListWidget, QListWidgetItem, QSize, QPixmap, QStyledItemDelegate
|
||||
)
|
||||
|
||||
from calibre import as_unicode
|
||||
from calibre.ebooks.metadata.pdf import page_images
|
||||
from calibre.gui2 import error_dialog, file_icon_provider
|
||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
||||
from calibre.gui2.progress_indicator import WaitLayout
|
||||
|
||||
|
||||
class CoverDelegate(QStyledItemDelegate):
|
||||
@ -44,14 +45,10 @@ class PDFCovers(QDialog):
|
||||
def __init__(self, pdfpath, parent=None):
|
||||
QDialog.__init__(self, parent)
|
||||
self.pdfpath = pdfpath
|
||||
self.stack = QStackedLayout(self)
|
||||
self.loading = QLabel('<b>'+_('Rendering PDF pages, please wait...'))
|
||||
self.stack.addWidget(self.loading)
|
||||
self.stack = WaitLayout(_('Rendering PDF pages, please wait...'), parent=self)
|
||||
self.container = self.stack.after
|
||||
|
||||
self.container = QWidget(self)
|
||||
self.stack.addWidget(self.container)
|
||||
self.container.l = l = QVBoxLayout(self.container)
|
||||
|
||||
self.la = la = QLabel(_('Choose a cover from the list of PDF pages below'))
|
||||
l.addWidget(la)
|
||||
self.covers = c = QListWidget(self)
|
||||
@ -113,7 +110,7 @@ class PDFCovers(QDialog):
|
||||
self.rendering_done.emit()
|
||||
|
||||
def hide_pages(self):
|
||||
self.stack.setCurrentIndex(0)
|
||||
self.stack.start()
|
||||
self.more_pages.setVisible(False)
|
||||
|
||||
def show_pages(self):
|
||||
@ -122,7 +119,7 @@ class PDFCovers(QDialog):
|
||||
_('Could not render this PDF file'), show=True, det_msg=self.error)
|
||||
self.reject()
|
||||
return
|
||||
self.stack.setCurrentIndex(1)
|
||||
self.stack.stop()
|
||||
files = glob(os.path.join(self.current_tdir, '*.jpg')) + glob(os.path.join(self.current_tdir, '*.jpeg'))
|
||||
if not files and not self.covers.count():
|
||||
error_dialog(self, _('Failed to render'),
|
||||
|
@ -7,7 +7,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
||||
|
||||
from PyQt5.Qt import (
|
||||
Qt, QWidget, QSizePolicy, QSize, QRect, QConicalGradient, QPen, QBrush,
|
||||
QPainter, QTimer, QVBoxLayout, QLabel, QStackedWidget, QDialog
|
||||
QPainter, QTimer, QVBoxLayout, QLabel, QStackedWidget, QDialog, QStackedLayout
|
||||
)
|
||||
|
||||
|
||||
@ -113,6 +113,7 @@ class ProgressSpinner(QWidget):
|
||||
traceback.print_exc()
|
||||
self.errored_out = True
|
||||
|
||||
|
||||
ProgressIndicator = ProgressSpinner
|
||||
|
||||
|
||||
@ -167,6 +168,35 @@ class WaitStack(QStackedWidget):
|
||||
def msg(self, val):
|
||||
self.wp.msg = val
|
||||
|
||||
|
||||
class WaitLayout(QStackedLayout):
|
||||
|
||||
def __init__(self, msg, after=None, parent=None, size=256, interval=10):
|
||||
QStackedLayout.__init__(self, parent)
|
||||
self.wp = WaitPanel(msg, parent, size, interval)
|
||||
if after is None:
|
||||
after = QWidget(parent)
|
||||
self.after = after
|
||||
self.addWidget(self.wp)
|
||||
self.addWidget(after)
|
||||
|
||||
def start(self):
|
||||
self.setCurrentWidget(self.wp)
|
||||
self.wp.start()
|
||||
|
||||
def stop(self):
|
||||
self.wp.stop()
|
||||
self.setCurrentWidget(self.after)
|
||||
|
||||
@property
|
||||
def msg(self):
|
||||
return self.wp.msg
|
||||
|
||||
@msg.setter
|
||||
def msg(self, val):
|
||||
self.wp.msg = val
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from calibre.gui2 import Application
|
||||
app = Application([])
|
||||
|
Loading…
x
Reference in New Issue
Block a user