MCPcopy Index your code
hub / github.com/python/cpython / _format_layoutlist

Function _format_layoutlist

Lib/tkinter/ttk.py:138–185  ·  view source on GitHub ↗

Formats a layout list so we can pass the result to ttk::style layout and ttk::style settings. Note that the layout doesn't have to be a list necessarily. E.g.: [("Menubutton.background", None), ("Menubutton.button", {"children": [("Menubutton.focus", {"children":

(layout, indent=0, indent_size=2)

Source from the content-addressed store, hash-verified

136
137
138def _format_layoutlist(layout, indent=0, indent_size=2):
139 """Formats a layout list so we can pass the result to ttk::style
140 layout and ttk::style settings. Note that the layout doesn't have to
141 be a list necessarily.
142
143 E.g.:
144 [("Menubutton.background", None),
145 ("Menubutton.button", {"children":
146 [("Menubutton.focus", {"children":
147 [("Menubutton.padding", {"children":
148 [("Menubutton.label", {"side": "left", "expand": 1})]
149 })]
150 })]
151 }),
152 ("Menubutton.indicator", {"side": "right"})
153 ]
154
155 returns:
156
157 Menubutton.background
158 Menubutton.button -children {
159 Menubutton.focus -children {
160 Menubutton.padding -children {
161 Menubutton.label -side left -expand 1
162 }
163 }
164 }
165 Menubutton.indicator -side right"""
166 script = []
167
168 for layout_elem in layout:
169 elem, opts = layout_elem
170 opts = opts or {}
171 fopts = ' '.join(_format_optdict(opts, True, ("children",)))
172 head = "%s%s%s" % (' ' * indent, elem, (" %s" % fopts) if fopts else '')
173
174 if "children" in opts:
175 script.append(head + " -children {")
176 indent += indent_size
177 newscript, indent = _format_layoutlist(opts['children'], indent,
178 indent_size)
179 script.append(newscript)
180 indent -= indent_size
181 script.append('%s}' % (' ' * indent))
182 else:
183 script.append(head)
184
185 return '\n'.join(script), indent
186
187def _script_from_settings(settings):
188 """Returns an appropriate script, based on settings, according to

Callers 2

_script_from_settingsFunction · 0.85
layoutMethod · 0.85

Calls 3

_format_optdictFunction · 0.85
joinMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…