-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_classes.py
More file actions
336 lines (257 loc) · 10.1 KB
/
Copy pathui_classes.py
File metadata and controls
336 lines (257 loc) · 10.1 KB
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
from zon_object_types import *
from formatting import *
import reference_lists
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QColor, QPalette
from PyQt6.QtWidgets import (
QApplication,
QHBoxLayout,
QMainWindow,
QPushButton,
QStackedLayout,
QVBoxLayout,
QWidget,
QLineEdit,
QLabel,
QComboBox,
QScrollArea,
QFileDialog,
)
from pathlib import Path
class Color(QWidget):
def __init__(self, color):
super().__init__()
self.setAutoFillBackground(True)
palette = self.palette()
palette.setColor(QPalette.ColorRole.Window, QColor(color))
self.setPalette(palette)
def deleteWithChildren(object):
if (object == None):
return
if (object.layout()):
for i in range(object.layout().count()):
if (object.itemAt(i).widget()):
object.itemAt(i).widget().deleteLater()
elif (object.itemAt(i).layout()):
if object.itemAt(i).layout().count() != 0:
deleteWithChildren(object.itemAt(i))
object.itemAt(i).layout().deleteLater()
else:
print("deleteWithChildren found a child it could not delete")
print(object)
elif (object.widget()):
object.widget().deleteLater()
else:
print("deleteWithChildren found a child it could not delete")
print(object)
def writeGivenZonObjectToFile(filepath, zonObject):
print("Writing to " + filepath)
actualText = zonObject.writeWithChildren([], "")
with open(filepath, "w") as f:
for line in actualText:
f.write(line)
f.write('\n')
def readFormat(givenFormat, baseParentLayout, childZonList):
for child in givenFormat:
if isinstance(child, zonValue):
newZonValue = uiTxtInputZonValue()
newZonValue.addZonValueInput(child.name, baseParentLayout, child.value)
childZonList.append(newZonValue)
elif isinstance(child, zonArray):
newZonArray = uiTxtInputZonArray()
newZonArray.addZonArrayInput(child.name, baseParentLayout, child.children[0])
childZonList.append(newZonArray)
elif isinstance(child, zonObject):
newZonObject = uiZonObject()
uiZonObject.children = []
newZonObject.addZonObjectInput(child.name, baseParentLayout)
readFormat(child.children, newZonObject.childUiLayout, newZonObject.children)
childZonList.append(newZonObject)
if isinstance(child, recipieZon):
newUI = uiRecipieZon()
newUI.addRecipieInput(baseParentLayout, reference_lists.getItemList())
childZonList.append(newUI)
#MARK: UiClasses
# smaller classes for ui
class uiTxtInputZonValue():
name = "ErrorNotDefined"
txtInput = None
def addZonValueInput(self, name, baseParentLayout, defaultText):
txtInputsLayout = QHBoxLayout()
self.name = name
self.txtInput = QLineEdit()
self.txtInput.setPlaceholderText(defaultText)
txtInputsLayout.addWidget(self.txtInput)
lineLayout = QHBoxLayout()#item 1 is always the actual value object(s)
namelabel = QLabel(name + " = ")
lineLayout.addWidget(namelabel)
lineLayout.addLayout(txtInputsLayout)
baseParentLayout.addLayout(lineLayout)
class uiComboBoxZonValue():
name = "ErrorNotDefined"
comboBox = None
def addZonValueInput(self, name, baseParentLayout, defaultText, givenList):
inputsLayout = QHBoxLayout()
self.name = name
self.comboBox = QComboBox()
self.comboBox.setPlaceholderText(defaultText)
self.comboBox.addItem("")
self.comboBox.addItems(givenList)
inputsLayout.addWidget(self.comboBox)
lineLayout = QHBoxLayout()#item 1 is always the actual value object(s)
namelabel = QLabel(name + " = ")
lineLayout.addWidget(namelabel)
lineLayout.addLayout(inputsLayout)
baseParentLayout.addLayout(lineLayout)
class uiTxtInputZonArray():
name = "ErrorNotDefined"
def addZonArrayInput(self, name, baseParentLayout, defaultText):
txtInputsLayout = QHBoxLayout()
self.txtInputList = []
self.createSingleArrayInput(defaultText, txtInputsLayout)
self.name = name
lineLayout = QHBoxLayout()#item 1 is always the actual value object(s)
namelabel = QLabel(name + " = ")
lineLayout.addWidget(namelabel)
lineLayout.addLayout(txtInputsLayout)
baseParentLayout.addLayout(lineLayout)
def createSingleArrayInput(self, defaultText, parentLayout):
txtInput = QLineEdit()
txtInput.setPlaceholderText(defaultText)
txtInput.textChanged.connect(lambda: self.checkArrayZonChildren(defaultText, parentLayout))
self.txtInputList.append(txtInput)
parentLayout.addWidget(txtInput)
def checkArrayZonChildren(self, defaultText, parentLayout):
widgetsRemovalList = []
for i in range(parentLayout.count()):
childButton = parentLayout.itemAt(i).widget()
if (childButton.text() == "") and (i + 1 != parentLayout.count()):
widgetsRemovalList.append(childButton)
elif (childButton.text() != "") and (i + 1 == parentLayout.count()):
self.createSingleArrayInput(defaultText, parentLayout)
for widget in widgetsRemovalList:
self.txtInputList.remove(widget)
widget.deleteLater()
class uiComboBoxZonArray():
name = "ErrorNotDefined"
updateParentFunction = None
def addZonArrayInput(self, name, baseParentLayout, defaultText, givenList):
self.givenList = givenList
self.comboBoxLayout = QHBoxLayout()
self.comboBoxList = []
self.createSingleArrayInput(defaultText, self.comboBoxLayout)
self.name = name
lineLayout = QHBoxLayout()#item 1 is always the actual value object(s)
namelabel = QLabel(name + " = ")
lineLayout.addWidget(namelabel)
lineLayout.addLayout(self.comboBoxLayout)
baseParentLayout.addLayout(lineLayout)
def createSingleArrayInput(self, defaultText, parentLayout):
comboBoxInput = QComboBox()
comboBoxInput.setPlaceholderText(defaultText)
comboBoxInput.addItem("")
comboBoxInput.addItems(self.givenList)
comboBoxInput.currentTextChanged.connect(lambda: self.checkArrayZonChildren(defaultText, parentLayout))
self.comboBoxList.append(comboBoxInput)
parentLayout.addWidget(comboBoxInput)
def checkArrayZonChildren(self, defaultText, parentLayout):
widgetsRemovalList = []
for i in range(parentLayout.count()):
childButton = parentLayout.itemAt(i).widget()
if (childButton.currentText() == "") and (i + 1 != parentLayout.count()):
widgetsRemovalList.append(childButton)
elif (childButton.currentText() != "") and (i + 1 == parentLayout.count()):
self.createSingleArrayInput(defaultText, parentLayout)
for widget in widgetsRemovalList:
self.comboBoxList.remove(widget)
widget.deleteLater()
if self.updateParentFunction: #lets this weird structure update a parent
self.updateParentFunction()
class uiZonObject():
name = "ErrorNotDefined"
children = []
childUiLayout = None
def addZonObjectInput(self, name, baseParentLayout):
self.childUiLayout = QVBoxLayout()
self.name = name
lineLayout = QHBoxLayout()#item 1 is always the actual value object(s)
namelabel = QLabel(name + " = ")
lineLayout.addWidget(namelabel)
lineLayout.addLayout(self.childUiLayout)
baseParentLayout.addLayout(lineLayout)
class uiFormatGroupZonMulti():
name = "ErrorNotDefined"
givenFormatGroup = []
dropdownBox = None
children = []
def addFormatGroupInput(self, name, baseParentLayout, givenFormatGroup):
print("added format group input")
self.childUiLayout = QVBoxLayout()
self.createDropdownInput(givenFormatGroup, self.childUiLayout)
self.name = name
self.givenFormatGroup = givenFormatGroup
lineLayout = QHBoxLayout()#item 1 is always the actual value object(s)
namelabel = QLabel(name + " = ")
lineLayout.addWidget(namelabel)
lineLayout.addLayout(self.childUiLayout)
baseParentLayout.addLayout(lineLayout)
def createDropdownInput(self, givenFormatGroup, parentLayout):
dropdownInput = QComboBox()
dropdownInput.addItem("")
dropdownInput.addItems(givenFormatGroup)
dropdownInput.currentTextChanged.connect(lambda: self.checkDropdownChildren(parentLayout))
self.dropdownBox = (dropdownInput)
parentLayout.addWidget(dropdownInput)
def checkDropdownChildren(self, parentLayout):
removalList = []
for i in range(parentLayout.count()):
removalList.append(parentLayout.itemAt(i).layout())
self.children = []
for thing in removalList:
deleteWithChildren(thing)
childUiZonLayout = QVBoxLayout()# we seperate it like this so that the children can be deleted without the dropdown deleting itself
parentLayout.addLayout(childUiZonLayout)
text = self.dropdownBox.currentText()
if text != "":
readFormat(readFormatFile(text).children, parentLayout, self.children)
class uiRecipieZon():
children = []
def addRecipieInput(self, baseParentLayout, listOfItems):
self.childUiLayout = QVBoxLayout()
self.itemFileList = listOfItems # MARK: WIP add reading to addon support
self.itemNameList = []
for selectableItem in listOfItems:
self.itemNameList.append("cubyz:" + selectableItem.name[:-8]) # removes .zig.zon from filenames
self.addSingleRecipieInput(baseParentLayout)
def addSingleRecipieInput(self, baseParentLayout):
uiRecipieList = []
recipieLayout = QVBoxLayout()
recipieLayout.widget
inputUi = uiComboBoxZonArray()
inputUi.addZonArrayInput("input", recipieLayout, "pick a item", self.itemNameList)
inputUi.updateParentFunction = (lambda: self.checkUiChildren(recipieLayout))
uiRecipieList.append(inputUi)
outputUi = uiComboBoxZonValue()
outputUi.addZonValueInput("output", recipieLayout, "pick a item", self.itemNameList)
outputUi.comboBox.currentTextChanged.connect(lambda: self.checkUiChildren(recipieLayout))
uiRecipieList.append(outputUi)
self.children.append(uiRecipieList)
baseParentLayout.addLayout(recipieLayout)
def checkUiChildren(self, parentLayout):
widgetsRemovalList = []
listRemovalList = []
for i in range(self.children.__len__()):
childInputs = self.children[i][0]
inputBool = (childInputs.comboBoxList[0].currentText() == "")
childOutputs = self.children[i][1].comboBox
outputBool = (childOutputs.currentText() == "")
if (inputBool) and (outputBool) and (i + 1 == parentLayout.count()):
widgetsRemovalList.append(self.children[i][0].comboBoxLayout)
widgetsRemovalList.append(childOutputs)
listRemovalList.append(self.children[i])
else:
if (i + 1 == self.children.__len__()): self.addSingleRecipieInput(parentLayout)
for widget in widgetsRemovalList:
widget.deleteLater()
for listToRemove in listRemovalList:
self.children.remove(listToRemove)