1- from PyQt5 .QtWidgets import QWidget , QDialog , QScrollArea , QLabel , QVBoxLayout , QApplication , QHBoxLayout , QSpacerItem , \
2- QSizePolicy , QPushButton , QFrame , QMessageBox , QFormLayout , QProgressDialog , QTextEdit , QComboBox
3- from githubApi import GitHub , Release , SourceManager , PingThread
41from PyQt5 .QtCore import QObject , pyqtSlot , Qt , pyqtSignal , QUrl , QPropertyAnimation , \
5- QRect , QSize , pyqtProperty , QVariantAnimation ,QDateTime ,QEvent ,QEasingCurve
6- from PyQt5 .QtGui import QDesktopServices , QFont , QIcon , QMouseEvent , QPainter , QPixmap , QPaintEvent ,QEnterEvent
2+ QSize , QVariantAnimation , QDateTime , QEvent , QEasingCurve
3+ from PyQt5 .QtGui import QDesktopServices , QFont , QMouseEvent , QPainter , QPixmap , QEnterEvent
4+ from PyQt5 .QtWidgets import QWidget , QDialog , QScrollArea , QLabel , QVBoxLayout , QHBoxLayout , QSpacerItem , \
5+ QSizePolicy , QPushButton , QFrame , QMessageBox , QFormLayout , QProgressDialog , QTextEdit , QComboBox
6+
7+ from githubApi import GitHub , ReleaseInfo , PingThread
78
89
910class AnimationButton (QPushButton ):
1011 def __init__ (self , parent = None ):
12+ """
13+ :param parent: QWidget
14+ AnimationButton的构造函数
15+ ."""
1116 super ().__init__ (parent )
1217 self .pixmap : QPixmap = None
1318 self .clicked .connect (self .animationStart )
@@ -22,6 +27,7 @@ def rotate(self):
2227 def setRotate (self , rotate ):
2328 self .__rotate = rotate
2429 self .update ()
30+
2531 # rotate = property(int,rotate, setRotate)
2632
2733 def paintEvent (self , event ):
@@ -32,11 +38,16 @@ def paintEvent(self, event):
3238 painter .translate (self .width () // 2 , self .height () // 2 )
3339 size = self .width () if self .width () < self .height () else self .height ()
3440 painter .rotate (self .rotate ())
35- painter .drawPixmap (- size // 2 , - size //
36- 2 , self .pixmap .scaled (size ,size ))
37- self .setMask (self .pixmap .scaled (size ,size ).mask ())
41+ painter .drawPixmap (- size // 2 , - size //
42+ 2 , self .pixmap .scaled (size , size ))
43+ self .setMask (self .pixmap .scaled (size , size ).mask ())
3844
3945 def animationStart (self , check ):
46+ """
47+ :param check: bool
48+ 点击按钮时,开始动画。
49+ check为True时,从0度到90度,否则从90度到0度,持续时间300ms。
50+ """
4051 if check :
4152 self .animation .setStartValue (0 )
4253 self .animation .setEndValue (90 )
@@ -48,15 +59,16 @@ def animationStart(self, check):
4859
4960
5061class ReleaseFrame (QFrame ):
51- downLoadFile = pyqtSignal (Release )
62+ downLoadFile = pyqtSignal (ReleaseInfo )
5263
53- def __init__ (self , release : Release , mode = ">" , parent = None , r_path = "" ):
64+ def __init__ (self , release : ReleaseInfo , mode = ">" , parent = None , r_path = "" ):
5465 super ().__init__ (parent )
55- self .release : Release = release
66+ self .release : ReleaseInfo = release
5667 self .showButton = AnimationButton ()
5768 self .showButton .setToolTip (self .tr ("unfold" ))
5869 self .showButton .setCheckable (True )
59- self .showButton .pixmap = QPixmap (str (r_path .with_name ('media' ).joinpath ('unfold.png' )).replace ("\\ " , "/" ))
70+ self .showButton .pixmap = QPixmap (str (r_path .with_name (
71+ 'media' ).joinpath ('unfold.png' )).replace ("\\ " , "/" ))
6072 self .dateTimeLabel = QLabel ()
6173 self .titleWidget = QWidget ()
6274 self .formWidget = QWidget ()
@@ -77,7 +89,8 @@ def initUi(self):
7789 row1 .addWidget (QLabel (self .release .tag_name ))
7890 row1 .addItem (QSpacerItem (
7991 20 , 20 , QSizePolicy .Expanding , QSizePolicy .Minimum ))
80- self .dateTimeLabel .setText (QDateTime .fromString (self .release .assets_created_at , "yyyy-MM-ddThh:mm:ssZ" ).toString ("yyyy-MM-dd hh:mm:ss" ))
92+ self .dateTimeLabel .setText (QDateTime .fromString (
93+ self .release .assets_created_at , "yyyy-MM-ddThh:mm:ssZ" ).toString ("yyyy-MM-dd hh:mm:ss" ))
8194 row1 .addWidget (self .dateTimeLabel )
8295 row1 .addItem (QSpacerItem (
8396 20 , 20 , QSizePolicy .Expanding , QSizePolicy .Minimum ))
@@ -102,7 +115,8 @@ def initUi(self):
102115 formLayout .addRow (QObject .tr (self , "download_count" ),
103116 QLabel (str (self .release .assets_download_count )))
104117 formLayout .addRow (QObject .tr (self , "created_at" ),
105- QLabel (QDateTime .fromString (self .release .assets_created_at , "yyyy-MM-ddThh:mm:ssZ" ).toString ("yyyy-MM-dd hh:mm:ss" )))
118+ QLabel (QDateTime .fromString (self .release .assets_created_at , "yyyy-MM-ddThh:mm:ssZ" ).toString (
119+ "yyyy-MM-dd hh:mm:ss" )))
106120 downloadUrlLabel = QLabel ()
107121 downloadUrlLabel .setText ("<a href='" + self .release .assets_browser_download_url +
108122 "'>" + QObject .tr (self , "open download links" ) + "</a>" )
@@ -124,25 +138,23 @@ def initUi(self):
124138 layout .addWidget (self .titleWidget )
125139 layout .addWidget (self .formWidget )
126140 self .setLayout (layout )
127- rgbStr = ""
128- if self .mode == ">" :
129- # 样式表绿色
130- rgbStr = "rgb(200,255,250)"
131- elif self .mode == "=" :
132- # 样式表蓝色
133- rgbStr = "rgb(200,216,230)"
134- else :
135- # 样式表红色背景
136- rgbStr = "rgb(249, 179, 163)"
137- # label字体微软雅黑Ui,大小13,圆角 8
138- self .setStyleSheet (
139- f"QFrame{{background-color:{ rgbStr } ; font-family:Microsoft YaHei UI; font-size:14px; border-radius: 5px;}}" )
141+ self .__setStyleSheet (False )
140142
141143 def initConnect (self ):
142144 self .showButton .clicked .connect (self .showButtonClicked )
143145 self .downloadButton .clicked .connect (self .downLoadButtonClicked )
144146
145147 def showButtonClicked (self , checked : bool ):
148+ """
149+ 切换显示和隐藏的按钮点击事件处理函数。
150+
151+ 根据参数checked的值,切换formWidget的可见性,并执行相应的展开或折叠动画。
152+ 当checked为True时,展开formWidget并设置按钮提示为"fold",
153+ 否则折叠formWidget并设置按钮提示为"unfold"。
154+
155+ Args:
156+ checked (bool): 指示按钮是否被选中的布尔值。
157+ """
146158 self .formWidget .setVisible (True )
147159 animation = QPropertyAnimation (self .formWidget , b"size" , self )
148160 easingCurveType = QEasingCurve .Type .OutBack if checked else QEasingCurve .Type .InBack
@@ -151,10 +163,6 @@ def showButtonClicked(self, checked: bool):
151163 animation2 .setEasingCurve (easingCurveType )
152164 animation .setDuration (300 )
153165 animation2 .setDuration (300 )
154- start : QSize = None
155- end : QSize = None
156- start1 : QSize = None
157- end1 : QSize = None
158166 if checked :
159167 self .showButton .setToolTip (QObject .tr (self , "fold" ))
160168 start = QSize (self .width (), 0 )
@@ -174,22 +182,23 @@ def showButtonClicked(self, checked: bool):
174182 animation2 .start (QPropertyAnimation .DeletionPolicy .DeleteWhenStopped )
175183 animation .start (QPropertyAnimation .DeletionPolicy .DeleteWhenStopped )
176184 animation .finished .connect (lambda : self .formWidget .setVisible (checked ))
177- animation .finished .connect (lambda : self .resWidth ())
185+ # animation.finished.connect(lambda: self.resWidth())
178186
179187 def downLoadButtonClicked (self ):
180188 self .downLoadFile .emit (self .release )
181189
182190 def resWidth (self ):
183- area :QScrollArea = self .parentWidget ().parentWidget ().parentWidget ()
184- width = area .verticalScrollBar ().width () if area .verticalScrollBar ().isVisible () else 0
191+ area : QScrollArea = self .parentWidget ().parentWidget ().parentWidget ()
192+ width = area .verticalScrollBar ().width (
193+ ) if area .verticalScrollBar ().isVisible () else 0
185194 self .resize (area .width () - width , self .height ())
186-
195+
187196 def mousePressEvent (self , a0 : QMouseEvent ) -> None :
188197 super ().mousePressEvent (a0 )
189198 if self .titleWidget .geometry ().contains (a0 .pos ()) and a0 .button () == Qt .LeftButton :
190199 self .showButton .click ()
191- def __setStyleSheet ( self , isEnter : bool ):
192- rgbStr = ""
200+
201+ def __setStyleSheet ( self , isEnter : bool ):
193202 if self .mode == ">" :
194203 # 样式表绿色
195204 rgbStr = "rgb(200,255,250)"
@@ -200,7 +209,6 @@ def __setStyleSheet(self,isEnter:bool):
200209 # 样式表红色背景
201210 rgbStr = "rgb(249, 179, 163)"
202211
203-
204212 if isEnter :
205213 # label字体微软雅黑Ui,大小13,圆角 8,1px的蓝色边框,只针对ReleaseFrame
206214 self .setStyleSheet (
@@ -210,21 +218,26 @@ def __setStyleSheet(self,isEnter:bool):
210218 else :
211219 # label字体微软雅黑Ui,大小13,圆角 8
212220 self .setStyleSheet (
213- f"QFrame{{background-color:{ rgbStr } ; font-family:Microsoft YaHei UI; font-size:14px; border-radius: 5px;}}" )
221+ f"""QFrame{{background-color:{ rgbStr } ; font-family:Microsoft YaHei UI; font-size:14px; border-radius: 5px;}}
222+ ReleaseFrame{{border: 1px solid transparent;}}
223+ """ )
224+
214225 def enterEvent (self , a0 : QEnterEvent ) -> None :
215226 self .__setStyleSheet (True )
216227 return super ().enterEvent (a0 )
217-
228+
218229 def leaveEvent (self , a0 : QEvent ) -> None :
219230 self .__setStyleSheet (False )
220231 return super ().leaveEvent (a0 )
221-
232+
233+
222234class CheckUpdateGui (QDialog ):
223235 def __init__ (self , github : GitHub , parent = None ):
224236 super ().__init__ (parent .mainWindow )
225237 self .setWindowTitle (QObject .tr (self , "CheckUpdate" ))
226238 # 去掉问号
227- self .setWindowFlags (self .windowFlags () & ~ Qt .WindowContextHelpButtonHint )
239+ self .setWindowFlags (self .windowFlags () & ~
240+ Qt .WindowContextHelpButtonHint )
228241 self .r_path = parent .r_path
229242 self .github : GitHub = github
230243 self .github .setParent (self )
@@ -236,6 +249,9 @@ def __init__(self, github: GitHub, parent=None):
236249 self .releaseArea .setHorizontalScrollBarPolicy (
237250 Qt .ScrollBarPolicy .ScrollBarAlwaysOff
238251 )
252+ self .releaseArea .setVerticalScrollBarPolicy (
253+ Qt .ScrollBarPolicy .ScrollBarAlwaysOn
254+ )
239255 self .pingThread = None
240256 self .sourceSpeedLabel = QLabel ()
241257 self .sourceCombo = QComboBox ()
@@ -290,15 +306,19 @@ def initConnect(self):
290306 self .github .downloadReleaseAsyncFinishSignal .connect (
291307 self .hideDownloadDialog )
292308 self .sourceCombo .currentTextChanged .connect (self .changeSource )
309+
293310 def changeSource (self , source : str ):
294- self .pingThread = PingThread (source , self .github .sourceManager .sources [source ])
311+ self .pingThread = PingThread (
312+ source , self .github .sourceManager .sources [source ])
295313 self .sourceSpeedLabel .setText ("---ms" )
296- self .pingThread .pingSignal .connect (lambda x ,y : self .sourceSpeedLabel .setText (f"{ int (y )} ms" ))
314+ self .pingThread .pingSignal .connect (
315+ lambda x , y : self .sourceSpeedLabel .setText (f"{ int (y )} ms" ))
297316 self .pingThread .start ()
298317 self .github .sourceManager .currentSource = source
299318 self .checkUpdateButton .click ()
319+
300320 @pyqtSlot (list )
301- def checkUpdate (self , releases : list [Release ]):
321+ def checkUpdate (self , releases : list [ReleaseInfo ]):
302322 widget = self .releaseArea .widget ()
303323 if widget is not None :
304324 widget .deleteLater ()
@@ -328,7 +348,7 @@ def showError(self, msg: str):
328348 widget .deleteLater ()
329349 QMessageBox .critical (self , QObject .tr (self , "Error" ), msg )
330350
331- def showDownloadDialog (self , release : Release ):
351+ def showDownloadDialog (self , release : ReleaseInfo ):
332352 if self .processDialog is not None :
333353 self .processDialog .close ()
334354 self .processDialog = QProgressDialog (self )
@@ -344,7 +364,7 @@ def updateDownloadDialog(self, a: int, b: int):
344364 self .processDialog .setValue (a )
345365 self .processDialog .setMaximum (b )
346366 self .processDialog .setLabelText (
347- f'{ a / 1000000 : .2f} /{ b / 1000000 : .2f} MB' )
367+ f'{ a / 1000000 : .2f} /{ b / 1000000 : .2f} MB' )
348368
349369 def hideDownloadDialog (self , path : str ):
350370 if self .processDialog is not None :
@@ -358,7 +378,6 @@ def downloadCancel(self):
358378 if self .processDialog is not None :
359379 self .processDialog .close ()
360380 self .processDialog = None
361-
362381# if __name__ == '__main__':
363382# import sys
364383# app = QApplication(sys.argv)
0 commit comments