1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
import sys import time
from PyQt5.QtCore import Qt, QRect, QThread, pyqtSignal from PyQt5.QtGui import QPixmap, QFont, QPainter from PyQt5.QtWidgets import QDesktopWidget from PyQt5.QtWidgets import QWidget, QPushButton, QApplication, QLabel, QVBoxLayout, QHBoxLayout
from Update_Gui import Local from Update_Gui import Network
class Update(QThread): finish = pyqtSignal() def __init__(self): super().__init__()
def __del__(self): self.wait()
def run(self): a = Local() b = Network()
b.download_update()
a.uncompression()
a.del_old_version() a.run_leagueskin()
time.sleep(4) a.reset() self.finish.emit()
class StartLeagueSkin(QThread): def __init__(self): super().__init__()
def __del__(self): self.wait()
def run(self): Local._run_leagueskin()
class MyWidget(QWidget): def __init__(self): super(QWidget, self).__init__() self.animation = None
def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.m_drag = True self.m_DragPosition = event.globalPos() - self.pos() event.accept()
def mouseMoveEvent(self, QMouseEvent): if QMouseEvent.buttons() and Qt.LeftButton: try: self.move(QMouseEvent.globalPos() - self.m_DragPosition) except: pass QMouseEvent.accept()
def mouseReleaseEvent(self, QMouseEvent): self.m_drag = False
def center(self): screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
class MainWindow(MyWidget): def __init__(self): super(QWidget, self).__init__()
self.netVersion = None self.localVersion = None self.checkTime = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) self.result = None self.updateBool = False self.startBool = False self.repairBool = False
self.initRoot()
self.setAttribute(Qt.WA_TranslucentBackground, True) self.setStyleSheet(open("./MainUi.qss").read()) self.SHADOW_WIDTH = 15 self.resize(465, 215) self.center() self.setWindowTitle('LeagueSkinUpdate') self.setFixedSize(self.width(), self.height()) self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.setButton(True) self.setInfo(True) self.setLogo(True) self.setCloseButton(True) self.setMinMaxButtons(True)
self.initLayout()
def drawShadow(self, painter): """ :param painter: 画笔 :return: """ self.pixmaps = list() self.pixmaps.append(str("./ico/frame/left_top.png")) self.pixmaps.append(str("./ico/frame/left_bottom.png")) self.pixmaps.append(str("./ico/frame/right_top.png")) self.pixmaps.append(str("./ico/frame/right_bottom.png")) self.pixmaps.append(str("./ico/frame/top_mid.png")) self.pixmaps.append(str("./ico/frame/bottom_mid.png")) self.pixmaps.append(str("./ico/frame/left_mid.png")) self.pixmaps.append(str("./ico/frame/right_mid.png"))
painter.drawPixmap(0, 0, self.SHADOW_WIDTH, self.SHADOW_WIDTH, QPixmap(self.pixmaps[0])) painter.drawPixmap(self.width() - self.SHADOW_WIDTH, 0, self.SHADOW_WIDTH, self.SHADOW_WIDTH, QPixmap(self.pixmaps[2])) painter.drawPixmap(0, self.height() - self.SHADOW_WIDTH, self.SHADOW_WIDTH, self.SHADOW_WIDTH, QPixmap(self.pixmaps[1])) painter.drawPixmap(self.width() - self.SHADOW_WIDTH, self.height() - self.SHADOW_WIDTH, self.SHADOW_WIDTH, self.SHADOW_WIDTH, QPixmap(self.pixmaps[3])) painter.drawPixmap(0, self.SHADOW_WIDTH, self.SHADOW_WIDTH, self.height() - 2 * self.SHADOW_WIDTH, QPixmap(self.pixmaps[6]).scaled(self.SHADOW_WIDTH, self.height() - 2 * self.SHADOW_WIDTH)) painter.drawPixmap(self.width() - self.SHADOW_WIDTH, self.SHADOW_WIDTH, self.SHADOW_WIDTH, self.height() - 2 * self.SHADOW_WIDTH, QPixmap(self.pixmaps[7]).scaled(self.SHADOW_WIDTH, self.height() - 2 * self.SHADOW_WIDTH)) painter.drawPixmap(self.SHADOW_WIDTH, 0, self.width() - 2 * self.SHADOW_WIDTH, self.SHADOW_WIDTH, QPixmap(self.pixmaps[4]).scaled(self.width() - 2 * self.SHADOW_WIDTH, self.SHADOW_WIDTH)) painter.drawPixmap(self.SHADOW_WIDTH, self.height() - self.SHADOW_WIDTH, self.width() - 2 * self.SHADOW_WIDTH, self.SHADOW_WIDTH, QPixmap(self.pixmaps[5]).scaled(self.width() - 2 * self.SHADOW_WIDTH, self.SHADOW_WIDTH))
def paintEvent(self, event): painter = QPainter(self) self.drawShadow(painter) painter.setPen(Qt.NoPen) painter.setBrush(Qt.white) painter.drawRect(QRect(self.SHADOW_WIDTH, self.SHADOW_WIDTH, self.width() - 2 * self.SHADOW_WIDTH, self.height() - 2 * self.SHADOW_WIDTH))
def initLayout(self): self.feedbackButton = QPushButton() self.feedbackButton.setText('问题反馈') self.feedbackButton.clicked.connect(self.fb_) self.aboutButton = QPushButton() self.aboutButton.setText(' 关于 ') self.aboutButton.clicked.connect(self.ab_)
self.bottomLayout = QHBoxLayout() self.bottomLayout.setContentsMargins(8, 0, 8, 8) self.bottomLayout.addWidget(self.feedbackButton) self.bottomLayout.addStretch() self.bottomLayout.addWidget(self.aboutButton)
self.titleBottonLayout = QHBoxLayout() self.titleBottonLayout.addWidget(self._MinimumButton) self.titleBottonLayout.addWidget(self._CloseButton)
self.titleTLayout = QHBoxLayout() self.titleTLayout.addStretch() self.titleTLayout.addLayout(self.titleBottonLayout)
self.titleRLayout = QVBoxLayout() self.titleRLayout.addLayout(self.titleTLayout) self.titleRLayout.addStretch()
self.logoLayout = QVBoxLayout() self.logoLayout.setContentsMargins(8, 8, 0, 0) self.logoLayout.addWidget(self.logo) self.logoLayout.addStretch()
self.titleLayout = QHBoxLayout() self.titleLayout.addLayout(self.logoLayout) self.titleLayout.addLayout(self.titleRLayout)
self.infoLayout = QHBoxLayout() self.infoLayout.addWidget(self.info)
self.buttonLayout = QHBoxLayout() self.buttonLayout.addWidget(self.updateButton) self.buttonLayout.addWidget(self.repairButton) self.buttonLayout.addWidget(self.startButton)
self._mainLayout = QVBoxLayout() self._mainLayout.setContentsMargins(15, 15, 15, 15) self._mainLayout.setSpacing(0) self._mainLayout.addLayout(self.titleLayout) self._mainLayout.addLayout(self.infoLayout) self._mainLayout.addLayout(self.buttonLayout) self._mainLayout.addStretch() self._mainLayout.addLayout(self.bottomLayout) self.setLayout(self._mainLayout)
def setButton(self, bool): if bool: self.repairButton = QPushButton() self.repairButton.setText('修复翻译错误') self.repairButton.setFixedWidth(100) self.repairButton.setEnabled(self.repairBool) self.repairButton.clicked.connect(self.repair_)
self.updateButton = QPushButton() self.updateButton.setText('更新LeagueSkin') self.updateButton.setFixedWidth(100) self.updateButton.setEnabled(self.updateBool) self.updateButton.clicked.connect(self.update_)
self.startButton = QPushButton() self.startButton.setText('启动LeagueSkin') self.startButton.setFixedWidth(100) self.startButton.setEnabled(self.startBool) self.startButton.clicked.connect(self.start_)
def ab_(self): self.info.setText('该程序基于Python3.6.6开发,\n用于检测并更新LeagueSkin;\n' '使用它,可以最大限度的避免\n因软件未及时更新而导致的其他后果\n(封号, 无法使用等);')
def fb_(self): self.info.setText('Bug反馈请邮件至550549443')
def start_(self): self.startButton.setEnabled(False) self.a = StartLeagueSkin() self.a.start() self.info.setText('正在启动LeagueSkin...\n如果未能成功启动,\n请检查是否赋予了管理员权限?')
def repair_(self): Local.repair_language() self.info.setText('修复完成, 下次启动LeagueSkin有效.') self.repairButton.setEnabled(False)
def update_(self): self.updateButton.setEnabled(False) self.info.setText('正在更新LeagueSkin, 请稍后...\n这个过程可能需要持续几分钟') self.thread = Update() self.thread.finish.connect(self.update_finish) self.thread.start()
def update_finish(self): self.info.setText('更新已完成.\n正在启动LeagueSkin...') self.repairButton.setEnabled(True)
def setInfo(self, bool): if bool: self.info = QLabel() self.info.setText("最新版本:%s\n当前版本:%s\n检测时间:%s\n检测结果:%s" % ( self.netVersion, self.localVersion, self.checkTime, self.result)) self.info.setFixedSize(200, 80) self.info.setAlignment(Qt.AlignCenter)
def setLogo(self, bool): if bool: self.logo = QLabel() self.logo.setScaledContents(True) self.logo.setPixmap(QPixmap('ico\\icon.ico')) self.logo.setFixedSize(25, 25) self.logo.setObjectName('TitleLabel')
def setCloseButton(self, bool): if bool: self._CloseButton = QTitleButton(b'\xef\x81\xb2'.decode("utf-8"), self) self._CloseButton.setObjectName("CloseButton") self._CloseButton.setToolTip("关闭") self._CloseButton.setMouseTracking(True) self._CloseButton.setFixedHeight(20) self._CloseButton.clicked.connect(self.close)
def setMinMaxButtons(self, bool): if bool == True: self._MinimumButton = QTitleButton(b'\xef\x80\xb0'.decode("utf-8"), self) self._MinimumButton.setObjectName("MinMaxButton") self._MinimumButton.setToolTip("最小化") self._MinimumButton.setMouseTracking(True) self._MinimumButton.setFixedHeight(20) self._MinimumButton.clicked.connect(self.showMinimized)
def initRoot(self): a = Local() a.get_local_version() b = Network() b.get_network_version()
self.localVersion = a.version self.netVersion = b.version
if a.version == b.version: self.result = '当前为最新版本.' self.startBool = True self.repairBool = True else: self.result = '需要下载最新版本.' self.updateBool = True
class QTitleButton(QPushButton): """ 新建标题栏按钮类 """ def __init__(self, *args): super(QTitleButton, self).__init__(*args) self.setFont(QFont("Webdings")) self.setFixedWidth(25)
if __name__ == '__main__': app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())
|