Skip to content

Commit 3cbd52b

Browse files
add all Type properties to add property dialog
1 parent b4c4985 commit 3cbd52b

File tree

1 file changed

+62
-26
lines changed

1 file changed

+62
-26
lines changed

src/main.py

+62-26
Original file line numberDiff line numberDiff line change
@@ -1015,17 +1015,18 @@ def updateProperties(self, obj : wmwpy.classes.Object = None):
10151015
self.properties['title'].set('Properties')
10161016

10171017
def addProperty(
1018-
property : str,
1019-
value : str,
1020-
type : typing.Literal['number', 'text'] = 'text',
1018+
property: str,
1019+
value: str,
1020+
type: typing.Literal['number', 'text'] = 'text',
10211021
show_button = True,
10221022
row = 0,
1023-
label_prefix : str = '',
1024-
label_editable : bool = True,
1025-
entry_callback : typing.Callable[[str], typing.Any] = None,
1026-
label_callback : typing.Callable[[str], bool] = None,
1027-
button_callback : typing.Callable = None,
1028-
button_text : str = '-',
1023+
label_prefix: str = '',
1024+
label_editable: bool = True,
1025+
entry_callback: typing.Callable[[str], typing.Any] = None,
1026+
label_callback: typing.Callable[[str], bool] = None,
1027+
button_callback: typing.Callable = None,
1028+
button_text: str = '-',
1029+
options: list[str] = None,
10291030
**kwargs,
10301031
) -> dict[typing.Literal[
10311032
'label',
@@ -1076,11 +1077,19 @@ def inputType(type, value):
10761077
)
10771078
else:
10781079
var = tk.StringVar(value = value)
1079-
input = ttk.Entry(
1080-
self.properties['right'],
1081-
textvariable = var,
1082-
**kwargs
1083-
)
1080+
if options and len(options) > 0:
1081+
input = ttk.Combobox(
1082+
self.properties['right'],
1083+
textvariable = var,
1084+
values = options,
1085+
**kwargs,
1086+
)
1087+
else:
1088+
input = ttk.Entry(
1089+
self.properties['right'],
1090+
textvariable = var,
1091+
**kwargs,
1092+
)
10841093

10851094
# input.insert(0, value)
10861095

@@ -1093,7 +1102,7 @@ def inputType(type, value):
10931102
input, var = inputType(t, value[column])
10941103
input.grid(column = column, row=row, sticky='ew', padx=2)
10951104
if callable(entry_callback):
1096-
var.trace('w', lambda *args, value = var.get, col = column: entry_callback(value(), col))
1105+
var.trace_add('write', lambda *args, value = var.get, col = column: entry_callback(value(), col))
10971106

10981107
input.bind('<Return>', lambda e: self.focus())
10991108

@@ -1132,11 +1141,11 @@ def inputType(type, value):
11321141
if show_button:
11331142
button = crossplatform.Button(
11341143
self.properties['right'],
1135-
text=button_text,
1136-
width=2,
1144+
text = button_text,
1145+
width = 2,
11371146
command = button_callback,
11381147
)
1139-
button.grid(column=2, row=row)
1148+
button.grid(column = 2, row = row)
11401149

11411150
if button.winfo_reqheight() > row_size:
11421151
row_size = button.winfo_reqheight()
@@ -1145,8 +1154,8 @@ def inputType(type, value):
11451154

11461155
logging.debug(f'{row_size = }')
11471156

1148-
self.properties['left'].rowconfigure(row, minsize=row_size)
1149-
self.properties['right'].rowconfigure(row, minsize=row_size)
1157+
self.properties['left'].rowconfigure(row, minsize = row_size)
1158+
self.properties['right'].rowconfigure(row, minsize = row_size)
11501159

11511160
return {
11521161
'label' : name,
@@ -1276,9 +1285,25 @@ def updatePosition(value, column):
12761285

12771286
# button_callback = lambda *args, prop = property : resetProperty(prop)
12781287

1288+
options = []
1289+
1290+
if not isLevel and obj.Type:
1291+
options_property = property
1292+
split_property = obj.Type.split_property_num(property)
1293+
if split_property[1]:
1294+
options_property = split_property[0] + '#'
1295+
1296+
logging.debug(f'options_property: {options_property}')
1297+
logging.debug(f'property_def: {obj.Type.PROPERTIES.get(options_property, {})}')
1298+
1299+
options = obj.Type.PROPERTIES.get(options_property, {}).get('options', [])
1300+
1301+
logging.debug(f'options: {options}')
1302+
12791303
self.objectProperties[property] = addProperty(
12801304
property,
12811305
obj.properties[property],
1306+
options = options,
12821307
row = row,
12831308
button_text = button_text,
12841309
label_editable = True,
@@ -1297,12 +1322,26 @@ def updatePosition(value, column):
12971322
self.properties['scrollFrame'].resetCanvasScroll()
12981323

12991324
def addNewProperty(row):
1300-
13011325
if isLevel:
13021326
properties = {}
13031327
else:
13041328
properties = deepcopy(obj.defaultProperties)
13051329

1330+
if not isLevel and obj.Type:
1331+
for prop in obj.Type.PROPERTIES:
1332+
property = prop
1333+
if prop.endswith('#'):
1334+
split_prop = obj.Type.split_property_num(prop)
1335+
num = 0
1336+
while split_prop[0] + str(num) in obj.properties:
1337+
num += 1
1338+
property = split_prop[0] + str(num)
1339+
1340+
if property in properties:
1341+
continue
1342+
1343+
properties[property] = obj.Type.PROPERTIES[prop].get('default', '')
1344+
13061345
for prop in obj.properties:
13071346
if prop in properties:
13081347
del properties[prop]
@@ -1312,15 +1351,12 @@ def addNewProperty(row):
13121351
'New property',
13131352
'New property',
13141353
validate_message = 'Property already exists',
1315-
options = list(properties.keys()),
1354+
options = sorted(properties),
13161355
validate_callback = lambda name : (name != '') and (name not in obj.properties),
13171356
)
13181357

13191358
if property != None:
1320-
if not isLevel and property in obj.defaultProperties:
1321-
obj.properties[property] = obj.defaultProperties[property]
1322-
else:
1323-
obj.properties[property] = ''
1359+
obj.properties[property] = properties.get(property, '')
13241360

13251361
self.updateProperties()
13261362

0 commit comments

Comments
 (0)