summaryrefslogtreecommitdiffstats
path: root/Demo/tkinter
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-11-02 06:50:05 (GMT)
committerGuido van Rossum <guido@python.org>2002-11-02 06:50:05 (GMT)
commitbfcd6533e42988e2b6ca0097e4998e9124860b7f (patch)
treebd0acd026bc96d43a5939a72823b20a473e8106d /Demo/tkinter
parent3669242ac978cdf49d093449dc351c3c864a8057 (diff)
downloadcpython-bfcd6533e42988e2b6ca0097e4998e9124860b7f.zip
cpython-bfcd6533e42988e2b6ca0097e4998e9124860b7f.tar.gz
cpython-bfcd6533e42988e2b6ca0097e4998e9124860b7f.tar.bz2
Add ESC key binding -- undo current cell editing.
Diffstat (limited to 'Demo/tkinter')
-rw-r--r--Demo/tkinter/guido/ss1.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/Demo/tkinter/guido/ss1.py b/Demo/tkinter/guido/ss1.py
index be5126f..559c491 100644
--- a/Demo/tkinter/guido/ss1.py
+++ b/Demo/tkinter/guido/ss1.py
@@ -538,6 +538,7 @@ class SheetGUI:
self.entry.bind("<Tab>", self.tab_event)
self.entry.bind("<Shift-Tab>", self.shift_tab_event)
self.entry.bind("<Delete>", self.delete_event)
+ self.entry.bind("<Escape>", self.escape_event)
# Now create the cell grid
self.makegrid(rows, columns)
# Select the top-left cell
@@ -556,6 +557,22 @@ class SheetGUI:
self.entry.delete(0, 'end')
return "break"
+ def escape_event(self, event):
+ x, y = self.currentxy
+ self.load_entry(x, y)
+
+ def load_entry(self, x, y):
+ cell = self.sheet.getcell(x, y)
+ if cell is None:
+ text = ""
+ elif isinstance(cell, FormulaCell):
+ text = '=' + cell.formula
+ else:
+ text, alignment = cell.format()
+ self.entry.delete(0, 'end')
+ self.entry.insert(0, text)
+ self.entry.selection_range(0, 'end')
+
def makegrid(self, rows, columns):
"""Helper to create the grid of GUI cells.
@@ -653,18 +670,8 @@ class SheetGUI:
if self.currentxy is not None:
self.change_cell()
self.clearfocus()
- name = cellname(x, y)
- cell = self.sheet.getcell(x, y)
- if cell is None:
- text = ""
- elif isinstance(cell, FormulaCell):
- text = '=' + cell.formula
- else:
- text, alignment = cell.format()
- self.beacon['text'] = name
- self.entry.delete(0, 'end')
- self.entry.insert(0, text)
- self.entry.selection_range(0, 'end')
+ self.beacon['text'] = cellname(x, y)
+ self.load_entry(x, y)
self.entry.focus_set()
self.currentxy = x, y
self.cornerxy = None