From 09becf8f213ef7eba0e41a2df022fefe9ca63ea9 Mon Sep 17 00:00:00 2001 From: Doushabao233 <3548173159@qq.com> Date: Sun, 15 Oct 2023 21:37:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC=E3=80=81=E6=B7=BB=E5=8A=A0=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1=E3=80=81=E8=BD=AF=E4=BB=B6=E5=9B=BE?= =?UTF-8?q?=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 整理了代码风格,统一大小引号、在合适的地方补空格 - 添加了下载进度条 - 支持识别并显示软件图标,具体体现在任务栏和窗口左上角 --- releases/v1.2/favicon.ico | Bin 0 -> 138982 bytes releases/v1.2/tchMaterial-parser.py | 118 ++++++++++++++++++++-------- 2 files changed, 84 insertions(+), 34 deletions(-) create mode 100644 releases/v1.2/favicon.ico diff --git a/releases/v1.2/favicon.ico b/releases/v1.2/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..6fe2db34a12efc6324db803bc65f0270d6f23d30 GIT binary patch literal 138982 zcmeHQPl#N{neVZd$Oj|m;9V4{U-!Tol0(=S5{M3FM-V{_3B-q8c7qL`?iNYFff#JC zU`?jM1{q>-AO;0|m_rUZD4+!`cwrXQpamc1-~}CY&|wC&SY~=gEzm&*g_-<*_2+f< z>w15>`*nBK>l)GO*YA5(@B3R{RefJo)oN?_w|A|E|JQ5(*LbG(54BqDJNWG3^G|E? zJ}zr7o_U5};V*{+gU$7C9&Mh#&~G&__uGx`QK#|gVY_+buoc}BpLS#SsNLAppTlY^v+>B+Qjcm{dV+&FMo0Fg&gz(IB=jc9QdjeeHS+N z7Hs4?Y~a4ljuw1xfcL?^n}5dlRki^K?Z(T&E-RyQD@(}9#oFINr!Pr==7g@D+I`0Ku~$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?PDb6ZdqvuEZiS7?tIE z8rD=r#FvEaYuLs(EN0r)I4ow236iwOjM37OkI46F0%LXwpn`QJGD?Y5%?j3&u%@~z zzZ6U%x?zJUL`OghPi5DmsA!n9>rqr<*glaNeO(L_q91)-3}dB 0: # 规避 ZeroDivisionError + download_progress = (download_size / total_size) * 100 + + download_progress_bar['value'] = download_progress + root.update_idletasks() + + # print(f'total, {total_size}; down, {download_size}; prog, {download_progress}') + messagebox.showinfo('完成', f'文件已下载到:{save_path}') # 显示完成对话框 # 解析并复制链接的函数 def analyze_and_copy(): - urls = [line.strip() for line in url_text.get("1.0", tk.END).splitlines() if line.strip()] # 获取所有非空行 + urls = [line.strip() for line in url_text.get('1.0', tk.END).splitlines() if line.strip()] # 获取所有非空行 pdf_links = [] failed_links = [] @@ -61,21 +98,21 @@ def analyze_and_copy(): pdf_links.append(pdf_url) if failed_links: - failed_msg = "以下链接无法解析:\n" + '\n'.join(failed_links) - messagebox.showwarning("警告", failed_msg) # 显示警告对话框 + failed_msg = '以下链接无法解析:\n' + '\n'.join(failed_links) + messagebox.showwarning('警告', failed_msg) # 显示警告对话框 if pdf_links: - pyperclip.copy("\n".join(pdf_links)) # 将链接复制到剪贴板 - messagebox.showinfo("提示", "PDF链接已复制到剪贴板") + pyperclip.copy('\n'.join(pdf_links)) # 将链接复制到剪贴板 + messagebox.showinfo('提示', 'PDF链接已复制到剪贴板') # 下载PDF文件的函数 def download(): - urls = [line.strip() for line in url_text.get("1.0", tk.END).splitlines() if line.strip()] # 获取所有非空行 + urls = [line.strip() for line in url_text.get('1.0', tk.END).splitlines() if line.strip()] # 获取所有非空行 failed_links = [] if len(urls) > 1: - messagebox.showinfo("提示", "您选择了多个链接,将在选定的文件夹中使用教材名称作为文件名进行下载。") - dir_path = filedialog.askdirectory().replace("/","\\") # 选择文件夹 + messagebox.showinfo('提示', '您选择了多个链接,将在选定的文件夹中使用教材名称作为文件名进行下载。') + dir_path = filedialog.askdirectory().replace('/','\\') # 选择文件夹 if not dir_path: return else: @@ -88,19 +125,26 @@ def download(): continue if dir_path: - default_filename = get_default_filename(contentId) or "download" - save_path = os.path.join(dir_path, f"{default_filename}.pdf") # 构造完整路径 + default_filename = get_default_filename(contentId) or 'download' + save_path = os.path.join(dir_path, f'{default_filename}.pdf') # 构造完整路径 else: - default_filename = get_default_filename(contentId) or "download" - save_path = filedialog.asksaveasfilename(defaultextension=".pdf", filetypes=[("PDF files", "*.pdf"), ("All files", "*.*")], initialfile=default_filename).replace("/","\\") # 选择保存路径 + default_filename = get_default_filename(contentId) or 'download' + save_path = filedialog.asksaveasfilename(defaultextension='.pdf', filetypes=[('PDF files', '*.pdf'), ('All files', '*.*')], initialfile=default_filename).replace('/','\\') # 选择保存路径 if not save_path: return - threading.Thread(target=download_file, args=(pdf_url, save_path)).start() # 开始下载 + thread_it(download_file, (pdf_url, save_path)) # 开始下载(多线程,防止窗口卡死) + # threading.Thread(target=download_file, args=(pdf_url, save_path)).start() # 开始下载 if failed_links: - failed_msg = "以下链接无法解析:\n" + '\n'.join(failed_links) - messagebox.showwarning("警告", failed_msg) # 显示警告对话框 + failed_msg = '以下链接无法解析:\n' + '\n'.join(failed_links) + messagebox.showwarning('警告', failed_msg) # 显示警告对话框 + +def thread_it(func, args: tuple): + # 打包函数到线程 + t = threading.Thread(target=func, args=args) + # t.daemon = True + t.start() scale = round(win32print.GetDeviceCaps(win32gui.GetDC(0), win32con.DESKTOPHORZRES) / win32api.GetSystemMetrics(0), 2) # 获取屏幕缩放比例 @@ -109,28 +153,32 @@ def download(): #----------高DPI适配start--------- -#获得当前的缩放因子 +# 获得当前的缩放因子 ScaleFactor=round(win32print.GetDeviceCaps(win32gui.GetDC(0), win32con.DESKTOPHORZRES) / win32api.GetSystemMetrics (0), 2) -#调用api设置成由应用程序缩放 +# 调用api设置成由应用程序缩放 try: # 系统版本 >= win 8.1 ctypes.windll.shcore.SetProcessDpiAwareness(2) except: # 系统版本 <= win 8.0 ctypes.windll.user32.SetProcessDPIAware() -#设置缩放因子 +# 设置缩放因子 root.tk.call('tk', 'scaling', ScaleFactor/0.75) #----------高DPI适配end--------- -root.title("国家中小学智慧教育平台 电子课本解析") # 设置窗口标题 -# root.geometry("900x600") # 设置窗口大小 +root.title('国家中小学智慧教育平台 电子课本解析') # 设置窗口标题 +# root.geometry('900x600') # 设置窗口大小 + +# 设置ico文件 +if os.path.exists('favicon.ico'): + root.iconbitmap('favicon.ico') # 创建一个容器框架 container_frame = ttk.Frame(root) container_frame.pack(anchor='center',expand='yes', padx=int(20*scale), pady=int(20*scale)) # 容器的中心位置放置,允许组件在容器中扩展,水平外边距40,垂直外边距40 -title_label = ttk.Label(container_frame, text="国家中小学智慧教育平台 电子课本解析", font=("微软雅黑", 16, "bold")) # 添加标题标签 +title_label = ttk.Label(container_frame, text='国家中小学智慧教育平台 电子课本解析', font=('微软雅黑', 16, 'bold')) # 添加标题标签 title_label.pack(pady=int(5*scale)) # 设置垂直外边距(跟随缩放) description = '''请在下面的文本框中粘贴一个或多个课本原网址(支持批量每个URL一行)。 @@ -139,16 +187,18 @@ def download(): assets_document&contentId=b8e9a3fe-dae7-49c0-86cb-d146f88 3fd8e&catalogType=tchMaterial&subCatalog=tchMaterial 点击下载按钮后,程序会解析并下载所有PDF文件。''' -description_label = ttk.Label(container_frame, text=description, justify="left") # 添加描述标签 +description_label = ttk.Label(container_frame, text=description, justify='left') # 添加描述标签 description_label.pack(pady=int(5*scale)) # 设置垂直外边距(跟随缩放) url_text = tk.Text(container_frame, width=70, height=12) # 添加URL输入框,长度和宽度不使用缩放!!! url_text.pack(padx=int(15*scale), pady=int(15*scale)) # 设置水平外边距、垂直外边距(跟随缩放) -download_btn = ttk.Button(container_frame, text="下载", command=download) # 添加下载按钮 -download_btn.pack(side="left", padx=int(40*scale), pady=int(5*scale), ipady=int(5*scale)) # 设置水平外边距、垂直外边距(跟随缩放),设置按钮高度(跟随缩放) +download_btn = ttk.Button(container_frame, text='下载', command=download) # 添加下载按钮 +download_btn.pack(side='left', padx=int(40*scale), pady=int(5*scale), ipady=int(5*scale)) # 设置水平外边距、垂直外边距(跟随缩放),设置按钮高度(跟随缩放) -copy_btn = ttk.Button(container_frame, text="解析并复制", command=analyze_and_copy) # 添加“解析并复制”按钮 -copy_btn.pack(side="right", padx=int(40*scale), pady=int(5*scale), ipady=int(5*scale)) # 设置水平外边距、垂直外边距(跟随缩放),设置按钮高度(跟随缩放) +copy_btn = ttk.Button(container_frame, text='解析并复制', command=analyze_and_copy) # 添加“解析并复制”按钮 +copy_btn.pack(side='right', padx=int(40*scale), pady=int(5*scale), ipady=int(5*scale)) # 设置水平外边距、垂直外边距(跟随缩放),设置按钮高度(跟随缩放) +download_progress_bar = ttk.Progressbar(container_frame, length=(125*scale), mode='determinate') +download_progress_bar.pack(side='bottom', padx=int(40*scale), pady=int(10*scale), ipady=int(10*scale)) root.mainloop() # 开始主循环 \ No newline at end of file From df3b8208eb8e2a875583ff8681b551c4576e7171 Mon Sep 17 00:00:00 2001 From: Doushabao233 <3548173159@qq.com> Date: Sun, 15 Oct 2023 21:47:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=9D=9E=E5=B8=B8=E9=9D=9E=E5=B8=B8?= =?UTF-8?q?=E5=B0=8F=E7=9A=84=E6=9B=B4=E6=94=B9=EF=BC=88=E7=9C=9F=E7=9A=84?= =?UTF-8?q?=E9=9D=9E=E5=B8=B8=E5=B0=8F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 漏了一处等于号的空格,这次补上 --- releases/v1.2/tchMaterial-parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releases/v1.2/tchMaterial-parser.py b/releases/v1.2/tchMaterial-parser.py index f3c94ad..4318f2a 100644 --- a/releases/v1.2/tchMaterial-parser.py +++ b/releases/v1.2/tchMaterial-parser.py @@ -154,7 +154,7 @@ def thread_it(func, args: tuple): #----------高DPI适配start--------- # 获得当前的缩放因子 -ScaleFactor=round(win32print.GetDeviceCaps(win32gui.GetDC(0), win32con.DESKTOPHORZRES) / win32api.GetSystemMetrics (0), 2) +ScaleFactor = round(win32print.GetDeviceCaps(win32gui.GetDC(0), win32con.DESKTOPHORZRES) / win32api.GetSystemMetrics (0), 2) # 调用api设置成由应用程序缩放 try: # 系统版本 >= win 8.1