From d183767ca4786c00d84e284ad6c89fa3c154bad2 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 1 Nov 2012 22:41:19 +0200 Subject: Issue #1207589: Add Cut/Copy/Paste items to IDLE right click Context Menu Patch by Todd Rovito. --- Lib/idlelib/PyShell.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'Lib/idlelib/PyShell.py') diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index 88c0390ba5..fb47b994d1 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -117,8 +117,14 @@ class PyShellEditorWindow(EditorWindow): old_hook() self.io.set_filename_change_hook(filename_changed_hook) - rmenu_specs = [("Set Breakpoint", "<>"), - ("Clear Breakpoint", "<>")] + rmenu_specs = [ + ("Cut", "<>", "rmenu_check_cut"), + ("Copy", "<>", "rmenu_check_copy"), + ("Paste", "<>", "rmenu_check_paste"), + (None, None, None), + ("Set Breakpoint", "<>", None), + ("Clear Breakpoint", "<>", None) + ] def set_breakpoint(self, lineno): text = self.text @@ -1240,6 +1246,19 @@ class PyShell(OutputWindow): raise KeyboardInterrupt return count + def rmenu_check_cut(self): + try: + if self.text.compare('sel.first', '<', 'iomark'): + return 'disabled' + except TclError: # no selection, so the index 'sel.first' doesn't exist + return 'disabled' + return super().rmenu_check_cut() + + def rmenu_check_paste(self): + if self.text.compare('insert','<','iomark'): + return 'disabled' + return super().rmenu_check_paste() + class PseudoFile(object): def __init__(self, shell, tags, encoding=None): -- cgit v1.2.1