summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-06-18 18:55:26 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-06-18 18:55:26 (GMT)
commit9c6c3fb4350cdf8064a4c90b84080e6a10adb65b (patch)
tree1f281f0354fb145fca24efce16cf8bcf75d2c5cd /Lib/tkinter
parent45ff4a54871abc01f8251100ad50385835c81b5f (diff)
downloadcpython-9c6c3fb4350cdf8064a4c90b84080e6a10adb65b.zip
cpython-9c6c3fb4350cdf8064a4c90b84080e6a10adb65b.tar.gz
cpython-9c6c3fb4350cdf8064a4c90b84080e6a10adb65b.tar.bz2
Issue #27294: Numerical state in the repr for Tkinter event objects is now
represented as a compination of known flags.
Diffstat (limited to 'Lib/tkinter')
-rw-r--r--Lib/tkinter/__init__.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index c687da5..aaa7d14 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -220,28 +220,41 @@ class Event:
delta - delta of wheel movement (MouseWheel)
"""
def __repr__(self):
- state = {k: v for k, v in self.__dict__.items() if v != '??'}
+ attrs = {k: v for k, v in self.__dict__.items() if v != '??'}
if not self.char:
- del state['char']
+ del attrs['char']
elif self.char != '??':
- state['char'] = repr(self.char)
+ attrs['char'] = repr(self.char)
if not getattr(self, 'send_event', True):
- del state['send_event']
+ del attrs['send_event']
if self.state == 0:
- del state['state']
+ del attrs['state']
+ elif isinstance(self.state, int):
+ state = self.state
+ mods = ('Shift', 'Lock', 'Control',
+ 'Mod1', 'Mod2', 'Mod3', 'Mod4', 'Mod5',
+ 'Button1', 'Button2', 'Button3', 'Button4', 'Button5')
+ s = []
+ for i, n in enumerate(mods):
+ if state & (1 << i):
+ s.append(n)
+ state = state & ~((1<< len(mods)) - 1)
+ if state or not s:
+ s.append(hex(state))
+ attrs['state'] = '|'.join(s)
if self.delta == 0:
- del state['delta']
+ del attrs['delta']
# widget usually is known
# serial and time are not very interesing
# keysym_num duplicates keysym
# x_root and y_root mostly duplicate x and y
keys = ('send_event',
- 'state', 'keycode', 'char', 'keysym',
+ 'state', 'keysym', 'keycode', 'char',
'num', 'delta', 'focus',
'x', 'y', 'width', 'height')
return '<%s event%s>' % (
self.type,
- ''.join(' %s=%s' % (k, state[k]) for k in keys if k in state)
+ ''.join(' %s=%s' % (k, attrs[k]) for k in keys if k in attrs)
)
_support_default_root = 1