def source_thread(self): try: self.source_Thread = Source_Thread() self.source_Thread.thread_signal.connect(self.Source_UI) self.source_Thread.start() except Exception as e: print(f"Source Thread: {e}") QMessageBox.information(self, '源码仓库发生错误', f'错误信息{e},请确定网络连接是否正常,然后尝试重启客户端,如问题还未解决,请点击反馈按钮留言')
class fun_main(Ui_MainWindow, QtWidgets.QMainWindow): def __init__(self): super(fun_main, self).__init__() self.setupUi(self) self.setWindowOpacity(1) # 设置窗口透明度 self.setAttribute(QtCore.Qt.WA_TranslucentBackground) # 主窗口透明 self.setWindowFlag(QtCore.Qt.FramelessWindowHint) # 隐藏边框 # 初始化功能 self.signal_on_btn() self.icon_on_btn() # 初始化参数 self.m_flag = False self.source_url = [] # 源码仓库链接初始化 self.article_url = [] # 文章教程链接初始化 self.label_10.hide() self.label_sys_info.hide() self.label_welcome.setText(soft_cfg.welcome) # 线程启动 self.time_thread() self.source_thread() self.article_thread() self.webDownloader_Thread = Downloader_Thread() self.webDownloader_Thread.start() self.update_thread() def signal_on_btn(self): # 基础按钮事件绑定 self.pushButton_close.clicked.connect(lambda: self.window_close(0)) self.pushButton_min.clicked.connect(lambda: self.showMinimized()) self.pushButton_feedback.clicked.connect( lambda: open_browser(soft_cfg.feed_back)) self.pushButton_web_site.clicked.connect( lambda: open_browser(soft_cfg.web_site)) self.pushButton_help_us.clicked.connect( lambda: open_browser(soft_cfg.help_us)) self.pushButton_web_rights.clicked.connect(self.licenses) self.pushButton_update.clicked.connect(self.update_thread) # List Widget点击事件 self.listWidget_source.itemClicked.connect(self.source_item_clicked) self.listWidget_article.itemClicked.connect(self.article_item_clicked) # 界面转换 self.pushButton_menu_soft.clicked.connect( lambda: self.stackedWidget.setCurrentIndex(0)) # self.pushButton_menu_api.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(1)) self.pushButton_menu_api.clicked.connect( lambda: open_browser(soft_cfg.api_site)) self.pushButton_menu_article.clicked.connect( lambda: self.stackedWidget.setCurrentIndex(2)) self.pushButton_menu_source.clicked.connect( lambda: self.stackedWidget.setCurrentIndex(3)) self.pushButton_menu_about_us.clicked.connect( lambda: self.stackedWidget.setCurrentIndex(4)) # self.pushButton_menu_downloader.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(7)) self.pushButton_menu_downloader.clicked.connect( lambda: open_browser(soft_cfg.download_url)) def icon_on_btn(self): self.pushButton_feedback.setIcon( qtawesome.icon('fa.envelope-o', color="blank")) self.pushButton_min.setIcon( qtawesome.icon('fa.window-minimize', color='blank')) self.pushButton_close.setIcon(qtawesome.icon('fa.close', color='blank')) self.pushButton_update.setIcon( qtawesome.icon('fa.arrow-circle-up', color='blank')) # 菜单栏图标 self.pushButton_menu_about_us.setIcon( qtawesome.icon('fa.yelp', color='white')) self.pushButton_menu_api.setIcon( qtawesome.icon('fa.link', color='white')) self.pushButton_menu_article.setIcon( qtawesome.icon('fa.file-text', color='white')) self.pushButton_menu_source.setIcon( qtawesome.icon('fa.code', color='white')) self.pushButton_menu_soft.setIcon( qtawesome.icon('fa.th-large', color='white')) self.pushButton_menu_downloader.setIcon( qtawesome.icon('fa.download', color='white')) # 自定义功能区 def window_close(self, code): res = QMessageBox.question(self, '是否关闭程序', '请确保没有下载任务', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if res == QMessageBox.Yes: self.webDownloader_Thread.stop() qApp.exit(code) else: pass def licenses(self): self.stackedWidget.setCurrentIndex(1) self.textEdit_licenses.append(soft_cfg.licenses) scrollbar = self.textEdit_licenses.verticalScrollBar() scrollbar.setSliderPosition(0) # 界面拖动 def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.m_flag = True self.m_Position = event.globalPos() - self.pos() # 获取鼠标相对窗口的位置 event.accept() self.setCursor(QCursor(Qt.OpenHandCursor)) # 更改鼠标图标 def mouseMoveEvent(self, QMouseEvent): if Qt.LeftButton and self.m_flag: self.move(QMouseEvent.globalPos() - self.m_Position) # 更改窗口位置 QMouseEvent.accept() def mouseReleaseEvent(self, QMouseEvent): self.m_flag = False self.setCursor(QCursor(Qt.ArrowCursor)) # 线程区 def time_thread(self): try: self.time_Thread = Time_Thread() self.time_Thread.thread_signal.connect(self.Time_UI) self.time_Thread.start() except Exception as e: print(f"Time Thread: {e}") QMessageBox.information(self, '时间进程发生错误', f'错误信息{e},请尝试重启客户端,如问题还未解决,请点击反馈按钮留言') def Time_UI(self, msm): self.label_time.setText(f"{msm}") def source_thread(self): try: self.source_Thread = Source_Thread() self.source_Thread.thread_signal.connect(self.Source_UI) self.source_Thread.start() except Exception as e: print(f"Source Thread: {e}") QMessageBox.information( self, '源码仓库发生错误', f'错误信息{e},请确定网络连接是否正常,然后尝试重启客户端,如问题还未解决,请点击反馈按钮留言') def Source_UI(self, msm): self.source_url = msm['url'] try: self.listWidget_source.clear() except Exception as e: print(f"source function.py: {e}") for i in zip(msm['title'], msm['info'], msm['language'], msm['url']): item = QListWidgetItem() widget = get_item_source(i) item.setSizeHint(QSize(widget.width(), widget.height())) self.listWidget_source.addItem(item) self.listWidget_source.setItemWidget(item, widget) def source_item_clicked(self, item): open_browser( self.source_url[self.listWidget_source.currentIndex().row()]) def article_thread(self): try: self.article_Thread = Article_Thread() self.article_Thread.thread_signal.connect(self.Article_UI) self.article_Thread.start() except Exception as e: print(f"Article Thread: {e}") QMessageBox.information( self, '文章教程发生错误', f'错误信息{e},请确定网络连接是否正常,然后尝试重启客户端,如问题还未解决,请点击反馈按钮留言') def Article_UI(self, msm): self.article_url = msm['url'] try: self.listWidget_article.clear() except Exception as e: print(f"article function.py: {e}") for i in zip(msm['title'], msm['info'], msm['date'], msm['url']): item = QListWidgetItem() widget = get_item_source(i) item.setSizeHint(QSize(widget.width(), widget.height())) self.listWidget_article.addItem(item) self.listWidget_article.setItemWidget(item, widget) def article_item_clicked(self, item): open_browser( self.article_url[self.listWidget_article.currentIndex().row()]) def update_thread(self, auto=True): try: self.update_Thread = Update_Thread(auto) self.update_Thread.display_signal.connect(self.Update_UI) self.update_Thread.start() except: QMessageBox.information( self, '小助手提示', '程序运行异常,请确定网络连接是否正常,然后尝试重启客户端,如问题还未解决,请点击反馈按钮留言') def Update_UI(self, msm): if msm['Version'] <= soft_cfg.version: if not msm["auto"] != False: QMessageBox.information(self, '小助手提示', '已经是最新版本') else: pass else: reply = QtWidgets.QMessageBox.question( self, '发现新版本,是否立即更新', f'发现新版本:V{msm["Version"]},更新内容如下:\n\n{msm["Update_des"]}\n\n是否立即更新?', QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if reply == QtWidgets.QMessageBox.Yes: subprocess.Popen( f"update_main.exe {msm['Update_url']} {soft_cfg.name}") qApp.exit(0) else: pass
class fun_main(Ui_MainWindow, QtWidgets.QMainWindow): def __init__(self): super(fun_main, self).__init__() self.setupUi(self) self.setWindowOpacity(1) # 设置窗口透明度 self.setAttribute(QtCore.Qt.WA_TranslucentBackground) # 主窗口透明 self.setWindowFlag(QtCore.Qt.FramelessWindowHint) # 隐藏边框 # self.setWindowFlag(QtCore.Qt.WindowStaysOnTopHint) # 窗口始终置顶 # 初始化功能 self.signal_on_btn() self.icon_on_btn() # 初始化参数 self.m_flag = False self.source_url = [] # 源码仓库链接初始化 self.article_url = [] # 文章教程链接初始化 self.label_10.hide() self.label_sys_info.hide() self.pros = [ self.progressBar_downloader_sub0, self.progressBar_downloader_sub1, self.progressBar_downloader_sub2, self.progressBar_downloader_sub3, self.progressBar_downloader_sub4, self.progressBar_downloader_sub5, self.progressBar_downloader_sub6, self.progressBar_downloader_sub7, self.progressBar_downloader_sub8, self.progressBar_downloader_sub9, self.progressBar_downloader_sub10, self.progressBar_downloader_sub11, self.progressBar_downloader_sub12, self.progressBar_downloader_sub13, self.progressBar_downloader_sub14, self.progressBar_downloader_sub15 ] for i in self.pros: i.hide() self.progressBar_downloader_main.hide() self.textEdit_download_sub.hide() msm = f"<center><h2>欢迎试用此下载器</h2>" \ f"<h4>本软件为开源项目,可点击左侧'源码仓库'菜单,点击'System-assistant'查看程序源码</h4>" \ f"<h4>当前版本仅支持http/https下载协议的下载链接,其他协议链接正在添加中</h4>" \ f"<h3>程序功能正在逐步完善中,敬请期待...</h3></center>" self.textEdit_download_top.append(msm) # 线程启动 self.time_thread() self.source_thread() self.article_thread() self.update_thread() def signal_on_btn(self): # 基础按钮事件绑定 self.pushButton_close.clicked.connect(lambda: self.window_close(0)) self.pushButton_min.clicked.connect(lambda: self.showMinimized()) self.pushButton_feedback.clicked.connect( lambda: open_browser(soft_cfg.feed_back)) self.pushButton_web_site.clicked.connect( lambda: open_browser(soft_cfg.web_site)) self.pushButton_help_us.clicked.connect( lambda: open_browser(soft_cfg.help_us)) self.pushButton_web_rights.clicked.connect(self.licenses) self.pushButton_update.clicked.connect(self.update_thread) self.pushButton_downloader_new.clicked.connect(self.open_download_win) # List Widget点击事件 self.listWidget_source.itemClicked.connect(self.source_item_clicked) self.listWidget_article.itemClicked.connect(self.article_item_clicked) # 界面转换 self.pushButton_menu_soft.clicked.connect( lambda: self.stackedWidget.setCurrentIndex(0)) # self.pushButton_menu_api.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(1)) self.pushButton_menu_api.clicked.connect(self.open_api_site) self.pushButton_menu_article.clicked.connect( lambda: self.stackedWidget.setCurrentIndex(2)) self.pushButton_menu_source.clicked.connect( lambda: self.stackedWidget.setCurrentIndex(3)) self.pushButton_menu_about_us.clicked.connect( lambda: self.stackedWidget.setCurrentIndex(4)) self.pushButton_menu_downloader.clicked.connect( lambda: self.stackedWidget.setCurrentIndex(7)) def icon_on_btn(self): self.pushButton_feedback.setIcon( qtawesome.icon('fa.envelope-o', color="blank")) self.pushButton_min.setIcon( qtawesome.icon('fa.window-minimize', color='blank')) self.pushButton_close.setIcon(qtawesome.icon('fa.close', color='blank')) self.pushButton_update.setIcon( qtawesome.icon('fa.arrow-circle-up', color='blank')) # 菜单栏图标 self.pushButton_menu_about_us.setIcon( qtawesome.icon('fa.yelp', color='white')) self.pushButton_menu_api.setIcon( qtawesome.icon('fa.link', color='white')) self.pushButton_menu_article.setIcon( qtawesome.icon('fa.file-text', color='white')) self.pushButton_menu_source.setIcon( qtawesome.icon('fa.code', color='white')) self.pushButton_menu_soft.setIcon( qtawesome.icon('fa.th-large', color='white')) self.pushButton_menu_downloader.setIcon( qtawesome.icon('fa.download', color='white')) # 下载器 self.pushButton_downloader_new.setIcon( qtawesome.icon('fa.plus', color='blue')) # 自定义功能区 def window_close(self, code): res = QMessageBox.question(self, '是否关闭程序', '请确保没有下载任务', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if res == QMessageBox.Yes: qApp.exit(code) else: pass def open_api_site(self): # 接口文档 --跳转到API网页 res = QMessageBox.question(self, '提示', '即将在浏览器中打开接口文档,需登录后才可使用本站API,是否继续?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if res == QMessageBox.Yes: open_browser(soft_cfg.api_site) else: pass def licenses(self): self.stackedWidget.setCurrentIndex(1) self.textEdit_licenses.append(soft_cfg.licenses) scrollbar = self.textEdit_licenses.verticalScrollBar() scrollbar.setSliderPosition(0) # 界面拖动 def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.m_flag = True self.m_Position = event.globalPos() - self.pos() # 获取鼠标相对窗口的位置 event.accept() self.setCursor(QCursor(Qt.OpenHandCursor)) # 更改鼠标图标 def mouseMoveEvent(self, QMouseEvent): if Qt.LeftButton and self.m_flag: self.move(QMouseEvent.globalPos() - self.m_Position) # 更改窗口位置 QMouseEvent.accept() def mouseReleaseEvent(self, QMouseEvent): self.m_flag = False self.setCursor(QCursor(Qt.ArrowCursor)) # 线程区 def time_thread(self): try: self.time_Thread = Time_Thread() self.time_Thread.thread_signal.connect(self.Time_UI) self.time_Thread.start() except Exception as e: print(f"Time Thread: {e}") QMessageBox.information(self, '时间进程发生错误', f'错误信息{e},请尝试重启客户端,如问题还未解决,请点击反馈按钮留言') def Time_UI(self, msm): self.label_time.setText(f"{msm}") def source_thread(self): try: self.source_Thread = Source_Thread() self.source_Thread.thread_signal.connect(self.Source_UI) self.source_Thread.start() except Exception as e: print(f"Source Thread: {e}") QMessageBox.information( self, '源码仓库发生错误', f'错误信息{e},请确定网络连接是否正常,然后尝试重启客户端,如问题还未解决,请点击反馈按钮留言') def Source_UI(self, msm): self.source_url = msm['url'] try: self.listWidget_source.clear() except Exception as e: print(f"source function.py: {e}") for i in zip(msm['title'], msm['info'], msm['language'], msm['url']): item = QListWidgetItem() widget = get_item_source(i) item.setSizeHint(QSize(widget.width(), widget.height())) self.listWidget_source.addItem(item) self.listWidget_source.setItemWidget(item, widget) def source_item_clicked(self, item): open_browser( self.source_url[self.listWidget_source.currentIndex().row()]) def article_thread(self): try: self.article_Thread = Article_Thread() self.article_Thread.thread_signal.connect(self.Article_UI) self.article_Thread.start() except Exception as e: print(f"Article Thread: {e}") QMessageBox.information( self, '文章教程发生错误', f'错误信息{e},请确定网络连接是否正常,然后尝试重启客户端,如问题还未解决,请点击反馈按钮留言') def Article_UI(self, msm): self.article_url = msm['url'] try: self.listWidget_article.clear() except Exception as e: print(f"article function.py: {e}") for i in zip(msm['title'], msm['info'], msm['date'], msm['url']): item = QListWidgetItem() widget = get_item_source(i) item.setSizeHint(QSize(widget.width(), widget.height())) self.listWidget_article.addItem(item) self.listWidget_article.setItemWidget(item, widget) def article_item_clicked(self, item): open_browser( self.article_url[self.listWidget_article.currentIndex().row()]) def open_download_win(self): downloadWin = Download_UI() downloadWin.mySignal.connect(self.download_thread) downloadWin.exec_() def download_thread(self, msm): url = msm[0] thread = msm[1] fileName = msm[2] self.progressBar_downloader_main.show() self.textEdit_download_top.clear() self.textEdit_download_sub.clear() self.textEdit_download_sub.show() try: self.download_Thread.stop() self.download_Thread.thread_signal.disconnect() except: pass self.download_Thread = Download_Thread(url, thread, fileName) self.download_Thread.thread_signal.connect(self.downloadThread) self.download_Thread.start() self.progressBar_downloader_main.setValue(0) for i in self.pros: i.setValue(0) for i in range(thread): self.pros[i].show() def downloadThread(self, msm): self.textEdit_download_top.clear() self.textEdit_download_sub.clear() isExists = msm.get('fileExists', 0) if isExists == 1: QMessageBox.information( self, '文件已经存在', f'检测到您要下载的文件已经存在,如果想要重新下载请删除 {msm["filePath"]} 后再进行下载') self.textEdit_download_top.append( f'<center><h2>检测到您要下载的文件已经存在</h2><p>如果想要重新下载请删除 {msm["filePath"]} 后再进行下载</p></center>' ) self.textEdit_download_sub.hide() self.progressBar_downloader_main.hide() for i in self.pros: i.hide() else: isStarted = msm['info']['started'] isMutiThread = msm['info']['downloader'] isFinished = msm['info']['averageSpeed'] if isStarted == 0: self.textEdit_download_top.append( f"下载程序正在初始化,这个过程不会很长\n请稍等...") else: if isMutiThread == 1 and isFinished == 0: ospeed = msm['main']['speed'] / 1024 if ospeed == 0: ospeed = 1 if ospeed > 1024: speed = f"{round(ospeed / 1024, 2)} M/s" else: speed = f"{ospeed} KB/s" underTime = (msm['info']['size'] - msm['main']['data']) / 1024 / ospeed if underTime > 60: underTime = f"{int(underTime / 60)} 分钟 {int(underTime % 60)} 秒" else: underTime = f"{int(underTime)} 秒" self.textEdit_download_top.append( f"文件来源:{msm['info']['url']}\n文件大小:{round(msm['info']['size'] / 1024 / 1024, 2)} MB\n已经下载:{round(msm['main']['data'] / 1024 / 1024, 2)} MB\n传输速度:{speed}\n剩余时间:{underTime}\n储存至:{msm['info']['saveTo']}\n" ) # 子进度条设置进度 for i in range(msm['info']['thread']): self.pros[i].setValue( int(msm['sub']['data'][i][0] / msm['sub']['data'][i][1] * 100)) # 主进度条设置进度 self.progressBar_downloader_main.setValue( int(msm['main']['data'] / msm['info']['size'] * 100)) # 子线程数据显示 self.textEdit_download_sub.clear() for i in range(msm['info']['thread']): savedSubData = msm['sub']['data'][i][0] / 1024 if savedSubData > 1024: savedSubData = f"{round(savedSubData / 1024, 2)} MB" else: savedSubData = f"{savedSubData} KB" if int(msm['sub']['data'][i][0] / 1024) >= int( msm['sub']['data'][i][1] / 1024): self.textEdit_download_sub.append( f"线程{i + 1}:已接收 {savedSubData},接收完成.") else: self.textEdit_download_sub.append( f"线程{i + 1}:已接收 {savedSubData},正在接收...") scrollbar = self.textEdit_download_sub.verticalScrollBar() scrollbar.setSliderPosition(0) elif isMutiThread == 1 and isFinished != 0: # 下载完成,隐藏子进度条 for i in range(msm['info']['thread']): self.pros[i].hide() # 子线程数据显示 self.textEdit_download_sub.clear() for i in range(msm['info']['thread']): savedSubData = msm['sub']['data'][i][0] / 1024 if savedSubData > 1024: savedSubData = f"{round(savedSubData / 1024, 2)} MB" else: savedSubData = f"{savedSubData} KB" self.textEdit_download_sub.append( f"线程{i + 1}:已接收 {savedSubData},接收完成.") self.textEdit_download_sub.append( f"文件下载完成,已经保存到了 {msm['info']['saveTo']} ") scrollbar = self.textEdit_download_sub.verticalScrollBar() scrollbar.setSliderPosition(0) speed = isFinished / 1024 if speed > 1024: speed = f"{round(speed / 1024, 2)} M/s" else: speed = f"{speed} KB/s" self.textEdit_download_top.append( f"文件来源:{msm['info']['url']}\n文件大小:{round(msm['info']['size'] / 1024 / 1024, 2)} MB\n已经下载:{round(msm['main']['data'] / 1024 / 1024, 2)} MB\n平均速度:{speed}\n已经储存至:{msm['info']['saveTo']}\n" ) self.progressBar_downloader_main.setValue(100) elif isMutiThread == 0 and isFinished == 0: ospeed = msm['main']['speed'] / 1024 if ospeed == 0: ospeed = 1 if ospeed > 1024: speed = f"{round(ospeed / 1024, 2)} M/s" else: speed = f"{ospeed} KB/s" self.textEdit_download_top.append( f"文件来源:{msm['info']['url']}\n文件大小:未知\n已经下载:{round(msm['main']['data'] / 1024 / 1024, 2)} MB\n传输速度:{speed}\n剩余时间:未知\n储存至:{msm['info']['saveTo']}\n" ) # 子进度条设置进度 for i in range(msm['info']['thread']): self.pros[i].hide() # 主进度条设置进度 self.progressBar_downloader_main.setValue(100) else: # 下载完成,隐藏子进度条 for i in range(msm['info']['thread']): self.pros[i].hide() speed = isFinished / 1024 if speed > 1024: speed = f"{round(speed / 1024, 2)} M/s" else: speed = f"{speed} KB/s" self.textEdit_download_top.append( f"文件来源:{msm['info']['url']}\n文件大小:{round(msm['main']['data'] / 1024 / 1024, 2)} MB\n已经下载:{round(msm['main']['data'] / 1024 / 1024, 2)} MB\n平均速度:{speed}\n已经储存至:{msm['info']['saveTo']}\n" ) def update_thread(self, auto=True): try: self.update_Thread = Update_Thread(auto) self.update_Thread.display_signal.connect(self.Update_UI) self.update_Thread.start() except: QMessageBox.information( self, '小助手提示', '程序运行异常,请确定网络连接是否正常,然后尝试重启客户端,如问题还未解决,请点击反馈按钮留言') def Update_UI(self, msm): if msm['Version'] <= soft_cfg.version: if not msm["auto"] != False: QMessageBox.information(self, '小助手提示', '已经是最新版本') else: pass else: reply = QtWidgets.QMessageBox.question( self, '发现新版本,是否立即更新', f'发现新版本:V{msm["Version"]},更新内容如下:\n\n{msm["Update_des"]}\n\n是否立即更新?', QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if reply == QtWidgets.QMessageBox.Yes: subprocess.Popen( f"update_main.exe {msm['Update_url']} {soft_cfg.name}") qApp.exit(0) else: pass