@@ -534,6 +534,7 @@ def load_translations(self):
534534 "no_text_lang_skip" : "不跳过目标语言文本" ,
535535 "skip_lang" : "跳过语言" ,
536536 "gpt_config" : "GPT配置文件路径" ,
537+ "high_quality_prompt_path" : "高质量翻译提示词" ,
537538 "translator_chain" : "链式翻译" ,
538539 "selective_translation" : "选择性翻译" ,
539540 "detector" : "文本检测器" ,
@@ -714,6 +715,37 @@ def create_param_widgets(self, data, parent_frame, prefix="", start_row=0):
714715 label .grid (row = row , column = 0 , padx = 5 , pady = 2 , sticky = "w" )
715716 widget_frame .grid (row = row , column = 1 , padx = 5 , pady = 2 , sticky = "ew" )
716717 continue
718+
719+ elif full_key == "translator.high_quality_prompt_path" :
720+ widget_frame = ctk .CTkFrame (parent_frame , fg_color = "transparent" )
721+ widget_frame .grid_columnconfigure (0 , weight = 1 )
722+
723+ # The combobox will be populated by the scan function
724+ def on_prompt_select (filename ):
725+ full_path = os .path .join (resource_path ('dict' ), filename ) if filename else None
726+ self ._save_widget_change ("translator.high_quality_prompt_path" , value = full_path )
727+
728+ widget = ctk .CTkComboBox (widget_frame , values = [], command = on_prompt_select )
729+
730+ # Bind the click event to refresh the list
731+ widget .bind ('<Button-1>' , lambda event : self ._scan_and_update_hq_prompt_dropdown ())
732+
733+ # When loading, we only have the full path, so we extract the filename
734+ filename = os .path .basename (value ) if value and os .path .exists (value ) else ""
735+ widget .set (filename )
736+ widget .grid (row = 0 , column = 0 , sticky = "ew" )
737+
738+ # Open directory button
739+ browse_button = ctk .CTkButton (widget_frame , text = "打开目录" , width = 80 , command = self ._open_dict_directory )
740+ browse_button .grid (row = 0 , column = 1 , padx = (5 , 0 ))
741+
742+ self .parameter_widgets [full_key ] = widget
743+ label .grid (row = row , column = 0 , padx = 5 , pady = 2 , sticky = "w" )
744+ widget_frame .grid (row = row , column = 1 , padx = 5 , pady = 2 , sticky = "ew" )
745+
746+ # Initial scan
747+ self .app .after (100 , self ._scan_and_update_hq_prompt_dropdown )
748+ continue
717749
718750 is_bool_by_schema = self .param_schema .get (full_key ) is bool
719751
@@ -1008,6 +1040,47 @@ def _open_font_directory(self):
10081040 if self .font_monitor :
10091041 self .font_monitor .refresh_fonts ()
10101042
1043+ def _open_dict_directory (self ):
1044+ dict_dir = resource_path ('dict' )
1045+ try :
1046+ if not os .path .exists (dict_dir ):
1047+ os .makedirs (dict_dir )
1048+ if sys .platform == "win32" :
1049+ os .startfile (dict_dir )
1050+ elif sys .platform == "darwin" :
1051+ subprocess .run (["open" , dict_dir ])
1052+ else :
1053+ subprocess .run (["xdg-open" , dict_dir ])
1054+ except Exception as e :
1055+ self .update_log (f"Error opening dict directory: { e } \n " )
1056+ # After opening, refresh the dropdown
1057+ self .app .after (1000 , self ._scan_and_update_hq_prompt_dropdown ) # Add a small delay
1058+
1059+ def _scan_and_update_hq_prompt_dropdown (self ):
1060+ try :
1061+ dict_dir = resource_path ('dict' )
1062+ if not os .path .isdir (dict_dir ):
1063+ self .update_log (f"Prompt directory not found: { dict_dir } \n " )
1064+ return []
1065+
1066+ prompt_files = sorted ([f for f in os .listdir (dict_dir ) if f .lower ().endswith ('.json' )])
1067+
1068+ widget = self .parameter_widgets .get ("translator.high_quality_prompt_path" )
1069+ if widget and isinstance (widget , ctk .CTkComboBox ):
1070+ current_value = widget .get ()
1071+ widget .configure (values = prompt_files )
1072+ # Try to keep the current selection if it's still valid
1073+ if current_value in prompt_files :
1074+ widget .set (current_value )
1075+ else :
1076+ widget .set ("" )
1077+
1078+ self .update_log (f"Refreshed high-quality prompt list: { len (prompt_files )} files found.\n " )
1079+ return prompt_files
1080+ except Exception as e :
1081+ self .update_log (f"Error scanning prompt directory: { e } \n " )
1082+ return []
1083+
10111084 def _select_font_path (self ):
10121085 font_path = filedialog .askopenfilename (
10131086 title = "Select Font File" ,
0 commit comments