From 5c8b325facea83210654c8326265fa37d7dea804 Mon Sep 17 00:00:00 2001 From: cadlaxa Date: Tue, 30 Jul 2024 14:37:28 +0800 Subject: [PATCH] updated many functions --- .../OpenUtau_Dictionary_Editor.pyw | 94 +++++++++++-------- OU Dictionary Editor/Readme.md | 3 + .../Templates/Localizations/ceb_PH.yaml | 3 + .../Templates/Localizations/en_US.yaml | 5 +- .../Templates/Localizations/es-LA.yaml | 3 + .../Templates/Localizations/fr_FR.yaml | 3 + .../Templates/Localizations/ja-JP.yaml | 3 + .../Templates/Localizations/ru_RU.yaml | 3 + .../Templates/Localizations/tg_PH.yaml | 5 +- .../Templates/phoneme systems.csv | 17 ++-- 10 files changed, 89 insertions(+), 50 deletions(-) diff --git a/OU Dictionary Editor/OpenUtau_Dictionary_Editor.pyw b/OU Dictionary Editor/OpenUtau_Dictionary_Editor.pyw index cddbf7e..47ac728 100644 --- a/OU Dictionary Editor/OpenUtau_Dictionary_Editor.pyw +++ b/OU Dictionary Editor/OpenUtau_Dictionary_Editor.pyw @@ -227,29 +227,28 @@ class Dictionary(TkinterDnD.Tk): s = 9 config = configparser.ConfigParser() config.read(self.config_file) - language = config.get('Settings', 'current_local') - if language == "English": + if self.current_local == "English": self.font = tkFont.Font(family=self.font_en, size=n) self.font_s = tkFont.Font(family=self.font_en, size=s) self.tree_font = tkFont.Font(family=self.font_en_R, size=n) self.tree_font_b = tkFont.Font(family=self.font_en, size=n) - elif language == "Japanese": + elif self.current_local == "Japanese": self.font = tkFont.Font(family=self.font_jp, size=n) self.font_s = tkFont.Font(family=self.font_jp, size=s) self.tree_font = tkFont.Font(family=self.font_jp_R, size=n) self.tree_font_b = tkFont.Font(family=self.font_jp, size=n) - elif language == "Chinese (Traditional)": + elif self.current_local == "Chinese (Traditional)": self.font = tkFont.Font(family=self.font_tc, size=n) self.font_s = tkFont.Font(family=self.font_tc, size=s) self.tree_font = tkFont.Font(family=self.font_tc_R, size=n) self.tree_font_b = tkFont.Font(family=self.font_tc, size=n) - elif language == "Chinese (Simplified)": + elif self.current_local == "Chinese (Simplified)": self.font = tkFont.Font(family=self.font_sc, size=n) self.font_s = tkFont.Font(family=self.font_sc, size=s) self.tree_font = tkFont.Font(family=self.font_sc_R, size=n) self.tree_font_b = tkFont.Font(family=self.font_sc, size=n) - elif language == "Cantonese": + elif self.current_local == "Cantonese": self.font = tkFont.Font(family=self.font_hk, size=n) self.font_s = tkFont.Font(family=self.font_hk, size=s) self.tree_font = tkFont.Font(family=self.font_hk_R, size=n) @@ -1496,7 +1495,8 @@ class Dictionary(TkinterDnD.Tk): # Get the edited values from entry widgets new_grapheme = self.entry_popup_g.get() - new_phoneme = self.entry_popup_p.get().replace(",", "").replace("'", "") + new_phoneme = self.entry_popup_p.get().replace("'", "") + phoneme_list = [phoneme.replace(" ", ",") if " " in phoneme else phoneme for phoneme in new_phoneme.split()] # Update Treeview with edited values self.viewer_tree.set(selected_item, grapheme_column, new_grapheme) @@ -1508,22 +1508,22 @@ class Dictionary(TkinterDnD.Tk): g2p_correction.destroy() self.current_entry_widgets = {} - # Get the index of the currently selected item - selected_index = self.viewer_tree.index(selected_item) - - # Delete the item above the edited row - if new_grapheme != initial_grapheme: - if selected_index > 0: - prev_item = self.viewer_tree.get_children()[selected_index - 1] - self.viewer_tree.delete(prev_item) - - self.add_entry_treeview(new_grapheme, new_phoneme.split()) - - if new_grapheme != initial_grapheme: - if selected_index > 0: - prev_item1 = self.viewer_tree.get_children()[selected_index + 1] - self.viewer_tree.selection_set(prev_item1) - self.delete_selected_entries() + # Preserve the index and update the dictionary + if initial_grapheme in self.dictionary: + # Get the current index of the initial grapheme + items = list(self.dictionary.items()) + index = [i for i, (k, v) in enumerate(items) if k == initial_grapheme][0] + # Create an ordered dictionary to preserve the order + ordered_dict = OrderedDict() + + # Populate the ordered dictionary with entries, updating or adding the new entry at the correct index + for i, (key, value) in enumerate(items): + if i == index: + ordered_dict[new_grapheme] = phoneme_list + elif key != initial_grapheme: + ordered_dict[key] = value + self.dictionary = ordered_dict + self.refresh_treeview() g2p_correction.bind("", on_validate) self.entry_popup_g.bind("", on_validate) @@ -1678,7 +1678,7 @@ class Dictionary(TkinterDnD.Tk): # Combobox for `From Selected Phonetic System` phone_frame_from = ttk.Frame(reg_frame) - phone_frame_from.grid(padx=(15,0), pady=(10,0), sticky="nsew", row=3, column=0) + phone_frame_from.grid(padx=(15,0), pady=(10,0), sticky='nsew', row=3, column=0) phone_frame_from.grid_columnconfigure(0, weight=30) phone_frame_from.grid_columnconfigure(1, weight=0) @@ -1700,7 +1700,7 @@ class Dictionary(TkinterDnD.Tk): self.combo_to.set("Phonetic System") rep_frame = ttk.Frame(reg_frame) - rep_frame.grid(padx=(10,15), pady=5, sticky="nsew", row=4, column=1) + rep_frame.grid(padx=(5,15), pady=5, sticky="nsew", row=4, column=1) rep_frame.grid_columnconfigure(0, weight=1) rep_frame.grid_columnconfigure(1, weight=3) @@ -1799,6 +1799,8 @@ class Dictionary(TkinterDnD.Tk): self.refresh_treeview() self.word_entry.delete(0, tk.END) self.phoneme_entry.delete(0, tk.END) + else: + apply_replace() if self.search_var.get(): self.filter_treeview() self.icon(self.replace_window) @@ -1811,12 +1813,12 @@ class Dictionary(TkinterDnD.Tk): # Ensure systems are selected if not system_from or not system_to: - messagebox.showinfo("Error", "Please select both 'From' and 'To' phonetic systems.") + messagebox.showinfo("Error", f"{self.localization.get('select_phonetic_sys', 'Please select both From and To phonetic systems.')}") return # Ensure the selected systems are in the phoneme map if system_from not in self.phoneme_map or system_to not in self.phoneme_map: - messagebox.showinfo("Error", "Selected systems are not available.") + messagebox.showinfo("Error", f"{self.localization.get('phonetic_na', 'Selected phonetic systems are not available.')}") return phoneme_map_from = self.phoneme_map[system_from] @@ -2654,14 +2656,19 @@ class Dictionary(TkinterDnD.Tk): def get_lyrics_from_tmp(self): lyrics = [] - with open(self.plugin_file, 'r', encoding='utf-8') as file: - lines = file.readlines() - for line in lines: - if line.startswith("Lyric="): - lyric = line.strip().split("=")[1] - if lyric and lyric not in {"R", "+", "-", "+~", "+*", "+-"}: - lyrics.append(lyric) - + if self.plugin_file: + with open(self.plugin_file, 'r', encoding='utf-8') as file: + lines = file.readlines() + for line in lines: + if line.startswith("Lyric="): + lyric = line.strip().split("=")[1] + if lyric and lyric not in {"R", "+", "-", "+~", "+*", "+-"}: + lyrics.append(lyric) + + if not self.plugin_file: + messagebox.showerror("Error", f"{self.localization.get('no_temp_file', 'No Lyrics found on track and on the temp file.')}") + return None + # Ensure G2P is enabled if not self.g2p_checkbox_var.get(): self.g2p_checkbox_var.set(True) # Enable G2P if it is off @@ -2701,12 +2708,16 @@ class Dictionary(TkinterDnD.Tk): def get_yaml_from_temp(self): voice_dir = None - with open(self.plugin_file, 'r', encoding='utf-8') as file: - lines = file.readlines() - for line in lines: - if line.startswith("VoiceDir="): - voice_dir = line.strip().split("=")[1] - break + if self.plugin_file: + with open(self.plugin_file, 'r', encoding='utf-8') as file: + lines = file.readlines() + for line in lines: + if line.startswith("VoiceDir="): + voice_dir = line.strip().split("=")[1] + break + if not self.plugin_file: + messagebox.showerror("Error", f"{self.localization.get('voicedir', 'VoiceDir not found in the temp file.')}") + return None # Find all .yaml files in the VoiceDir, including subfolders, excluding specific files excluded_files = {'character.yaml', 'dsconfig.yaml', 'enuconfig.yaml', 'config_rmdn.yaml', 'vocoder.yaml'} @@ -3167,6 +3178,7 @@ class Dictionary(TkinterDnD.Tk): g2p_enabled = config.getboolean('Settings', 'G2P_Enabled') self.g2p_checkbox_var.set(g2p_enabled) except (configparser.NoSectionError, configparser.NoOptionError): + self.g2p_checkbox_var.set(True) print("G2P checkbox state not found in config. Using default.") def save_g2p(self, selected_value): diff --git a/OU Dictionary Editor/Readme.md b/OU Dictionary Editor/Readme.md index 2e472bc..c0bd4b0 100644 --- a/OU Dictionary Editor/Readme.md +++ b/OU Dictionary Editor/Readme.md @@ -9,6 +9,9 @@ - Added Regenate YAML template from reclist function - Separate `Plugins` tab - Added Phonetic System replace (Users can add other phonetic systems by editing the `phoneme systems.csv` on the `Templates` folder) +- Revamp Regex dialog +- Changed default G2p state to true +- Update Localizations and fixes to the code **`(7/24/24)`** - Regex find and replace now directly iterates and edits the self.dictionary (the data that holds the graphemes and phonemes) instead of the treeview diff --git a/OU Dictionary Editor/Templates/Localizations/ceb_PH.yaml b/OU Dictionary Editor/Templates/Localizations/ceb_PH.yaml index a5bdbe9..513c104 100644 --- a/OU Dictionary Editor/Templates/Localizations/ceb_PH.yaml +++ b/OU Dictionary Editor/Templates/Localizations/ceb_PH.yaml @@ -183,3 +183,6 @@ voicedir: "Wala mahibal-i ang VoiceDir sa temporaryong file." no_voicedir: "Walay .yaml nga mga file nga nakit-an sa VoiceDir." multi_voicedir: "Daghang .yaml nga mga file ang nakit-an sa VoiceDir. Pag-abli sa direktoryo aron makapili ka." plugin_focus: "Plugins" +phonetic_na: "Ang napili nga mga sistema sa ponetika dili magamit." +select_phonetic_sys: "Palihug pagpili sa duha ka mga sistema sa ponetika gikan ug padulong." +no_temp_file: "Walay nakit-an nga lyrics sa track ug sa temporary file." diff --git a/OU Dictionary Editor/Templates/Localizations/en_US.yaml b/OU Dictionary Editor/Templates/Localizations/en_US.yaml index 50d6e4f..c3b0c6f 100644 --- a/OU Dictionary Editor/Templates/Localizations/en_US.yaml +++ b/OU Dictionary Editor/Templates/Localizations/en_US.yaml @@ -182,4 +182,7 @@ import_vb: "Import VB Dictionary" voicedir: "VoiceDir not found in the temp file." no_voicedir: "No .yaml files found in the VoiceDir." multi_voicedir: "Multiple .yaml files found in the VoiceDir. Opening the directory for you to choose." -plugin_focus: "Plugins" \ No newline at end of file +plugin_focus: "Plugins" +phonetic_na: "Selected phonetic systems are not available." +select_phonetic_sys: "Please select both From and To phonetic systems." +no_temp_file: "No Lyrics found on track and on the temp file." \ No newline at end of file diff --git a/OU Dictionary Editor/Templates/Localizations/es-LA.yaml b/OU Dictionary Editor/Templates/Localizations/es-LA.yaml index 73ad00a..75375f2 100644 --- a/OU Dictionary Editor/Templates/Localizations/es-LA.yaml +++ b/OU Dictionary Editor/Templates/Localizations/es-LA.yaml @@ -183,3 +183,6 @@ voicedir: "No se encontró VoiceDir en el archivo temporal." no_voicedir: "No se encontraron archivos .yaml en VoiceDir." multi_voicedir: "Se encontraron varios archivos .yaml en VoiceDir. Abriendo el directorio para que elijas." plugin_focus: "Plugins" +phonetic_na: "Los sistemas fonéticos seleccionados no están disponibles." +select_phonetic_sys: "Por favor, seleccione tanto el sistema fonético de origen como el de destino." +no_temp_file: "No se encontraron letras en la pista ni en el archivo temporal." diff --git a/OU Dictionary Editor/Templates/Localizations/fr_FR.yaml b/OU Dictionary Editor/Templates/Localizations/fr_FR.yaml index 5065df7..9245eb2 100644 --- a/OU Dictionary Editor/Templates/Localizations/fr_FR.yaml +++ b/OU Dictionary Editor/Templates/Localizations/fr_FR.yaml @@ -183,3 +183,6 @@ voicedir: "VoiceDir non trouvé dans le fichier temporaire." no_voicedir: "Aucun fichier .yaml trouvé dans le VoiceDir." multi_voicedir: "Plusieurs fichiers .yaml trouvés dans le VoiceDir. Ouverture du répertoire pour que vous puissiez choisir." plugin_focus: "Plugins" +phonetic_na: "Les systèmes phonétiques sélectionnés ne sont pas disponibles." +select_phonetic_sys: "Veuillez sélectionner à la fois les systèmes phonétiques de départ et d'arrivée." +no_temp_file: "Aucun texte de chanson trouvé sur la piste ni dans le fichier temporaire." diff --git a/OU Dictionary Editor/Templates/Localizations/ja-JP.yaml b/OU Dictionary Editor/Templates/Localizations/ja-JP.yaml index a281fe6..d17b8ae 100644 --- a/OU Dictionary Editor/Templates/Localizations/ja-JP.yaml +++ b/OU Dictionary Editor/Templates/Localizations/ja-JP.yaml @@ -186,3 +186,6 @@ voicedir: "テンポラリファイルにVoiceDirが見つかりません。" no_voicedir: "VoiceDir内に.yamlファイルが見つかりません。" multi_voicedir: "VoiceDir内に複数の.yamlファイルが見つかりました。選択するためにディレクトリを開きます。" plugin_focus: "プラグイン" +phonetic_na: "選択した音声システムは利用できません。" +select_phonetic_sys: "「From」と「To」の音声システムを両方選択してください。" +no_temp_file: "トラックと一時ファイルに歌詞が見つかりません。" diff --git a/OU Dictionary Editor/Templates/Localizations/ru_RU.yaml b/OU Dictionary Editor/Templates/Localizations/ru_RU.yaml index 00d2c18..0c32fe5 100644 --- a/OU Dictionary Editor/Templates/Localizations/ru_RU.yaml +++ b/OU Dictionary Editor/Templates/Localizations/ru_RU.yaml @@ -182,3 +182,6 @@ voicedir: "VoiceDir не найден в временном файле." no_voicedir: "В VoiceDir не найдено .yaml файлов." multi_voicedir: "Найдено несколько .yaml файлов в VoiceDir. Открываю директорию для выбора." plugin_focus: "Плагины" +phonetic_na: "Выбранные фонетические системы недоступны." +select_phonetic_sys: "Пожалуйста, выберите обе фонетические системы: исходную и целевую." +no_temp_file: "На дорожке и во временном файле не найдено текста песен." diff --git a/OU Dictionary Editor/Templates/Localizations/tg_PH.yaml b/OU Dictionary Editor/Templates/Localizations/tg_PH.yaml index a8a432f..c5ef61c 100644 --- a/OU Dictionary Editor/Templates/Localizations/tg_PH.yaml +++ b/OU Dictionary Editor/Templates/Localizations/tg_PH.yaml @@ -181,4 +181,7 @@ import_vb: "I-import ang VB Dictionary" voicedir: "Hindi natagpuan ang VoiceDir sa temp file." no_voicedir: "Walang .yaml na mga file na natagpuan sa VoiceDir." multi_voicedir: "Maraming .yaml na mga file ang natagpuan sa VoiceDir. Binubuksan ang direktoryo upang pumili ka." -plugin_focus: "Plugins" \ No newline at end of file +plugin_focus: "Plugins" +phonetic_na: "Ang napiling mga ponetikong sistema ay hindi magagamit." +select_phonetic_sys: "Pakiusap piliin ang parehong Mula at Patungong mga ponetikong sistema." +no_temp_file: "Walang nakitang mga liriko sa track at sa pansamantalang file." \ No newline at end of file diff --git a/OU Dictionary Editor/Templates/phoneme systems.csv b/OU Dictionary Editor/Templates/phoneme systems.csv index 2021d06..0467616 100644 --- a/OU Dictionary Editor/Templates/phoneme systems.csv +++ b/OU Dictionary Editor/Templates/phoneme systems.csv @@ -3,6 +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