22 QSizePolicy , QPushButton , QFrame , QMessageBox , QFormLayout , QProgressDialog , QTextEdit , QComboBox
33from githubApi import GitHub , Release , SourceManager , PingThread
44from PyQt5 .QtCore import QObject , pyqtSlot , Qt , pyqtSignal , QUrl , QPropertyAnimation , \
5- QRect , QSize , pyqtProperty , QVariantAnimation
5+ QRect , QSize , pyqtProperty , QVariantAnimation , QDateTime
66from PyQt5 .QtGui import QDesktopServices , QFont , QIcon , QPainter , QPixmap , QPaintEvent
77
88
@@ -53,6 +53,7 @@ def __init__(self, release: Release, mode=">", parent=None):
5353 self .showButton = AnimationButton ()
5454 self .showButton .setCheckable (True )
5555 self .showButton .pixmap = QPixmap ("media/unfold.png" )
56+ self .dateTimeLabel = QLabel ()
5657 self .titleWidget = QWidget ()
5758 self .formWidget = QWidget ()
5859 self .downloadButton = QPushButton (QObject .tr (self , "Download" ))
@@ -70,6 +71,10 @@ def initUi(self):
7071 row1 = QHBoxLayout ()
7172 row1 .addWidget (self .showButton )
7273 row1 .addWidget (QLabel (self .release .tag_name ))
74+ row1 .addItem (QSpacerItem (
75+ 20 , 20 , QSizePolicy .Expanding , QSizePolicy .Minimum ))
76+ self .dateTimeLabel .setText (QDateTime .fromString (self .release .assets_created_at , "yyyy-MM-ddThh:mm:ssZ" ).toString ("yyyy-MM-dd hh:mm:ss" ))
77+ row1 .addWidget (self .dateTimeLabel )
7378 row1 .addItem (QSpacerItem (
7479 20 , 20 , QSizePolicy .Expanding , QSizePolicy .Minimum ))
7580 self .downloadButton .setEnabled (self .mode == ">" )
@@ -93,7 +98,7 @@ def initUi(self):
9398 formLayout .addRow (QObject .tr (self , "download_count" ),
9499 QLabel (str (self .release .assets_download_count )))
95100 formLayout .addRow (QObject .tr (self , "created_at" ),
96- QLabel (self .release .assets_created_at ))
101+ QLabel (QDateTime . fromString ( self .release .assets_created_at , "yyyy-MM-ddThh:mm:ssZ" ). toString ( "yyyy-MM-dd hh:mm:ss" ) ))
97102 downloadUrlLabel = QLabel ()
98103 downloadUrlLabel .setText ("<a href='" + self .release .assets_browser_download_url +
99104 "'>" + QObject .tr (self , "open download links" ) + "</a>" )
@@ -236,6 +241,8 @@ def changeSource(self, source: str):
236241 self .sourceSpeedLabel .setText ("---ms" )
237242 self .pingThread .pingSignal .connect (lambda x ,y : self .sourceSpeedLabel .setText (f"{ int (y )} ms" ))
238243 self .pingThread .start ()
244+ self .github .sourceManager .currentSource = source
245+ self .checkUpdateButton .click ()
239246 @pyqtSlot (list )
240247 def checkUpdate (self , releases : list ):
241248 widget = self .releaseArea .widget ()
@@ -266,6 +273,10 @@ def showDownloadDialog(self, release: Release):
266273 if self .processDialog is not None :
267274 self .processDialog .close ()
268275 self .processDialog = QProgressDialog (self )
276+ # 取消信号
277+ self .processDialog .canceled .connect (
278+ self .downloadCancel
279+ )
269280 self .processDialog .setWindowTitle (QObject .tr (
270281 self , f"{ release .tag_name } Downloading..." ))
271282
@@ -283,6 +294,11 @@ def hideDownloadDialog(self, path: str):
283294 # 使用系统默认方式打开文件
284295 QDesktopServices .openUrl (QUrl .fromLocalFile (path ))
285296
297+ def downloadCancel (self ):
298+ self .github .closeAllRequest ()
299+ if self .processDialog is not None :
300+ self .processDialog .close ()
301+ self .processDialog = None
286302
287303if __name__ == '__main__' :
288304 import sys
0 commit comments