def check_update(self): url = 'https://raw.githubusercontent.com/Zheng-Yejian/xyplayer-package/master/changelog' version, req = self.url_open(url) if not version: self.newestVersionLabel.setText('联网出错,检查新版本失败!') return try: versionNum = version_to_num(version) if versionNum != self.changelogVersionNum: with open(Configures.Changelog, 'w') as f: content = req.read().decode() content = '%s\n%s'%(version, content) f.write(content) f.close() self.changeLogText.clear() self.fill_changelog_text() if self.changeLogText.isHidden(): self.changeLogText.show() if versionNum > app_version_num : self.newestVersion = version[1:] self.newestVersionLabel.setText('最新版本:v%s' %self.newestVersion) self.updateButton.show() else: self.newestVersionLabel.setText('已是最新版,谢谢使用!') except: self.newestVersionLabel.setText('联网出错,检查新版本失败!')
def setup_ui(self): currentVersion = QLabel('当前版本:v%s'%app_version) self.newestVersionLabel = QLabel('最新版本:未检查') self.checkUpdateButton = QPushButton("检查更新") self.checkUpdateButton.setFixedSize(70, 30) self.updateButton = QPushButton('在线更新') self.updateButton.setFixedSize(70, 30) self.updateButton.hide() self.changeLogText = QTextEdit() self.changeLogText.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.changeLogText.setReadOnly(True) self.changeLogText.setMinimumHeight(450) self.progressBar = QProgressBar() self.updateState = QLabel() self.updateState.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.progressBar.hide() self.updateState.hide() self.changelogVersionNum = 0 if os.path.exists(Configures.Changelog): changelogVersion = self.fill_changelog_text() self.changelogVersionNum = version_to_num(changelogVersion) if self.changelogVersionNum > app_version_num: self.newestVersionLabel.setText('最新版本:存在%s或更高版本'%changelogVersion ) else: self.newestVersionLabel.setText('最新版本:未检查') else: self.changeLogText.hide() updateLayout = QGridLayout(self) updateLayout.setContentsMargins(3, 4, 3, 4) updateLayout.addWidget(currentVersion, 0, 0) updateLayout.addWidget(self.checkUpdateButton, 0, 1) updateLayout.addWidget(self.newestVersionLabel, 1, 0) updateLayout.addWidget(self.updateButton, 1, 1) updateLayout.addWidget(self.progressBar, 2, 0) updateLayout.addWidget(self.updateState, 2, 1) updateLayout.addWidget(self.changeLogText, 3, 0, 3, 2)