@@ -382,7 +382,7 @@ def __init__(self, root):
382382 ## [DEBUG] 用于测试记录QReader所使用的隐藏导入模块
383383 # start_tracking()
384384 from qreader import QReader
385- self .qreader = QReader (model_size = 'm ' , min_confidence = 0.3 , reencode_to = 'cp65001' )
385+ self .qreader = QReader (model_size = 'l ' , min_confidence = 0.3 , reencode_to = 'cp65001' )
386386
387387 # P5:初始化界面
388388 update_splash_status ("构建用户界面..." )
@@ -439,6 +439,7 @@ def create_ui(self):
439439
440440 placeholder_frame = tk .Frame (horizontal_frame , bg = "white" ) # 透明占位
441441 placeholder_frame .pack (side = "right" , anchor = "ne" , pady = 30 )
442+ self .formart_and_extract_frame = tk .Frame (self .root , bg = "white" )
442443 self .format_frame = tk .Frame (self .root , bg = "white" )
443444 self .frm_extract_mode = tk .Frame (self .root , bg = "white" )
444445 self .algorithm_frame = tk .Frame (self .root , bg = "white" )
@@ -468,11 +469,11 @@ def create_ui(self):
468469 )
469470 self .show_orignal_extract_picture_check .pack (anchor = 'e' )
470471
471- # 嵌入自定图片
472+ # 使用自定水印文件
472473 self .is_custom_file = BooleanVar (value = False )
473474 self .custom_check = Checkbutton (
474475 options_frame_down ,
475- text = "嵌入自定水印 " ,
476+ text = "使用自定水印 " ,
476477 variable = self .is_custom_file ,
477478 command = self .toggle_custom_data_input_frame
478479 )
@@ -625,6 +626,9 @@ def toggle_extract_mode_selection(self):
625626 print ("extract mode." )
626627 self .frm_extract_mode .pack (pady = 2 , fill = "x" , anchor = "nw" , padx = 20 , before = self .algorithm_frame )
627628 self .format_frame .pack_forget ()
629+ # 重新渲染以防止覆盖复选框
630+ self .custom_check .pack_forget ()
631+ self .custom_check .pack (anchor = 'e' ,pady = (0 ,2 ))
628632 else :
629633 self .format_frame .pack (pady = 2 , fill = "x" , anchor = "nw" , padx = 20 , before = self .algorithm_frame )
630634 self .frm_extract_mode .pack_forget ()
@@ -825,21 +829,30 @@ def on_close(self):
825829 def show_processing_window (self , message ):
826830 """显示处理中窗口"""
827831 import tkinter as tk
832+
828833 if not self .processing_window :
834+ # 第一次创建窗口
829835 self .processing_window = tk .Toplevel (self .root )
830836 self .processing_window .title ("处理中" )
831837 self .processing_window .geometry ("300x100" )
832838 self .processing_window .resizable (False , False )
833839 self .processing_window .protocol ("WM_DELETE_WINDOW" , lambda : None ) # 禁用关闭按钮
834-
840+
835841 self .processing_label = tk .Label (self .processing_window , text = message )
836842 self .processing_label .pack (pady = 10 )
837-
843+
838844 # 简单的动画效果
839845 self .processing_animation = tk .Label (self .processing_window , text = "◐" )
840846 self .processing_animation .pack ()
841847 self .animate_processing ()
848+ else :
849+ # 窗口已存在,只更新文本内容
850+ self .processing_label .config (text = message )
842851
852+ # 确保窗口显示在前面
853+ self .processing_window .lift ()
854+ self .processing_window .focus_force ()
855+
843856 self .processing_active = True
844857
845858 def hide_processing_window (self ):
@@ -856,15 +869,14 @@ def show_qr_code(self, qr_path, text=None, status=None, *images):
856869 # if self.qr_window:
857870 # self.qr_window.destroy()
858871 # 每次调用都创建一个新的 Toplevel 窗口实例
859-
872+
860873 new_qr_window = tk .Toplevel (self .root )
861874 new_qr_window .title ("水印提取结果" )
862875 new_qr_window .geometry ("600x700" )
863-
876+
864877 # 清理文件回调
865878 def cleanup_callback ():
866879 return True
867-
868880 # 添加窗口关闭事件处理
869881 def on_close_show_qr_window ():
870882 if qr_path and os .path .exists (qr_path ):
@@ -875,19 +887,69 @@ def on_close_show_qr_window():
875887 return cleanup_callback
876888 pass
877889 new_qr_window .destroy ()
878-
879- new_qr_window .protocol ("WM_DELETE_WINDOW" , on_close_show_qr_window )
880890
891+ new_qr_window .protocol ("WM_DELETE_WINDOW" , on_close_show_qr_window )
892+
881893 # 显示状态标题
882894 if status == True :
883895 tk .Label (new_qr_window , text = "水印提取成功" , font = ("Arial" , 12 , "bold" )).pack ()
884896 else :
885897 tk .Label (new_qr_window , text = "水印未提取到文本,请检查是否存在二维码 或 图像" , font = ("Arial" , 12 , "bold" )).pack ()
886-
898+
887899 # 处理传入的图片
888900 if images :
889- for img_data in images :
890- if img_data is not None :
901+ # 计算有效图片数量
902+ valid_images = [img_data for img_data in images if img_data is not None ]
903+ image_count = len (valid_images )
904+
905+ if image_count > 2 :
906+ # 使用网格布局 - 每列最多2个图片
907+ cols = (image_count + 1 ) // 2 # 计算需要的列数
908+
909+ # 创建一个frame来容纳所有图片
910+ img_frame = tk .Frame (new_qr_window )
911+ img_frame .pack (pady = 10 )
912+
913+ row , col = 0 , 0
914+ for img_data in valid_images :
915+ size , img_array = img_data
916+ # 将numpy数组转换回PIL Image
917+ img = imported_modules ['Image' ].fromarray (img_array )
918+ # 对小于256的图片进行放大
919+ if max (img .size ) < 256 :
920+ scale = 256 / max (img .size )
921+ new_size = (int (img .size [0 ] * scale ), int (img .size [1 ] * scale ))
922+ img = img .resize (new_size , imported_modules ['Image' ].Resampling .LANCZOS )
923+
924+ img_tk = imported_modules ['ImageTk' ].PhotoImage (img )
925+
926+ # 创建一个子frame来包含图片和尺寸标签
927+ sub_frame = tk .Frame (img_frame )
928+ sub_frame .grid (row = row , column = col , padx = 10 , pady = 5 )
929+
930+ # 图片标签
931+ label = tk .Label (sub_frame , image = img_tk )
932+ label .image = img_tk # 保持引用
933+ label .pack ()
934+
935+ # 显示尺寸标签
936+ tk .Label (sub_frame , text = f"尺寸: { size } " , font = ("Arial" , 9 )).pack (pady = 2 )
937+
938+ # 更新网格位置
939+ row += 1
940+ if row >= 2 : # 每列最多2个图片
941+ row = 0
942+ col += 1
943+
944+ # 根据列数调整窗口宽度
945+ base_width = 400
946+ extra_width = (cols - 1 ) * 300 # 每额外一列增加300像素
947+ new_width = min (base_width + extra_width , 1200 ) # 限制最大宽度
948+ new_qr_window .geometry (f"{ new_width } x700" )
949+
950+ else :
951+ # 图片数量<=2,使用原来的垂直pack布局
952+ for img_data in valid_images :
891953 size , img_array = img_data
892954 # 将numpy数组转换回PIL Image
893955 img = imported_modules ['Image' ].fromarray (img_array )
@@ -902,6 +964,7 @@ def on_close_show_qr_window():
902964 label .pack (pady = 5 )
903965 # 显示尺寸标签
904966 tk .Label (new_qr_window , text = f"尺寸: { size } " ).pack ()
967+
905968 elif qr_path :
906969 try :
907970 img = imported_modules ['Image' ].open (qr_path )
@@ -911,14 +974,15 @@ def on_close_show_qr_window():
911974 label .pack (pady = 5 )
912975 except Exception as e :
913976 messagebox .showerror ("错误" , f"无法显示图片: { str (e )} " )
977+
914978 # 显示解码文本(如果有)
915979 if text :
916980 tk .Label (new_qr_window , text = "解码文本:" , font = ("Arial" , 10 , "bold" )).pack ()
917981 text_label = tk .Label (new_qr_window , text = text , wraplength = 380 , justify = "left" )
918982 text_label .pack (pady = 5 )
919-
983+
920984 # 关闭按钮
921- close_btn = tk .Button (new_qr_window , text = "关闭" ,
985+ close_btn = tk .Button (new_qr_window , text = "关闭" ,
922986 command = lambda : [os .unlink (qr_path ) if qr_path and os .path .exists (qr_path ) else None ,
923987 new_qr_window .destroy ()])
924988 close_btn .pack (pady = 10 )
0 commit comments