@@ -162,7 +162,7 @@ def set_callback(self,callback,fctn):
162
162
:param fctn: The function to call. Note, the function must take in two parameters, a @Database instance, and a @PySimpleGUI.Window instance, and return True or False
163
163
:return: None
164
164
"""
165
- callback = callback . lower ()
165
+
166
166
supported = [
167
167
'before_save' , 'after_save' , 'before_delete' , 'after_delete' ,
168
168
'before_update' , 'after_update' , # Aliases for before/after_save
@@ -506,7 +506,7 @@ def add_selector(self, control): # _listBox,_pk,_field):
506
506
# Associate a listbox with this query object. This will be used to select the appropriate record
507
507
# self.selector={'control':_listBox,'pk':_pk,'field':_field}
508
508
509
- if type (control ) not in [sg .PySimpleGUI .Listbox , sg .PySimpleGUI .Slider , sg .Combo ]:
509
+ if type (control ) not in [sg .PySimpleGUI .Listbox , sg .PySimpleGUI .Slider , sg .Combo , sg . Table ]:
510
510
raise RuntimeError (f'add_selector() error: { control } is not a supported control.' )
511
511
512
512
logger .info (f'Adding { control .Key } as a selector for the { self .table } table.' )
@@ -770,19 +770,20 @@ def set_callback(self, callback, fctn):
770
770
:param fctn: The function to call. Note, the function must take in two parameters, a @Database instance, and a @PySimpleGUI.Window instance
771
771
:return: None
772
772
"""
773
- callback = callback .lower ()
774
- supported = [
775
- 'update_controls' , 'edit_enable' , 'edit_disable'
776
- ]
777
- # Add in support fow Window keys
773
+ supported = ['update_controls' , 'edit_enable' , 'edit_disable' ]
778
774
775
+ # Add in mapped controls
779
776
for control in self .control_map :
780
- supported .append (control ['control' ].Key .lower ())
777
+ supported .append (control ['control' ].Key )
778
+
779
+ # Add in other window controls
780
+ for control in self .window .AllKeysDict :
781
+ supported .append (control )
781
782
782
783
if callback in supported :
783
784
self .callbacks [callback ] = fctn
784
785
else :
785
- raise RuntimeError ( f'Callback "{ callback } " not supported.' )
786
+ raise RuntimeError ( f'Callback "{ callback } " not supported. callback: { callback } supported: { supported } ' )
786
787
787
788
def auto_bind (self , win ):
788
789
"""
@@ -1069,9 +1070,10 @@ def update_controls(self,table=''): # table type: str
1069
1070
1070
1071
updated_val = None
1071
1072
1072
- if d ['control' ].Key .lower () in self .callbacks :
1073
- # The user has set a callback for this control, we will use it!
1074
- updated_val = self .callbacks [d ['control' ].Key .lower ()]()
1073
+ # If there is a callback for this control, use it
1074
+ if d ['control' ].Key in self .callbacks :
1075
+ print (f'{ d ["control" ].Key } is in callbacks!' )
1076
+ self .callbacks [d ['control' ].Key ]()
1075
1077
1076
1078
elif type (d ['control' ]) is sg .PySimpleGUI .Combo :
1077
1079
# Update controls with foreign queries first
@@ -1103,32 +1105,33 @@ def update_controls(self,table=''): # table type: str
1103
1105
elif type (d ['control' ]) is sg .PySimpleGUI .Table :
1104
1106
# Tables use an array of arrays for values. Note that the headings can't be changed.
1105
1107
# Generate a new list!
1106
- updated_val = [[]] # List that will contain other lists
1108
+ # List that will contain other lists
1107
1109
# TODO: Fix this with some kind of sane default behavior.
1108
1110
# For now, just use the Database callbacks to handle Tables
1109
-
1111
+ pass
1110
1112
1111
1113
elif type (d ['control' ]) is sg .PySimpleGUI .InputText or type (d ['control' ]) is sg .PySimpleGUI .Multiline :
1112
1114
# Lets now update the control in the GUI
1113
1115
# For text objects, lets clear the field...
1114
1116
d ['control' ].update ('' ) # HACK for sqlite query not making needed keys! This will blank it out at least
1117
+ updated_val = d ['table' ][d ['field' ]]
1115
1118
1116
1119
elif type (d ['control' ]) is sg .PySimpleGUI .Checkbox :
1117
1120
# TODO: FIXME
1118
1121
# d['control'].update(0)
1119
1122
# print('Checkbox...')
1120
- pass
1123
+ updated_val = d [ 'table' ][ d [ 'field' ]]
1121
1124
else :
1122
1125
sg .popup (f'Unknown control type { type (d ["control" ])} ' )
1123
1126
1124
- # If no field has been set, we will get it from the query object
1125
- if not updated_val :
1126
- # print('updatedVal not set...')
1127
- updated_val = d ['table' ][d ['field' ]]
1128
1127
1129
1128
# Finally, we will update the actual GUI control!
1130
- d ['control' ].update (updated_val )
1129
+ if updated_val is not None :
1130
+ d ['control' ].update (updated_val )
1131
1131
1132
+ # ---------
1133
+ # SELECTORS
1134
+ # ---------
1132
1135
# We can update the selector controls
1133
1136
# We do it down here because it's not a mapped control...
1134
1137
# Check for selector events
@@ -1149,6 +1152,12 @@ def update_controls(self,table=''): # table type: str
1149
1152
l = len (table .rows )
1150
1153
control .update (value = table ._current_index + 1 ,range = (1 ,l ))
1151
1154
1155
+ elif type (d ['control' ]) is sg .PySimpleGUI .Table :
1156
+ # Make all the headings
1157
+ for k ,v in enumerate (self .rows ()):
1158
+ print (f'k: { k } ' )
1159
+ print (f'v:{ v } ' )
1160
+
1152
1161
1153
1162
1154
1163
# Enable/Disable controls based on the edit protection button and presence of a record
@@ -1182,7 +1191,7 @@ def update_controls(self,table=''): # table type: str
1182
1191
1183
1192
1184
1193
1185
- # Run callback
1194
+ # Run callbacks
1186
1195
if 'update_controls' in self .callbacks .keys ():
1187
1196
# Running user update function
1188
1197
logger .info ('Running the update_controls callback...' )
@@ -1209,7 +1218,7 @@ def process_events(self, event, values):
1209
1218
for e in self .event_map :
1210
1219
if e ['event' ] == event :
1211
1220
logger .info (f'Executing event { event } via event mapping.' )
1212
- e ['function' ]()
1221
+ e ['function' ](event , values )
1213
1222
return True
1214
1223
1215
1224
# Check for selector events
@@ -1379,6 +1388,15 @@ def selector(table,control=sg.LBox,size=None):
1379
1388
layout = [control (enable_events = True ,size = size or _default_control_size ,orientation = 'h' ,disable_number_display = True ,key = key )]
1380
1389
elif control == sg .Combo :
1381
1390
layout = [control (values = (), size = size or _default_control_size , readonly = True , enable_events = True , key = key ,auto_size_text = False )]
1391
+ elif control == sg .Table :
1392
+ # We have to get header information directly from the sqlite3 database, as the Database class has not been
1393
+ # instanced yet!
1394
+ headings = []
1395
+ q = f'PRAGMA table_info(table);'
1396
+
1397
+ for k ,v in db [table ].rows :
1398
+ headings .append (f'k:{ k } v:{ v } ' )
1399
+ layout = [control (values = ([[1 ,2 ,3 ]]), headings = headings , enable_events = True , key = key )]
1382
1400
else :
1383
1401
raise RuntimeError (f'Control type "{ control } " not supported as a selector.' )
1384
1402
return layout
0 commit comments