diff options
author | Guido van Rossum <guido@python.org> | 1999-02-01 19:34:53 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-02-01 19:34:53 (GMT) |
commit | 14b2d30b11544bc78374f4afe230fcd680a850b4 (patch) | |
tree | 8d8454d643776363452a7beb210b2c1871b07031 /Tools | |
parent | 6aa42579be55f82141b183d547f71ce10303677a (diff) | |
download | cpython-14b2d30b11544bc78374f4afe230fcd680a850b4.zip cpython-14b2d30b11544bc78374f4afe230fcd680a850b4.tar.gz cpython-14b2d30b11544bc78374f4afe230fcd680a850b4.tar.bz2 |
Protect against accessing an empty stack.
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/idle/StackViewer.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Tools/idle/StackViewer.py b/Tools/idle/StackViewer.py index d4b8baa..16823a6 100644 --- a/Tools/idle/StackViewer.py +++ b/Tools/idle/StackViewer.py @@ -100,6 +100,7 @@ class StackViewer(ScrolledList): ScrolledList.__init__(self, master) self.flist = flist self.browser = browser + self.stack = [] def load_stack(self, stack, index=None): self.stack = stack @@ -132,6 +133,10 @@ class StackViewer(ScrolledList): if index is not None: self.select(index) + def popup_event(self, event): + if self.stack: + return ScrolledList.popup_event(self, event) + def fill_menu(self): menu = self.menu menu.add_command(label="Go to source line", @@ -140,7 +145,8 @@ class StackViewer(ScrolledList): command=self.show_stack_frame) def on_select(self, index): - self.browser.show_frame(self.stack[index]) + if 0 <= index < len(self.stack): + self.browser.show_frame(self.stack[index]) def on_double(self, index): self.show_source(index) @@ -151,9 +157,12 @@ class StackViewer(ScrolledList): def show_stack_frame(self): index = self.listbox.index("active") - self.browser.show_frame(self.stack[index]) + if 0 <= index < len(self.stack): + self.browser.show_frame(self.stack[index]) def show_source(self, index): + if not (0 <= index < len(self.stack)): + return frame, lineno = self.stack[index] code = frame.f_code filename = code.co_filename |