@@ -1015,17 +1015,18 @@ def updateProperties(self, obj : wmwpy.classes.Object = None):
1015
1015
self .properties ['title' ].set ('Properties' )
1016
1016
1017
1017
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' ,
1021
1021
show_button = True ,
1022
1022
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 ,
1029
1030
** kwargs ,
1030
1031
) -> dict [typing .Literal [
1031
1032
'label' ,
@@ -1076,11 +1077,19 @@ def inputType(type, value):
1076
1077
)
1077
1078
else :
1078
1079
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
+ )
1084
1093
1085
1094
# input.insert(0, value)
1086
1095
@@ -1093,7 +1102,7 @@ def inputType(type, value):
1093
1102
input , var = inputType (t , value [column ])
1094
1103
input .grid (column = column , row = row , sticky = 'ew' , padx = 2 )
1095
1104
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 ))
1097
1106
1098
1107
input .bind ('<Return>' , lambda e : self .focus ())
1099
1108
@@ -1132,11 +1141,11 @@ def inputType(type, value):
1132
1141
if show_button :
1133
1142
button = crossplatform .Button (
1134
1143
self .properties ['right' ],
1135
- text = button_text ,
1136
- width = 2 ,
1144
+ text = button_text ,
1145
+ width = 2 ,
1137
1146
command = button_callback ,
1138
1147
)
1139
- button .grid (column = 2 , row = row )
1148
+ button .grid (column = 2 , row = row )
1140
1149
1141
1150
if button .winfo_reqheight () > row_size :
1142
1151
row_size = button .winfo_reqheight ()
@@ -1145,8 +1154,8 @@ def inputType(type, value):
1145
1154
1146
1155
logging .debug (f'{ row_size = } ' )
1147
1156
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 )
1150
1159
1151
1160
return {
1152
1161
'label' : name ,
@@ -1276,9 +1285,25 @@ def updatePosition(value, column):
1276
1285
1277
1286
# button_callback = lambda *args, prop = property : resetProperty(prop)
1278
1287
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
+
1279
1303
self .objectProperties [property ] = addProperty (
1280
1304
property ,
1281
1305
obj .properties [property ],
1306
+ options = options ,
1282
1307
row = row ,
1283
1308
button_text = button_text ,
1284
1309
label_editable = True ,
@@ -1297,12 +1322,26 @@ def updatePosition(value, column):
1297
1322
self .properties ['scrollFrame' ].resetCanvasScroll ()
1298
1323
1299
1324
def addNewProperty (row ):
1300
-
1301
1325
if isLevel :
1302
1326
properties = {}
1303
1327
else :
1304
1328
properties = deepcopy (obj .defaultProperties )
1305
1329
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
+
1306
1345
for prop in obj .properties :
1307
1346
if prop in properties :
1308
1347
del properties [prop ]
@@ -1312,15 +1351,12 @@ def addNewProperty(row):
1312
1351
'New property' ,
1313
1352
'New property' ,
1314
1353
validate_message = 'Property already exists' ,
1315
- options = list (properties . keys () ),
1354
+ options = sorted (properties ),
1316
1355
validate_callback = lambda name : (name != '' ) and (name not in obj .properties ),
1317
1356
)
1318
1357
1319
1358
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 , '' )
1324
1360
1325
1361
self .updateProperties ()
1326
1362
0 commit comments