Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3..../tkinter
File: ttk.py
"""Ttk wrapper.
[0] Fix | Delete
[1] Fix | Delete
This module provides classes to allow using Tk themed widget set.
[2] Fix | Delete
[3] Fix | Delete
Ttk is based on a revised and enhanced version of
[4] Fix | Delete
TIP #48 (http://tip.tcl.tk/48) specified style engine.
[5] Fix | Delete
[6] Fix | Delete
Its basic idea is to separate, to the extent possible, the code
[7] Fix | Delete
implementing a widget's behavior from the code implementing its
[8] Fix | Delete
appearance. Widget class bindings are primarily responsible for
[9] Fix | Delete
maintaining the widget state and invoking callbacks, all aspects
[10] Fix | Delete
of the widgets appearance lies at Themes.
[11] Fix | Delete
"""
[12] Fix | Delete
[13] Fix | Delete
__version__ = "0.3.1"
[14] Fix | Delete
[15] Fix | Delete
__author__ = "Guilherme Polo <ggpolo@gmail.com>"
[16] Fix | Delete
[17] Fix | Delete
__all__ = ["Button", "Checkbutton", "Combobox", "Entry", "Frame", "Label",
[18] Fix | Delete
"Labelframe", "LabelFrame", "Menubutton", "Notebook", "Panedwindow",
[19] Fix | Delete
"PanedWindow", "Progressbar", "Radiobutton", "Scale", "Scrollbar",
[20] Fix | Delete
"Separator", "Sizegrip", "Spinbox", "Style", "Treeview",
[21] Fix | Delete
# Extensions
[22] Fix | Delete
"LabeledScale", "OptionMenu",
[23] Fix | Delete
# functions
[24] Fix | Delete
"tclobjs_to_py", "setup_master"]
[25] Fix | Delete
[26] Fix | Delete
import tkinter
[27] Fix | Delete
from tkinter import _flatten, _join, _stringify, _splitdict
[28] Fix | Delete
[29] Fix | Delete
# Verify if Tk is new enough to not need the Tile package
[30] Fix | Delete
_REQUIRE_TILE = True if tkinter.TkVersion < 8.5 else False
[31] Fix | Delete
[32] Fix | Delete
def _load_tile(master):
[33] Fix | Delete
if _REQUIRE_TILE:
[34] Fix | Delete
import os
[35] Fix | Delete
tilelib = os.environ.get('TILE_LIBRARY')
[36] Fix | Delete
if tilelib:
[37] Fix | Delete
# append custom tile path to the list of directories that
[38] Fix | Delete
# Tcl uses when attempting to resolve packages with the package
[39] Fix | Delete
# command
[40] Fix | Delete
master.tk.eval(
[41] Fix | Delete
'global auto_path; '
[42] Fix | Delete
'lappend auto_path {%s}' % tilelib)
[43] Fix | Delete
[44] Fix | Delete
master.tk.eval('package require tile') # TclError may be raised here
[45] Fix | Delete
master._tile_loaded = True
[46] Fix | Delete
[47] Fix | Delete
def _format_optvalue(value, script=False):
[48] Fix | Delete
"""Internal function."""
[49] Fix | Delete
if script:
[50] Fix | Delete
# if caller passes a Tcl script to tk.call, all the values need to
[51] Fix | Delete
# be grouped into words (arguments to a command in Tcl dialect)
[52] Fix | Delete
value = _stringify(value)
[53] Fix | Delete
elif isinstance(value, (list, tuple)):
[54] Fix | Delete
value = _join(value)
[55] Fix | Delete
return value
[56] Fix | Delete
[57] Fix | Delete
def _format_optdict(optdict, script=False, ignore=None):
[58] Fix | Delete
"""Formats optdict to a tuple to pass it to tk.call.
[59] Fix | Delete
[60] Fix | Delete
E.g. (script=False):
[61] Fix | Delete
{'foreground': 'blue', 'padding': [1, 2, 3, 4]} returns:
[62] Fix | Delete
('-foreground', 'blue', '-padding', '1 2 3 4')"""
[63] Fix | Delete
[64] Fix | Delete
opts = []
[65] Fix | Delete
for opt, value in optdict.items():
[66] Fix | Delete
if not ignore or opt not in ignore:
[67] Fix | Delete
opts.append("-%s" % opt)
[68] Fix | Delete
if value is not None:
[69] Fix | Delete
opts.append(_format_optvalue(value, script))
[70] Fix | Delete
[71] Fix | Delete
return _flatten(opts)
[72] Fix | Delete
[73] Fix | Delete
def _mapdict_values(items):
[74] Fix | Delete
# each value in mapdict is expected to be a sequence, where each item
[75] Fix | Delete
# is another sequence containing a state (or several) and a value
[76] Fix | Delete
# E.g. (script=False):
[77] Fix | Delete
# [('active', 'selected', 'grey'), ('focus', [1, 2, 3, 4])]
[78] Fix | Delete
# returns:
[79] Fix | Delete
# ['active selected', 'grey', 'focus', [1, 2, 3, 4]]
[80] Fix | Delete
opt_val = []
[81] Fix | Delete
for *state, val in items:
[82] Fix | Delete
if len(state) == 1:
[83] Fix | Delete
# if it is empty (something that evaluates to False), then
[84] Fix | Delete
# format it to Tcl code to denote the "normal" state
[85] Fix | Delete
state = state[0] or ''
[86] Fix | Delete
else:
[87] Fix | Delete
# group multiple states
[88] Fix | Delete
state = ' '.join(state) # raise TypeError if not str
[89] Fix | Delete
opt_val.append(state)
[90] Fix | Delete
if val is not None:
[91] Fix | Delete
opt_val.append(val)
[92] Fix | Delete
return opt_val
[93] Fix | Delete
[94] Fix | Delete
def _format_mapdict(mapdict, script=False):
[95] Fix | Delete
"""Formats mapdict to pass it to tk.call.
[96] Fix | Delete
[97] Fix | Delete
E.g. (script=False):
[98] Fix | Delete
{'expand': [('active', 'selected', 'grey'), ('focus', [1, 2, 3, 4])]}
[99] Fix | Delete
[100] Fix | Delete
returns:
[101] Fix | Delete
[102] Fix | Delete
('-expand', '{active selected} grey focus {1, 2, 3, 4}')"""
[103] Fix | Delete
[104] Fix | Delete
opts = []
[105] Fix | Delete
for opt, value in mapdict.items():
[106] Fix | Delete
opts.extend(("-%s" % opt,
[107] Fix | Delete
_format_optvalue(_mapdict_values(value), script)))
[108] Fix | Delete
[109] Fix | Delete
return _flatten(opts)
[110] Fix | Delete
[111] Fix | Delete
def _format_elemcreate(etype, script=False, *args, **kw):
[112] Fix | Delete
"""Formats args and kw according to the given element factory etype."""
[113] Fix | Delete
spec = None
[114] Fix | Delete
opts = ()
[115] Fix | Delete
if etype in ("image", "vsapi"):
[116] Fix | Delete
if etype == "image": # define an element based on an image
[117] Fix | Delete
# first arg should be the default image name
[118] Fix | Delete
iname = args[0]
[119] Fix | Delete
# next args, if any, are statespec/value pairs which is almost
[120] Fix | Delete
# a mapdict, but we just need the value
[121] Fix | Delete
imagespec = _join(_mapdict_values(args[1:]))
[122] Fix | Delete
spec = "%s %s" % (iname, imagespec)
[123] Fix | Delete
[124] Fix | Delete
else:
[125] Fix | Delete
# define an element whose visual appearance is drawn using the
[126] Fix | Delete
# Microsoft Visual Styles API which is responsible for the
[127] Fix | Delete
# themed styles on Windows XP and Vista.
[128] Fix | Delete
# Availability: Tk 8.6, Windows XP and Vista.
[129] Fix | Delete
class_name, part_id = args[:2]
[130] Fix | Delete
statemap = _join(_mapdict_values(args[2:]))
[131] Fix | Delete
spec = "%s %s %s" % (class_name, part_id, statemap)
[132] Fix | Delete
[133] Fix | Delete
opts = _format_optdict(kw, script)
[134] Fix | Delete
[135] Fix | Delete
elif etype == "from": # clone an element
[136] Fix | Delete
# it expects a themename and optionally an element to clone from,
[137] Fix | Delete
# otherwise it will clone {} (empty element)
[138] Fix | Delete
spec = args[0] # theme name
[139] Fix | Delete
if len(args) > 1: # elementfrom specified
[140] Fix | Delete
opts = (_format_optvalue(args[1], script),)
[141] Fix | Delete
[142] Fix | Delete
if script:
[143] Fix | Delete
spec = '{%s}' % spec
[144] Fix | Delete
opts = ' '.join(opts)
[145] Fix | Delete
[146] Fix | Delete
return spec, opts
[147] Fix | Delete
[148] Fix | Delete
def _format_layoutlist(layout, indent=0, indent_size=2):
[149] Fix | Delete
"""Formats a layout list so we can pass the result to ttk::style
[150] Fix | Delete
layout and ttk::style settings. Note that the layout doesn't have to
[151] Fix | Delete
be a list necessarily.
[152] Fix | Delete
[153] Fix | Delete
E.g.:
[154] Fix | Delete
[("Menubutton.background", None),
[155] Fix | Delete
("Menubutton.button", {"children":
[156] Fix | Delete
[("Menubutton.focus", {"children":
[157] Fix | Delete
[("Menubutton.padding", {"children":
[158] Fix | Delete
[("Menubutton.label", {"side": "left", "expand": 1})]
[159] Fix | Delete
})]
[160] Fix | Delete
})]
[161] Fix | Delete
}),
[162] Fix | Delete
("Menubutton.indicator", {"side": "right"})
[163] Fix | Delete
]
[164] Fix | Delete
[165] Fix | Delete
returns:
[166] Fix | Delete
[167] Fix | Delete
Menubutton.background
[168] Fix | Delete
Menubutton.button -children {
[169] Fix | Delete
Menubutton.focus -children {
[170] Fix | Delete
Menubutton.padding -children {
[171] Fix | Delete
Menubutton.label -side left -expand 1
[172] Fix | Delete
}
[173] Fix | Delete
}
[174] Fix | Delete
}
[175] Fix | Delete
Menubutton.indicator -side right"""
[176] Fix | Delete
script = []
[177] Fix | Delete
[178] Fix | Delete
for layout_elem in layout:
[179] Fix | Delete
elem, opts = layout_elem
[180] Fix | Delete
opts = opts or {}
[181] Fix | Delete
fopts = ' '.join(_format_optdict(opts, True, ("children",)))
[182] Fix | Delete
head = "%s%s%s" % (' ' * indent, elem, (" %s" % fopts) if fopts else '')
[183] Fix | Delete
[184] Fix | Delete
if "children" in opts:
[185] Fix | Delete
script.append(head + " -children {")
[186] Fix | Delete
indent += indent_size
[187] Fix | Delete
newscript, indent = _format_layoutlist(opts['children'], indent,
[188] Fix | Delete
indent_size)
[189] Fix | Delete
script.append(newscript)
[190] Fix | Delete
indent -= indent_size
[191] Fix | Delete
script.append('%s}' % (' ' * indent))
[192] Fix | Delete
else:
[193] Fix | Delete
script.append(head)
[194] Fix | Delete
[195] Fix | Delete
return '\n'.join(script), indent
[196] Fix | Delete
[197] Fix | Delete
def _script_from_settings(settings):
[198] Fix | Delete
"""Returns an appropriate script, based on settings, according to
[199] Fix | Delete
theme_settings definition to be used by theme_settings and
[200] Fix | Delete
theme_create."""
[201] Fix | Delete
script = []
[202] Fix | Delete
# a script will be generated according to settings passed, which
[203] Fix | Delete
# will then be evaluated by Tcl
[204] Fix | Delete
for name, opts in settings.items():
[205] Fix | Delete
# will format specific keys according to Tcl code
[206] Fix | Delete
if opts.get('configure'): # format 'configure'
[207] Fix | Delete
s = ' '.join(_format_optdict(opts['configure'], True))
[208] Fix | Delete
script.append("ttk::style configure %s %s;" % (name, s))
[209] Fix | Delete
[210] Fix | Delete
if opts.get('map'): # format 'map'
[211] Fix | Delete
s = ' '.join(_format_mapdict(opts['map'], True))
[212] Fix | Delete
script.append("ttk::style map %s %s;" % (name, s))
[213] Fix | Delete
[214] Fix | Delete
if 'layout' in opts: # format 'layout' which may be empty
[215] Fix | Delete
if not opts['layout']:
[216] Fix | Delete
s = 'null' # could be any other word, but this one makes sense
[217] Fix | Delete
else:
[218] Fix | Delete
s, _ = _format_layoutlist(opts['layout'])
[219] Fix | Delete
script.append("ttk::style layout %s {\n%s\n}" % (name, s))
[220] Fix | Delete
[221] Fix | Delete
if opts.get('element create'): # format 'element create'
[222] Fix | Delete
eopts = opts['element create']
[223] Fix | Delete
etype = eopts[0]
[224] Fix | Delete
[225] Fix | Delete
# find where args end, and where kwargs start
[226] Fix | Delete
argc = 1 # etype was the first one
[227] Fix | Delete
while argc < len(eopts) and not hasattr(eopts[argc], 'items'):
[228] Fix | Delete
argc += 1
[229] Fix | Delete
[230] Fix | Delete
elemargs = eopts[1:argc]
[231] Fix | Delete
elemkw = eopts[argc] if argc < len(eopts) and eopts[argc] else {}
[232] Fix | Delete
spec, opts = _format_elemcreate(etype, True, *elemargs, **elemkw)
[233] Fix | Delete
[234] Fix | Delete
script.append("ttk::style element create %s %s %s %s" % (
[235] Fix | Delete
name, etype, spec, opts))
[236] Fix | Delete
[237] Fix | Delete
return '\n'.join(script)
[238] Fix | Delete
[239] Fix | Delete
def _list_from_statespec(stuple):
[240] Fix | Delete
"""Construct a list from the given statespec tuple according to the
[241] Fix | Delete
accepted statespec accepted by _format_mapdict."""
[242] Fix | Delete
if isinstance(stuple, str):
[243] Fix | Delete
return stuple
[244] Fix | Delete
result = []
[245] Fix | Delete
it = iter(stuple)
[246] Fix | Delete
for state, val in zip(it, it):
[247] Fix | Delete
if hasattr(state, 'typename'): # this is a Tcl object
[248] Fix | Delete
state = str(state).split()
[249] Fix | Delete
elif isinstance(state, str):
[250] Fix | Delete
state = state.split()
[251] Fix | Delete
elif not isinstance(state, (tuple, list)):
[252] Fix | Delete
state = (state,)
[253] Fix | Delete
if hasattr(val, 'typename'):
[254] Fix | Delete
val = str(val)
[255] Fix | Delete
result.append((*state, val))
[256] Fix | Delete
[257] Fix | Delete
return result
[258] Fix | Delete
[259] Fix | Delete
def _list_from_layouttuple(tk, ltuple):
[260] Fix | Delete
"""Construct a list from the tuple returned by ttk::layout, this is
[261] Fix | Delete
somewhat the reverse of _format_layoutlist."""
[262] Fix | Delete
ltuple = tk.splitlist(ltuple)
[263] Fix | Delete
res = []
[264] Fix | Delete
[265] Fix | Delete
indx = 0
[266] Fix | Delete
while indx < len(ltuple):
[267] Fix | Delete
name = ltuple[indx]
[268] Fix | Delete
opts = {}
[269] Fix | Delete
res.append((name, opts))
[270] Fix | Delete
indx += 1
[271] Fix | Delete
[272] Fix | Delete
while indx < len(ltuple): # grab name's options
[273] Fix | Delete
opt, val = ltuple[indx:indx + 2]
[274] Fix | Delete
if not opt.startswith('-'): # found next name
[275] Fix | Delete
break
[276] Fix | Delete
[277] Fix | Delete
opt = opt[1:] # remove the '-' from the option
[278] Fix | Delete
indx += 2
[279] Fix | Delete
[280] Fix | Delete
if opt == 'children':
[281] Fix | Delete
val = _list_from_layouttuple(tk, val)
[282] Fix | Delete
[283] Fix | Delete
opts[opt] = val
[284] Fix | Delete
[285] Fix | Delete
return res
[286] Fix | Delete
[287] Fix | Delete
def _val_or_dict(tk, options, *args):
[288] Fix | Delete
"""Format options then call Tk command with args and options and return
[289] Fix | Delete
the appropriate result.
[290] Fix | Delete
[291] Fix | Delete
If no option is specified, a dict is returned. If an option is
[292] Fix | Delete
specified with the None value, the value for that option is returned.
[293] Fix | Delete
Otherwise, the function just sets the passed options and the caller
[294] Fix | Delete
shouldn't be expecting a return value anyway."""
[295] Fix | Delete
options = _format_optdict(options)
[296] Fix | Delete
res = tk.call(*(args + options))
[297] Fix | Delete
[298] Fix | Delete
if len(options) % 2: # option specified without a value, return its value
[299] Fix | Delete
return res
[300] Fix | Delete
[301] Fix | Delete
return _splitdict(tk, res, conv=_tclobj_to_py)
[302] Fix | Delete
[303] Fix | Delete
def _convert_stringval(value):
[304] Fix | Delete
"""Converts a value to, hopefully, a more appropriate Python object."""
[305] Fix | Delete
value = str(value)
[306] Fix | Delete
try:
[307] Fix | Delete
value = int(value)
[308] Fix | Delete
except (ValueError, TypeError):
[309] Fix | Delete
pass
[310] Fix | Delete
[311] Fix | Delete
return value
[312] Fix | Delete
[313] Fix | Delete
def _to_number(x):
[314] Fix | Delete
if isinstance(x, str):
[315] Fix | Delete
if '.' in x:
[316] Fix | Delete
x = float(x)
[317] Fix | Delete
else:
[318] Fix | Delete
x = int(x)
[319] Fix | Delete
return x
[320] Fix | Delete
[321] Fix | Delete
def _tclobj_to_py(val):
[322] Fix | Delete
"""Return value converted from Tcl object to Python object."""
[323] Fix | Delete
if val and hasattr(val, '__len__') and not isinstance(val, str):
[324] Fix | Delete
if getattr(val[0], 'typename', None) == 'StateSpec':
[325] Fix | Delete
val = _list_from_statespec(val)
[326] Fix | Delete
else:
[327] Fix | Delete
val = list(map(_convert_stringval, val))
[328] Fix | Delete
[329] Fix | Delete
elif hasattr(val, 'typename'): # some other (single) Tcl object
[330] Fix | Delete
val = _convert_stringval(val)
[331] Fix | Delete
[332] Fix | Delete
return val
[333] Fix | Delete
[334] Fix | Delete
def tclobjs_to_py(adict):
[335] Fix | Delete
"""Returns adict with its values converted from Tcl objects to Python
[336] Fix | Delete
objects."""
[337] Fix | Delete
for opt, val in adict.items():
[338] Fix | Delete
adict[opt] = _tclobj_to_py(val)
[339] Fix | Delete
[340] Fix | Delete
return adict
[341] Fix | Delete
[342] Fix | Delete
def setup_master(master=None):
[343] Fix | Delete
"""If master is not None, itself is returned. If master is None,
[344] Fix | Delete
the default master is returned if there is one, otherwise a new
[345] Fix | Delete
master is created and returned.
[346] Fix | Delete
[347] Fix | Delete
If it is not allowed to use the default root and master is None,
[348] Fix | Delete
RuntimeError is raised."""
[349] Fix | Delete
if master is None:
[350] Fix | Delete
master = tkinter._get_default_root()
[351] Fix | Delete
return master
[352] Fix | Delete
[353] Fix | Delete
[354] Fix | Delete
class Style(object):
[355] Fix | Delete
"""Manipulate style database."""
[356] Fix | Delete
[357] Fix | Delete
_name = "ttk::style"
[358] Fix | Delete
[359] Fix | Delete
def __init__(self, master=None):
[360] Fix | Delete
master = setup_master(master)
[361] Fix | Delete
[362] Fix | Delete
if not getattr(master, '_tile_loaded', False):
[363] Fix | Delete
# Load tile now, if needed
[364] Fix | Delete
_load_tile(master)
[365] Fix | Delete
[366] Fix | Delete
self.master = master
[367] Fix | Delete
self.tk = self.master.tk
[368] Fix | Delete
[369] Fix | Delete
[370] Fix | Delete
def configure(self, style, query_opt=None, **kw):
[371] Fix | Delete
"""Query or sets the default value of the specified option(s) in
[372] Fix | Delete
style.
[373] Fix | Delete
[374] Fix | Delete
Each key in kw is an option and each value is either a string or
[375] Fix | Delete
a sequence identifying the value for that option."""
[376] Fix | Delete
if query_opt is not None:
[377] Fix | Delete
kw[query_opt] = None
[378] Fix | Delete
result = _val_or_dict(self.tk, kw, self._name, "configure", style)
[379] Fix | Delete
if result or query_opt:
[380] Fix | Delete
return result
[381] Fix | Delete
[382] Fix | Delete
[383] Fix | Delete
def map(self, style, query_opt=None, **kw):
[384] Fix | Delete
"""Query or sets dynamic values of the specified option(s) in
[385] Fix | Delete
style.
[386] Fix | Delete
[387] Fix | Delete
Each key in kw is an option and each value should be a list or a
[388] Fix | Delete
tuple (usually) containing statespecs grouped in tuples, or list,
[389] Fix | Delete
or something else of your preference. A statespec is compound of
[390] Fix | Delete
one or more states and then a value."""
[391] Fix | Delete
if query_opt is not None:
[392] Fix | Delete
result = self.tk.call(self._name, "map", style, '-%s' % query_opt)
[393] Fix | Delete
return _list_from_statespec(self.tk.splitlist(result))
[394] Fix | Delete
[395] Fix | Delete
result = self.tk.call(self._name, "map", style, *_format_mapdict(kw))
[396] Fix | Delete
return {k: _list_from_statespec(self.tk.splitlist(v))
[397] Fix | Delete
for k, v in _splitdict(self.tk, result).items()}
[398] Fix | Delete
[399] Fix | Delete
[400] Fix | Delete
def lookup(self, style, option, state=None, default=None):
[401] Fix | Delete
"""Returns the value specified for option in style.
[402] Fix | Delete
[403] Fix | Delete
If state is specified it is expected to be a sequence of one
[404] Fix | Delete
or more states. If the default argument is set, it is used as
[405] Fix | Delete
a fallback value in case no specification for option is found."""
[406] Fix | Delete
state = ' '.join(state) if state else ''
[407] Fix | Delete
[408] Fix | Delete
return self.tk.call(self._name, "lookup", style, '-%s' % option,
[409] Fix | Delete
state, default)
[410] Fix | Delete
[411] Fix | Delete
[412] Fix | Delete
def layout(self, style, layoutspec=None):
[413] Fix | Delete
"""Define the widget layout for given style. If layoutspec is
[414] Fix | Delete
omitted, return the layout specification for given style.
[415] Fix | Delete
[416] Fix | Delete
layoutspec is expected to be a list or an object different than
[417] Fix | Delete
None that evaluates to False if you want to "turn off" that style.
[418] Fix | Delete
If it is a list (or tuple, or something else), each item should be
[419] Fix | Delete
a tuple where the first item is the layout name and the second item
[420] Fix | Delete
should have the format described below:
[421] Fix | Delete
[422] Fix | Delete
LAYOUTS
[423] Fix | Delete
[424] Fix | Delete
A layout can contain the value None, if takes no options, or
[425] Fix | Delete
a dict of options specifying how to arrange the element.
[426] Fix | Delete
The layout mechanism uses a simplified version of the pack
[427] Fix | Delete
geometry manager: given an initial cavity, each element is
[428] Fix | Delete
allocated a parcel. Valid options/values are:
[429] Fix | Delete
[430] Fix | Delete
side: whichside
[431] Fix | Delete
Specifies which side of the cavity to place the
[432] Fix | Delete
element; one of top, right, bottom or left. If
[433] Fix | Delete
omitted, the element occupies the entire cavity.
[434] Fix | Delete
[435] Fix | Delete
sticky: nswe
[436] Fix | Delete
Specifies where the element is placed inside its
[437] Fix | Delete
allocated parcel.
[438] Fix | Delete
[439] Fix | Delete
children: [sublayout... ]
[440] Fix | Delete
Specifies a list of elements to place inside the
[441] Fix | Delete
element. Each element is a tuple (or other sequence)
[442] Fix | Delete
where the first item is the layout name, and the other
[443] Fix | Delete
is a LAYOUT."""
[444] Fix | Delete
lspec = None
[445] Fix | Delete
if layoutspec:
[446] Fix | Delete
lspec = _format_layoutlist(layoutspec)[0]
[447] Fix | Delete
elif layoutspec is not None: # will disable the layout ({}, '', etc)
[448] Fix | Delete
lspec = "null" # could be any other word, but this may make sense
[449] Fix | Delete
# when calling layout(style) later
[450] Fix | Delete
[451] Fix | Delete
return _list_from_layouttuple(self.tk,
[452] Fix | Delete
self.tk.call(self._name, "layout", style, lspec))
[453] Fix | Delete
[454] Fix | Delete
[455] Fix | Delete
def element_create(self, elementname, etype, *args, **kw):
[456] Fix | Delete
"""Create a new element in the current theme of given etype."""
[457] Fix | Delete
spec, opts = _format_elemcreate(etype, False, *args, **kw)
[458] Fix | Delete
self.tk.call(self._name, "element", "create", elementname, etype,
[459] Fix | Delete
spec, *opts)
[460] Fix | Delete
[461] Fix | Delete
[462] Fix | Delete
def element_names(self):
[463] Fix | Delete
"""Returns the list of elements defined in the current theme."""
[464] Fix | Delete
return tuple(n.lstrip('-') for n in self.tk.splitlist(
[465] Fix | Delete
self.tk.call(self._name, "element", "names")))
[466] Fix | Delete
[467] Fix | Delete
[468] Fix | Delete
def element_options(self, elementname):
[469] Fix | Delete
"""Return the list of elementname's options."""
[470] Fix | Delete
return tuple(o.lstrip('-') for o in self.tk.splitlist(
[471] Fix | Delete
self.tk.call(self._name, "element", "options", elementname)))
[472] Fix | Delete
[473] Fix | Delete
[474] Fix | Delete
def theme_create(self, themename, parent=None, settings=None):
[475] Fix | Delete
"""Creates a new theme.
[476] Fix | Delete
[477] Fix | Delete
It is an error if themename already exists. If parent is
[478] Fix | Delete
specified, the new theme will inherit styles, elements and
[479] Fix | Delete
layouts from the specified parent theme. If settings are present,
[480] Fix | Delete
they are expected to have the same syntax used for theme_settings."""
[481] Fix | Delete
script = _script_from_settings(settings) if settings else ''
[482] Fix | Delete
[483] Fix | Delete
if parent:
[484] Fix | Delete
self.tk.call(self._name, "theme", "create", themename,
[485] Fix | Delete
"-parent", parent, "-settings", script)
[486] Fix | Delete
else:
[487] Fix | Delete
self.tk.call(self._name, "theme", "create", themename,
[488] Fix | Delete
"-settings", script)
[489] Fix | Delete
[490] Fix | Delete
[491] Fix | Delete
def theme_settings(self, themename, settings):
[492] Fix | Delete
"""Temporarily sets the current theme to themename, apply specified
[493] Fix | Delete
settings and then restore the previous theme.
[494] Fix | Delete
[495] Fix | Delete
Each key in settings is a style and each value may contain the
[496] Fix | Delete
keys 'configure', 'map', 'layout' and 'element create' and they
[497] Fix | Delete
are expected to have the same format as specified by the methods
[498] Fix | Delete
configure, map, layout and element_create respectively."""
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function