diff -r cbb5c5da28f2 Lib/idlelib/idle_test/test_edit.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/idlelib/idle_test/test_edit.py Wed Jun 08 01:47:28 2016 -0400 @@ -0,0 +1,48 @@ +'''Test (selected) IDLE Edit menu items. + +Edit modules have their own test files files +''' +from test.support import requires +requires('gui') +import tkinter as tk +import unittest +from idlelib import editor +from idlelib import macosx +from idlelib import pyshell + +class PasteTest(unittest.TestCase): + + @classmethod + def setUpClass(cls): + cls.root = tk.Tk() + macosx._initializeTkVariantTests(cls.root) + pyshell.fix_x11_paste(cls.root) + cls.text = tk.Text(cls.root) + + @classmethod + def tearDownClass(cls): + del cls.text + cls.root.destroy() + del cls.root + + def tearDown(self): + self.text.delete('1.0', 'end') + self.text.clipboard_clear() + + def test_paste_noselection(self): + text = self.text + text.insert('insert', 'one') + text.clipboard_append('two') + text.event_generate('<>') + self.assertEqual(text.get('1.0', 'end'), 'onetwo\n') + + def test_paste_selection(self): + text = self.text + text.insert('insert', 'one', 'sel') + text.clipboard_append('two') + text.event_generate('<>') + self.assertEqual(text.get('1.0', 'end'), 'two\n') + + +if __name__ == '__main__': + unittest.main(verbosity=2) diff -r cbb5c5da28f2 Lib/idlelib/pyshell.py --- a/Lib/idlelib/pyshell.py Tue Jun 07 15:35:37 2016 -0400 +++ b/Lib/idlelib/pyshell.py Wed Jun 08 01:47:28 2016 -0400 @@ -1396,6 +1396,17 @@ self.shell.close() +def fix_x11_paste(root): + "Make paste replace selection on x11. See issue #5124." + if root._windowingsystem == 'x11': + for cls in 'Text', 'Entry', 'Spinbox': + root.bind_class( + cls, + '<>', + 'catch {%W delete sel.first sel.last}\n' + + root.bind_class(cls, '<>')) + + usage_msg = """\ USAGE: idle [-deins] [-t title] [file]* @@ -1528,8 +1539,10 @@ 'editor-on-startup', type='bool') enable_edit = enable_edit or edit_start enable_shell = enable_shell or not enable_edit + # start editor and/or shell windows: root = Tk(className="Idle") + root.withdraw() # set application icon icondir = os.path.join(os.path.dirname(__file__), 'Icons') @@ -1544,7 +1557,7 @@ root.wm_iconphoto(True, *icons) fixwordbreaks(root) - root.withdraw() + fix_x11_paste(root) flist = PyShellFileList(root) macosx.setupApp(root, flist)