77@site: https://pyqt.site , https://github.com/PyQt5
88@email: 892768447@qq.com
99@file: RlatticeEffect
10- @description:
10+ @description:
1111"""
12+
1213from random import random
1314from time import time
1415
1516try :
16- from PyQt5 .QtCore import QPropertyAnimation , QObject , QEasingCurve , Qt , QRectF , pyqtSignal , pyqtProperty
17- from PyQt5 .QtGui import QColor , QPainterPath , QPainter
17+ from PyQt5 .QtCore import (
18+ QEasingCurve ,
19+ QObject ,
20+ QPropertyAnimation ,
21+ QRectF ,
22+ Qt ,
23+ pyqtProperty ,
24+ pyqtSignal ,
25+ )
26+ from PyQt5 .QtGui import QColor , QPainter , QPainterPath
1827 from PyQt5 .QtWidgets import QApplication , QWidget
1928except ImportError :
20- from PySide2 .QtCore import QPropertyAnimation , QObject , QEasingCurve , Qt , QRectF , Signal as pyqtSignal , \
21- Property as pyqtProperty
22- from PySide2 .QtGui import QColor , QPainterPath , QPainter
29+ from PySide2 .QtCore import Property as pyqtProperty
30+ from PySide2 .QtCore import QEasingCurve , QObject , QPropertyAnimation , QRectF , Qt
31+ from PySide2 .QtCore import Signal as pyqtSignal
32+ from PySide2 .QtGui import QColor , QPainter , QPainterPath
2333 from PySide2 .QtWidgets import QApplication , QWidget
2434
2535try :
2636 from Lib import pointtool # @UnusedImport @UnresolvedImport
2737
2838 getDistance = pointtool .getDistance
2939 findClose = pointtool .findClose
30- except :
40+ except Exception :
3141 import math
3242
33-
3443 def getDistance (p1 , p2 ):
3544 return math .pow (p1 .x - p2 .x , 2 ) + math .pow (p1 .y - p2 .y , 2 )
3645
37-
3846 def findClose (points ):
3947 plen = len (points )
4048 for i in range (plen ):
@@ -59,13 +67,12 @@ def findClose(points):
5967
6068
6169class Target :
62-
6370 def __init__ (self , x , y ):
6471 self .x = x
6572 self .y = y
6673
6774
68- class Point (QObject ):
75+ class Point (QObject ): # type: ignore
6976 valueChanged = pyqtSignal (int )
7077
7178 def __init__ (self , x , ox , y , oy , * args , ** kwargs ):
@@ -87,20 +94,22 @@ def __init__(self, x, ox, y, oy, *args, **kwargs):
8794
8895 def initAnimation (self ):
8996 # 属性动画
90- if not hasattr (self , ' xanimation' ):
97+ if not hasattr (self , " xanimation" ):
9198 self .xanimation = QPropertyAnimation (
92- self , b'x' , self , easingCurve = QEasingCurve .InOutSine )
99+ self , b"x" , self , easingCurve = QEasingCurve .InOutSine
100+ )
93101 self .xanimation .valueChanged .connect (self .valueChanged .emit )
94102 self .yanimation = QPropertyAnimation (
95- self , b'y' , self , easingCurve = QEasingCurve .InOutSine )
103+ self , b"y" , self , easingCurve = QEasingCurve .InOutSine
104+ )
96105 self .yanimation .valueChanged .connect (self .valueChanged .emit )
97106 self .yanimation .finished .connect (self .updateAnimation )
98107 self .updateAnimation ()
99108
100109 def updateAnimation (self ):
101110 self .xanimation .stop ()
102111 self .yanimation .stop ()
103- duration = ( 1 + random ()) * 1000
112+ duration = int (( 1 + random ()) * 1000 )
104113 self .xanimation .setDuration (duration )
105114 self .yanimation .setDuration (duration )
106115 self .xanimation .setStartValue (self .__x )
@@ -111,24 +120,23 @@ def updateAnimation(self):
111120 self .yanimation .start ()
112121
113122 @pyqtProperty (float )
114- def x (self ):
123+ def x (self ): # type: ignore
115124 return self ._x
116125
117- @x .setter
126+ @x .setter # type: ignore
118127 def x (self , x ):
119128 self ._x = x
120129
121130 @pyqtProperty (float )
122- def y (self ):
131+ def y (self ): # type: ignore
123132 return self ._y
124133
125- @y .setter
134+ @y .setter # type: ignore
126135 def y (self , y ):
127136 self ._y = y
128137
129138
130- class Window (QWidget ):
131-
139+ class Window (QWidget ): # type: ignore
132140 def __init__ (self , * args , ** kwargs ):
133141 super (Window , self ).__init__ (* args , ** kwargs )
134142 self .setMouseTracking (True )
@@ -211,19 +219,22 @@ def animate(self, painter):
211219 painter .save ()
212220 painter .setPen (Qt .NoPen )
213221 painter .setBrush (p .circleColor )
214- painter .drawRoundedRect (QRectF (
215- p .x - p .radius , p .y - p .radius , 2 * p .radius , 2 * p .radius ), p .radius , p .radius )
222+ painter .drawRoundedRect (
223+ QRectF (p .x - p .radius , p .y - p .radius , 2 * p .radius , 2 * p .radius ),
224+ p .radius ,
225+ p .radius ,
226+ )
216227 painter .restore ()
217228
218229 # 开启动画
219230 p .initAnimation ()
220231
221232
222- if __name__ == '__main__' :
223- import sys
233+ if __name__ == "__main__" :
224234 import cgitb
235+ import sys
225236
226- cgitb .enable (format = ' text' )
237+ cgitb .enable (format = " text" )
227238
228239 app = QApplication (sys .argv )
229240 w = Window ()
0 commit comments