cpython: 639dd6e62de4 (original) (raw)
Mercurial > cpython
changeset 80172:639dd6e62de4 2.7
Issue #1207589: Add Cut/Copy/Paste items to IDLE right click Context Menu Patch by Todd Rovito. [#1207589]
Andrew Svetlov andrew.svetlov@gmail.com | |
---|---|
date | Thu, 01 Nov 2012 22:39:14 +0200 |
parents | 7dda9dc5e830 |
children | 466cbfb3c0c6 |
files | Doc/library/idle.rst Lib/idlelib/EditorWindow.py Lib/idlelib/OutputWindow.py Lib/idlelib/PyShell.py Lib/idlelib/help.txt Misc/NEWS |
diffstat | 6 files changed, 96 insertions(+), 13 deletions(-)[+] [-] Doc/library/idle.rst 21 Lib/idlelib/EditorWindow.py 42 Lib/idlelib/OutputWindow.py 6 Lib/idlelib/PyShell.py 22 Lib/idlelib/help.txt 15 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Doc/library/idle.rst +++ b/Doc/library/idle.rst @@ -183,6 +183,15 @@ Edit context menu
Set Breakpoint Sets a breakpoint. Breakpoints are only enabled when the debugger is open. @@ -190,6 +199,9 @@ Clear Breakpoint Clears the breakpoint on that line. .. index::
- single: Cut
- single: Copy
- single: Paste single: Set Breakpoint single: Clear Breakpoint single: breakpoints @@ -200,6 +212,15 @@ Shell context menu
Go to file/line Same as in Debug menu.
--- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -470,7 +470,6 @@ class EditorWindow(object): rmenu = None def right_menu_event(self, event):
self.text.tag_remove("sel", "1.0", "end")[](#l2.7) self.text.mark_set("insert", "@%d,%d" % (event.x, event.y))[](#l2.8) if not self.rmenu:[](#l2.9) self.make_rmenu()[](#l2.10)
@@ -479,23 +478,52 @@ class EditorWindow(object): iswin = sys.platform[:3] == 'win' if iswin: self.text.config(cursor="arrow") +
for label, eventname, verify_state in self.rmenu_specs:[](#l2.16)
if verify_state is None:[](#l2.17)
continue[](#l2.18)
state = getattr(self, verify_state)()[](#l2.19)
rmenu.entryconfigure(label, state=state)[](#l2.20)
+ rmenu.tk_popup(event.x_root, event.y_root) if iswin: self.text.config(cursor="ibeam") rmenu_specs = [
# ("Label", "<<virtual-event>>"), ...[](#l2.27)
("Close", "<<close-window>>"), # Example[](#l2.28)
# ("Label", "<<virtual-event>>", "statefuncname"), ...[](#l2.29)
] def make_rmenu(self): rmenu = Menu(self.text, tearoff=0)("Close", "<<close-window>>", None), # Example[](#l2.30)
for label, eventname in self.rmenu_specs:[](#l2.35)
def command(text=self.text, eventname=eventname):[](#l2.36)
text.event_generate(eventname)[](#l2.37)
rmenu.add_command(label=label, command=command)[](#l2.38)
for label, eventname, _ in self.rmenu_specs:[](#l2.39)
if label is not None:[](#l2.40)
def command(text=self.text, eventname=eventname):[](#l2.41)
text.event_generate(eventname)[](#l2.42)
rmenu.add_command(label=label, command=command)[](#l2.43)
else:[](#l2.44)
rmenu.add_separator()[](#l2.45) self.rmenu = rmenu[](#l2.46)
- def rmenu_check_copy(self):
try:[](#l2.52)
indx = self.text.index('sel.first')[](#l2.53)
except TclError:[](#l2.54)
return 'disabled'[](#l2.55)
else:[](#l2.56)
return 'normal' if indx else 'disabled'[](#l2.57)
- def rmenu_check_paste(self):
try:[](#l2.60)
self.text.tk.call('tk::GetSelection', self.text, 'CLIPBOARD')[](#l2.61)
except TclError:[](#l2.62)
return 'disabled'[](#l2.63)
else:[](#l2.64)
return 'normal'[](#l2.65)
+ def about_dialog(self, event=None): aboutDialog.AboutDialog(self.top,'About IDLE')
--- a/Lib/idlelib/OutputWindow.py +++ b/Lib/idlelib/OutputWindow.py @@ -57,7 +57,11 @@ class OutputWindow(EditorWindow): # Our own right-button menu rmenu_specs = [
("Go to file/line", "<<goto-file-line>>"),[](#l3.7)
("Cut", "<<cut>>", "rmenu_check_cut"),[](#l3.8)
("Copy", "<<copy>>", "rmenu_check_copy"),[](#l3.9)
("Paste", "<<paste>>", "rmenu_check_paste"),[](#l3.10)
(None, None, None),[](#l3.11)
] file_line_pats = [("Go to file/line", "<<goto-file-line>>", None),[](#l3.12)
--- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -122,8 +122,13 @@ class PyShellEditorWindow(EditorWindow): old_hook() self.io.set_filename_change_hook(filename_changed_hook)
- rmenu_specs = [("Set Breakpoint", "<>"),
("Clear Breakpoint", "<<clear-breakpoint-here>>")][](#l4.8)
- rmenu_specs = [
("Cut", "<<cut>>", "rmenu_check_cut"),[](#l4.10)
("Copy", "<<copy>>", "rmenu_check_copy"),[](#l4.11)
("Paste", "<<paste>>", "rmenu_check_paste"),[](#l4.12)
("Set Breakpoint", "<<set-breakpoint-here>>", None),[](#l4.13)
("Clear Breakpoint", "<<clear-breakpoint-here>>", None)[](#l4.14)
- ]
def set_breakpoint(self, lineno): text = self.text @@ -1261,6 +1266,19 @@ class PyShell(OutputWindow): if not use_subprocess: raise KeyboardInterrupt
- def rmenu_check_cut(self):
try:[](#l4.24)
if self.text.compare('sel.first', '<', 'iomark'):[](#l4.25)
return 'disabled'[](#l4.26)
except TclError: # no selection, so the index 'sel.first' doesn't exist[](#l4.27)
return 'disabled'[](#l4.28)
return super(PyShell, self).rmenu_check_cut()[](#l4.29)
- def rmenu_check_paste(self):
if self.text.compare('insert', '<', 'iomark'):[](#l4.32)
return 'disabled'[](#l4.33)
return super(PyShell, self).rmenu_check_paste()[](#l4.34)
+ class PseudoFile(object): def init(self, shell, tags, encoding=None):
--- a/Lib/idlelib/help.txt +++ b/Lib/idlelib/help.txt @@ -120,14 +120,23 @@ Help Menu: --- (Additional Help Sources may be added here) -Edit context menu (Right-click / Control-click in Edit window): +Edit context menu (Right-click / Control-click on OS X in Edit window):
Cut -- Copy a selection into system-wide clipboard,[](#l5.10)
then delete the selection[](#l5.11)
- Copy -- Copy selection into system-wide clipboard
- Paste -- Insert system-wide clipboard into window Set Breakpoint -- Sets a breakpoint (when debugger open) Clear Breakpoint -- Clears the breakpoint on that line -Shell context menu (Right-click / Control-click in Shell window): +Shell context menu (Right-click / Control-click on OS X in Shell window):
- Cut -- Copy a selection into system-wide clipboard,
then delete the selection[](#l5.22)
- Copy -- Copy selection into system-wide clipboard
- Paste -- Insert system-wide clipboard into window
---[](#l5.25)
- Go to file/line -- Same as in Debug menu ** TIPS **
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -130,6 +130,9 @@ Core and Builtins Library ------- +- Issue #1207589: Add Cut/Copy/Paste items to IDLE right click Context Menu