mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement new spinner for metadata download dialog
This commit is contained in:
parent
261f153fe6
commit
79dc721611
@ -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,
|
||||
|
@ -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 ;
|
||||
|
@ -3,8 +3,8 @@
|
||||
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user