Manipulate style database.
| 337 | |
| 338 | |
| 339 | class Style(object): |
| 340 | """Manipulate style database.""" |
| 341 | |
| 342 | _name = "ttk::style" |
| 343 | |
| 344 | def __init__(self, master=None): |
| 345 | master = setup_master(master) |
| 346 | self.master = master |
| 347 | self.tk = self.master.tk |
| 348 | |
| 349 | |
| 350 | def configure(self, style, query_opt=None, **kw): |
| 351 | """Query or sets the default value of the specified option(s) in |
| 352 | style. |
| 353 | |
| 354 | Each key in kw is an option and each value is either a string or |
| 355 | a sequence identifying the value for that option.""" |
| 356 | if query_opt is not None: |
| 357 | kw[query_opt] = None |
| 358 | result = _val_or_dict(self.tk, kw, self._name, "configure", style) |
| 359 | if result or query_opt: |
| 360 | return result |
| 361 | |
| 362 | |
| 363 | def map(self, style, query_opt=None, **kw): |
| 364 | """Query or sets dynamic values of the specified option(s) in |
| 365 | style. |
| 366 | |
| 367 | Each key in kw is an option and each value should be a list or a |
| 368 | tuple (usually) containing statespecs grouped in tuples, or list, |
| 369 | or something else of your preference. A statespec is compound of |
| 370 | one or more states and then a value.""" |
| 371 | if query_opt is not None: |
| 372 | result = self.tk.call(self._name, "map", style, '-%s' % query_opt) |
| 373 | return _list_from_statespec(self.tk.splitlist(result)) |
| 374 | |
| 375 | result = self.tk.call(self._name, "map", style, *_format_mapdict(kw)) |
| 376 | return {k: _list_from_statespec(self.tk.splitlist(v)) |
| 377 | for k, v in _splitdict(self.tk, result).items()} |
| 378 | |
| 379 | |
| 380 | def lookup(self, style, option, state=None, default=None): |
| 381 | """Returns the value specified for option in style. |
| 382 | |
| 383 | If state is specified it is expected to be a sequence of one |
| 384 | or more states. If the default argument is set, it is used as |
| 385 | a fallback value in case no specification for option is found.""" |
| 386 | state = ' '.join(state) if state else '' |
| 387 | |
| 388 | return self.tk.call(self._name, "lookup", style, '-%s' % option, |
| 389 | state, default) |
| 390 | |
| 391 | |
| 392 | def layout(self, style, layoutspec=None): |
| 393 | """Define the widget layout for given style. If layoutspec is |
| 394 | omitted, return the layout specification for given style. |
| 395 | |
| 396 | layoutspec is expected to be a list or an object different than |