Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3..../tkinter
File: ttk.py
# Extensions
[1500] Fix | Delete
[1501] Fix | Delete
class LabeledScale(Frame):
[1502] Fix | Delete
"""A Ttk Scale widget with a Ttk Label widget indicating its
[1503] Fix | Delete
current value.
[1504] Fix | Delete
[1505] Fix | Delete
The Ttk Scale can be accessed through instance.scale, and Ttk Label
[1506] Fix | Delete
can be accessed through instance.label"""
[1507] Fix | Delete
[1508] Fix | Delete
def __init__(self, master=None, variable=None, from_=0, to=10, **kw):
[1509] Fix | Delete
"""Construct a horizontal LabeledScale with parent master, a
[1510] Fix | Delete
variable to be associated with the Ttk Scale widget and its range.
[1511] Fix | Delete
If variable is not specified, a tkinter.IntVar is created.
[1512] Fix | Delete
[1513] Fix | Delete
WIDGET-SPECIFIC OPTIONS
[1514] Fix | Delete
[1515] Fix | Delete
compound: 'top' or 'bottom'
[1516] Fix | Delete
Specifies how to display the label relative to the scale.
[1517] Fix | Delete
Defaults to 'top'.
[1518] Fix | Delete
"""
[1519] Fix | Delete
self._label_top = kw.pop('compound', 'top') == 'top'
[1520] Fix | Delete
[1521] Fix | Delete
Frame.__init__(self, master, **kw)
[1522] Fix | Delete
self._variable = variable or tkinter.IntVar(master)
[1523] Fix | Delete
self._variable.set(from_)
[1524] Fix | Delete
self._last_valid = from_
[1525] Fix | Delete
[1526] Fix | Delete
self.label = Label(self)
[1527] Fix | Delete
self.scale = Scale(self, variable=self._variable, from_=from_, to=to)
[1528] Fix | Delete
self.scale.bind('<<RangeChanged>>', self._adjust)
[1529] Fix | Delete
[1530] Fix | Delete
# position scale and label according to the compound option
[1531] Fix | Delete
scale_side = 'bottom' if self._label_top else 'top'
[1532] Fix | Delete
label_side = 'top' if scale_side == 'bottom' else 'bottom'
[1533] Fix | Delete
self.scale.pack(side=scale_side, fill='x')
[1534] Fix | Delete
# Dummy required to make frame correct height
[1535] Fix | Delete
dummy = Label(self)
[1536] Fix | Delete
dummy.pack(side=label_side)
[1537] Fix | Delete
dummy.lower()
[1538] Fix | Delete
self.label.place(anchor='n' if label_side == 'top' else 's')
[1539] Fix | Delete
[1540] Fix | Delete
# update the label as scale or variable changes
[1541] Fix | Delete
self.__tracecb = self._variable.trace_variable('w', self._adjust)
[1542] Fix | Delete
self.bind('<Configure>', self._adjust)
[1543] Fix | Delete
self.bind('<Map>', self._adjust)
[1544] Fix | Delete
[1545] Fix | Delete
[1546] Fix | Delete
def destroy(self):
[1547] Fix | Delete
"""Destroy this widget and possibly its associated variable."""
[1548] Fix | Delete
try:
[1549] Fix | Delete
self._variable.trace_vdelete('w', self.__tracecb)
[1550] Fix | Delete
except AttributeError:
[1551] Fix | Delete
pass
[1552] Fix | Delete
else:
[1553] Fix | Delete
del self._variable
[1554] Fix | Delete
super().destroy()
[1555] Fix | Delete
self.label = None
[1556] Fix | Delete
self.scale = None
[1557] Fix | Delete
[1558] Fix | Delete
[1559] Fix | Delete
def _adjust(self, *args):
[1560] Fix | Delete
"""Adjust the label position according to the scale."""
[1561] Fix | Delete
def adjust_label():
[1562] Fix | Delete
self.update_idletasks() # "force" scale redraw
[1563] Fix | Delete
[1564] Fix | Delete
x, y = self.scale.coords()
[1565] Fix | Delete
if self._label_top:
[1566] Fix | Delete
y = self.scale.winfo_y() - self.label.winfo_reqheight()
[1567] Fix | Delete
else:
[1568] Fix | Delete
y = self.scale.winfo_reqheight() + self.label.winfo_reqheight()
[1569] Fix | Delete
[1570] Fix | Delete
self.label.place_configure(x=x, y=y)
[1571] Fix | Delete
[1572] Fix | Delete
from_ = _to_number(self.scale['from'])
[1573] Fix | Delete
to = _to_number(self.scale['to'])
[1574] Fix | Delete
if to < from_:
[1575] Fix | Delete
from_, to = to, from_
[1576] Fix | Delete
newval = self._variable.get()
[1577] Fix | Delete
if not from_ <= newval <= to:
[1578] Fix | Delete
# value outside range, set value back to the last valid one
[1579] Fix | Delete
self.value = self._last_valid
[1580] Fix | Delete
return
[1581] Fix | Delete
[1582] Fix | Delete
self._last_valid = newval
[1583] Fix | Delete
self.label['text'] = newval
[1584] Fix | Delete
self.after_idle(adjust_label)
[1585] Fix | Delete
[1586] Fix | Delete
@property
[1587] Fix | Delete
def value(self):
[1588] Fix | Delete
"""Return current scale value."""
[1589] Fix | Delete
return self._variable.get()
[1590] Fix | Delete
[1591] Fix | Delete
@value.setter
[1592] Fix | Delete
def value(self, val):
[1593] Fix | Delete
"""Set new scale value."""
[1594] Fix | Delete
self._variable.set(val)
[1595] Fix | Delete
[1596] Fix | Delete
[1597] Fix | Delete
class OptionMenu(Menubutton):
[1598] Fix | Delete
"""Themed OptionMenu, based after tkinter's OptionMenu, which allows
[1599] Fix | Delete
the user to select a value from a menu."""
[1600] Fix | Delete
[1601] Fix | Delete
def __init__(self, master, variable, default=None, *values, **kwargs):
[1602] Fix | Delete
"""Construct a themed OptionMenu widget with master as the parent,
[1603] Fix | Delete
the resource textvariable set to variable, the initially selected
[1604] Fix | Delete
value specified by the default parameter, the menu values given by
[1605] Fix | Delete
*values and additional keywords.
[1606] Fix | Delete
[1607] Fix | Delete
WIDGET-SPECIFIC OPTIONS
[1608] Fix | Delete
[1609] Fix | Delete
style: stylename
[1610] Fix | Delete
Menubutton style.
[1611] Fix | Delete
direction: 'above', 'below', 'left', 'right', or 'flush'
[1612] Fix | Delete
Menubutton direction.
[1613] Fix | Delete
command: callback
[1614] Fix | Delete
A callback that will be invoked after selecting an item.
[1615] Fix | Delete
"""
[1616] Fix | Delete
kw = {'textvariable': variable, 'style': kwargs.pop('style', None),
[1617] Fix | Delete
'direction': kwargs.pop('direction', None)}
[1618] Fix | Delete
Menubutton.__init__(self, master, **kw)
[1619] Fix | Delete
self['menu'] = tkinter.Menu(self, tearoff=False)
[1620] Fix | Delete
[1621] Fix | Delete
self._variable = variable
[1622] Fix | Delete
self._callback = kwargs.pop('command', None)
[1623] Fix | Delete
if kwargs:
[1624] Fix | Delete
raise tkinter.TclError('unknown option -%s' % (
[1625] Fix | Delete
next(iter(kwargs.keys()))))
[1626] Fix | Delete
[1627] Fix | Delete
self.set_menu(default, *values)
[1628] Fix | Delete
[1629] Fix | Delete
[1630] Fix | Delete
def __getitem__(self, item):
[1631] Fix | Delete
if item == 'menu':
[1632] Fix | Delete
return self.nametowidget(Menubutton.__getitem__(self, item))
[1633] Fix | Delete
[1634] Fix | Delete
return Menubutton.__getitem__(self, item)
[1635] Fix | Delete
[1636] Fix | Delete
[1637] Fix | Delete
def set_menu(self, default=None, *values):
[1638] Fix | Delete
"""Build a new menu of radiobuttons with *values and optionally
[1639] Fix | Delete
a default value."""
[1640] Fix | Delete
menu = self['menu']
[1641] Fix | Delete
menu.delete(0, 'end')
[1642] Fix | Delete
for val in values:
[1643] Fix | Delete
menu.add_radiobutton(label=val,
[1644] Fix | Delete
command=tkinter._setit(self._variable, val, self._callback),
[1645] Fix | Delete
variable=self._variable)
[1646] Fix | Delete
[1647] Fix | Delete
if default:
[1648] Fix | Delete
self._variable.set(default)
[1649] Fix | Delete
[1650] Fix | Delete
[1651] Fix | Delete
def destroy(self):
[1652] Fix | Delete
"""Destroy this widget and its associated variable."""
[1653] Fix | Delete
try:
[1654] Fix | Delete
del self._variable
[1655] Fix | Delete
except AttributeError:
[1656] Fix | Delete
pass
[1657] Fix | Delete
super().destroy()
[1658] Fix | Delete
[1659] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function