-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
95 lines (81 loc) · 3.45 KB
/
main.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
import PySimpleGUI as sg
from editor import Editor
table = sg.Table(
values=[],
headings=['Name', 'Type'],
justification='left',
auto_size_columns=False,
col_widths=[50, 10],
expand_x=True,
expand_y=True,
enable_events=True,
key='-TABLE-',
display_row_numbers=True,
vertical_scroll_only=False,
select_mode=sg.TABLE_SELECT_MODE_BROWSE
)
layout = [
[sg.Button("Open"), sg.Button("Save"), sg.VerticalSeparator(),
sg.Button("Extract"), sg.Button("Up"), sg.Button("Down"), sg.Button("Add"), sg.Button("Remove")],
[table]
]
def TexInfo_to_TableValues(TexInfo):
return [*[[idx['name'], idx['type']] for idx in TexInfo ]]
if __name__ == '__main__':
window = sg.Window("GT3PMBBINEditor", layout=layout, size=(640,480));
selected_texture = 0
editor = None
while True:
event, values = window.read();
if event in (sg.WIN_CLOSED, 'Exit'):
break;
elif event == 'Open':
try:
filepath = sg.popup_get_file("Choose the .bin file to edit.")
editor = Editor(filepath)
window['-TABLE-'].update(values=TexInfo_to_TableValues(editor.TexInfo), select_rows=[selected_texture])
except Exception as e:
sg.popup(e)
elif event == 'Up':
index = selected_texture
if(index > 0 and editor != None):
textures = editor.TexInfo
textures[index-1], textures[index] = textures[index], textures[index-1]
editor.TexInfo = textures
window['-TABLE-'].update(values=TexInfo_to_TableValues(textures), select_rows=[index-1])
elif event == 'Down':
index = selected_texture
if(editor != None and index < editor.texture_count-1 ):
textures = editor.TexInfo
textures[index+1], textures[index] = textures[index], textures[index+1]
editor.TexInfo = textures
window['-TABLE-'].update(values=TexInfo_to_TableValues(textures), select_rows=[index+1])
elif event == '-TABLE-':
if(len(values['-TABLE-']) >= 1):
selected_texture = values['-TABLE-'][0]
else:
selected_texture = 0
elif event == 'Save':
if(editor != None):
editor.assemble_and_save("out.bin")
sg.popup("Saved as "+"out.bin")
elif event == 'Extract':
if(editor != None):
editor.extract_texture(selected_texture)
elif event == 'Add':
if(editor != None):
try:
filepath = sg.popup_get_file("Choose the texture file to add.")
editor.add_texture(filepath)
window['-TABLE-'].update(values=TexInfo_to_TableValues(editor.TexInfo), select_rows=[editor.texture_count-1])
except Exception as e:
sg.popup(e)
elif event == 'Remove':
if(editor != None and editor.texture_count):
editor.remove_texture(selected_texture)
selected_texture = min(selected_texture, editor.texture_count-1)
window['-TABLE-'].update(
values=TexInfo_to_TableValues(editor.TexInfo),
select_rows=[] if editor.texture_count == 0 else [selected_texture]
)
window.close()