Skip to content

Commit 3c043b1

Browse files
committed
add progress
1 parent 78ea06f commit 3c043b1

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

Widgets/Dialogs/SkinDialog.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(self, *args, **kwargs):
3636
self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
3737
self.widgetBottom.setVisible(False)
3838
Signals.pictureItemAdded.connect(self.onPictureItemAdded)
39+
Signals.pictureDownFinished.connect(self.onPictureDownFinished)
3940
# 加载鼠标样式
4041
ThemeManager.loadCursor(self)
4142
self.on_tabWidgetSkinMain_currentChanged(0)
@@ -82,8 +83,12 @@ def onCategoryChanged(self, button, toggled):
8283
if not hasattr(self, '_threadPool'):
8384
self._threadPool = QThreadPool(self)
8485
self._threadPool.setMaxThreadCount(5)
86+
widget.showWaiting()
8587
self._threadPool.start(runnable)
8688

89+
def onPictureDownFinished(self, widget):
90+
widget.showWaiting(False)
91+
8792
def onPictureItemAdded(self, widget, index, title, path):
8893
"""添加分类图片Item
8994
:param widget: 该分类对应的PictureWidget

Widgets/Skins/PictureWidget.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
@file: Widgets.Skins.PictureWidget
1010
@description:
1111
"""
12+
from PyQt5.QtCore import QObject, pyqtSignal, pyqtProperty, Qt, QRectF,\
13+
QSequentialAnimationGroup, QPauseAnimation, QParallelAnimationGroup,\
14+
QPropertyAnimation
15+
from PyQt5.QtGui import QColor, QPainter
16+
1217
from Utils.CommonUtil import Signals
1318
from Utils.ThemeThread import GetAllCategoryRunnable
1419
from Widgets.Skins.SkinBaseWidget import SkinBaseWidget, SkinBaseItemWidget
@@ -17,11 +22,53 @@
1722
__Author__ = 'Irony'
1823
__Copyright__ = 'Copyright (c) 2019'
1924

25+
26+
class CircleItem(QObject):
27+
28+
_x = 0 # x坐标
29+
_opacity = 1 # 透明度0~1
30+
valueChanged = pyqtSignal()
31+
32+
@pyqtProperty(float)
33+
def x(self):
34+
return self._x
35+
36+
@x.setter
37+
def x(self, x):
38+
self._x = x
39+
self.valueChanged.emit()
40+
41+
@pyqtProperty(float)
42+
def opacity(self):
43+
return self._opacity
44+
45+
@opacity.setter
46+
def opacity(self, opacity):
47+
self._opacity = opacity
48+
49+
2050
class PictureWidget(SkinBaseWidget):
2151

52+
_waiting = False
53+
_circleRadius = 3 # 半径
54+
_circleColor = QColor(39, 174, 97) # 圆圈颜色
55+
2256
def __init__(self, category, *args, **kwargs):
2357
super(PictureWidget, self).__init__(*args, **kwargs)
2458
self.category = category
59+
self._items = []
60+
61+
def showWaiting(self, show=True):
62+
self.setEnabled(not show)
63+
self._waiting = show
64+
if show:
65+
self._items.clear()
66+
self._initAnimations()
67+
for _, animation in self._items:
68+
animation.start()
69+
else:
70+
for _, animation in self._items:
71+
animation.stop()
2572

2673
def addItem(self, index, title, path):
2774
# 计算行列
@@ -36,3 +83,91 @@ def init(self):
3683
if self.gridLayout.count() > 0:
3784
return
3885
return GetAllCategoryRunnable(self.category, self)
86+
87+
def paintEvent(self, event):
88+
if not self._waiting:
89+
# 交给原来的绘制
90+
super(PictureWidget, self).paintEvent(event)
91+
return
92+
# 自定义绘制
93+
painter = QPainter(self)
94+
painter.setRenderHint(QPainter.Antialiasing)
95+
painter.setRenderHint(QPainter.SmoothPixmapTransform)
96+
painter.setPen(Qt.NoPen)
97+
98+
for item, _ in self._items:
99+
painter.save()
100+
color = self._circleColor.toRgb()
101+
color.setAlphaF(item.opacity)
102+
painter.setBrush(color)
103+
diameter = 2 * self._circleRadius
104+
painter.drawRoundedRect(
105+
QRectF(
106+
item.x / 100 * self.width() - diameter,
107+
self._circleRadius / 2,
108+
# (self.height() - self._circleRadius) / 2,
109+
diameter, diameter
110+
), self._circleRadius, self._circleRadius)
111+
painter.restore()
112+
113+
def _initAnimations(self):
114+
for index in range(5): # 5个小圆
115+
item = CircleItem(self)
116+
item.valueChanged.connect(self.update)
117+
# 串行动画组
118+
seqAnimation = QSequentialAnimationGroup(self)
119+
seqAnimation.setLoopCount(-1)
120+
self._items.append((item, seqAnimation))
121+
122+
# 暂停延迟动画
123+
seqAnimation.addAnimation(QPauseAnimation(150 * index, self))
124+
125+
# 加速,并行动画组1
126+
parAnimation1 = QParallelAnimationGroup(self)
127+
# 透明度
128+
parAnimation1.addAnimation(QPropertyAnimation(
129+
item, b'opacity', self, duration=400, startValue=0, endValue=1.0))
130+
# x坐标
131+
parAnimation1.addAnimation(QPropertyAnimation(
132+
item, b'x', self, duration=400, startValue=0, endValue=25.0))
133+
seqAnimation.addAnimation(parAnimation1)
134+
##
135+
136+
# 匀速
137+
seqAnimation.addAnimation(QPropertyAnimation(
138+
item, b'x', self, duration=2000, startValue=25.0, endValue=75.0))
139+
140+
# 加速,并行动画组2
141+
parAnimation2 = QParallelAnimationGroup(self)
142+
# 透明度
143+
parAnimation2.addAnimation(QPropertyAnimation(
144+
item, b'opacity', self, duration=400, startValue=1.0, endValue=0))
145+
# x坐标
146+
parAnimation2.addAnimation(QPropertyAnimation(
147+
item, b'x', self, duration=400, startValue=75.0, endValue=100.0))
148+
seqAnimation.addAnimation(parAnimation2)
149+
##
150+
151+
# 暂停延迟动画
152+
seqAnimation.addAnimation(
153+
QPauseAnimation((5 - index - 1) * 150, self))
154+
155+
@pyqtProperty(int)
156+
def circleRadius(self):
157+
return self._circleRadius
158+
159+
@circleRadius.setter
160+
def circleRadius(self, radius):
161+
if self._circleRadius != radius:
162+
self._circleRadius = radius
163+
self.update()
164+
165+
@pyqtProperty(QColor)
166+
def circleColor(self):
167+
return self._circleColor
168+
169+
@circleColor.setter
170+
def circleColor(self, color):
171+
if self._circleColor != color:
172+
self._circleColor = color
173+
self.update()

0 commit comments

Comments
 (0)