MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / _BuildKeyDictForWindow

Method _BuildKeyDictForWindow

PySimpleGUI/PySimpleGUI.py:11046–11099  ·  view source on GitHub ↗

Loop through all Rows and all Container Elements for this window and create the keys for all of them. Note that the calls are recursive as all pathes must be walked :param top_window: The highest level of the window :type top_window: (Window) :param window:

(self, top_window, window, key_dict)

Source from the content-addressed store, hash-verified

11044 self.AllKeysDict = self._BuildKeyDictForWindow(self, self, dict)
11045
11046 def _BuildKeyDictForWindow(self, top_window, window, key_dict):
11047 """
11048 Loop through all Rows and all Container Elements for this window and create the keys for all of them.
11049 Note that the calls are recursive as all pathes must be walked
11050
11051 :param top_window: The highest level of the window
11052 :type top_window: (Window)
11053 :param window: The "sub-window" (container element) to be searched
11054 :type window: Column | Frame | TabGroup | Pane | Tab
11055 :param key_dict: The dictionary as it currently stands.... used as part of recursive call
11056 :type key_dict:
11057 :return: (dict) Dictionary filled with all keys in the window
11058 :rtype:
11059 """
11060 for row_num, row in enumerate(window.Rows):
11061 for col_num, element in enumerate(row):
11062 if element.Type == ELEM_TYPE_COLUMN:
11063 key_dict = self._BuildKeyDictForWindow(top_window, element, key_dict)
11064 if element.Type == ELEM_TYPE_FRAME:
11065 key_dict = self._BuildKeyDictForWindow(top_window, element, key_dict)
11066 if element.Type == ELEM_TYPE_TAB_GROUP:
11067 key_dict = self._BuildKeyDictForWindow(top_window, element, key_dict)
11068 if element.Type == ELEM_TYPE_PANE:
11069 key_dict = self._BuildKeyDictForWindow(top_window, element, key_dict)
11070 if element.Type == ELEM_TYPE_TAB:
11071 key_dict = self._BuildKeyDictForWindow(top_window, element, key_dict)
11072 if element.Key is None: # if no key has been assigned.... create one for input elements
11073 if element.Type == ELEM_TYPE_BUTTON:
11074 element.Key = element.ButtonText
11075 elif element.Type == ELEM_TYPE_TAB:
11076 element.Key = element.Title
11077 if element.Type in (ELEM_TYPE_MENUBAR, ELEM_TYPE_BUTTONMENU,
11078 ELEM_TYPE_INPUT_SLIDER, ELEM_TYPE_GRAPH, ELEM_TYPE_IMAGE,
11079 ELEM_TYPE_INPUT_CHECKBOX, ELEM_TYPE_INPUT_LISTBOX, ELEM_TYPE_INPUT_COMBO,
11080 ELEM_TYPE_INPUT_MULTILINE, ELEM_TYPE_INPUT_OPTION_MENU, ELEM_TYPE_INPUT_SPIN,
11081 ELEM_TYPE_INPUT_RADIO, ELEM_TYPE_INPUT_TEXT, ELEM_TYPE_PROGRESS_BAR,
11082 ELEM_TYPE_TABLE, ELEM_TYPE_TREE,
11083 ELEM_TYPE_TAB_GROUP, ELEM_TYPE_SEPARATOR):
11084 element.Key = top_window.DictionaryKeyCounter
11085 top_window.DictionaryKeyCounter += 1
11086 if element.Key is not None:
11087 if element.Key in key_dict.keys():
11088 if element.Type == ELEM_TYPE_BUTTON and WARN_DUPLICATE_BUTTON_KEY_ERRORS: # for Buttons see if should complain
11089 warnings.warn('*** Duplicate key found in your layout {} ***'.format(element.Key), UserWarning)
11090 warnings.warn('*** Replaced new key with {} ***'.format(str(element.Key) + str(self.UniqueKeyCounter)))
11091 if not SUPPRESS_ERROR_POPUPS:
11092 _error_popup_with_traceback('Duplicate key found in your layout', 'Dupliate key: {}'.format(element.Key),
11093 'Is being replaced with: {}'.format(str(element.Key) + str(self.UniqueKeyCounter)),
11094 'The line of code above shows you which layout, but does not tell you exactly where the element was defined',
11095 'The element type is {}'.format(element.Type))
11096 element.Key = str(element.Key) + str(self.UniqueKeyCounter)
11097 self.UniqueKeyCounter += 1
11098 key_dict[element.Key] = element
11099 return key_dict
11100
11101 def element_list(self):
11102 """

Callers 3

extend_layoutMethod · 0.95
_BuildKeyDictMethod · 0.95
add_tabMethod · 0.80

Calls 1

Tested by

no test coverage detected