From 44913e584bcf4e2a0e1a6372c304c2d5ea521fc6 Mon Sep 17 00:00:00 2001 From: terryjreedy Date: Tue, 27 Jun 2017 01:23:55 -0400 Subject: bpo-21519: IDLE basic custom key entry better detects duplicates. (#2428) --- Lib/idlelib/config_key.py | 6 +++--- Lib/idlelib/idle_test/test_config_key.py | 14 ++++++++++---- .../next/IDLE/2017-06-27-00-29-56.bpo-21519.fTj9T0.rst | 2 ++ 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 Misc/NEWS.d/next/IDLE/2017-06-27-00-29-56.bpo-21519.fTj9T0.rst diff --git a/Lib/idlelib/config_key.py b/Lib/idlelib/config_key.py index 8d575ec..fc6e341 100644 --- a/Lib/idlelib/config_key.py +++ b/Lib/idlelib/config_key.py @@ -250,10 +250,10 @@ class GetKeysDialog(Toplevel): ''' 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') @@ -267,7 +267,7 @@ class GetKeysDialog(Toplevel): 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: diff --git a/Lib/idlelib/idle_test/test_config_key.py b/Lib/idlelib/idle_test/test_config_key.py index a4227ed..9074e23 100644 --- a/Lib/idlelib/idle_test/test_config_key.py +++ b/Lib/idlelib/idle_test/test_config_key.py @@ -28,8 +28,9 @@ class ValidationTest(unittest.TestCase): requires('gui') cls.root = Tk() cls.root.withdraw() + keylist = [[''], ['', '']] cls.dialog = cls.Validator( - cls.root, 'Title', '<>', [['']], _utest=True) + cls.root, 'Title', '<>', keylist, _utest=True) @classmethod def tearDownClass(cls): @@ -78,10 +79,15 @@ class ValidationTest(unittest.TestCase): self.dialog.GetModifiers.result = [] def test_keys_dup(self): - self.dialog.listKeysFinal.get.result = 'F12' + for mods, final, seq in (([], 'F12', ''), + (['Control'], 'x', ''), + (['Control'], '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('')) - self.assertIn('already in use', self.dialog.showerror.message) def test_bind_ok(self): self.assertTrue(self.dialog.bind_ok('')) diff --git a/Misc/NEWS.d/next/IDLE/2017-06-27-00-29-56.bpo-21519.fTj9T0.rst b/Misc/NEWS.d/next/IDLE/2017-06-27-00-29-56.bpo-21519.fTj9T0.rst new file mode 100644 index 0000000..b224f6b --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2017-06-27-00-29-56.bpo-21519.fTj9T0.rst @@ -0,0 +1,2 @@ +IDLE's basic custom key entry dialog now detects duplicates properly. +Original patch by Saimadhav Heblikar. -- cgit v0.12