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

Function _script_from_settings

Lib/tkinter/ttk.py:187–227  ·  view source on GitHub ↗

Returns an appropriate script, based on settings, according to theme_settings definition to be used by theme_settings and theme_create.

(settings)

Source from the content-addressed store, hash-verified

185 return '\n'.join(script), indent
186
187def _script_from_settings(settings):
188 """Returns an appropriate script, based on settings, according to
189 theme_settings definition to be used by theme_settings and
190 theme_create."""
191 script = []
192 # a script will be generated according to settings passed, which
193 # will then be evaluated by Tcl
194 for name, opts in settings.items():
195 # will format specific keys according to Tcl code
196 if opts.get('configure'): # format 'configure'
197 s = ' '.join(_format_optdict(opts['configure'], True))
198 script.append("ttk::style configure %s %s;" % (name, s))
199
200 if opts.get('map'): # format 'map'
201 s = ' '.join(_format_mapdict(opts['map'], True))
202 script.append("ttk::style map %s %s;" % (name, s))
203
204 if 'layout' in opts: # format 'layout' which may be empty
205 if not opts['layout']:
206 s = 'null' # could be any other word, but this one makes sense
207 else:
208 s, _ = _format_layoutlist(opts['layout'])
209 script.append("ttk::style layout %s {\n%s\n}" % (name, s))
210
211 if opts.get('element create'): # format 'element create'
212 eopts = opts['element create']
213 etype = eopts[0]
214
215 # find where args end, and where kwargs start
216 argc = 1 # etype was the first one
217 while argc < len(eopts) and not hasattr(eopts[argc], 'items'):
218 argc += 1
219
220 elemargs = eopts[1:argc]
221 elemkw = eopts[argc] if argc < len(eopts) and eopts[argc] else {}
222 specs, eopts = _format_elemcreate(etype, True, *elemargs, **elemkw)
223
224 script.append("ttk::style element create %s %s %s %s" % (
225 name, etype, specs, eopts))
226
227 return '\n'.join(script)
228
229def _list_from_statespec(stuple):
230 """Construct a list from the given statespec tuple according to the

Callers 2

theme_createMethod · 0.85
theme_settingsMethod · 0.85

Calls 8

_format_optdictFunction · 0.85
_format_mapdictFunction · 0.85
_format_layoutlistFunction · 0.85
_format_elemcreateFunction · 0.85
itemsMethod · 0.45
getMethod · 0.45
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…