Skip to content

Commit 7028b08

Browse files
committed
整理格式
1 parent d80bedf commit 7028b08

2 files changed

Lines changed: 140 additions & 114 deletions

File tree

src/CheckUpdateGui.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from PyQt5.QtWidgets import QWidget, QDialog, QScrollArea, QLabel, QVBoxLayout, QApplication, QHBoxLayout, QSpacerItem, \
1+
from PyQt5.QtWidgets import QWidget, QDialog, QScrollArea, QLabel, QVBoxLayout, QHBoxLayout, QSpacerItem, \
22
QSizePolicy, QPushButton, QFrame, QMessageBox, QFormLayout, QProgressDialog, QTextEdit, QComboBox
3-
from githubApi import GitHub, Release, SourceManager, PingThread
3+
from githubApi import GitHub, Release, PingThread
44
from 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
5+
QSize, QVariantAnimation, QDateTime, QEvent, QEasingCurve
6+
from PyQt5.QtGui import QDesktopServices, QFont, QMouseEvent, QPainter, QPixmap, QEnterEvent
77

88

99
class AnimationButton(QPushButton):
@@ -32,9 +32,9 @@ def paintEvent(self, event):
3232
painter.translate(self.width() // 2, self.height() // 2)
3333
size = self.width() if self.width() < self.height() else self.height()
3434
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())
35+
painter.drawPixmap(-size // 2, -size //
36+
2, self.pixmap.scaled(size, size))
37+
self.setMask(self.pixmap.scaled(size, size).mask())
3838

3939
def animationStart(self, check):
4040
if check:
@@ -56,7 +56,8 @@ def __init__(self, release: Release, mode=">", parent=None, r_path=""):
5656
self.showButton = AnimationButton()
5757
self.showButton.setToolTip(self.tr("unfold"))
5858
self.showButton.setCheckable(True)
59-
self.showButton.pixmap = QPixmap(str(r_path.with_name('media').joinpath('unfold.png')).replace("\\", "/"))
59+
self.showButton.pixmap = QPixmap(str(r_path.with_name(
60+
'media').joinpath('unfold.png')).replace("\\", "/"))
6061
self.dateTimeLabel = QLabel()
6162
self.titleWidget = QWidget()
6263
self.formWidget = QWidget()
@@ -77,7 +78,8 @@ def initUi(self):
7778
row1.addWidget(QLabel(self.release.tag_name))
7879
row1.addItem(QSpacerItem(
7980
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"))
81+
self.dateTimeLabel.setText(QDateTime.fromString(
82+
self.release.assets_created_at, "yyyy-MM-ddThh:mm:ssZ").toString("yyyy-MM-dd hh:mm:ss"))
8183
row1.addWidget(self.dateTimeLabel)
8284
row1.addItem(QSpacerItem(
8385
20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum))
@@ -180,15 +182,17 @@ def downLoadButtonClicked(self):
180182
self.downLoadFile.emit(self.release)
181183

182184
def resWidth(self):
183-
area:QScrollArea = self.parentWidget().parentWidget().parentWidget()
184-
width = area.verticalScrollBar().width() if area.verticalScrollBar().isVisible() else 0
185+
area: QScrollArea = self.parentWidget().parentWidget().parentWidget()
186+
width = area.verticalScrollBar().width(
187+
) if area.verticalScrollBar().isVisible() else 0
185188
self.resize(area.width() - width, self.height())
186-
189+
187190
def mousePressEvent(self, a0: QMouseEvent) -> None:
188191
super().mousePressEvent(a0)
189192
if self.titleWidget.geometry().contains(a0.pos()) and a0.button() == Qt.LeftButton:
190193
self.showButton.click()
191-
def __setStyleSheet(self,isEnter:bool):
194+
195+
def __setStyleSheet(self, isEnter: bool):
192196
rgbStr = ""
193197
if self.mode == ">":
194198
# 样式表绿色
@@ -200,7 +204,6 @@ def __setStyleSheet(self,isEnter:bool):
200204
# 样式表红色背景
201205
rgbStr = "rgb(249, 179, 163)"
202206

203-
204207
if isEnter:
205208
# label字体微软雅黑Ui,大小13,圆角 8,1px的蓝色边框,只针对ReleaseFrame
206209
self.setStyleSheet(
@@ -211,20 +214,23 @@ def __setStyleSheet(self,isEnter:bool):
211214
# label字体微软雅黑Ui,大小13,圆角 8
212215
self.setStyleSheet(
213216
f"QFrame{{background-color:{rgbStr}; font-family:Microsoft YaHei UI; font-size:14px; border-radius: 5px;}}")
217+
214218
def enterEvent(self, a0: QEnterEvent) -> None:
215219
self.__setStyleSheet(True)
216220
return super().enterEvent(a0)
217-
221+
218222
def leaveEvent(self, a0: QEvent) -> None:
219223
self.__setStyleSheet(False)
220224
return super().leaveEvent(a0)
221-
225+
226+
222227
class CheckUpdateGui(QDialog):
223228
def __init__(self, github: GitHub, parent=None):
224229
super().__init__(parent.mainWindow)
225230
self.setWindowTitle(QObject.tr(self, "CheckUpdate"))
226231
# 去掉问号
227-
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
232+
self.setWindowFlags(self.windowFlags() & ~
233+
Qt.WindowContextHelpButtonHint)
228234
self.r_path = parent.r_path
229235
self.github: GitHub = github
230236
self.github.setParent(self)
@@ -290,13 +296,17 @@ def initConnect(self):
290296
self.github.downloadReleaseAsyncFinishSignal.connect(
291297
self.hideDownloadDialog)
292298
self.sourceCombo.currentTextChanged.connect(self.changeSource)
299+
293300
def changeSource(self, source: str):
294-
self.pingThread = PingThread(source, self.github.sourceManager.sources[source])
301+
self.pingThread = PingThread(
302+
source, self.github.sourceManager.sources[source])
295303
self.sourceSpeedLabel.setText("---ms")
296-
self.pingThread.pingSignal.connect(lambda x,y: self.sourceSpeedLabel.setText(f"{int(y)}ms"))
304+
self.pingThread.pingSignal.connect(
305+
lambda x, y: self.sourceSpeedLabel.setText(f"{int(y)}ms"))
297306
self.pingThread.start()
298307
self.github.sourceManager.currentSource = source
299308
self.checkUpdateButton.click()
309+
300310
@pyqtSlot(list)
301311
def checkUpdate(self, releases: list[Release]):
302312
widget = self.releaseArea.widget()
@@ -344,7 +354,7 @@ def updateDownloadDialog(self, a: int, b: int):
344354
self.processDialog.setValue(a)
345355
self.processDialog.setMaximum(b)
346356
self.processDialog.setLabelText(
347-
f'{a/1000000 : .2f}/{b/1000000 : .2f} MB')
357+
f'{a/1000000: .2f}/{b/1000000: .2f} MB')
348358

349359
def hideDownloadDialog(self, path: str):
350360
if self.processDialog is not None:
@@ -358,7 +368,6 @@ def downloadCancel(self):
358368
if self.processDialog is not None:
359369
self.processDialog.close()
360370
self.processDialog = None
361-
362371
# if __name__ == '__main__':
363372
# import sys
364373
# app = QApplication(sys.argv)

0 commit comments

Comments
 (0)