MCPcopy Index your code
hub / github.com/python/cpython / update_code_context

Method update_code_context

Lib/idlelib/codecontext.py:179–217  ·  view source on GitHub ↗

Update context information and lines visible in the context pane. No update is done if the text hasn't been scrolled. If the text was scrolled, the lines that should be shown in the context will be retrieved and the context area will be updated with the code, up to

(self)

Source from the content-addressed store, hash-verified

177 return lines, lastindent
178
179 def update_code_context(self):
180 """Update context information and lines visible in the context pane.
181
182 No update is done if the text hasn't been scrolled. If the text
183 was scrolled, the lines that should be shown in the context will
184 be retrieved and the context area will be updated with the code,
185 up to the number of maxlines.
186 """
187 new_topvisible = self.editwin.getlineno("@0,0")
188 if self.topvisible == new_topvisible: # Haven't scrolled.
189 return
190 if self.topvisible < new_topvisible: # Scroll down.
191 lines, lastindent = self.get_context(new_topvisible,
192 self.topvisible)
193 # Retain only context info applicable to the region
194 # between topvisible and new_topvisible.
195 while self.info[-1][1] >= lastindent:
196 del self.info[-1]
197 else: # self.topvisible > new_topvisible: # Scroll up.
198 stopindent = self.info[-1][1] + 1
199 # Retain only context info associated
200 # with lines above new_topvisible.
201 while self.info[-1][0] >= new_topvisible:
202 stopindent = self.info[-1][1]
203 del self.info[-1]
204 lines, lastindent = self.get_context(new_topvisible,
205 self.info[-1][0]+1,
206 stopindent)
207 self.info.extend(lines)
208 self.topvisible = new_topvisible
209 # Last context_depth context lines.
210 context_strings = [x[2] for x in self.info[-self.context_depth:]]
211 showfirst = 0 if context_strings[0] else 1
212 # Update widget.
213 self.context['height'] = len(context_strings) - showfirst
214 self.context['state'] = 'normal'
215 self.context.delete('1.0', 'end')
216 self.context.insert('end', '\n'.join(context_strings[showfirst:]))
217 self.context['state'] = 'disabled'
218
219 def jumptoline(self, event=None):
220 """ Show clicked context line at top of editor.

Callers 4

jumptolineMethod · 0.95
timer_eventMethod · 0.95
test_jumptolineMethod · 0.80

Calls 6

get_contextMethod · 0.95
getlinenoMethod · 0.45
extendMethod · 0.45
deleteMethod · 0.45
insertMethod · 0.45
joinMethod · 0.45

Tested by 2

test_jumptolineMethod · 0.64