77
88from tkinter import filedialog
99from tkinter import messagebox
10+ from tkinter import TclError
1011from tkinter .simpledialog import askstring # loadfile encoding.
1112
1213from idlelib .config import idleConf
@@ -33,6 +34,8 @@ def __init__(self, editwin):
3334 self .save_a_copy )
3435 self .fileencoding = 'utf-8'
3536 self .__id_print = self .text .bind ("<<print-window>>" , self .print_window )
37+ self .__id_copy = self .text .bind ("<<copy>>" , self .copy )
38+ self .__id_cut = self .text .bind ("<<cut>>" , self .cut )
3639
3740 def close (self ):
3841 # Undo command bindings
@@ -41,6 +44,8 @@ def close(self):
4144 self .text .unbind ("<<save-window-as-file>>" ,self .__id_saveas )
4245 self .text .unbind ("<<save-copy-of-window-as-file>>" , self .__id_savecopy )
4346 self .text .unbind ("<<print-window>>" , self .__id_print )
47+ self .text .unbind ("<<copy>>" , self .__id_copy )
48+ self .text .unbind ("<<cut>>" , self .__id_cut )
4449 # Break cycles
4550 self .editwin = None
4651 self .text = None
@@ -348,6 +353,20 @@ def print_window(self, event):
348353 os .unlink (tempfilename )
349354 return "break"
350355
356+ def copy (self , event ):
357+ if not self .text .tag_ranges ("sel" ):
358+ self .text .tag_add ("sel" , "insert linestart" , "insert+1l linestart" )
359+ self .text .mark_set ("insert" , "insert linestart" )
360+ self .text .event_generate ("<<Copy>>" )
361+ return "break"
362+
363+ def cut (self , event ):
364+ if not self .text .tag_ranges ("sel" ):
365+ self .text .tag_add ("sel" , "insert linestart" , "insert+1l linestart" )
366+ self .text .mark_set ("insert" , "insert linestart" )
367+ self .text .event_generate ("<<Cut>>" )
368+ return "break"
369+
351370 opendialog = None
352371 savedialog = None
353372
0 commit comments