[Python-checkins] bpo-22703: IDLE: Improve Code Context and Zoom Height menu labels (GH-11214)

Miss Islington (bot) webhook-mailer at python.org
Sat Dec 22 01:25:50 EST 2018


https://github.com/python/cpython/commit/c1b4b0f6160e1919394586f44b12538505fed300
commit: c1b4b0f6160e1919394586f44b12538505fed300
branch: master
author: Cheryl Sabella <cheryl.sabella at gmail.com>
committer: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
date: 2018-12-21T22:25:45-08:00
summary:

 bpo-22703: IDLE: Improve Code Context and Zoom Height menu labels (GH-11214)



The Code Context menu label now toggles between Show/Hide Code Context. 
 The Zoom Height menu now toggles between Zoom/Restore Height. 
 Zoom Height has moved from the Window menu to the Options menu. 

 
https://bugs.python.org/issue22703

files:
A Misc/NEWS.d/next/IDLE/2018-12-18-13-56-31.bpo-22703.UlsjKQ.rst
M Doc/library/idle.rst
M Lib/idlelib/NEWS.txt
M Lib/idlelib/codecontext.py
M Lib/idlelib/editor.py
M Lib/idlelib/idle_test/test_codecontext.py
M Lib/idlelib/mainmenu.py
M Lib/idlelib/zoomheight.py

diff --git a/Doc/library/idle.rst b/Doc/library/idle.rst
index 80a2fdc4bf02..ef9bd2698f5b 100644
--- a/Doc/library/idle.rst
+++ b/Doc/library/idle.rst
@@ -275,7 +275,12 @@ Configure IDLE
    menu. For more, see
    :ref:`Setting preferences <preferences>` under Help and preferences.
 
-Code Context (toggle)(Editor Window only)
+Zoom/Restore Height
+   Toggles the window between normal size and maximum height. The initial size
+   defaults to 40 lines by 80 chars unless changed on the General tab of the
+   Configure IDLE dialog.
+
+Show/Hide Code Context (Editor Window only)
    Open a pane at the top of the edit window which shows the block context
    of the code which has scrolled above the top of the window.  See
    :ref:`Code Context <code-context>` in the Editing and Navigation section below.
@@ -283,13 +288,8 @@ Code Context (toggle)(Editor Window only)
 Window menu (Shell and Editor)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-Zoom Height
-   Toggles the window between normal size and maximum height. The initial size
-   defaults to 40 lines by 80 chars unless changed on the General tab of the
-   Configure IDLE dialog.
-
-The rest of this menu lists the names of all open windows; select one to bring
-it to the foreground (deiconifying it if necessary).
+Lists the names of all open windows; select one to bring it to the foreground
+(deiconifying it if necessary).
 
 Help menu (Shell and Editor)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index b02b96bf476d..f46a2d7d8028 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -3,6 +3,11 @@ Released on 2019-10-20?
 ======================================
 
 
+bpo-22703: Improve the Code Context and Zoom Height menu labels.
+The Code Context menu label now toggles between Show/Hide Code Context.
+The Zoom Height menu now toggles between Zoom/Restore Height.
+Zoom Height has moved from the Window menu to the Options menu.
+
 bpo-35521: Document the editor code context feature.
 Add some internal references within the IDLE doc.
 
diff --git a/Lib/idlelib/codecontext.py b/Lib/idlelib/codecontext.py
index ef8852852d1f..2aed76de7fb6 100644
--- a/Lib/idlelib/codecontext.py
+++ b/Lib/idlelib/codecontext.py
@@ -122,9 +122,13 @@ def toggle_code_context_event(self, event=None):
             # 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'
         else:
             self.context.destroy()
             self.context = None
+            menu_status = 'Show'
+        self.editwin.update_menu_label(menu='options', index='* Code Context',
+                                       label=f'{menu_status} Code Context')
         return "break"
 
     def get_context(self, new_topvisible, stopline=1, stopindent=0):
diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py
index 6689af64c429..d92b32b24004 100644
--- a/Lib/idlelib/editor.py
+++ b/Lib/idlelib/editor.py
@@ -446,6 +446,11 @@ def postwindowsmenu(self):
             menu.delete(self.wmenu_end+1, end)
         window.add_windows_to_menu(menu)
 
+    def update_menu_label(self, menu, index, label):
+        "Update label for menu item at index ."
+        menuitem = self.menudict[menu]
+        menuitem.entryconfig(index, label=label)
+
     def handle_yview(self, event, *args):
         "Handle scrollbar."
         if event == 'moveto':
diff --git a/Lib/idlelib/idle_test/test_codecontext.py b/Lib/idlelib/idle_test/test_codecontext.py
index ef8170e3b696..6c6893580f42 100644
--- a/Lib/idlelib/idle_test/test_codecontext.py
+++ b/Lib/idlelib/idle_test/test_codecontext.py
@@ -40,6 +40,10 @@ def __init__(self, root, frame, text):
         self.top = root
         self.text_frame = frame
         self.text = text
+        self.label = ''
+
+    def update_menu_label(self, **kwargs):
+        self.label = kwargs['label']
 
 
 class CodeContextTest(unittest.TestCase):
@@ -127,10 +131,12 @@ def test_toggle_code_context_event(self):
         eq(cc.context['fg'], cc.colors['foreground'])
         eq(cc.context['bg'], cc.colors['background'])
         eq(cc.context.get('1.0', 'end-1c'), '')
+        eq(cc.editwin.label, 'Hide Code Context')
 
         # Toggle off.
         eq(toggle(), 'break')
         self.assertIsNone(cc.context)
+        eq(cc.editwin.label, 'Show Code Context')
 
     def test_get_context(self):
         eq = self.assertEqual
diff --git a/Lib/idlelib/mainmenu.py b/Lib/idlelib/mainmenu.py
index 9fe6b5229446..6081a5f1003d 100644
--- a/Lib/idlelib/mainmenu.py
+++ b/Lib/idlelib/mainmenu.py
@@ -94,11 +94,12 @@
 
  ('options', [
    ('Configure _IDLE', '<<open-config-dialog>>'),
-   ('_Code Context', '<<toggle-code-context>>'),
+   None,
+   ('Show _Code Context', '<<toggle-code-context>>'),
+   ('Zoom Height', '<<zoom-height>>'),
    ]),
 
  ('window', [
-   ('Zoom Height', '<<zoom-height>>'),
    ]),
 
  ('help', [
diff --git a/Lib/idlelib/zoomheight.py b/Lib/idlelib/zoomheight.py
index 73f1df071bf3..35e285f0ba41 100644
--- a/Lib/idlelib/zoomheight.py
+++ b/Lib/idlelib/zoomheight.py
@@ -13,7 +13,10 @@ def __init__(self, editwin):
 
     def zoom_height_event(self, event=None):
         top = self.editwin.top
-        zoom_height(top)
+        zoomed = zoom_height(top)
+        menu_status = 'Restore' if zoomed else 'Zoom'
+        self.editwin.update_menu_label(menu='options', index='* Height',
+                                       label=f'{menu_status} Height')
         return "break"
 
 
@@ -46,6 +49,7 @@ def zoom_height(top):
     else:
         newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy)
     top.wm_geometry(newgeom)
+    return newgeom != ""
 
 
 if __name__ == "__main__":
diff --git a/Misc/NEWS.d/next/IDLE/2018-12-18-13-56-31.bpo-22703.UlsjKQ.rst b/Misc/NEWS.d/next/IDLE/2018-12-18-13-56-31.bpo-22703.UlsjKQ.rst
new file mode 100644
index 000000000000..d1129c4f155c
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2018-12-18-13-56-31.bpo-22703.UlsjKQ.rst
@@ -0,0 +1,3 @@
+The Code Context menu label now toggles between Show/Hide Code Context.
+The Zoom Height menu now toggles between Zoom/Restore Height.
+Zoom Height has moved from the Window menu to the Options menu.



More information about the Python-checkins mailing list