@@ -538,6 +538,7 @@ def __init__(self, filename="sheet1.xml", rows=10, columns=5):
538538 self .entry .bind ("<Tab>" , self .tab_event )
539539 self .entry .bind ("<Shift-Tab>" , self .shift_tab_event )
540540 self .entry .bind ("<Delete>" , self .delete_event )
541+ self .entry .bind ("<Escape>" , self .escape_event )
541542 # Now create the cell grid
542543 self .makegrid (rows , columns )
543544 # Select the top-left cell
@@ -556,6 +557,22 @@ def delete_event(self, event):
556557 self .entry .delete (0 , 'end' )
557558 return "break"
558559
560+ def escape_event (self , event ):
561+ x , y = self .currentxy
562+ self .load_entry (x , y )
563+
564+ def load_entry (self , x , y ):
565+ cell = self .sheet .getcell (x , y )
566+ if cell is None :
567+ text = ""
568+ elif isinstance (cell , FormulaCell ):
569+ text = '=' + cell .formula
570+ else :
571+ text , alignment = cell .format ()
572+ self .entry .delete (0 , 'end' )
573+ self .entry .insert (0 , text )
574+ self .entry .selection_range (0 , 'end' )
575+
559576 def makegrid (self , rows , columns ):
560577 """Helper to create the grid of GUI cells.
561578
@@ -653,18 +670,8 @@ def setcurrent(self, x, y):
653670 if self .currentxy is not None :
654671 self .change_cell ()
655672 self .clearfocus ()
656- name = cellname (x , y )
657- cell = self .sheet .getcell (x , y )
658- if cell is None :
659- text = ""
660- elif isinstance (cell , FormulaCell ):
661- text = '=' + cell .formula
662- else :
663- text , alignment = cell .format ()
664- self .beacon ['text' ] = name
665- self .entry .delete (0 , 'end' )
666- self .entry .insert (0 , text )
667- self .entry .selection_range (0 , 'end' )
673+ self .beacon ['text' ] = cellname (x , y )
674+ self .load_entry (x , y )
668675 self .entry .focus_set ()
669676 self .currentxy = x , y
670677 self .cornerxy = None
0 commit comments