Skip to content

Commit

Permalink
bpo-21519: IDLE basic custom key entry better detects duplicates. (#2428
Browse files Browse the repository at this point in the history
)
  • Loading branch information
terryjreedy committed Jun 27, 2017
1 parent 213ce12 commit 44913e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Lib/idlelib/config_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ def KeysOK(self, keys):
'''
finalKey = self.listKeysFinal.get(ANCHOR)
modifiers = self.GetModifiers()
# create a key sequence list for overlap check:
keySequence = keys.split()
keysOK = False
title = self.keyerror_title
key_sequences = [key for keylist in self.currentKeySequences
for key in keylist]
if not keys.endswith('>'):
self.showerror(title, parent=self,
message='Missing the final Key')
Expand All @@ -267,7 +267,7 @@ def KeysOK(self, keys):
msg = 'The shift modifier by itself may not be used with'\
' this key symbol.'
self.showerror(title=title, parent=self, message=msg)
elif keySequence in self.currentKeySequences:
elif keys in key_sequences:
msg = 'This key combination is already in use.'
self.showerror(title=title, parent=self, message=msg)
else:
Expand Down
14 changes: 10 additions & 4 deletions Lib/idlelib/idle_test/test_config_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def setUpClass(cls):
requires('gui')
cls.root = Tk()
cls.root.withdraw()
keylist = [['<Key-F12>'], ['<Control-Key-x>', '<Control-Key-X>']]
cls.dialog = cls.Validator(
cls.root, 'Title', '<<Test>>', [['<Key-F12>']], _utest=True)
cls.root, 'Title', '<<Test>>', keylist, _utest=True)

@classmethod
def tearDownClass(cls):
Expand Down Expand Up @@ -78,10 +79,15 @@ def test_keys_shift_bad(self):
self.dialog.GetModifiers.result = []

def test_keys_dup(self):
self.dialog.listKeysFinal.get.result = 'F12'
for mods, final, seq in (([], 'F12', '<Key-F12>'),
(['Control'], 'x', '<Control-Key-x>'),
(['Control'], 'X', '<Control-Key-X>')):
with self.subTest(m=mods, f=final, s=seq):
self.dialog.listKeysFinal.get.result = final
self.dialog.GetModifiers.result = mods
self.assertFalse(self.dialog.KeysOK(seq))
self.assertIn('already in use', self.dialog.showerror.message)
self.dialog.GetModifiers.result = []
self.assertFalse(self.dialog.KeysOK('<Key-F12>'))
self.assertIn('already in use', self.dialog.showerror.message)

def test_bind_ok(self):
self.assertTrue(self.dialog.bind_ok('<Control-Shift-Key-a>'))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IDLE's basic custom key entry dialog now detects duplicates properly.
Original patch by Saimadhav Heblikar.

0 comments on commit 44913e5

Please sign in to comment.