Skip to content

[3.7] bpo-33610: IDLE's code-context always shows current context immediately (GH-14821) #14847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Lib/idlelib/codecontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ def __init__(self, editwin):
"""
self.editwin = editwin
self.text = editwin.text
self._reset()

def _reset(self):
self.context = None
self.t1 = None
self.topvisible = 1
self.info = [(0, -1, "", False)]
self.t1 = None

@classmethod
def reload(cls):
Expand Down Expand Up @@ -112,17 +115,17 @@ def toggle_code_context_event(self, event=None):
padx=padx, border=border, relief=SUNKEN, state='disabled')
self.update_highlight_colors()
self.context.bind('<ButtonRelease-1>', self.jumptoline)
# Get the current context and initiate the recurring update event.
self.timer_event()
# Pack the context widget before and above the text_frame widget,
# thus ensuring that it will appear directly above text_frame.
self.context.pack(side=TOP, fill=X, expand=False,
before=self.editwin.text_frame)
menu_status = 'Hide'
self.t1 = self.text.after(self.UPDATEINTERVAL, self.timer_event)
else:
self.context.destroy()
self.context = None
self.text.after_cancel(self.t1)
self.t1 = None
self._reset()
menu_status = 'Show'
self.editwin.update_menu_label(menu='options', index='* Code Context',
label=f'{menu_status} Code Context')
Expand Down
17 changes: 14 additions & 3 deletions Lib/idlelib/idle_test/test_codecontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_toggle_code_context_event(self):
toggle()

# Toggle on.
eq(toggle(), 'break')
toggle()
self.assertIsNotNone(cc.context)
eq(cc.context['font'], self.text['font'])
eq(cc.context['fg'], self.highlight_cfg['foreground'])
Expand All @@ -145,11 +145,22 @@ def test_toggle_code_context_event(self):
eq(self.root.tk.call('after', 'info', self.cc.t1)[1], 'timer')

# Toggle off.
eq(toggle(), 'break')
toggle()
self.assertIsNone(cc.context)
eq(cc.editwin.label, 'Show Code Context')
self.assertIsNone(self.cc.t1)

# Scroll down and toggle back on.
line11_context = '\n'.join(x[2] for x in cc.get_context(11)[0])
cc.text.yview(11)
toggle()
eq(cc.context.get('1.0', 'end-1c'), line11_context)

# Toggle off and on again.
toggle()
toggle()
eq(cc.context.get('1.0', 'end-1c'), line11_context)

def test_get_context(self):
eq = self.assertEqual
gc = self.cc.get_context
Expand Down Expand Up @@ -329,7 +340,7 @@ def test_font(self):
eq = self.assertEqual
cc = self.cc
save_font = cc.text['font']
test_font = 'TkFixedFont'
test_font = 'TkTextFont'

# Ensure code context is not active.
if cc.context is not None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix code context not showing the correct context when first toggled on.