[Python-checkins] r74363 - in python/branches/tk_and_idle_maintenance/Lib/idlelib: EditorWindow.py OutputWindow.py PyShell.py
guilherme.polo
python-checkins at python.org
Thu Aug 13 05:56:30 CEST 2009
Author: guilherme.polo
Date: Thu Aug 13 05:56:30 2009
New Revision: 74363
Log:
Added cut/copy/paste to the popup menu (right-click menu).
Modified:
python/branches/tk_and_idle_maintenance/Lib/idlelib/EditorWindow.py
python/branches/tk_and_idle_maintenance/Lib/idlelib/OutputWindow.py
python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py
Modified: python/branches/tk_and_idle_maintenance/Lib/idlelib/EditorWindow.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/idlelib/EditorWindow.py (original)
+++ python/branches/tk_and_idle_maintenance/Lib/idlelib/EditorWindow.py Thu Aug 13 05:56:30 2009
@@ -408,7 +408,6 @@
rmenu = None
def right_menu_event(self, event):
- self.text.tag_remove("sel", "1.0", "end")
self.text.mark_set("insert", "@%d,%d" % (event.x, event.y))
if not self.rmenu:
self.make_rmenu()
@@ -417,23 +416,63 @@
iswin = sys.platform[:3] == 'win'
if iswin:
self.text.config(cursor="arrow")
+
+ for label, eventname, verify_state in self.rmenu_specs:
+ if verify_state is None:
+ continue
+ state = getattr(self, verify_state)()
+ rmenu.entryconfigure(label, state=state)
+
rmenu.tk_popup(event.x_root, event.y_root)
if iswin:
self.text.config(cursor="ibeam")
rmenu_specs = [
- # ("Label", "<<virtual-event>>"), ...
- ("Close", "<<close-window>>"), # Example
+ # ("Label", "<<virtual-event>>", "statefuncname"), ...
+ ("Close", "<<close-window>>", None), # Example
]
def make_rmenu(self):
rmenu = Menu(self.text, tearoff=0)
- for label, eventname in self.rmenu_specs:
- def command(text=self.text, eventname=eventname):
- text.event_generate(eventname)
- rmenu.add_command(label=label, command=command)
+ for label, eventname, _ in self.rmenu_specs:
+ if label is not None:
+ def command(text=self.text, eventname=eventname):
+ text.event_generate(eventname)
+ rmenu.add_command(label=label, command=command)
+ else:
+ rmenu.add_separator()
self.rmenu = rmenu
+ def rmenu_check_cut(self):
+ if getattr(self, 'interp', None) is None:
+ return self.rmenu_check_copy()
+
+ text = self.text
+ try:
+ indx = text.index('sel.first')
+ except TclError:
+ return 'disabled'
+ else:
+ if indx and text.compare(indx, '>=', text.index('iomark')):
+ return 'normal'
+ return 'disabled'
+
+ def rmenu_check_copy(self):
+ try:
+ indx = self.text.index('sel.first')
+ except TclError:
+ return 'disabled'
+ else:
+ return 'normal' if indx else 'disabled'
+
+ def rmenu_check_paste(self):
+ try:
+ self.text.tk.call('tk::GetSelection', self.text, 'CLIPBOARD')
+ except TclError:
+ return 'disabled'
+ else:
+ return 'normal'
+
def about_dialog(self, event=None):
aboutDialog.AboutDialog(self.top,'About IDLE')
Modified: python/branches/tk_and_idle_maintenance/Lib/idlelib/OutputWindow.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/idlelib/OutputWindow.py (original)
+++ python/branches/tk_and_idle_maintenance/Lib/idlelib/OutputWindow.py Thu Aug 13 05:56:30 2009
@@ -56,7 +56,11 @@
# Our own right-button menu
rmenu_specs = [
- ("Go to file/line", "<<goto-file-line>>"),
+ ("Cut", "<<cut>>", "rmenu_check_cut"),
+ ("Copy", "<<copy>>", "rmenu_check_copy"),
+ ("Paste", "<<paste>>", "rmenu_check_paste"),
+ (None, None, None),
+ ("Go to file/line", "<<goto-file-line>>", None)
]
file_line_pats = [
Modified: python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py (original)
+++ python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py Thu Aug 13 05:56:30 2009
@@ -118,8 +118,14 @@
old_hook()
self.io.set_filename_change_hook(filename_changed_hook)
- rmenu_specs = [("Set Breakpoint", "<<set-breakpoint-here>>"),
- ("Clear Breakpoint", "<<clear-breakpoint-here>>")]
+ rmenu_specs = [
+ ("Cut", "<<cut>>", "rmenu_check_cut"),
+ ("Copy", "<<copy>>", "rmenu_check_copy"),
+ ("Paste", "<<paste>>", "rmenu_check_paste"),
+ (None, None, None),
+ ("Set Breakpoint", "<<set-breakpoint-here>>", None),
+ ("Clear Breakpoint", "<<clear-breakpoint-here>>", None)
+ ]
def set_breakpoint(self, lineno):
text = self.text
More information about the Python-checkins
mailing list