Skip to content

Commit 47a599f

Browse files
committed
update_elements now has a mode to only update elements that are affected by the edit_protect mode
1 parent 9268d89 commit 47a599f

File tree

2 files changed

+49
-46
lines changed

2 files changed

+49
-46
lines changed

PySimpleSQL.py

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ def edit_protect(self,event=None, values=None):
12391239
return
12401240

12411241
self._edit_protect = not self._edit_protect
1242-
self.update_elements()
1242+
self.update_elements(edit_protect_only=True)
12431243

12441244

12451245
def save_records(self, cascade_only=False):
@@ -1275,12 +1275,58 @@ def save_records(self, cascade_only=False):
12751275
self.update_elements()
12761276

12771277

1278-
def update_elements(self, table=''): # table type: str
1278+
def update_elements(self, table='', edit_protect_only=False): # table type: str
12791279
# TODO Fix bug where listbox first element is ghost selected
12801280
# TODO: Dosctring
12811281
logger.info('Updating PySimpleGUI elements...')
12821282
# Update the current values
12831283
# 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+
12841330
for d in self.control_map:
12851331
# If the optional table parameter was passed, we will only update controls bound to that table
12861332
if table != '':
@@ -1409,50 +1455,7 @@ def update_elements(self, table=''): # table type: str
14091455
control.update(values=values,select_rows=index)
14101456
eat_events(self.window)
14111457

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)
14521458

1453-
# Enable/Disable quick edit buttons
1454-
if '.quick_edit' in m['event']:
1455-
win[m['event']].update(disabled=hide)
14561459

14571460

14581461
# Run callbacks

examples/journal_with_data_manipulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
ss.record('Journal.entry', sg.MLine, size=(71,20))
4545
]
4646
win=sg.Window('Journal example', layout, finalize=True)
47-
db=ss.Database('journal.db', win, sql_commands=sql) #<=== Here is the magic!
47+
db=ss.Database(':memory:', win, sql_commands=sql) #<=== Here is the magic!
4848
# Note: sql_commands in only run if journal.db does not exist! This has the effect of creating a new blank
4949
# database as defined by the sql_commands if the database does not yet exist, otherwise it will use the database!
5050

0 commit comments

Comments
 (0)