bpo-33642: IDLE: Use variable number of lines in CodeContext. (GH-7106)

Instead of displaying a fixed number of lines, some blank, Code Context
now displays the variable number of actual context lines.  When there
are no context lines, it shows a single blank line to indicate that the
feature is turned on.

The Code Context configuration option is changed from 'numlines'
(default 3) to 'maxlines' (default 15) to avoid possible interference
between user settings for the old and new versions of Code Context.
This commit is contained in:
Cheryl Sabella 2018-06-01 19:23:00 -04:00 committed by Terry Jan Reedy
parent 6854e803b7
commit 29996a1c4e
6 changed files with 40 additions and 29 deletions

View file

@ -4,7 +4,7 @@ Once code has scrolled off the top of a window, it can be difficult to
determine which block you are in. This extension implements a pane at the top
of each IDLE edit window which provides block structure hints. These hints are
the lines which contain the block opening keywords, e.g. 'if', for the
enclosing block. The number of hint lines is determined by the numlines
enclosing block. The number of hint lines is determined by the maxlines
variable in the codecontext section of config-extensions.def. Lines which do
not open blocks are not shown in the context hints pane.
@ -80,7 +80,7 @@ class CodeContext:
def reload(cls):
"Load class variables from config."
cls.context_depth = idleConf.GetOption("extensions", "CodeContext",
"numlines", type="int", default=3)
"maxlines", type="int", default=15)
## cls.bgcolor = idleConf.GetOption("extensions", "CodeContext",
## "bgcolor", type="str", default="LightGray")
## cls.fgcolor = idleConf.GetOption("extensions", "CodeContext",
@ -116,7 +116,7 @@ class CodeContext:
padx += widget.tk.getint(widget.cget('padx'))
border += widget.tk.getint(widget.cget('border'))
self.label = tkinter.Label(
self.editwin.top, text="\n" * (self.context_depth - 1),
self.editwin.top, text="",
anchor=W, justify=LEFT, font=self.textfont,
bg=self.bgcolor, fg=self.fgcolor,
width=1, # Don't request more than we get.
@ -191,11 +191,10 @@ class CodeContext:
stopindent)
self.info.extend(lines)
self.topvisible = new_topvisible
# Empty lines in context pane.
context_strings = [""] * max(0, self.context_depth - len(self.info))
# Followed by the context hint lines.
context_strings += [x[2] for x in self.info[-self.context_depth:]]
self.label["text"] = '\n'.join(context_strings)
# Last context_depth context lines.
context_strings = [x[2] for x in self.info[-self.context_depth:]]
showfirst = 0 if context_strings[0] else 1
self.label["text"] = '\n'.join(context_strings[showfirst:])
def timer_event(self):
"Event on editor text widget triggered every UPDATEINTERVAL ms."