Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 1 | from repr import Repr |
| 2 | from Tkinter import * |
| 3 | |
| 4 | class FrameViewer: |
| 5 | |
| 6 | def __init__(self, root, frame): |
| 7 | self.root = root |
| 8 | self.frame = frame |
| 9 | self.top = Toplevel(self.root) |
| 10 | self.repr = Repr() |
| 11 | self.repr.maxstring = 60 |
| 12 | self.load_variables() |
Guido van Rossum | 504b0bf | 1999-01-02 21:28:54 +0000 | [diff] [blame^] | 13 | |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 14 | def load_variables(self): |
| 15 | row = 0 |
| 16 | if self.frame.f_locals is not self.frame.f_globals: |
| 17 | l = Label(self.top, text="Local Variables", |
| 18 | borderwidth=2, relief="raised") |
| 19 | l.grid(row=row, column=0, columnspan=2, sticky="ew") |
| 20 | row = self.load_names(self.frame.f_locals, row+1) |
| 21 | l = Label(self.top, text="Global Variables", |
| 22 | borderwidth=2, relief="raised") |
| 23 | l.grid(row=row, column=0, columnspan=2, sticky="ew") |
| 24 | row = self.load_names(self.frame.f_globals, row+1) |
Guido van Rossum | 504b0bf | 1999-01-02 21:28:54 +0000 | [diff] [blame^] | 25 | |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 26 | def load_names(self, dict, row): |
| 27 | names = dict.keys() |
| 28 | names.sort() |
| 29 | for name in names: |
| 30 | value = dict[name] |
| 31 | svalue = self.repr.repr(value) |
| 32 | l = Label(self.top, text=name) |
| 33 | l.grid(row=row, column=0, sticky="w") |
| 34 | l = Entry(self.top, width=60, borderwidth=0) |
| 35 | l.insert(0, svalue) |
| 36 | l.grid(row=row, column=1, sticky="w") |
| 37 | row = row+1 |
| 38 | return row |