]> granicus.if.org Git - python/commitdiff
bpo-33610: IDLE's code-context always shows current context immediately (GH-14821)
authorTal Einat <taleinat@gmail.com>
Thu, 18 Jul 2019 20:03:18 +0000 (23:03 +0300)
committerTerry Jan Reedy <tjreedy@udel.edu>
Thu, 18 Jul 2019 20:03:18 +0000 (16:03 -0400)
Eliminate delay of up to 100ms and accompanying visual artifact.
Fix bug of never showing context when hide and show.

Lib/idlelib/codecontext.py
Lib/idlelib/idle_test/test_codecontext.py
Misc/NEWS.d/next/IDLE/2019-07-18-10-11-36.bpo-33610.xYqMLg.rst [new file with mode: 0644]

index 9bd0fa1753fc6b06947eb5304a0312be6985a458..3103391cfe58be0ac7ed9da49e493c62198df45d 100644 (file)
@@ -63,10 +63,13 @@ class CodeContext:
         """
         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):
@@ -112,17 +115,17 @@ class CodeContext:
                 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')
index 05d3209db568884475741e835a5cf661823b6d82..c6c8e8efcd4fdac6dfed6f60f7ed52d9b4837cf4 100644 (file)
@@ -135,7 +135,7 @@ class CodeContextTest(unittest.TestCase):
             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'])
@@ -145,11 +145,22 @@ class CodeContextTest(unittest.TestCase):
         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
@@ -329,7 +340,7 @@ class CodeContextTest(unittest.TestCase):
         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:
diff --git a/Misc/NEWS.d/next/IDLE/2019-07-18-10-11-36.bpo-33610.xYqMLg.rst b/Misc/NEWS.d/next/IDLE/2019-07-18-10-11-36.bpo-33610.xYqMLg.rst
new file mode 100644 (file)
index 0000000..6775b04
--- /dev/null
@@ -0,0 +1 @@
+Fix code context not showing the correct context when first toggled on.