Files
git-days-of-europe-test/useful_python_programs/Event_Loc_GeneratorGUI.py
T

120 lines
3.6 KiB
Python

#By Wendell08, Writes events placeholder loc
import tkinter as tk
from tkinter import filedialog, Text
import os
global target_output
global label_name
global inp_name
target_output = os.getcwd()
root = tk.Tk()
line_loc_list = []
path_list = os.path.split(os.getcwd())
get_path = path_list[0]
inp_name = tk.StringVar()
inp_name.set("")
label_name = tk.StringVar()
label_name.set("Current Output:\n {}".format(target_output))
def select_event_path():
global target_file
target_file = filedialog.askopenfilename(initialdir=get_path+r"\events")
update_input_text()
def select_output_path():
global target_output
target_output = filedialog.askdirectory(initialdir=get_path+r"\useful_python_programs")
update_output_text()
def run_app():
starting_event = entry1.get()
end_event = entry2.get()
starting_event_found = False
bracket_count = 0
end_event_found = False
def find_text_in_triggered_text(text_line):
desc_trigger_list = text_line.replace("\t", "").split(" ")
find_text = desc_trigger_list.index("text")
line_loc_list.append(desc_trigger_list[find_text+2])
with open(target_file, "r") as inp:
line_list = inp.readlines()
for i, line in enumerate(line_list):
n = 0
if "{" in line:
bracket_count += 1
if "}" in line:
bracket_count -= 1
if starting_event_found == False:
if starting_event in line:
starting_event_found = True
else:
continue
if "title =" in line and not " " in line and not "{" in line:
line_loc_list.append(line[9:-1])
if "title = {" in line and not " " in line:
if "}" in line:
find_text_in_triggered_text(line)
continue
else:
while not "text" in line_list[i+n]:
n += 1
find_text_in_triggered_text(line_list[i+n])
if "desc =" in line and not " " in line and not "{" in line:
line_loc_list.append(line[8:-1])
if "desc = {" in line and not " " in line:
if "}" in line:
find_text_in_triggered_text(line)
else:
while not "text" in line_list[i+n]:
n += 1
find_text_in_triggered_text(line_list[i+n])
if " name =" in line and not " " in line:
line_loc_list.append(line[9:-1])
if end_event in line and not " " in line:
end_event_found = True
if end_event_found == True and bracket_count == 0:
break
print(line_loc_list)
with open(f"{target_output}\Events_l_english.yml", "a+") as out:
for checkline in line_loc_list:
if ".t" in checkline:
out.write("\n")
out.write(f" {checkline}:0 \"\"\n")
def update_input_text():
inp_name.set("Current Event File:\n {}".format(target_file))
input_text = tk.Label(root, textvariable=inp_name, wraplength=170).place(x=20, y=315)
def update_output_text():
label_name.set("Current Output:\n {}".format(target_output))
output_path = tk.Label(root, textvariable=label_name, wraplength=170).place(x=20, y=210)
canvas = tk.Canvas(root, height=430, width=200)
canvas.pack()
entry1 = tk.Entry(root)
canvas.create_window(100, 140, window=entry1)
entry2 = tk.Entry(root)
canvas.create_window(100, 190, window=entry2)
entry1text = tk.Label(root, text="Starting Event Loc:", wraplength=170).place(x=45, y=110)
entry1text = tk.Label(root, text="Final Event Loc:", wraplength=170).place(x=45, y=160)
run_application = tk.Button(root, text=" Run Program ", fg="black", command=run_app).place(x=55, y=20)
open_file = tk.Button(root, text="Open Event File", fg="black", command=select_event_path).place(x=55, y=50)
select_output = tk.Button(root, text=" Output Path ", fg="black", command=select_output_path).place(x=55, y=80)
update_output_text()
root.title("Event Loc Generator")
root.mainloop()