-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateGUI.py
More file actions
118 lines (95 loc) · 4.47 KB
/
Copy pathupdateGUI.py
File metadata and controls
118 lines (95 loc) · 4.47 KB
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
import maliang
from maliang import theme
from loguru import logger
import threading
import downloader
import update
import time
import err
# 全局变量,用于控制下载是否中断
download_interrupted = threading.Event()
def stop(cv, window):
"""停止下载"""
logger.info("调用函数 stop")
downloader.stop_download()
update_info(cv, window)
def get_progress_bar(progress_bar_name):
"""获取当前进度条进度"""
return progress_bar_name.get()
def update_progress_bar(cv, window, progress_bar_name, progress):
if progress != 0:
progress_bar_name.set(0)
"""更新进度条"""
while not progress_bar_name.get() >= 1 and not download_interrupted.is_set():
if progress_bar_name.get() >= 1:
logger.info("进度条已完成")
return
if download_interrupted.is_set():
logger.info("下载已中断")
return
progress = downloader.get_download_progress()
progress_bar_name.set(progress)
time.sleep(0.2)
ready_install_update(cv, window)
def update_progress_bar_threading(cv, window, progress_bar_name, progress):
"""在单独线程中更新进度条"""
logger.info("调用函数 update_progress_bar_threading")
thread = threading.Thread(
target=update_progress_bar,
args=(cv, window, progress_bar_name, progress)
)
thread.start()
return thread
def update_window():
logger.info("调用函数 update_window")
logger.info("创建 update_window 窗口")
update_window = maliang.Tk(size=(600, 400), icon="./img/EECT_logo.ico")
update_window.center()
update_window.title("EECT更新")
update_window.resizable(False, False)
theme.customize_window(update_window, hide_button="all")
update_window.topmost(True)
update_cv = maliang.Canvas(update_window, auto_zoom=False)
update_cv.place(width=600, height=400)
updateGUI(update_cv, update_window)
update_window.mainloop()
def updateGUI(cv, window):
logger.info("调用函数 updateGUI")
cv.clear()
title = maliang.Text(cv, (20, 20), text="EECT更新", fontsize=32)
version = maliang.Text(cv, (20, 80), text="当前版本:%s\n版本码:%s" % (update.check_version(1), update.check_version(0)))
cheek_update = maliang.Button(cv, (20, 160), text="检查更新", command=lambda: update_info(cv, window))
close = maliang.Button(cv, (20, 210), text="关闭", command=lambda: window.destroy())
def update_info(cv, window):
logger.info("调用函数 update_info")
cv.clear()
back = maliang.Button(cv, (0, 0), text="← ", command=lambda: updateGUI(cv, window), fontsize=16)
cheek_version = update.update()
update_text = maliang.Text(cv, (45, 0), text="EECT更新信息", fontsize=26)
version_info = maliang.Text(cv, (20, 80), text=f"当前版本:{update.check_version(1)}\n版本码:{update.check_version(0)}\n\n最新版本:{cheek_version[1]}\n版本码:{cheek_version[2]}\n发布日期:{cheek_version[3]}\n更新日志:{cheek_version[4]}\n重要程度:{[cheek_version[5]]}", fontsize=14)
if cheek_version[0]:
logger.info("检测到新版本")
compare = "有可用更新!"
download = maliang.Button(cv, (20, 350), text="下载更新", command=lambda: download_update(cv, window, cheek_version[6], cheek_version[7]))
else:
logger.info("当前已是最新版本")
compare = "当前已是最新版本!"
update_text = maliang.Text(cv, (20, 50), text=compare)
def download_update(cv, window, name, url):
logger.info("调用函数 download_update")
cv.clear()
wait = maliang.Spinner(cv, (150, 180), mode="indeterminate")
update_text = maliang.Text(cv, (210, 180), text="正在下载更新,请稍等...")
download_progress = maliang.ProgressBar(cv, (100, 220))
download_progress.set(0)
update_progress_bar_threading(cv, window, download_progress, downloader.get_download_progress())
back = maliang.Button(cv, (240, 300), text="取消下载", command=lambda: stop(cv, window))
downloader.download_in_thread(name, url, "./cache/download")
def ready_install_update(cv, window):
logger.info("调用函数 read_install_update")
cv.clear()
title = maliang.Text(cv, (200, 180), text="更新下载完成,立即安装?")
yes = maliang.Button(cv, (240, 300), text="安装更新")
no = maliang.Button(cv, (240, 350), text="暂不安装", command=lambda: update_info(cv, window))
if __name__ == "__main__":
update_window()