@@ -1239,7 +1239,7 @@ def edit_protect(self,event=None, values=None):
1239
1239
return
1240
1240
1241
1241
self ._edit_protect = not self ._edit_protect
1242
- self .update_elements ()
1242
+ self .update_elements (edit_protect_only = True )
1243
1243
1244
1244
1245
1245
def save_records (self , cascade_only = False ):
@@ -1275,12 +1275,58 @@ def save_records(self, cascade_only=False):
1275
1275
self .update_elements ()
1276
1276
1277
1277
1278
- def update_elements (self , table = '' ): # table type: str
1278
+ def update_elements (self , table = '' , edit_protect_only = False ): # table type: str
1279
1279
# TODO Fix bug where listbox first element is ghost selected
1280
1280
# TODO: Dosctring
1281
1281
logger .info ('Updating PySimpleGUI elements...' )
1282
1282
# Update the current values
1283
1283
# d= dictionary (the control map dictionary)
1284
+
1285
+ # Enable/Disable controls based on the edit protection button and presence of a record
1286
+ # Note that we also must disable controls if there are no records!
1287
+ # TODO FIXME!!!
1288
+ win = self .window
1289
+ for e in self .event_map :
1290
+ if '.edit_protect' in e ['event' ]:
1291
+ self .disable_controls (self ._edit_protect )
1292
+
1293
+ # Disable/Enable action elements based on edit_protect or other situations
1294
+ for t in self .tables :
1295
+ for m in self .event_map :
1296
+ # Disable delete and mapped controls for this table if there are no records in this table or edit protect mode
1297
+ hide = len (self [t ].rows ) == 0 or self ._edit_protect
1298
+ if '.table_delete' in m ['event' ]:
1299
+ if m ['table' ] == t :
1300
+ win [m ['event' ]].update (disabled = hide )
1301
+ # self.disable_controls(hide, t)
1302
+
1303
+ # Disable insert on children with no parent records or edit protect mode
1304
+ parent = self .get_parent (t )
1305
+ if parent is not None :
1306
+ hide = len (self [parent ].rows ) == 0 or self ._edit_protect
1307
+ else :
1308
+ hide = self ._edit_protect
1309
+ if '.table_insert' in m ['event' ]:
1310
+ if m ['table' ] == t :
1311
+ win [m ['event' ]].update (disabled = hide )
1312
+ pass
1313
+ # Disable db_save when needed
1314
+ # TODO: Disable when no changes to data?
1315
+ hide = self ._edit_protect
1316
+ if '.db_save' in m ['event' ]:
1317
+ win [m ['event' ]].update (disabled = hide )
1318
+
1319
+ # Disable table_save when needed
1320
+ # TODO: Disable when no changes to data?
1321
+ hide = self ._edit_protect
1322
+ if '.table_save' in m ['event' ]:
1323
+ win [m ['event' ]].update (disabled = hide )
1324
+
1325
+ # Enable/Disable quick edit buttons
1326
+ if '.quick_edit' in m ['event' ]:
1327
+ win [m ['event' ]].update (disabled = hide )
1328
+ if edit_protect_only : return
1329
+
1284
1330
for d in self .control_map :
1285
1331
# If the optional table parameter was passed, we will only update controls bound to that table
1286
1332
if table != '' :
@@ -1409,50 +1455,7 @@ def update_elements(self, table=''): # table type: str
1409
1455
control .update (values = values ,select_rows = index )
1410
1456
eat_events (self .window )
1411
1457
1412
- # Enable/Disable controls based on the edit protection button and presence of a record
1413
- # Note that we also must disable controls if there are no records!
1414
- # TODO FIXME!!!
1415
- win = self .window
1416
- for e in self .event_map :
1417
- if '.edit_protect' in e ['event' ]:
1418
- self .disable_controls (self ._edit_protect )
1419
-
1420
-
1421
- # Disable/Enable action elements based on edit_protect or other situations
1422
- for t in self .tables :
1423
- for m in self .event_map :
1424
- # Disable delete and mapped controls for this table if there are no records in this table or edit protect mode
1425
- hide = len (self [t ].rows ) == 0 or self ._edit_protect
1426
- if '.table_delete' in m ['event' ]:
1427
- if m ['table' ] == t :
1428
- win [m ['event' ]].update (disabled = hide )
1429
- #self.disable_controls(hide, t)
1430
-
1431
- # Disable insert on children with no parent records or edit protect mode
1432
- parent = self .get_parent (t )
1433
- if parent is not None :
1434
- hide = len (self [parent ].rows )== 0 or self ._edit_protect
1435
- else :
1436
- hide = self ._edit_protect
1437
- if '.table_insert' in m ['event' ]:
1438
- if m ['table' ] == t :
1439
- win [m ['event' ]].update (disabled = hide )
1440
- pass
1441
- # Disable db_save when needed
1442
- # TODO: Disable when no changes to data?
1443
- hide = self ._edit_protect
1444
- if '.db_save' in m ['event' ]:
1445
- win [m ['event' ]].update (disabled = hide )
1446
-
1447
- # Disable table_save when needed
1448
- # TODO: Disable when no changes to data?
1449
- hide = self ._edit_protect
1450
- if '.table_save' in m ['event' ]:
1451
- win [m ['event' ]].update (disabled = hide )
1452
1458
1453
- # Enable/Disable quick edit buttons
1454
- if '.quick_edit' in m ['event' ]:
1455
- win [m ['event' ]].update (disabled = hide )
1456
1459
1457
1460
1458
1461
# Run callbacks
0 commit comments