Restructured and more consistent. Save checkboxes across instantiations.

This commit is contained in:
Guido van Rossum 1998-10-16 21:09:05 +00:00
parent baf53b4ea8
commit 3fb3515303

View file

@ -10,6 +10,8 @@ class Debugger(bdb.Bdb):
interacting = 0 interacting = 0
vstack = vsource = vlocals = vglobals = None
def __init__(self, pyshell): def __init__(self, pyshell):
bdb.Bdb.__init__(self) bdb.Bdb.__init__(self)
self.pyshell = pyshell self.pyshell = pyshell
@ -52,7 +54,7 @@ class Debugger(bdb.Bdb):
# #
self.bcont = b = Button(bframe, text="Go", command=self.cont) self.bcont = b = Button(bframe, text="Go", command=self.cont)
bl.append(b) bl.append(b)
self.bstep = b = Button(bframe, text="Into", command=self.step) self.bstep = b = Button(bframe, text="Step", command=self.step)
bl.append(b) bl.append(b)
self.bnext = b = Button(bframe, text="Over", command=self.next) self.bnext = b = Button(bframe, text="Over", command=self.next)
bl.append(b) bl.append(b)
@ -66,19 +68,27 @@ class Debugger(bdb.Bdb):
self.cframe = cframe = Frame(bframe) self.cframe = cframe = Frame(bframe)
self.cframe.pack(side="left") self.cframe.pack(side="left")
# #
self.vstack = BooleanVar(top) if not self.vstack:
self.__class__.vstack = BooleanVar(top)
self.vstack.set(1)
self.bstack = Checkbutton(cframe, self.bstack = Checkbutton(cframe,
text="Stack", command=self.show_stack, variable=self.vstack) text="Stack", command=self.show_stack, variable=self.vstack)
self.bstack.grid(row=0, column=0) self.bstack.grid(row=0, column=0)
self.vsource = BooleanVar(top) if not self.vsource:
self.__class__.vsource = BooleanVar(top)
self.vsource.set(1)
self.bsource = Checkbutton(cframe, self.bsource = Checkbutton(cframe,
text="Source", command=self.show_source, variable=self.vsource) text="Source", command=self.show_source, variable=self.vsource)
self.bsource.grid(row=0, column=1) self.bsource.grid(row=0, column=1)
self.vlocals = BooleanVar(top) if not self.vlocals:
self.__class__.vlocals = BooleanVar(top)
self.vlocals.set(1)
self.blocals = Checkbutton(cframe, self.blocals = Checkbutton(cframe,
text="Locals", command=self.show_locals, variable=self.vlocals) text="Locals", command=self.show_locals, variable=self.vlocals)
self.blocals.grid(row=1, column=0) self.blocals.grid(row=1, column=0)
self.vglobals = BooleanVar(top) if not self.vglobals:
self.__class__.vglobals = BooleanVar(top)
self.vglobals.set(1)
self.bglobals = Checkbutton(cframe, self.bglobals = Checkbutton(cframe,
text="Globals", command=self.show_globals, variable=self.vglobals) text="Globals", command=self.show_globals, variable=self.vglobals)
self.bglobals.grid(row=1, column=1) self.bglobals.grid(row=1, column=1)
@ -87,6 +97,7 @@ class Debugger(bdb.Bdb):
self.status.pack(anchor="w") self.status.pack(anchor="w")
self.error = Label(top, anchor="w") self.error = Label(top, anchor="w")
self.error.pack(anchor="w") self.error.pack(anchor="w")
self.errorbg = self.error.cget("background")
# #
self.fstack = Frame(top, height=1) self.fstack = Frame(top, height=1)
self.fstack.pack(expand=1, fill="both") self.fstack.pack(expand=1, fill="both")
@ -94,6 +105,15 @@ class Debugger(bdb.Bdb):
self.flocals.pack(expand=1, fill="both") self.flocals.pack(expand=1, fill="both")
self.fglobals = Frame(top, height=1) self.fglobals = Frame(top, height=1)
self.fglobals.pack(expand=1, fill="both") self.fglobals.pack(expand=1, fill="both")
#
if self.vstack.get():
self.show_stack()
if self.vlocals.get():
self.show_locals()
if self.vglobals.get():
self.show_globals()
frame = None
def interaction(self, frame, info=None): def interaction(self, frame, info=None):
self.frame = frame self.frame = frame
@ -101,10 +121,12 @@ class Debugger(bdb.Bdb):
file = code.co_filename file = code.co_filename
base = os.path.basename(file) base = os.path.basename(file)
lineno = frame.f_lineno lineno = frame.f_lineno
#
message = "%s:%s" % (base, lineno) message = "%s:%s" % (base, lineno)
if code.co_name != "?": if code.co_name != "?":
message = "%s: %s()" % (message, code.co_name) message = "%s: %s()" % (message, code.co_name)
self.status.configure(text=message) self.status.configure(text=message)
#
if info: if info:
type, value, tb = info type, value, tb = info
try: try:
@ -116,33 +138,33 @@ class Debugger(bdb.Bdb):
m1 = "%s: %s" % (m1, str(value)) m1 = "%s: %s" % (m1, str(value))
except: except:
pass pass
bg = "yellow"
else: else:
m1 = "" m1 = ""
tb = None tb = None
self.error.configure(text=m1) bg = self.errorbg
self.error.configure(text=m1, background=bg)
#
sv = self.stackviewer sv = self.stackviewer
if sv: if sv:
stack, i = self.get_stack(self.frame, tb) stack, i = self.get_stack(self.frame, tb)
sv.load_stack(stack, i) sv.load_stack(stack, i)
lv = self.localsviewer #
gv = self.globalsviewer self.show_variables()
if lv: #
if not gv or self.frame.f_locals is not self.frame.f_globals:
lv.load_dict(self.frame.f_locals)
else:
lv.load_dict(None)
if gv:
gv.load_dict(self.frame.f_globals)
if self.vsource.get(): if self.vsource.get():
self.sync_source_line() self.sync_source_line()
#
for b in self.buttons: for b in self.buttons:
b.configure(state="normal") b.configure(state="normal")
#
self.top.tkraise() self.top.tkraise()
self.root.mainloop() self.root.mainloop()
#
for b in self.buttons: for b in self.buttons:
b.configure(state="disabled") b.configure(state="disabled")
self.status.configure(text="") self.status.configure(text="")
self.error.configure(text="") self.error.configure(text="", background=self.errorbg)
self.frame = None self.frame = None
def sync_source_line(self): def sync_source_line(self):
@ -194,30 +216,50 @@ class Debugger(bdb.Bdb):
self.sync_source_line() self.sync_source_line()
def show_frame(self, (frame, lineno)): def show_frame(self, (frame, lineno)):
pass self.frame = frame
self.show_variables()
localsviewer = None localsviewer = None
globalsviewer = None
def show_locals(self): def show_locals(self):
lv = self.localsviewer lv = self.localsviewer
if not lv and self.vlocals.get(): if self.vlocals.get():
self.localsviewer = lv = StackViewer.NamespaceViewer( if not lv:
self.localsviewer = StackViewer.NamespaceViewer(
self.flocals, "Locals") self.flocals, "Locals")
if self.frame: else:
lv.load_dict(self.frame.f_locals) if lv:
elif lv and not self.vlocals.get():
self.localsviewer = None self.localsviewer = None
lv.close() lv.close()
self.flocals['height'] = 1
globalsviewer = None self.show_variables()
def show_globals(self): def show_globals(self):
lv = self.globalsviewer gv = self.globalsviewer
if not lv and self.vglobals.get(): if self.vglobals.get():
self.globalsviewer = lv = StackViewer.NamespaceViewer( if not gv:
self.fglobals, "Locals") self.globalsviewer = StackViewer.NamespaceViewer(
if self.frame: self.fglobals, "Globals")
lv.load_dict(self.frame.f_globals) else:
elif lv and not self.vglobals.get(): if gv:
self.globalsviewer = None self.globalsviewer = None
lv.close() gv.close()
self.fglobals['height'] = 1
self.show_variables()
def show_variables(self):
lv = self.localsviewer
gv = self.globalsviewer
frame = self.frame
if not frame:
ldict = gdict = None
else:
ldict = frame.f_locals
gdict = frame.f_globals
if lv and gv and ldict is gdict:
ldict = None
if lv:
lv.load_dict(ldict)
if gv:
gv.load_dict(gdict)