Skip to content

Commit

Permalink
updated many functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadlaxa committed Jul 30, 2024
1 parent dd64510 commit 5c8b325
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 50 deletions.
94 changes: 53 additions & 41 deletions OU Dictionary Editor/OpenUtau_Dictionary_Editor.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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("<Return>", on_validate)
self.entry_popup_g.bind("<Return>", on_validate)
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'}
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions OU Dictionary Editor/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions OU Dictionary Editor/Templates/Localizations/ceb_PH.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
5 changes: 4 additions & 1 deletion OU Dictionary Editor/Templates/Localizations/en_US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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."
3 changes: 3 additions & 0 deletions OU Dictionary Editor/Templates/Localizations/es-LA.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
3 changes: 3 additions & 0 deletions OU Dictionary Editor/Templates/Localizations/fr_FR.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
3 changes: 3 additions & 0 deletions OU Dictionary Editor/Templates/Localizations/ja-JP.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: "トラックと一時ファイルに歌詞が見つかりません。"
3 changes: 3 additions & 0 deletions OU Dictionary Editor/Templates/Localizations/ru_RU.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,6 @@ voicedir: "VoiceDir не найден в временном файле."
no_voicedir: "В VoiceDir не найдено .yaml файлов."
multi_voicedir: "Найдено несколько .yaml файлов в VoiceDir. Открываю директорию для выбора."
plugin_focus: "Плагины"
phonetic_na: "Выбранные фонетические системы недоступны."
select_phonetic_sys: "Пожалуйста, выберите обе фонетические системы: исходную и целевую."
no_temp_file: "На дорожке и во временном файле не найдено текста песен."
5 changes: 4 additions & 1 deletion OU Dictionary Editor/Templates/Localizations/tg_PH.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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."
17 changes: 10 additions & 7 deletions OU Dictionary Editor/Templates/phoneme systems.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ aa,aa,a,Q,A,ɑ,a
aa r,ar,ar,Q@,Ar,ɒɹ,a r
ae,ae,@,{,{,æ,a
ae n,ea n,&n,{ n,e@n,eən,e N
ae m,ea m,& m,{ m,e@m,eə m,e m
ae ng,ea ng,Ang,{ N,E~N,ɛ̃ŋ,e ng
ah,ah,u,V,V,ʌ,a
ao,ao,9,O:,Q,ɒ,o
Expand All @@ -11,9 +12,9 @@ ao r,or,0r,O@,Or,ɔɹ,o r
ax,ax,x,@,@,ə,a
eh,eh,e,e,E,ɛ,e
eh r,air,Ar,e@,er,eɹ,e r
er,er,3,@r,@`,ə˞,a w
er,er,3,@r,3,ə˞,a u
ih,ih,i,I,I,ɪ,i
ih ng,ing,1ng,I N,I~N,ɪ̃ŋ,i ng
ih ng,ix ng,1ng,I N,I~N,ɪ̃ŋ,i ng
ih r,ir,Er,I@,ir,iɹ,i r
iy,iy,E,i:,i,i,i
uh,uh,6,U,U,ʊ,u
Expand All @@ -28,7 +29,8 @@ oy,oy,Q,OI,OI,ɔɪ,o y
b,b,b,bh,b,b,b
ch,ch,ch,tS,tS,tʃ,ch
d,d,d,dh,d,d,d
dh,dh,dh,D,D,ð,d
dh,dh,dh,D,D,ð,dh
dr,dr,d r,dZ r,d r,d ɹ,d r
dx,dx,dd,4,4,ɾ,r
ax l,el,6l,@l,5=,ɫ̩,u l
f,f,f,f,f,f,f
Expand All @@ -40,20 +42,21 @@ k,k,k,kh,k,k,k
l,l,l,l0,l,l,l
l,l,l,l,5,ɫ,l
m,m,m,m,m,m,m
n,n,n,n,n,n,n
n,n,n,n,n,n,N
ng,ng,ng,N,N,ŋ,ng
p,p,p,ph,p,p,p
q,q,?,?,?,ʔ,?
q,q,?,?,?,ʔ,
r,r,r,r,r,ɹ,r
s,s,s,s,s,s,s
sh,sh,sh,S,S,ʃ,sh
t,t,t,th,t,t,t
th,th,th,T,T,θ,t
th,th,th,T,T,θ,th
tr,tr,t r,th r,t r,t ɹ,t r
v,v,v,v,v,v,v
w,w,w,w,w,w,w
y,y,y,j,j,j,y
z,z,z,z,z,z,z
zh,zh,zh,Z,Z,ʒ,j
zh,zh,zh,Z,Z,ʒ,zh
b y,b y,b y,bh j,b j,b j,by
b w,b w,b w,bh w,b w,b w,bw
d y,d y,d y,dh j,d j,d j,dy
Expand Down

0 comments on commit 5c8b325

Please sign in to comment.