bpo-31459: Rename IDLE's module browser from Class Browser to Module Browser. (#3704)

The original module-level class and method browser became a module
browser, with the addition of module-level functions, years ago.
Nested classes and functions were added yesterday.  For back-
compatibility, the virtual event <<open-class-browser>>, which
appears on the Keys tab of the Settings dialog, is not changed.
Patch by Cheryl Sabella.
This commit is contained in:
Cheryl Sabella 2017-09-23 16:46:01 -04:00 committed by Terry Jan Reedy
parent 99167f85b7
commit cd99e79dc7
7 changed files with 44 additions and 37 deletions

View File

@ -1,4 +1,4 @@
"""Class browser.
"""Module browser.
XXX TO DO:
@ -55,7 +55,7 @@ def transform_children(child_dict, modname=None):
return sorted(obs, key=lambda o: o.lineno)
class ClassBrowser:
class ModuleBrowser:
"""Browse module classes and functions in IDLE.
"""
# This class is the base class for pathbrowser.PathBrowser.
@ -122,8 +122,8 @@ class ClassBrowser:
def settitle(self):
"Set the window title."
self.top.wm_title("Class Browser - " + self.name)
self.top.wm_iconname("Class Browser")
self.top.wm_title("Module Browser - " + self.name)
self.top.wm_iconname("Module Browser")
def rootnode(self):
"Return a ModuleBrowserTreeItem as the root of the tree."
@ -226,7 +226,7 @@ class ChildBrowserTreeItem(TreeItem):
pass
def _class_browser(parent): # htest #
def _module_browser(parent): # htest #
try:
file = sys.argv[1] # If pass file on command line
# If this succeeds, unittest will fail.
@ -242,10 +242,10 @@ def _class_browser(parent): # htest #
flist = pyshell.PyShellFileList(parent)
global file_open
file_open = flist.open
ClassBrowser(flist, name, [dir], _htest=True)
ModuleBrowser(flist, name, [dir], _htest=True)
if __name__ == "__main__":
from unittest import main
main('idlelib.idle_test.test_browser', verbosity=2, exit=False)
from idlelib.idle_test.htest import run
run(_class_browser)
run(_module_browser)

View File

@ -190,7 +190,7 @@ class EditorWindow(object):
flist.dict[key] = self
text.bind("<<open-new-window>>", self.new_callback)
text.bind("<<close-all-windows>>", self.flist.close_all_callback)
text.bind("<<open-class-browser>>", self.open_class_browser)
text.bind("<<open-class-browser>>", self.open_module_browser)
text.bind("<<open-path-browser>>", self.open_path_browser)
text.bind("<<open-turtle-demo>>", self.open_turtle_demo)
@ -632,10 +632,10 @@ class EditorWindow(object):
def open_module(self):
"""Get module name from user and open it.
Return module path or None for calls by open_class_browser
Return module path or None for calls by open_module_browser
when latter is not invoked in named editor window.
"""
# XXX This, open_class_browser, and open_path_browser
# XXX This, open_module_browser, and open_path_browser
# would fit better in iomenu.IOBinding.
try:
name = self.text.get("sel.first", "sel.last").strip()
@ -657,7 +657,7 @@ class EditorWindow(object):
self.open_module()
return "break"
def open_class_browser(self, event=None):
def open_module_browser(self, event=None):
filename = self.io.filename
if not (self.__class__.__name__ == 'PyShellEditorWindow'
and filename):
@ -667,7 +667,7 @@ class EditorWindow(object):
head, tail = os.path.split(filename)
base, ext = os.path.splitext(tail)
from idlelib import browser
browser.ClassBrowser(self.flist, base, [head])
browser.ModuleBrowser(self.flist, base, [head])
return "break"
def open_path_browser(self, event=None):

View File

@ -86,7 +86,7 @@ _calltip_window_spec = {
"Typing ') should hide the calltip.\n"
}
_class_browser_spec = {
_module_browser_spec = {
'file': 'browser',
'kwds': {},
'msg': "Inspect names of module, class(with superclass if "

View File

@ -17,7 +17,7 @@ from idlelib.idle_test.mock_idle import Func
from collections import deque
class ClassBrowserTest(unittest.TestCase):
class ModuleBrowserTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
@ -28,41 +28,41 @@ class ClassBrowserTest(unittest.TestCase):
cls.file = __file__
cls.path = os.path.dirname(cls.file)
cls.module = os.path.basename(cls.file).rstrip('.py')
cls.cb = browser.ClassBrowser(cls.flist, cls.module, [cls.path], _utest=True)
cls.mb = browser.ModuleBrowser(cls.flist, cls.module, [cls.path], _utest=True)
@classmethod
def tearDownClass(cls):
cls.cb.close()
cls.mb.close()
cls.root.destroy()
del cls.root, cls.flist, cls.cb
del cls.root, cls.flist, cls.mb
def test_init(self):
cb = self.cb
mb = self.mb
eq = self.assertEqual
eq(cb.name, self.module)
eq(cb.file, self.file)
eq(cb.flist, self.flist)
eq(mb.name, self.module)
eq(mb.file, self.file)
eq(mb.flist, self.flist)
eq(pyclbr._modules, {})
self.assertIsInstance(cb.node, TreeNode)
self.assertIsInstance(mb.node, TreeNode)
def test_settitle(self):
cb = self.cb
self.assertIn(self.module, cb.top.title())
self.assertEqual(cb.top.iconname(), 'Class Browser')
mb = self.mb
self.assertIn(self.module, mb.top.title())
self.assertEqual(mb.top.iconname(), 'Module Browser')
def test_rootnode(self):
cb = self.cb
rn = cb.rootnode()
mb = self.mb
rn = mb.rootnode()
self.assertIsInstance(rn, browser.ModuleBrowserTreeItem)
def test_close(self):
cb = self.cb
cb.top.destroy = Func()
cb.node.destroy = Func()
cb.close()
self.assertTrue(cb.top.destroy.called)
self.assertTrue(cb.node.destroy.called)
del cb.top.destroy, cb.node.destroy
mb = self.mb
mb.top.destroy = Func()
mb.node.destroy = Func()
mb.close()
self.assertTrue(mb.top.destroy.called)
self.assertTrue(mb.node.destroy.called)
del mb.top.destroy, mb.node.destroy
# Nested tree same as in test_pyclbr.py except for supers on C0. C1.

View File

@ -25,7 +25,7 @@ menudefs = [
('_New File', '<<open-new-window>>'),
('_Open...', '<<open-window-from-file>>'),
('Open _Module...', '<<open-module>>'),
('Class _Browser', '<<open-class-browser>>'),
('Module _Browser', '<<open-class-browser>>'),
('_Path Browser', '<<open-path-browser>>'),
None,
('_Save', '<<save-window>>'),

View File

@ -2,12 +2,12 @@ import importlib.machinery
import os
import sys
from idlelib.browser import ClassBrowser, ModuleBrowserTreeItem
from idlelib.browser import ModuleBrowser, ModuleBrowserTreeItem
from idlelib.pyshell import PyShellFileList
from idlelib.tree import TreeItem
class PathBrowser(ClassBrowser):
class PathBrowser(ModuleBrowser):
def __init__(self, flist, _htest=False, _utest=False):
"""

View File

@ -0,0 +1,7 @@
Rename IDLE's module browser from Class Browser to Module Browser.
The original module-level class and method browser became a module
browser, with the addition of module-level functions, years ago.
Nested classes and functions were added yesterday. For back-
compatibility, the virtual event <<open-class-browser>>, which
appears on the Keys tab of the Settings dialog, is not changed.
Patch by Cheryl Sabella.