/
make_template.py
104 lines (83 loc) · 4.58 KB
/
make_template.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
import kg
from kg import ui_tools
#kg.template_util.loadTemplate('')
from kg.template_util import loadTemplate, loadTemplate
#from kg.file_util import load_nif, load_tri, get_files, save_file
#from kg.search_util import mainSearch, setSeams, setTriSeams
from kg.ui_tools import uiButton, uiToggle, mainUI, uiComboSlider, uiRadio, uiFrame, uiLabel, constructMenu
#from operator import itemgetter
from pyffi.formats.nif import NifFormat
import tkinter
import re
from os import path, makedirs
ui_tools.button_width = 20
ui_tools.entry_width = 5
ui_tools.slider_length = 100
menu = mainUI("Export Seam Template Options")
config_file = 'makeTemplate.cfg'
r_nif_end = re.compile('.nif$', flags=re.IGNORECASE)
"""
Menu Window Frames
"""
# left_frame = uiFrame(menu.frame, column = 0, columnspan = 1, row = 0, rowspan = 6, relief = True)
# left_frame.grid(sticky = tkinter.W + tkinter.E + tkinter.N + tkinter.S)
# right_frame = uiFrame(menu.frame, column = 1, columnspan = 2, row = 0, rowspan = 6, relief = True)
# right_frame.grid(sticky = tkinter.W + tkinter.E + tkinter.N + tkinter.S)
option_frame_1 = uiFrame(menu.frame, column = 0, columnspan = 1, row = 0, rowspan = 4, relief = True)
option_frame_1.grid(sticky = tkinter.W + tkinter.E + tkinter.N + tkinter.S)
option_frame_2 = uiFrame(menu.frame, column = 2, columnspan = 1, row = 0, rowspan = 4, relief = True)
option_frame_2.grid(sticky = tkinter.W + tkinter.E + tkinter.N + tkinter.S)
utility_frame = uiFrame(menu.frame, column = 0, columnspan = 3, row = 8, rowspan = 2, relief = True)
utility_frame.grid(sticky = tkinter.W + tkinter.E + tkinter.N + tkinter.S)
menu.version = 'b_13'
menu.name = 'seamTemplate_Options'
menu.file = config_file
menu.menu_values = {\
'subfolder': (tkinter.IntVar(), 0),\
'female_template': (tkinter.StringVar(), '/test/female.nif'),\
'male_template': (tkinter.StringVar(), '/test/male.nif'),\
'neutral_template': (tkinter.StringVar(), '/test/template.nif'),\
'target': (tkinter.StringVar(), '/test/'),\
'destination': (tkinter.StringVar(), '/test/output/'),\
}
"""
Build a dictionary that defines the menu structure
"""
menu_structure = [
{'File': [\
{"Select Female Template..." : {'command': menu.OpenFemaleTemplate}},\
{"Select Male Template..." : {'command': menu.OpenMaleTemplate}},\
{"Select Neutral Template..." : {'command': menu.OpenNeutralTemplate}},\
{"Select Destination Folder..." : {'command': menu.SelectDestinationFolder}},\
]},\
{'Help': [\
{"About" : {'command': menu.About}}]}\
]
file_menu = constructMenu(menu, menu_structure, menu.menu_values)
menu.template_mask = mask = [("nif files","*.nif")]
menu.target_mask = mask = [("nif files","*.nif"), ("tri files","*.tri")]
menu.load_buttons({\
'template_mesh' : uiRadio(option_frame_1, 'Template Mesh',['Edges Only','Exclude Edges','All'], column = 0, columnspan = 1, row = 1, rowspan = 4, default = 'Edges Only', pack = True),\
'female': uiToggle(option_frame_2, 'Female Template', 'GRID', column = 0, columnspan = 1, row = 0, default = True),\
'male': uiToggle(option_frame_2, 'Male Template', 'GRID', column = 0, columnspan = 1, row = 1, default = True),\
'neutral': uiToggle(option_frame_2, 'Neutral Template', 'GRID', column = 0, columnspan = 1, row = 2, default = True),\
#'gender' : uiRadio(option_frame_2, 'Templates',['Female Only','Male Only','Both', 'Neither'], column = 1, columnspan = 1, row = 1, rowspan = 4, default = 'Both', pack = True),\
'save': uiButton(utility_frame, 'Save Current Settings', 'GRID', column = 0, columnspan = 1, row = 9, buttonFunction = menu.save),\
'load': uiButton(utility_frame, 'Load Settings', 'GRID', column = 2, columnspan = 1, row = 9, buttonFunction = menu.load),\
'default': uiButton(utility_frame, 'Load Defaults', 'GRID', column = 1, columnspan = 1, row = 9, buttonFunction = menu.applyDefaultSettings),\
'cancel': uiButton(utility_frame, 'Cancel', 'GRID', column = 0, columnspan = 1, row = 10, buttonFunction = menu.cancel),\
'ok': uiButton(utility_frame, 'OK', 'GRID', column = 2, columnspan = 1, row = 10, buttonFunction = menu.ok, sticky = 'E'),\
})
current_settings = menu.openMenu()
print(current_settings)
try: menu.destroy()
except: menu.end = True
def Main():
if not path.exists(current_settings['destination']):
print ('destination', current_settings['destination'])
makedirs(current_settings['destination'])
kg.template_util.saveTemplate(current_settings)
return
if not menu.end:
menu.save(file = config_file)
Main()