forked from karantras/Translation-CDDA-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
126 lines (97 loc) · 3.97 KB
/
GUI.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import tkinter as tk
import tkinter.messagebox as mb
from tkinter.ttk import Button, Style, Label, Scrollbar
import utilities as ut
import os
import sys
from configparser import ConfigParser
import utilities_user as uut
configs = ConfigParser()
configs.read('configs.ini')
game_folder = configs.get('Folders', 'game folder')
mods_folder = configs.get('Folders', 'mod folder')
translator_folder = configs.get('Folders', 'translator folder')
user_folder = translator_folder+"\\user\\"+ configs.get('Mods', 'mod')
def check(configs, translator_folder, __file__):
if translator_folder != os.getcwd():
trans_path = os.getcwd()
configs['Folders']["translator folder"] = trans_path
with open ('configs.ini', 'w') as configfiles:
configs.write(configfiles)
translator_folder = configs.get('Folders', 'translator folder')
class Translator(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent, background="#333333")
self.parent = parent
self.name = 'name'
self.parent.title("CDDA Translator")
self.mod = tk.StringVar()
self.mod.set("Current mod: "+ configs.get('Mods', 'mod'))
modbar = tk.Frame(self, background="#424242")
modbar.pack(side="top", fill="x")
toolbar = tk.Frame(self, background="light grey")
toolbar.pack(side="top", fill="y")
self.text = tk.Text(self, wrap="word")
self.text.pack(side="top", fill="both", expand=True)
self.text.tag_configure("stderr", foreground="#b22222")
scroll = Scrollbar(command=self.text.yview)
scroll.pack(side="right", fill="y")
self.text.config(yscrollcommand=scroll.set)
self.pack(fill=tk.BOTH, expand=1)
self.centerWindow()
sys.stdout = TextRedirector(self.text, "stdout")
sys.stderr = TextRedirector(self.text, "stderr")
btn_file = Button(self, text="Select mod",command=self.select_mod, width = 14 )
btn_file.pack(in_=toolbar, side="left", padx = 3, pady = 1)
btn_settings = Button(self, text='Extract strings',command=self.extractor, width = 14)
btn_settings.pack(in_=toolbar, side="left", padx = 3, pady = 1)
btn_convert = Button(self, text='Update strings',command=self.converter, width = 14)
btn_convert.pack(in_=toolbar, side="left", padx = 3, pady = 1)
btn_convert = Button(self, text='Rewrite json',command=self.rewrite, width = 14)
btn_convert.pack(in_=toolbar, side="left", padx = 3, pady = 1)
dynlabel = Label(self, textvariable = self.mod, background="#424242", foreground ="#dddddd", font = "Courier 10 bold")
dynlabel.pack(in_= modbar, side = "bottom", fill ="y", anchor=tk.NW)
def centerWindow(self):
w = 500
h = 150
sw = self.parent.winfo_screenwidth()
sh = self.parent.winfo_screenheight()
x = (sw-w)/2
y = (sh-h)/2
self.parent.geometry('%dx%d+%d+%d' % (w, h, x, y))
def select_mod(self):
ut.select_mod(configs)
self.mod.set("Current mod: " + configs.get('Mods', 'mod'))
def converter(self):
if configs.get('Mods', 'mod') == "NONE":
print("Сначала выберите мод")
else:
ut.updater(user_folder)
def extractor(self):
if configs.get('Mods', 'mod') == "NONE" or configs.get('Mods', 'mod') == "":
print("Сначала выберите мод")
else:
ut.extractor(configs.get('Folders', 'mod folder'), configs.get('Mods', 'mod'), translator_folder)
def rewrite(self):
if configs.get('Mods', 'mod') == "NONE":
print("Сначала выберите мод")
else:
uut.replacer(translator_folder+"\\user\\"+ configs.get('Mods', 'mod'), configs.get('Folders', 'mod folder'),configs.get('Mods', 'mod'))
class TextRedirector(object):
def __init__(self, widget, tag="stdout"):
self.widget = widget
self.tag = tag
def write(self, str):
self.widget.configure(state="normal")
self.widget.insert("end", str, (self.tag,))
self.widget.configure(state="disabled")
def main():
root = tk.Tk()
app = Translator(root)
check(configs, translator_folder, __file__)
root.iconbitmap('icon.ico')
root.mainloop()
if __name__ == '__main__':
main()