-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
304 lines (249 loc) · 10.1 KB
/
ui.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
"""GUI, user can interact with the program here"""
# Built-in Modules
import os
import sys
import tkinter as tk
from tkinter import filedialog, Button, messagebox
from tkinter.scrolledtext import ScrolledText
# Third Party Modules
from PIL import Image, ImageTk
# Project Modules
sys.path.append("functions")
from functions.checkID import checkID
from functions.class_chara import Chara
from functions.class_work import Work
CharaList: list[Chara] = []
# will create a new window
# used to show current chara list
def view_chara_list():
"""
for viewing the current character list
"""
chara_list_window = tk.Toplevel()
chara_list_window.geometry("300x350")
# setup safe exit
def close_window():
chara_list_window.destroy()
# exit when click X
chara_list_window.protocol("WM_DELETE_WINDOW", lambda: close_window())
# show_chara_list
show_chara_list = tk.Label(chara_list_window, text = "Chara List:")
show_chara_list.place(x = 50, y = 50, width=100, height=25)
# Display all Character and their Images here
list_area = ScrolledText(chara_list_window, width=30, height=15)
list_area.grid(row=2, column=0, padx=10, pady=10)
list_area.images = []
for i in CharaList:
temp_name_list = i.getname_str()
temp_png_list = i.get_image()
print(temp_png_list)
# for j in range(len(temp_name_list)):
# list_area.insert(tk.END, temp_name_list[j] + "\n")
# temp_img = Image.open(temp_png_list[j]).resize((64, 64))
# temp_img = ImageTk.PhotoImage(temp_img)
# list_area.image_create(tk.END, padx=5, pady=5, image=temp_img)
# list_area.images.append(temp_img)
# list_area.insert(tk.END, "\n")
for j in enumerate(temp_name_list):
list_area.insert(tk.END, j[1] + "\n")
temp_img = Image.open(temp_png_list[j[0]]).resize((64, 64))
temp_img = ImageTk.PhotoImage(temp_img)
list_area.image_create(tk.END, padx=5, pady=5, image=temp_img)
list_area.images.append(temp_img)
list_area.insert(tk.END, "\n")
#exit_button
exit_button = Button(chara_list_window, text="Exit",command = lambda: close_window())
exit_button.place(x = 100, y = 300, width=100, height=50)
def create_character(win = None):
"""
function for creating a new character
"""
root = tk.Toplevel()
root.geometry("550x350")
root.lift()
# name_text
name_text = tk.Label(root, text="Name:")
name_text.place(x = 350, y = 50, width=50, height=25)
# name_entry
name_entry = tk.Entry(root)
name_entry.place(x = 400, y = 50, width=100, height=25)
# id_text
id_text = tk.Label(root, text="ID:")
id_text.place(x = 340, y = 100, width=50, height=25)
# id_entry
id_entry = tk.Entry(root)
id_entry.place(x = 400, y = 100, width=100, height=25)
# show_img
img = ""
show_img = tk.Label(root, image = img)
show_img.place(x = 23, y = 50)
# PS
tk.Label(root,
text="*preview might seems starange if input image is not square",
font=("Arial", 8)).place(x = 23, y = 300)
tk.Label(root,
text = "*but it will be croped to square in output",
font=("Arial", 8)).place(x = 23, y = 317)
# choose_img function
def choose_img():
try:
global file_path
file_path = filedialog.askopenfilename()
img = Image.open(file_path)
img = img.resize((250, 250))
img = ImageTk.PhotoImage(img)
show_img.configure(image = img)
# Why image doesn't show up without this line?
show_img.image = img
except AttributeError:
pass
root.lift()
# choose_img_button
choose_img_button = Button(root, text="Choose Image",command = lambda: choose_img())
choose_img_button.place(x = 25, y = 25, width=100, height=25)
# setup safe exit
def close_window():
win.attributes("-disabled", 0)
root.destroy()
# exit when click X
root.protocol("WM_DELETE_WINDOW", lambda: close_window())
# finish function
def append_chara(name, ID):
if name == "" or ID == "":
messagebox.showerror("Error", "Please enter name and ID.")
root.lift()
return
elif not checkID(ID):
messagebox.showerror("Error",
"Please enter a correct character ID(ID should be exact 4 NUMBER).")
root.lift()
return
elif show_img.image == "":
messagebox.showerror("Error", "Please choose an image.")
root.lift()
return
else:
CharaList.append(Chara(name, ID, file_path, rank_reward = [], transfer_rank = []))
def finish_chara(name, ID):
try:
append_chara(name, ID)
close_window()
except AttributeError:
messagebox.showerror("Error", "Please choose an image.")
root.lift()
return
# finish_button
finish_button = Button(root, text="Done",
command = lambda: finish_chara(name_entry.get(),
id_entry.get()))
finish_button.place(x = 380, y = 220, width=100, height=25)
def addtransform(name, ID):
append_chara(name, ID)
transform_win()
# add_transform_button
add_transform_button = Button(root,
text="Add Transform",
command = lambda: addtransform(name_entry.get(), id_entry.get()))
add_transform_button.place(x = 380, y = 260, width=100, height=25)
def transform_win():
if len(CharaList[len(CharaList)-1].get_image()) > 8:
add_transform_button.configure(state="disabled")
# id_text
id_text.destroy()
# id_entry
id_entry.destroy()
# ranl_text
rank_text = tk.Label(root, text="Transfer Rank:")
rank_text.place(x = 305, y = 100, width=100, height=25)
# rank_entry
rank_entry = tk.Entry(root)
rank_entry.place(x = 400, y = 100, width=100, height=25)
# show_img
show_img.image = ""
def entry_processing():
"""
Function for chjecking the user input,
There should be an image and the numeric rank
If requirements meet, the entry will be added to the current character
"""
if file_path is None:
messagebox.showerror("Error", "Please choose an image.")
root.lift()
return
elif rank_entry.get() == "" or not rank_entry.get().isnumeric():
messagebox.showerror("Error", "Please enter a correct rank.")
root.lift()
return
CharaList[len(CharaList)-1].add_image(file_path)
CharaList[len(CharaList)-1].addname_str(name_entry.get())
print(rank_entry.get())
CharaList[len(CharaList)-1].transfer_rank.append(rank_entry.get())
def transform_finish():
"""
finish the transform
"""
entry_processing()
close_window()
finish_button.configure(command= lambda: transform_finish())
def add_more_transform():
"""
add more transform
"""
entry_processing()
transform_win()
add_transform_button.configure(command= lambda: add_more_transform())
# exit_button
exit_button = Button(root, text="Exit",command = lambda: close_window())
exit_button.place(x = 380, y = 300, width=100, height=25)
root.mainloop()
def main():
"""
The main function for the GUI
"""
root = tk.Tk()
root.geometry("300x350")
root.attributes("-top")
def open_create_character(win = root):
win.attributes("-disabled", 1)
create_character(win)
def generate_file():
# This part for input work id and work string
root = tk.Toplevel()
root.lift()
root.geometry("300x350")
work_id_label = tk.Label(root, text="Work ID:", justify = "left", anchor = "w")
work_id_label.place(x = 50, y = 50, width=100, height=25)
work_id_entry = tk.Entry(root)
work_id_entry.place(x = 150, y = 50, width=100, height=25)
work_str_label = tk.Label(root, text="Work String:", justify = "left", anchor = "w")
work_str_label.place(x = 50, y = 100, width=100, height=25)
work_str_entry = tk.Entry(root)
work_str_entry.place(x = 150, y = 100, width=100, height=25)
confirm_button = Button(root, text="Confirm", command = lambda: finish())
confirm_button.place(x = 100, y = 150, width=100, height=25)
hint_label = tk.Label(root,
text="*Default value will be applied if left blank\n work id: 514, work string: 自製",
justify = "left")
hint_label.place(x = 40, y = 200, width=250, height=50)
work_id = work_id_entry.get() or "514"
work_str = work_str_entry.get() or "自製"
def finish():
for i in CharaList:
i.set_works(work_id, work_str)
i.xml_edit()
i.to_dds()
Work(work_id, work_str).edit_xml()
messagebox.showinfo("Info", "File generated ~(∠・ω< )⌒★")
root.destroy()
create_button = Button(root, text="CreateChar",command = lambda: open_create_character())
create_button.place(x = 100, y = 50, width=100, height=50)
view_button = Button(root, text="ViewChar",command = lambda: view_chara_list())
view_button.place(x = 100, y = 125, width=100, height=50)
generate_button = Button(root, text="Generate File",command = lambda: generate_file())
generate_button.place(x = 100, y = 200, width=100, height=50)
exit_button = Button(root, text="Exit",command = lambda: root.destroy())
exit_button.place(x = 100, y = 275, width=100, height=50)
root.mainloop()
if __name__ == "__main__":
main()
os.system('pause')