Skip to content

Commit 44913e5

Browse files
authored
bpo-21519: IDLE basic custom key entry better detects duplicates. (#2428)
1 parent 213ce12 commit 44913e5

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

Lib/idlelib/config_key.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ def KeysOK(self, keys):
250250
'''
251251
finalKey = self.listKeysFinal.get(ANCHOR)
252252
modifiers = self.GetModifiers()
253-
# create a key sequence list for overlap check:
254-
keySequence = keys.split()
255253
keysOK = False
256254
title = self.keyerror_title
255+
key_sequences = [key for keylist in self.currentKeySequences
256+
for key in keylist]
257257
if not keys.endswith('>'):
258258
self.showerror(title, parent=self,
259259
message='Missing the final Key')
@@ -267,7 +267,7 @@ def KeysOK(self, keys):
267267
msg = 'The shift modifier by itself may not be used with'\
268268
' this key symbol.'
269269
self.showerror(title=title, parent=self, message=msg)
270-
elif keySequence in self.currentKeySequences:
270+
elif keys in key_sequences:
271271
msg = 'This key combination is already in use.'
272272
self.showerror(title=title, parent=self, message=msg)
273273
else:

Lib/idlelib/idle_test/test_config_key.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ def setUpClass(cls):
2828
requires('gui')
2929
cls.root = Tk()
3030
cls.root.withdraw()
31+
keylist = [['<Key-F12>'], ['<Control-Key-x>', '<Control-Key-X>']]
3132
cls.dialog = cls.Validator(
32-
cls.root, 'Title', '<<Test>>', [['<Key-F12>']], _utest=True)
33+
cls.root, 'Title', '<<Test>>', keylist, _utest=True)
3334

3435
@classmethod
3536
def tearDownClass(cls):
@@ -78,10 +79,15 @@ def test_keys_shift_bad(self):
7879
self.dialog.GetModifiers.result = []
7980

8081
def test_keys_dup(self):
81-
self.dialog.listKeysFinal.get.result = 'F12'
82+
for mods, final, seq in (([], 'F12', '<Key-F12>'),
83+
(['Control'], 'x', '<Control-Key-x>'),
84+
(['Control'], 'X', '<Control-Key-X>')):
85+
with self.subTest(m=mods, f=final, s=seq):
86+
self.dialog.listKeysFinal.get.result = final
87+
self.dialog.GetModifiers.result = mods
88+
self.assertFalse(self.dialog.KeysOK(seq))
89+
self.assertIn('already in use', self.dialog.showerror.message)
8290
self.dialog.GetModifiers.result = []
83-
self.assertFalse(self.dialog.KeysOK('<Key-F12>'))
84-
self.assertIn('already in use', self.dialog.showerror.message)
8591

8692
def test_bind_ok(self):
8793
self.assertTrue(self.dialog.bind_ok('<Control-Shift-Key-a>'))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
IDLE's basic custom key entry dialog now detects duplicates properly.
2+
Original patch by Saimadhav Heblikar.

0 commit comments

Comments
 (0)