Returns an appropriate script, based on settings, according to theme_settings definition to be used by theme_settings and theme_create.
(settings)
| 185 | return '\n'.join(script), indent |
| 186 | |
| 187 | def _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 | |
| 229 | def _list_from_statespec(stuple): |
| 230 | """Construct a list from the given statespec tuple according to the |
no test coverage detected
searching dependent graphs…