cpython: 5b635a3ca3d5 (original) (raw)
--- a/Lib/idlelib/help.py +++ b/Lib/idlelib/help.py @@ -55,12 +55,11 @@ class HelpParser(HTMLParser): self.hdrlink = False # used so we don't show header links self.level = 0 # indentation level self.pre = False # displaying preformatted text
self.hprefix = '' # strip e.g. '25.5' from headings[](#l1.7)
self.hprefix = '' # prefix such as '25.5' to strip from headings[](#l1.8) self.nested_dl = False # if we're in a nested <dl>[](#l1.9) self.simplelist = False # simple list (no double spacing)[](#l1.10)
self.tocid = 1 # id for table of contents entries[](#l1.11)
self.contents = [] # map toc ids to section titles[](#l1.12)
self.data = '' # to record data within header tags for toc[](#l1.13)
self.toc = [] # pair headers with text indexes for toc[](#l1.14)
self.header = '' # text within header tags for toc[](#l1.15)
def indent(self, amt=1): self.level += amt @@ -111,14 +110,10 @@ class HelpParser(HTMLParser): elif tag == 'a' and class_ == 'headerlink': self.hdrlink = True elif tag == 'h1':
self.text.mark_set('toc'+str(self.tocid),[](#l1.23)
self.text.index('end-1line'))[](#l1.24) self.tags = tag[](#l1.25) elif tag in ['h2', 'h3']:[](#l1.26) if self.show:[](#l1.27)
self.data = ''[](#l1.28)
self.text.mark_set('toc'+str(self.tocid),[](#l1.29)
self.text.index('end-1line'))[](#l1.30)
self.header = ''[](#l1.31) self.text.insert('end', '\n\n')[](#l1.32) self.tags = tag[](#l1.33) if self.show:[](#l1.34)
@@ -128,10 +123,8 @@ class HelpParser(HTMLParser): "Handle endtags in help.html." if tag in ['h1', 'h2', 'h3']: self.indent(0) # clear tag, reset indent
if self.show and tag in ['h1', 'h2', 'h3']:[](#l1.39)
title = self.data[](#l1.40)
self.contents.append(('toc'+str(self.tocid), title))[](#l1.41)
self.tocid += 1[](#l1.42)
if self.show:[](#l1.43)
self.toc.append((self.header, self.text.index('insert')))[](#l1.44) elif tag in ['span', 'em']:[](#l1.45) self.chartags = ''[](#l1.46) elif tag == 'a':[](#l1.47)
@@ -151,7 +144,7 @@ class HelpParser(HTMLParser): if self.tags in ['h1', 'h2', 'h3'] and self.hprefix != '': if d[0:len(self.hprefix)] == self.hprefix: d = d[len(self.hprefix):].strip()
self.data += d[](#l1.52)
self.header += d[](#l1.53) self.text.insert('end', d, (self.tags, self.chartags))[](#l1.54)
@@ -205,19 +198,18 @@ class HelpFrame(Frame): self['background'] = text['background'] scroll = Scrollbar(self, command=text.yview) text['yscrollcommand'] = scroll.set
self.rowconfigure(0, weight=1)[](#l1.61)
self.columnconfigure(1, weight=1) # text[](#l1.62)
self.toc_menu(text).grid(column=0, row=0, sticky='nw')[](#l1.63) text.grid(column=1, row=0, sticky='nsew')[](#l1.64) scroll.grid(column=2, row=0, sticky='ns')[](#l1.65)
self.grid_columnconfigure(1, weight=1)[](#l1.66)
self.grid_rowconfigure(0, weight=1)[](#l1.67)
toc = self.contents_widget(text)[](#l1.68)
toc.grid(column=0, row=0, sticky='nw')[](#l1.69)
- def toc_menu(self, text):
"Create table of contents as drop-down menu."[](#l1.74) toc = Menubutton(self, text='TOC')[](#l1.75) drop = Menu(toc, tearoff=False)[](#l1.76)
for tag, lbl in text.parser.contents:[](#l1.77)
drop.add_command(label=lbl, command=lambda mark=tag:text.see(mark))[](#l1.78)
for lbl, dex in text.parser.toc:[](#l1.79)
drop.add_command(label=lbl, command=lambda dex=dex:text.yview(dex))[](#l1.80) toc['menu'] = drop[](#l1.81) return toc[](#l1.82)