Skip to content

Commit 83118c6

Browse files
committed
Clear associated breakpoints when closing an edit window.
M Debugger.py : Added clear_file_breaks() M EditorWindow.py : Clear breaks when closed, commments->docstrings, comment out some debugging print statements M PyShell.py : comments->docstrings ; clarify extending EditorWindow methods. M RemoteDebugger.py: Add clear_all_file_breaks() functionality, clarify some comments.
1 parent ab5dae3 commit 83118c6

4 files changed

Lines changed: 78 additions & 66 deletions

File tree

Lib/idlelib/Debugger.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,27 @@ def set_breakpoint_here(self, edit):
320320
text.tag_add("BREAK", "insert linestart", "insert lineend +1char")
321321

322322
def clear_breakpoint_here(self, edit):
323-
text = edit.text
324-
filename = edit.io.filename
325-
if not filename:
326-
text.bell()
327-
return
328-
lineno = int(float(text.index("insert")))
329-
msg = self.idb.clear_break(filename, lineno)
330-
if msg:
331-
text.bell()
332-
return
333-
text.tag_remove("BREAK", "insert linestart",\
334-
"insert lineend +1char")
335-
323+
text = edit.text
324+
filename = edit.io.filename
325+
if not filename:
326+
text.bell()
327+
return
328+
lineno = int(float(text.index("insert")))
329+
msg = self.idb.clear_break(filename, lineno)
330+
if msg:
331+
text.bell()
332+
return
333+
text.tag_remove("BREAK", "insert linestart",\
334+
"insert lineend +1char")
336335

336+
def clear_file_breaks(self, edit):
337+
text = edit.text
338+
filename = edit.io.filename
339+
if not filename:
340+
text.bell()
341+
return
342+
msg = self.idb.clear_all_file_breaks(filename)
343+
if msg:
344+
text.bell()
345+
return
346+
text.tag_delete("BREAK")

Lib/idlelib/EditorWindow.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,15 @@ def rmcolorizer(self):
490490
self.per.insertfilter(self.undo)
491491

492492
def ResetColorizer(self):
493-
#this function is called from configDialog.py
494-
#to update the colour theme if it is changed
493+
"Update the colour theme if it is changed"
494+
# Called from configDialog.py
495495
if self.color:
496496
self.color = self.ColorDelegator()
497497
self.per.insertfilter(self.color)
498498

499499
def ResetFont(self):
500-
#this function is called from configDialog.py
501-
#to update the text widgets' font if it is changed
500+
"Update the text widgets' font if it is changed"
501+
# Called from configDialog.py
502502
fontWeight='normal'
503503
if idleConf.GetOption('main','EditorWindow','font-bold',type='bool'):
504504
fontWeight='bold'
@@ -507,8 +507,8 @@ def ResetFont(self):
507507
fontWeight))
508508

509509
def ResetKeybindings(self):
510-
#this function is called from configDialog.py
511-
#to update the keybindings if they are changed
510+
"Update the keybindings if they are changed"
511+
# Called from configDialog.py
512512
self.Bindings.default_keydefs=idleConf.GetCurrentKeySet()
513513
keydefs = self.Bindings.default_keydefs
514514
for event, keylist in keydefs.items():
@@ -540,7 +540,7 @@ def ResetKeybindings(self):
540540
#print 'accel now:',accel,'\n'
541541

542542
def ResetExtraHelpMenu(self):
543-
#load or update the Extra Help menu if required
543+
"Load or update the Extra Help menu if required"
544544
menuList=idleConf.GetAllExtraHelpSourcesList()
545545
helpMenu=self.menudict['help']
546546
cascadeIndex=helpMenu.index(END)-1
@@ -564,7 +564,7 @@ def DisplayExtraHelp(helpFile=helpFile):
564564
return DisplayExtraHelp
565565

566566
def UpdateRecentFilesList(self,newFile=None):
567-
#load or update the recent files list, and menu if required
567+
"Load or update the recent files list, and menu if required"
568568
rfList=[]
569569
if os.path.exists(self.recentFilesPath):
570570
RFfile=open(self.recentFilesPath,'r')
@@ -578,8 +578,9 @@ def UpdateRecentFilesList(self,newFile=None):
578578
rfList.remove(newFile)
579579
rfList.insert(0,newFile)
580580
rfList=self.__CleanRecentFiles(rfList)
581-
print self.top.instanceDict
582-
print self
581+
#print self.flist.inversedict
582+
#print self.top.instanceDict
583+
#print self
583584
if rfList:
584585
for instance in self.top.instanceDict.keys():
585586
instance.menuRecentFiles.delete(1,END)
@@ -695,10 +696,12 @@ def close(self):
695696
return reply
696697

