forked from OpenNaja/cobra-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matcol_editor_gui.py
137 lines (113 loc) · 4.55 KB
/
matcol_editor_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
127
128
129
130
131
132
133
134
135
136
137
import logging
import sys
import time
from gui import widgets, startup, GuiOptions # Import widgets before everything except built-ins!
from ovl_util import config
from generated.formats.matcol.compounds.MatcolRoot import MatcolRoot
from generated.formats.ovl_base import OvlContext
from PyQt5 import QtWidgets
class MainWindow(widgets.MainWindow):
def __init__(self, opts: GuiOptions):
self.scrollarea = QtWidgets.QScrollArea()
self.scrollarea.setWidgetResizable(True)
# the actual scrollable stuff
self.widget = QtWidgets.QWidget()
self.scrollarea.setWidget(self.widget)
widgets.MainWindow.__init__(self, "Matcol Editor", opts=opts, central_widget=self.scrollarea)
self.resize(450, 500)
self.context = OvlContext()
self.matcol_data = MatcolRoot(self.context)
self.file_widget = self.make_file_widget(ftype="materialcollection")
self.tooltips = config.read_str_dict("gui/tooltips/matcol.txt")
self.default_fgms = config.read_list("gui/tooltips/matcol-fgm-names.txt")
main_menu = self.menu_bar
file_menu = main_menu.addMenu('File')
help_menu = main_menu.addMenu('Help')
button_data = (
(file_menu, "Open", self.file_widget.ask_open, "CTRL+O", "dir"),
(file_menu, "Save", self.file_widget.ask_save, "CTRL+S", "save"),
(file_menu, "Save As", self.file_widget.ask_save_as, "CTRL+SHIFT+S", "save"),
(file_menu, "Exit", self.close, "", "exit"),
(help_menu, "Report Bug", self.report_bug, "", "report"),
(help_menu, "Documentation", self.online_support, "", "manual"))
self.add_to_menu(button_data)
self.tex_container = QtWidgets.QGroupBox("Slots")
self.attrib_container = QtWidgets.QGroupBox("Attributes")
self.vbox = QtWidgets.QVBoxLayout()
self.vbox.addWidget(self.file_widget)
self.vbox.addWidget(self.tex_container)
self.vbox.addWidget(self.attrib_container)
self.vbox.addStretch(1)
self.widget.setLayout(self.vbox)
self.tex_grid = self.create_grid()
self.attrib_grid = self.create_grid()
self.tex_container.setLayout(self.tex_grid)
self.attrib_container.setLayout(self.attrib_grid)
def create_grid(self,):
g = QtWidgets.QGridLayout()
g.setHorizontalSpacing(3)
g.setVerticalSpacing(3)
return g
def clear_layout(self, layout):
w = QtWidgets.QWidget()
w.setLayout(layout)
while layout.count():
item = layout.takeAt(0)
widget = item.widget()
widget.deleteLater()
def open(self, filepath):
if filepath:
try:
self.matcol_data = self.matcol_data.from_xml_file(filepath, self.context)
# delete existing widgets
self.clear_layout(self.tex_grid)
self.clear_layout(self.attrib_grid)
self.tex_grid = self.create_grid()
self.attrib_grid = self.create_grid()
self.tex_container.setLayout(self.tex_grid)
self.attrib_container.setLayout(self.attrib_grid)
main = self.matcol_data.main.data
line_i = 0
for i, tex in enumerate(main.textures.data):
box = widgets.CollapsibleBox(f"Slot {i}")
self.tex_grid.addWidget(box, line_i, 0)
line_i += 1
lay = self.create_grid()
a = QtWidgets.QLabel("texture type")
b = QtWidgets.QLabel("texture suffix")
x = QtWidgets.QLineEdit(tex.texture_type.data)
y = QtWidgets.QLineEdit(tex.texture_suffix.data)
combo = widgets.LabelCombo("First FGM:", self.default_fgms)
combo.entry.setText(tex.fgm_name.data)
lay.addWidget(a, 0, 0)
lay.addWidget(b, 1, 0)
lay.addWidget(x, 0, 1)
lay.addWidget(y, 1, 1)
lay.addWidget(combo.label, 2, 0)
lay.addWidget(combo.entry, 2, 1)
box.setLayout(lay)
line_i = 0
for i, attrib in enumerate(main.materials.data):
box = widgets.CollapsibleBox(f"Slot {i}")
self.attrib_grid.addWidget(box, line_i, 0)
line_i += 1
lay = self.create_grid()
combo = widgets.LabelCombo("FGM:", self.default_fgms)
combo.entry.setText(attrib.layer_name.data)
lay.addWidget(combo.label, 0, 0)
lay.addWidget(combo.entry, 0, 1)
sub_line_i = 1
for float_attribute in attrib.float_attributes.data:
w = widgets.MatcolFloatAttrib(float_attribute, self.tooltips)
lay.addWidget(w.label, sub_line_i, 0)
lay.addWidget(w.data, sub_line_i, 1)
sub_line_i += 1
box.setLayout(lay)
except:
logging.exception(f"Something went wrong")
logging.info("Done!")
def save(self, filepath):
with self.matcol_data.to_xml_file(self.matcol_data, filepath) as xml_root:
pass
if __name__ == '__main__':
startup(MainWindow, GuiOptions(log_name="matcol_editor_gui"))