MCPcopy Index your code
hub / github.com/RustPython/RustPython / _format_layoutlist

Function _format_layoutlist

Lib/tkinter/ttk.py:140–187  ·  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

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