summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/codecontext.py
diff options
context:
space:
mode:
authorCheryl Sabella <cheryl.sabella@gmail.com>2018-06-01 23:23:00 (GMT)
committerTerry Jan Reedy <tjreedy@udel.edu>2018-06-01 23:23:00 (GMT)
commit29996a1c4e8bd6dde6adce2b44d11a0982a47a3a (patch)
treec6f08943343b54a41e9ed3da85a15325819aebf0 /Lib/idlelib/codecontext.py
parent6854e803b73ac4d02ba160d514b8a53dd7a62905 (diff)
downloadcpython-29996a1c4e8bd6dde6adce2b44d11a0982a47a3a.zip
cpython-29996a1c4e8bd6dde6adce2b44d11a0982a47a3a.tar.gz
cpython-29996a1c4e8bd6dde6adce2b44d11a0982a47a3a.tar.bz2
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.
Diffstat (limited to 'Lib/idlelib/codecontext.py')
-rw-r--r--Lib/idlelib/codecontext.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/Lib/idlelib/codecontext.py b/Lib/idlelib/codecontext.py
index 635f68c..b061f3b 100644
--- a/Lib/idlelib/codecontext.py
+++ b/Lib/idlelib/codecontext.py
@@ -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."