697698
def _close(self):
698-
print self.io.filename
699+
#print self.io.filename
699700
if self.io.filename:
700701
self.UpdateRecentFilesList(newFile=self.io.filename)
701-
702+
shell = self.flist.pyshell
703+
if shell and shell.interp.debugger:
704+
shell.interp.debugger.clear_file_breaks(self)
702705
WindowList.unregister_callback(self.postwindowsmenu)
703706
if self.close_hook:
704707
self.close_hook()
@@ -756,7 +759,6 @@ def load_extension(self, name):
756759
methodname = methodname + "_event"
757760
if hasattr(ins, methodname):
758761
self.text.bind(vevent, getattr(ins, methodname))
759-
760762
if hasattr(ins, "menudefs"):
761763
self.fill_menus(ins.menudefs, keydefs)
762764
return ins
@@ -771,8 +773,10 @@ def apply_bindings(self, keydefs=None):
771773
apply(text.event_add, (event,) + tuple(keylist))
772774

773775
def fill_menus(self, defs=None, keydefs=None):
774-
# Fill the menus. Menus that are absent or None in
775-
# self.menudict are ignored.
776+
"""Add appropriate entries to the menus and submenus
777+
778+
Menus that are absent or None in self.menudict are ignored.
779+
"""
776780
if defs is None:
777781
defs = self.Bindings.menudefs
778782
if keydefs is None:

Lib/idlelib/PyShell.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ def clear_breakpoint_here(self, event=None):
119119

120120

121121
class PyShellFileList(FileList):
122-
123-
# File list when a shell is present
122+
"Extend base class: file list when a shell is present"
124123

125124
EditorWindow = PyShellEditorWindow
126125

@@ -136,8 +135,7 @@ def open_shell(self, event=None):
136135

137136

138137
class ModifiedColorDelegator(ColorDelegator):
139-
140-
# Colorizer for the shell window itself
138+
"Extend base class: colorizer for the shell window itself"
141139

142140
def __init__(self):
143141
ColorDelegator.__init__(self)
@@ -161,8 +159,7 @@ def LoadTagDefs(self):
161159
})
162160

163161
class ModifiedUndoDelegator(UndoDelegator):
164-
165-
# Forbid insert/delete before the I/O mark
162+
"Extend base class: forbid insert/delete before the I/O mark"
166163

167164
def insert(self, index, chars, tags=None):
168165
try:
@@ -283,12 +280,12 @@ def remote_stack_viewer(self):
283280
gid = 0
284281

285282
def execsource(self, source):
286-
# Like runsource() but assumes complete exec source
283+
"Like runsource() but assumes complete exec source"
287284
filename = self.stuffsource(source)
288285
self.execfile(filename, source)
289286

290287
def execfile(self, filename, source=None):
291-
# Execute an existing file
288+
"Execute an existing file"
292289
if source is None:
293290
source = open(filename, "r").read()
294291
try:
@@ -300,7 +297,7 @@ def execfile(self, filename, source=None):
300297
self.runcode(code)
301298

302299
def runsource(self, source):
303-
# Extend base class to stuff the source in the line cache first
300+
"Extend base class method: Stuff the source in the line cache first"
304301
filename = self.stuffsource(source)
305302
self.more = 0
306303
self.save_warnings_filters = warnings.filters[:]
@@ -313,16 +310,20 @@ def runsource(self, source):
313310
self.save_warnings_filters = None
314311

315312
def stuffsource(self, source):
316-
# Stuff source in the filename cache
313+
"Stuff source in the filename cache"
317314
filename = "<pyshell#%d>" % self.gid
318315
self.gid = self.gid + 1
319316
lines = string.split(source, "\n")
320317
linecache.cache[filename] = len(source)+1, 0, lines, filename
321318
return filename
322319

323320
def showsyntaxerror(self, filename=None):
324-
# Extend base class to color the offending position
325-
# (instead of printing it and pointing at it with a caret)
321+
"""Extend base class method: Add Colorizing
322+
323+
Color the offending position instead of printing it and pointing at it
324+
with a caret.
325+
326+
"""
326327
text = self.tkconsole.text
327328
stuff = self.unpackerror()
328329
if not stuff:
@@ -357,7 +358,7 @@ def unpackerror(self):
357358
return None
358359

359360
def showtraceback(self):
360-
# Extend base class method to reset output properly
361+
"Extend base class method to reset output properly"
361362
self.tkconsole.resetoutput()
362363
self.checklinecache()
363364
InteractiveInterpreter.showtraceback(self)
@@ -379,7 +380,7 @@ def getdebugger(self):
379380
return self.debugger
380381

