mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Simplify code to draw snake spinner
This commit is contained in:
parent
21763cf0b1
commit
a26462d633
@ -5,7 +5,6 @@
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
|
||||
import math
|
||||
from PyQt5.Qt import (
|
||||
Qt, QWidget, QSizePolicy, QSize, QRect, QConicalGradient, QPen, QBrush,
|
||||
QPainter, QTimer, QVBoxLayout, QLabel, QStackedWidget, QDialog
|
||||
@ -24,21 +23,16 @@ def draw_snake_spinner(painter, rect, angle, light, dark):
|
||||
disc_width = max(4, rect.width() // 10)
|
||||
|
||||
drawing_rect = QRect(rect.x() + disc_width, rect.y() + disc_width, rect.width() - 2 * disc_width, rect.height() - 2 *disc_width)
|
||||
try:
|
||||
angle_for_width = math.degrees(math.atan2(1.3 * disc_width, drawing_rect.width()))
|
||||
except ZeroDivisionError:
|
||||
angle_for_width = 5
|
||||
|
||||
gradient = QConicalGradient(drawing_rect.center(), angle - angle_for_width)
|
||||
gap = 20 # degrees
|
||||
gradient = QConicalGradient(drawing_rect.center(), angle - gap // 2)
|
||||
gradient.setColorAt(1, light)
|
||||
gradient.setColorAt(0, dark)
|
||||
|
||||
painter.setPen(QPen(light, disc_width))
|
||||
painter.drawArc(drawing_rect, 0, 360 * 16)
|
||||
pen = QPen(QBrush(gradient), disc_width)
|
||||
pen.setCapStyle(Qt.RoundCap)
|
||||
painter.setPen(pen)
|
||||
painter.drawArc(drawing_rect, angle * 16, (360 - 2 * angle_for_width) * 16)
|
||||
painter.drawArc(drawing_rect, angle * 16, (360 - gap) * 16)
|
||||
|
||||
|
||||
class ProgressSpinner(QWidget):
|
||||
@ -163,6 +157,14 @@ class WaitStack(QStackedWidget):
|
||||
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