diff --git a/src/calibre/gui2/metadata/single_download.py b/src/calibre/gui2/metadata/single_download.py index 6121a2ad3f..c80eeb24e1 100644 --- a/src/calibre/gui2/metadata/single_download.py +++ b/src/calibre/gui2/metadata/single_download.py @@ -29,7 +29,7 @@ from calibre.ebooks.metadata.sources.identify import urls_from_identifiers from calibre.ebooks.metadata.book.base import Metadata from calibre.ebooks.metadata.opf2 import OPF from calibre.gui2 import error_dialog, rating_font, gprefs -from calibre.gui2.progress_indicator import draw_snake_spinner +from calibre.gui2.progress_indicator import SpinAnimator from calibre.gui2.widgets2 import HTMLDisplay from calibre.utils.date import (utcnow, fromordinal, format_date, UNDEFINED_DATE, as_utc) @@ -88,33 +88,25 @@ class CoverDelegate(QStyledItemDelegate): # {{{ def __init__(self, parent): QStyledItemDelegate.__init__(self, parent) - - self.angle = 0 - self.timer = QTimer(self) - self.timer.timeout.connect(self.frame_changed) - self.dark_color = parent.palette().color(QPalette.ColorRole.WindowText) - self.light_color = parent.palette().color(QPalette.ColorRole.Window) + self.animator = SpinAnimator(self) + self.animator.updated.connect(self.needs_redraw) + self.color = parent.palette().color(QPalette.ColorRole.WindowText) self.spinner_width = 64 - def frame_changed(self, *args): - self.angle = (self.angle-2)%360 - self.needs_redraw.emit() - def start_animation(self): - self.angle = 0 - self.timer.start(10) + self.animator.start() def stop_animation(self): - self.timer.stop() + self.animator.stop() def paint(self, painter, option, index): QStyledItemDelegate.paint(self, painter, option, index) style = QApplication.style() - waiting = self.timer.isActive() and bool(index.data(Qt.ItemDataRole.UserRole)) + waiting = self.animator.is_running() and bool(index.data(Qt.ItemDataRole.UserRole)) if waiting: rect = QRect(0, 0, self.spinner_width, self.spinner_width) rect.moveCenter(option.rect.center()) - draw_snake_spinner(painter, rect, self.angle, self.light_color, self.dark_color) + self.animator.draw(painter, rect, self.color) else: # Ensure the cover is rendered over any selection rect style.drawItemPixmap(painter, option.rect, Qt.AlignmentFlag.AlignTop|Qt.AlignmentFlag.AlignHCenter, diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.sip b/src/calibre/gui2/progress_indicator/QProgressIndicator.sip index 9f1aade836..7387099234 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.sip +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.sip @@ -19,7 +19,7 @@ class SpinAnimator : QObject { %End public: - SpinAnimator(QWidget *parent /TransferThis/ = 0, int speed_factor=300); + SpinAnimator(QObject *parent /TransferThis/ = 0, int speed_factor=300); float get_arc_length() const ; int get_arc_rotation() const ; int get_overall_rotation() const ; diff --git a/src/calibre/gui2/progress_indicator/__init__.py b/src/calibre/gui2/progress_indicator/__init__.py index c7d6710e5a..d4fe715d9a 100644 --- a/src/calibre/gui2/progress_indicator/__init__.py +++ b/src/calibre/gui2/progress_indicator/__init__.py @@ -3,8 +3,8 @@ # License: GPLv3 Copyright: 2015, Kovid Goyal from PyQt5.Qt import ( - QDialog, QLabel, QSizePolicy, QStackedLayout, QStackedWidget, Qt, QVBoxLayout, - QWidget + QDialog, QLabel, QObject, QSizePolicy, QStackedLayout, QStackedWidget, Qt, + QVBoxLayout, QWidget, pyqtSignal ) from calibre_extensions.progress_indicator import ( @@ -13,6 +13,30 @@ from calibre_extensions.progress_indicator import ( draw_snake_spinner +try: + from calibre_extensions.progress_indicator import SpinAnimator +except ImportError: + # dummy class for people running from source without updated binaries + class SpinAnimator(QObject): + + updated = pyqtSignal() + + def __init__(self, parent): + QObject.__init__(self, parent) + self.running = False + + def draw(self, *a): + pass + + def start(self): + self.running = True + + def stop(self): + self.running = False + + def is_running(self): + return self.running + class WaitPanel(QWidget): @@ -95,7 +119,8 @@ class WaitLayout(QStackedLayout): def develop(): - from PyQt5.Qt import QPalette, QPainter + from PyQt5.Qt import QPainter, QPalette + from calibre.gui2 import Application from calibre_extensions.progress_indicator import SpinAnimator