381382
def runcommand(self, code):
382-
# This runs the code without invoking the debugger.
383+
"Run the code without invoking the debugger"
383384
# The code better not raise an exception!
384385
if self.tkconsole.executing:
385386
tkMessageBox.showerror(
@@ -395,15 +396,15 @@ def runcommand(self, code):
395396
return 1
396397

397398
def runcode(self, code):
398-
# Override base class method
399+
"Override base class method"
399400
if self.tkconsole.executing:
400401
tkMessageBox.showerror(
401402
"Already executing",
402403
"The Python Shell window is already executing a command; "
403404
"please wait until it is finished.",
404405
master=self.tkconsole.text)
405406
return
406-
407+
#
407408
self.checklinecache()
408409
if self.save_warnings_filters is not None:
409410
warnings.filters[:] = self.save_warnings_filters
@@ -414,7 +415,7 @@ def runcode(self, code):
414415
self.active_seq = self.rpcclt.asynccall("exec", "runcode",
415416
(code,), {})
416417
return
417-
418+
#
418419
try:
419420
self.tkconsole.beginexecuting()
420421
try:
@@ -433,12 +434,12 @@ def runcode(self, code):
433434
self.showtraceback()
434435
except:
435436
self.showtraceback()
436-
437+
#
437438
finally:
438439
self.tkconsole.endexecuting()
439440

440441
def write(self, s):
441-
# Override base class write
442+
"Override base class method"
442443
self.tkconsole.console.write(s)
443444

444445
class PyShell(OutputWindow):
@@ -565,15 +566,15 @@ def beginexecuting(self):
565566
##sys.settrace(self._cancel_check)
566567

567568
def endexecuting(self):
568-
# Helper for ModifiedInterpreter
569+
"Helper for ModifiedInterpreter"
569570
##sys.settrace(None)
570571
##self._cancel_check = None
571572
self.executing = 0
572573
self.canceled = 0
573574
self.showprompt()
574575

575576
def close(self):
576-
# Extend base class method
577+
"Extend EditorWindow.close()"
577578
if self.executing:
578579
# XXX Need to ask a question here
579580
if not tkMessageBox.askokcancel(
@@ -586,9 +587,10 @@ def close(self):
586587
if self.reading:
587588
self.top.quit()
588589
return "cancel"
589-
return OutputWindow.close(self)
590+
return EditorWindow.close(self)
590591

591592
def _close(self):
593+
"Extend EditorWindow._close(), shut down debugger and execution server"
592594
self.close_debugger()
593595
self.interp.kill_subprocess()
594596
# Restore std streams
@@ -601,10 +603,10 @@ def _close(self):
601603
self.auto = None
602604
self.flist.pyshell = None
603605
self.history = None
604-
OutputWindow._close(self) # Really EditorWindow._close
606+
EditorWindow._close(self)
605607

606608
def ispythonsource(self, filename):
607-
# Override this so EditorWindow never removes the colorizer
609+
"Override EditorWindow method: never remove the colorizer"
608610
return 1
609611

610612
def short_title(self):
@@ -781,9 +783,6 @@ def runit(self):
781783
i = i-1
782784
line = line[:i]
783785
more = self.interp.runsource(line)
784-
# XXX This was causing extra prompt with shell KBK
785-
# if not more:
786-
# self.showprompt()
787786

788787
def cancel_check(self, frame, what, args,
789788
dooneevent=tkinter.dooneevent,

Lib/idlelib/RemoteDebugger.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def set_break(self, filename, lineno):
101101
def clear_break(self, filename, lineno):
102102
msg = self.idb.clear_break(filename, lineno)
103103

104+
def clear_all_file_breaks(self, filename):
105+
msg = self.idb.clear_all_file_breaks(filename)
106+
104107
#----------called by a FrameProxy----------
105108

106109
def frame_attr(self, fid, name):
@@ -148,14 +151,6 @@ def dict_item(self, did, key):
148151
dict = dicttable[did]
149152
value = dict[key]
150153
value = repr(value)
151-
# try:
152-
# # Test for picklability
153-
# import cPickle
154-
# pklstr = cPickle.dumps(value)
155-
# except:
156-
# print >>sys.__stderr__, "** dict_item pickle failed: ", value
157-
# raise
158-
# #value = None
159154
return value
160155

161156
#----------end class IdbAdapter----------
@@ -165,9 +160,9 @@ def start_debugger(conn, gui_adap_oid):
165160
"""Start the debugger and its RPC link in the Python subprocess
166161
167162
Start the subprocess side of the split debugger and set up that side of the
168-
RPC link by instantiating the GUIProxy, Idle debugger, and IdbAdapter
163+
RPC link by instantiating the GUIProxy, Idb debugger, and IdbAdapter
169164
objects and linking them together. Register the IdbAdapter to handle RPC
170-
requests from the split Debugger GUI via the IdbProxy.
165+
requests from the split debugger GUI via the IdbProxy.
171166
172167
"""
173168
gui_proxy = GUIProxy(conn, gui_adap_oid)
@@ -316,12 +311,16 @@ def set_break(self, filename, lineno):
316311
def clear_break(self, filename, lineno):
317312
msg = self.call("clear_break", filename, lineno)
318313

314+
def clear_all_file_breaks(self, filename):
315+
msg = self.call("clear_all_file_breaks", filename)
316+
317+
319318
def start_remote_debugger(conn, pyshell):
320319
"""Start the subprocess debugger, initialize the debugger GUI and RPC link
321320
322321
Request the RPCServer start the Python subprocess debugger and link. Set
323322
up the Idle side of the split debugger by instantiating the IdbProxy,
324-
Debugger GUI, and Debugger GUIAdapter objects and linking them together.
323+
debugger GUI, and debugger GUIAdapter objects and linking them together.
325324
326325
Register the GUIAdapter to handle debugger GUI interaction requests coming
327326
from the subprocess debugger via the GUIProxy.

0 commit comments

Comments
 (0)