-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaa1se.py
149 lines (117 loc) · 4.37 KB
/
aa1se.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import tkinter
import tkinter.filedialog
from tkinter import *
from tkinter import messagebox
root = Tk()
root.option_add("*Font", "Verdana 10")
#########################################################################
def scan():
start = "1.0"
end = "end"
mycount = IntVar()
regex_patterns = [r'".*"', r'#.*']
for pattern in regex_patterns:
Text.mark_set("start", start)
Text.mark_set("end", end)
num = int(regex_patterns.index(pattern))
while True:
index = Text.search(pattern, "start", "end", count=mycount, regexp = True)
if index == "": break
Text.mark_set("start", "%s+%sc" % (index, mycount.get()))
def cypher():
alll = Text.get("1.0",END)
alphabet = 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя'
i = 64
for j in range(len(alphabet)):
char = alphabet[j]
alll = alll.replace(char, "{"+str(i)+"}")
i = i+1
alll = alll.replace('№', "{130}")
#alll = alll.replace('-', "{131}")
alll = alll.replace('—', "{132}")
alll = alll.replace('«', "{<<}")
alll = alll.replace('»', "{>>}")
alll=alll[:-1]
Text.delete("0.0", "end")
Text.insert("0.0", alll)
def decypher():
alll = Text.get("0.0",END)
alphabet = 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя'
i = 64
for j in range(len(alphabet)):
char = alphabet[j]
alll = alll.replace("{"+str(i)+"}", char)
i = i+1
alll = alll.replace("{130}", '№')
alll = alll.replace("{131}", '-')
alll = alll.replace("{132}", '—')
alll = alll.replace("{<<}", '«')
alll = alll.replace("{>>}", '»')
alll=alll[:-1]
Text.delete("0.0", "end")
Text.insert("0.0", alll)
def update():
scan()
def clear():
Text.delete("1.0", "end")
def load():
ftypes = [('Txt file', '*.txt'), ('All files', '*')]
fn = tkinter.filedialog.Open(root, filetypes = ftypes).show()
if fn == '':
return
Text.delete('1.0', 'end')
Text.insert('1.0', open(fn).read())
def save():
fn = tkinter.filedialog.SaveAs(root, filetypes = [('Txt file', '*.txt'), ('All files', '*')]).show()
if fn == '':
return
open(fn, 'wt').write(Text.get('1.0', 'end'))
def on_closing():
if messagebox.askokcancel("Quit", "Do you want to quit?"):
root.destroy()
def about():
tkinter.messagebox.showinfo(title='About', message='''This is a program to fast convert translit. It was written for Ace Attorney NDS games.
Program author: dzhemvrot
Program version: 2.0
Program restributed using GPL-3.0 license''')
#########################################################################
menubar = Menu(root)
root.config(menu=menubar)
file_menu = Menu(menubar,tearoff=0)
file_menu.add_command(label='Open', command = load)
file_menu.add_command(label='Save', command = save)
file_menu.add_separator()
file_menu.add_command(
label='Exit',
command=on_closing
)
menubar.add_cascade(
label="File",
menu=file_menu
)
menubar.add_command(label='About', command=about)
#########################################################################
Label = Label(root, text = "Ace Attorney Script Editor")
Label.grid(row=0, column=0, columnspan=5)
Text = Text(root)
Text.grid(row = 1, column = 0, columnspan = 5)
ClearB = Button(root, text = "Clear", width = 8, command = clear)
ClearB.grid(row = 2, column = 1, padx=20, pady=10)
CB = Button(root, text = "Cypher", width = 8, command = cypher)
CB.grid(row = 2, column = 2, padx=20, pady=10)
DCB = Button(root, text = "Decypher", width = 8, command = decypher)
DCB.grid(row = 2, column = 3, padx=20, pady=10)
scrollbar = Scrollbar(root, orient='vertical', command=Text.yview)
scrollbar.grid(row=1, column=5, sticky=NS)
Text['yscrollcommand'] = scrollbar.set
try:
root.iconbitmap('icon.ico')
except:
pass
root.title(u'Ace Attorney Script Editor')
root.resizable(False, False)
root.protocol("WM_DELETE_WINDOW", on_closing)
root.bind("<Key>", lambda event: update())
root.bind("<Control-s>", lambda event: save())
root.bind("<Control-o>", lambda event: load())
root.mainloop()