-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
191 lines (144 loc) · 5.28 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
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
#!/usr/bin/env python3
from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QPushButton, QGridLayout, QLabel
from PyQt5.QtWidgets import QListWidget, QComboBox, QFileDialog, QMessageBox
from PIL import Image, ImageTk
from os import path
import os
import time
from Napp_Gen import generate_resourcepacks
from Text_Split import split_text
from Splitter_GUI import splitter_GUI
from tkinter import Tk
'''
PyQt5 Line edit widget that adds drag n drop funcionality
'''
class DnDLineEdit(QLineEdit):
def __init__(self, folders = False):
# Basic widget config
super().__init__()
# For Drag n drops
print(self.setAcceptDrops(True))
self.file_url = ''
self.accept_folders = folders
def dropEvent(self, event):
# For the nature of the widget we just take the first
# element
self.setText(event.mimeData().urls()[0].path()[1:])
def dragEnterEvent(self, event):
print('drop')
event.accept()
return
if event.mimeData().hasUrls():
event.accept()
else:
event.ignore()
#def image_compress_GUI(window):
compr_result = 'None'
pack_res = 1024
compress_list = []
list_view = None
def popup_dialog(txt):
msg = QMessageBox()
msg.setText(txt)
msg.exec_()
def options_dialog_GUI(window):
grid = QGridLayout()
resolution_input = QLineEdit()
compression_picker = QComboBox()
compression_picker.addItems(['None', 'Light', 'Hard', 'Light w/Hard Speculars'])
grid.addWidget(QLabel('Destination pack resolution:'), 0, 0)
grid.addWidget(QLabel('Compression Levels:'), 0, 3)
grid.addWidget(resolution_input, 1, 0)
grid.addWidget(compression_picker, 1, 3)
#Button events
def add_compression():
global compr_result, pack_res, list_view
compr_result = compression_picker.currentText()
pack_res = resolution_input.text()
tmp = str(pack_res) + '-' + compr_result
compress_list.append((pack_res, compr_result))
list_view.addItem(tmp)
window.close()
add_button = QPushButton('Add')
add_button.clicked.connect(add_compression)
grid.addWidget(add_button, 2, 2)
window.setLayout(grid)
def main_GUI(window):
global list_view
grid = QGridLayout()
origin_input = DnDLineEdit()
result_input = DnDLineEdit()
pack_version_input = QLineEdit()
list_view = QListWidget()
origin_search_button = QPushButton('Search')
result_search_button = QPushButton('Search')
add_compress_button = QPushButton('Add resolution')
scale_button = QPushButton('Scale')
scale_zip_button = QPushButton('Scale and Zip')
splitter_button = QPushButton('Texture splitter')
# Button events
def origin_search():
filename = QFileDialog.getExistingDirectory(None, "Open Folder", '.')
if filename:
origin_input.setText(filename)
def result_search():
filename = QFileDialog.getExistingDirectory(None, "Open Folder", '.')
if filename:
result_input.setText(filename)
def show_splitter():
split_window = QWidget()
window = Tk()
splitter_GUI(window)
window.mainloop()
def add_resolution():
res_window = QWidget()
options_dialog_GUI(res_window)
res_window.show()
def resize():
scale_button.setEnabled(False)
scale_zip_button.setEnabled(False)
popup_dialog('Processing...')
generate_resourcepacks(origin_input.text(), compress_list, result_input.text(), pack_version_input.text())
scale_button.setEnabled(True)
scale_zip_button.setEnabled(True)
popup_dialog('Finished!')
def resize_zip():
scale_button.setEnabled(False)
scale_zip_button.setEnabled(False)
popup_dialog('Processing...')
generate_resourcepacks(origin_input.text(), compress_list, result_input.text(), pack_version_input.text(), True)
scale_button.setEnabled(True)
scale_zip_button.setEnabled(True)
popup_dialog('Finished!')
origin_search_button.clicked.connect(origin_search)
result_search_button.clicked.connect(result_search)
add_compress_button.clicked.connect(add_resolution)
scale_button.clicked.connect(resize)
scale_zip_button.clicked.connect(resize_zip)
splitter_button.clicked.connect(show_splitter)
# First col
grid.addWidget(QLabel('Origin Resource pack:'), 1,0)
grid.addWidget(origin_input, 2, 0)
grid.addWidget(origin_search_button, 2, 1)
grid.addWidget(QLabel('Resource pack version:'), 5, 0)
grid.addWidget(pack_version_input, 6, 0)
# Second col
grid.addWidget(QLabel('Result Pack Direction:'), 1, 3)
grid.addWidget(result_input, 2, 3)
grid.addWidget(result_search_button, 2, 4)
grid.addWidget(QPushButton('Convert a single image'), 5, 4)
# Third col
grid.addWidget(splitter_button, 2, 6)
grid.addWidget(add_compress_button, 3, 6)
grid.addWidget(list_view, 4, 6)
grid.addWidget(scale_button, 5, 6)
grid.addWidget(scale_zip_button, 6, 6)
window.setLayout(grid)
if __name__ == '__main__':
app = QApplication([])
main_window = QWidget()
main_GUI(main_window)
#options_dialog_GUI(main_window)
#texture_splitter_GUI(main_window)
main_window.show()
app.exec()