@@ -3444,17 +3444,46 @@ def __init__(
34443444 self ._list [i ][- 2 ] = header_index
34453445 for n in self ._list :
34463446 logger .error (f'{ n } ' )
3447+ '''
3448+
3449+ # do not read keys.json to self._keys_to_classes
3450+ # use self._precompute_context_map to populate it dynamically
3451+ # keys.json will not be part of the package
3452+
34473453 keys_file = path.join(path.dirname(__file__), 'keyboard', 'keys.json')
34483454 logger.error(f'{keys_file = }')
34493455 with open(keys_file, 'r', encoding='utf-8') as f:
34503456 self._keys_to_classes = json.load(f)
3457+
3458+ '''
34513459 keys_file = path .join (path .dirname (__file__ ), 'keyboard' , 'classes.json' )
3452- logger .error (f'{ keys_file = } ' )
3460+ # logger.error(f'{keys_file = }')
34533461 with open (keys_file , 'r' , encoding = 'utf-8' ) as f :
34543462 self ._classes = json .load (f )
3463+ # logger.error(f'{self._classes = }')
3464+ self ._keys_to_classes = self ._precompute_context_map (self ._classes )
3465+ # logger.error(f'{self._keys_to_classes = }')
34553466 self ._needs_update = False
34563467
34573468
3469+ def _precompute_context_map (self , results ):
3470+ """
3471+ Precompute a map of keys to the classes or contexts they belong to.
3472+
3473+ Args:
3474+ results (dict): The `results` dictionary mapping class names to their keys.
3475+
3476+ Returns:
3477+ dict: A map of keys to their associated contexts.
3478+ """
3479+ context_map = {}
3480+ for class_name , keys in results .items ():
3481+ for key in keys :
3482+ if key not in context_map :
3483+ context_map [key ] = []
3484+ context_map [key ].append (class_name )
3485+ return context_map
3486+
34583487 def item (self , an_item_id = None ):
34593488 logger .debug (f'{ an_item_id = } ' )
34603489 if an_item_id is None :
0 commit comments