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:
parent
99167f85b7
commit
cd99e79dc7
|
@ -1,4 +1,4 @@
|
||||||
"""Class browser.
|
"""Module browser.
|
||||||
|
|
||||||
XXX TO DO:
|
XXX TO DO:
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ def transform_children(child_dict, modname=None):
|
||||||
return sorted(obs, key=lambda o: o.lineno)
|
return sorted(obs, key=lambda o: o.lineno)
|
||||||
|
|
||||||
|
|
||||||
class ClassBrowser:
|
class ModuleBrowser:
|
||||||
"""Browse module classes and functions in IDLE.
|
"""Browse module classes and functions in IDLE.
|
||||||
"""
|
"""
|
||||||
# This class is the base class for pathbrowser.PathBrowser.
|
# This class is the base class for pathbrowser.PathBrowser.
|
||||||
|
@ -122,8 +122,8 @@ class ClassBrowser:
|
||||||
|
|
||||||
def settitle(self):
|
def settitle(self):
|
||||||
"Set the window title."
|
"Set the window title."
|
||||||
self.top.wm_title("Class Browser - " + self.name)
|
self.top.wm_title("Module Browser - " + self.name)
|
||||||
self.top.wm_iconname("Class Browser")
|
self.top.wm_iconname("Module Browser")
|
||||||
|
|
||||||
def rootnode(self):
|
def rootnode(self):
|
||||||
"Return a ModuleBrowserTreeItem as the root of the tree."
|
"Return a ModuleBrowserTreeItem as the root of the tree."
|
||||||
|
@ -226,7 +226,7 @@ class ChildBrowserTreeItem(TreeItem):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _class_browser(parent): # htest #
|
def _module_browser(parent): # htest #
|
||||||
try:
|
try:
|
||||||
file = sys.argv[1] # If pass file on command line
|
file = sys.argv[1] # If pass file on command line
|
||||||
# If this succeeds, unittest will fail.
|
# If this succeeds, unittest will fail.
|
||||||
|
@ -242,10 +242,10 @@ def _class_browser(parent): # htest #
|
||||||
flist = pyshell.PyShellFileList(parent)
|
flist = pyshell.PyShellFileList(parent)
|
||||||
global file_open
|
global file_open
|
||||||
file_open = flist.open
|
file_open = flist.open
|
||||||
ClassBrowser(flist, name, [dir], _htest=True)
|
ModuleBrowser(flist, name, [dir], _htest=True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from unittest import main
|
from unittest import main
|
||||||
main('idlelib.idle_test.test_browser', verbosity=2, exit=False)
|
main('idlelib.idle_test.test_browser', verbosity=2, exit=False)
|
||||||
from idlelib.idle_test.htest import run
|
from idlelib.idle_test.htest import run
|
||||||
run(_class_browser)
|
run(_module_browser)
|
||||||
|
|
|
@ -190,7 +190,7 @@ class EditorWindow(object):
|
||||||
flist.dict[key] = self
|
flist.dict[key] = self
|
||||||
text.bind("<<open-new-window>>", self.new_callback)
|
text.bind("<<open-new-window>>", self.new_callback)
|
||||||
text.bind("<<close-all-windows>>", self.flist.close_all_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-path-browser>>", self.open_path_browser)
|
||||||
text.bind("<<open-turtle-demo>>", self.open_turtle_demo)
|
text.bind("<<open-turtle-demo>>", self.open_turtle_demo)
|
||||||
|
|
||||||
|
@ -632,10 +632,10 @@ class EditorWindow(object):
|
||||||
def open_module(self):
|
def open_module(self):
|
||||||
"""Get module name from user and open it.
|
"""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.
|
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.
|
# would fit better in iomenu.IOBinding.
|
||||||
try:
|
try:
|
||||||
name = self.text.get("sel.first", "sel.last").strip()
|
name = self.text.get("sel.first", "sel.last").strip()
|
||||||
|
@ -657,7 +657,7 @@ class EditorWindow(object):
|
||||||
self.open_module()
|
self.open_module()
|
||||||
return "break"
|
return "break"
|
||||||
|
|
||||||
def open_class_browser(self, event=None):
|
def open_module_browser(self, event=None):
|
||||||
filename = self.io.filename
|
filename = self.io.filename
|
||||||
if not (self.__class__.__name__ == 'PyShellEditorWindow'
|
if not (self.__class__.__name__ == 'PyShellEditorWindow'
|
||||||
and filename):
|
and filename):
|
||||||
|
@ -667,7 +667,7 @@ class EditorWindow(object):
|
||||||
head, tail = os.path.split(filename)
|
head, tail = os.path.split(filename)
|
||||||
base, ext = os.path.splitext(tail)
|
base, ext = os.path.splitext(tail)
|
||||||
from idlelib import browser
|
from idlelib import browser
|
||||||
browser.ClassBrowser(self.flist, base, [head])
|
browser.ModuleBrowser(self.flist, base, [head])
|
||||||
return "break"
|
return "break"
|
||||||
|
|
||||||
def open_path_browser(self, event=None):
|
def open_path_browser(self, event=None):
|
||||||
|
|
|
@ -86,7 +86,7 @@ _calltip_window_spec = {
|
||||||
"Typing ') should hide the calltip.\n"
|
"Typing ') should hide the calltip.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
_class_browser_spec = {
|
_module_browser_spec = {
|
||||||
'file': 'browser',
|
'file': 'browser',
|
||||||
'kwds': {},
|
'kwds': {},
|
||||||
'msg': "Inspect names of module, class(with superclass if "
|
'msg': "Inspect names of module, class(with superclass if "
|
||||||
|
|
|
@ -17,7 +17,7 @@ from idlelib.idle_test.mock_idle import Func
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
|
|
||||||
class ClassBrowserTest(unittest.TestCase):
|
class ModuleBrowserTest(unittest.TestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
@ -28,41 +28,41 @@ class ClassBrowserTest(unittest.TestCase):
|
||||||
cls.file = __file__
|
cls.file = __file__
|
||||||
cls.path = os.path.dirname(cls.file)
|
cls.path = os.path.dirname(cls.file)
|
||||||
cls.module = os.path.basename(cls.file).rstrip('.py')
|
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
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
cls.cb.close()
|
cls.mb.close()
|
||||||
cls.root.destroy()
|
cls.root.destroy()
|
||||||
del cls.root, cls.flist, cls.cb
|
del cls.root, cls.flist, cls.mb
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
cb = self.cb
|
mb = self.mb
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
eq(cb.name, self.module)
|
eq(mb.name, self.module)
|
||||||
eq(cb.file, self.file)
|
eq(mb.file, self.file)
|
||||||
eq(cb.flist, self.flist)
|
eq(mb.flist, self.flist)
|
||||||
eq(pyclbr._modules, {})
|
eq(pyclbr._modules, {})
|
||||||
self.assertIsInstance(cb.node, TreeNode)
|
self.assertIsInstance(mb.node, TreeNode)
|
||||||
|
|
||||||
def test_settitle(self):
|
def test_settitle(self):
|
||||||
cb = self.cb
|
mb = self.mb
|
||||||
self.assertIn(self.module, cb.top.title())
|
self.assertIn(self.module, mb.top.title())
|
||||||
self.assertEqual(cb.top.iconname(), 'Class Browser')
|
self.assertEqual(mb.top.iconname(), 'Module Browser')
|
||||||
|
|
||||||
def test_rootnode(self):
|
def test_rootnode(self):
|
||||||
cb = self.cb
|
mb = self.mb
|
||||||
rn = cb.rootnode()
|
rn = mb.rootnode()
|
||||||
self.assertIsInstance(rn, browser.ModuleBrowserTreeItem)
|
self.assertIsInstance(rn, browser.ModuleBrowserTreeItem)
|
||||||
|
|
||||||
def test_close(self):
|
def test_close(self):
|
||||||
cb = self.cb
|
mb = self.mb
|
||||||
cb.top.destroy = Func()
|
mb.top.destroy = Func()
|
||||||
cb.node.destroy = Func()
|
mb.node.destroy = Func()
|
||||||
cb.close()
|
mb.close()
|
||||||
self.assertTrue(cb.top.destroy.called)
|
self.assertTrue(mb.top.destroy.called)
|
||||||
self.assertTrue(cb.node.destroy.called)
|
self.assertTrue(mb.node.destroy.called)
|
||||||
del cb.top.destroy, cb.node.destroy
|
del mb.top.destroy, mb.node.destroy
|
||||||
|
|
||||||
|
|
||||||
# Nested tree same as in test_pyclbr.py except for supers on C0. C1.
|
# Nested tree same as in test_pyclbr.py except for supers on C0. C1.
|
||||||
|
|
|
@ -25,7 +25,7 @@ menudefs = [
|
||||||
('_New File', '<<open-new-window>>'),
|
('_New File', '<<open-new-window>>'),
|
||||||
('_Open...', '<<open-window-from-file>>'),
|
('_Open...', '<<open-window-from-file>>'),
|
||||||
('Open _Module...', '<<open-module>>'),
|
('Open _Module...', '<<open-module>>'),
|
||||||
('Class _Browser', '<<open-class-browser>>'),
|
('Module _Browser', '<<open-class-browser>>'),
|
||||||
('_Path Browser', '<<open-path-browser>>'),
|
('_Path Browser', '<<open-path-browser>>'),
|
||||||
None,
|
None,
|
||||||
('_Save', '<<save-window>>'),
|
('_Save', '<<save-window>>'),
|
||||||
|
|
|
@ -2,12 +2,12 @@ import importlib.machinery
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from idlelib.browser import ClassBrowser, ModuleBrowserTreeItem
|
from idlelib.browser import ModuleBrowser, ModuleBrowserTreeItem
|
||||||
from idlelib.pyshell import PyShellFileList
|
from idlelib.pyshell import PyShellFileList
|
||||||
from idlelib.tree import TreeItem
|
from idlelib.tree import TreeItem
|
||||||
|
|
||||||
|
|
||||||
class PathBrowser(ClassBrowser):
|
class PathBrowser(ModuleBrowser):
|
||||||
|
|
||||||
def __init__(self, flist, _htest=False, _utest=False):
|
def __init__(self, flist, _htest=False, _utest=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -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.
|
Loading…
Reference in New Issue