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

Function _script_from_settings

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

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

Callers 2

theme_createMethod · 0.85
theme_settingsMethod · 0.85

Calls 10

_format_optdictFunction · 0.85
_format_mapdictFunction · 0.85
_format_layoutlistFunction · 0.85
lenFunction · 0.85
hasattrFunction · 0.85
_format_elemcreateFunction · 0.85
itemsMethod · 0.45
getMethod · 0.45
joinMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected