Skip to content

gh-79951: IDLE - Convert menudefs to dictionary #11615

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions Lib/idlelib/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,11 @@ def ApplyKeybindings(self):
self.apply_bindings(xkeydefs)
#update menu accelerators
menuEventDict = {}
for menu in self.mainmenu.menudefs:
menuEventDict[menu[0]] = {}
for item in menu[1]:
for menu, items in self.mainmenu.menudefs.items():
menuEventDict[menu] = {}
for item in items:
if item:
menuEventDict[menu[0]][prepstr(item[0])[1]] = item[1]
menuEventDict[menu][prepstr(item[0])[1]] = item[1]
for menubarItem in self.menudict:
menu = self.menudict[menubarItem]
end = menu.index(END)
Expand Down Expand Up @@ -1117,7 +1117,7 @@ def fill_menus(self, menudefs=None, keydefs=None):
keydefs = self.mainmenu.default_keydefs
menudict = self.menudict
text = self.text
for mname, entrylist in menudefs:
for mname, entrylist in menudefs.items():
menu = menudict.get(mname)
if not menu:
continue
Expand Down
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/test_mainmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class MainMenuTest(unittest.TestCase):

def test_menudefs(self):
actual = [item[0] for item in mainmenu.menudefs]
actual = list(mainmenu.menudefs.keys())
expect = ['file', 'edit', 'format', 'run', 'shell',
'debug', 'options', 'window', 'help']
self.assertEqual(actual, expect)
Expand Down
22 changes: 11 additions & 11 deletions Lib/idlelib/macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,20 @@ def overrideRootMenu(root, flist):
from idlelib import mainmenu
from idlelib import window

closeItem = mainmenu.menudefs[0][1][-2]
closeItem = mainmenu.menudefs['file'][-2]

# Remove the last 3 items of the file menu: a separator, close window and
# quit. Close window will be reinserted just above the save item, where
# it should be according to the HIG. Quit is in the application menu.
del mainmenu.menudefs[0][1][-3:]
mainmenu.menudefs[0][1].insert(6, closeItem)
del mainmenu.menudefs['file'][-3:]
mainmenu.menudefs['file'].insert(6, closeItem)

# Remove the 'About' entry from the help menu, it is in the application
# menu
del mainmenu.menudefs[-1][1][0:2]
del mainmenu.menudefs['help'][0:2]
# Remove the 'Configure Idle' entry from the options menu, it is in the
# application menu as 'Preferences'
del mainmenu.menudefs[-2][1][0]
del mainmenu.menudefs['options'][0]
menubar = Menu(root)
root.configure(menu=menubar)
menudict = {}
Expand Down Expand Up @@ -236,18 +236,18 @@ def help_dialog(event=None):
menudict['application'] = menu = Menu(menubar, name='apple',
tearoff=0)
menubar.add_cascade(label='IDLE', menu=menu)
mainmenu.menudefs.insert(0,
('application', [
('About IDLE', '<<about-idle>>'),
None,
]))
appmenu = {'application': [
('About IDLE', '<<about-idle>>'),
None,
]}
mainmenu.menudefs = {**appmenu, **mainmenu.menudefs}
if isCocoaTk():
# replace default About dialog with About IDLE one
root.createcommand('tkAboutDialog', about_dialog)
# replace default "Help" item in Help menu
root.createcommand('::tk::mac::ShowHelp', help_dialog)
# remove redundant "IDLE Help" from menu
del mainmenu.menudefs[-1][1][0]
del mainmenu.menudefs['help'][0]

def fixb2context(root):
'''Removed bad AquaTk Button-2 (right) and Paste bindings.
Expand Down
42 changes: 21 additions & 21 deletions Lib/idlelib/mainmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
# without altering overrideRootMenu() as well.
# TODO: Make this more robust

menudefs = [
menudefs = {
# underscore prefixes character to underscore
('file', [
'file': [
('_New File', '<<open-new-window>>'),
('_Open...', '<<open-window-from-file>>'),
('Open _Module...', '<<open-module>>'),
Expand All @@ -36,9 +36,9 @@
None,
('_Close', '<<close-window>>'),
('E_xit', '<<close-all-windows>>'),
]),
],

('edit', [
'edit': [
('_Undo', '<<undo>>'),
('_Redo', '<<redo>>'),
None,
Expand All @@ -57,9 +57,9 @@
('E_xpand Word', '<<expand-word>>'),
('Show C_all Tip', '<<force-open-calltip>>'),
('Show Surrounding P_arens', '<<flash-paren>>'),
]),
],

('format', [
'format': [
('_Indent Region', '<<indent-region>>'),
('_Dedent Region', '<<dedent-region>>'),
('Comment _Out Region', '<<comment-region>>'),
Expand All @@ -70,51 +70,51 @@
('New Indent Width', '<<change-indentwidth>>'),
('F_ormat Paragraph', '<<format-paragraph>>'),
('S_trip Trailing Whitespace', '<<do-rstrip>>'),
]),
],

('run', [
'run': [
('Python Shell', '<<open-python-shell>>'),
('C_heck Module', '<<check-module>>'),
('R_un Module', '<<run-module>>'),
]),
],

('shell', [
'shell': [
('_View Last Restart', '<<view-restart>>'),
('_Restart Shell', '<<restart-shell>>'),
None,
('_Previous History', '<<history-previous>>'),
('_Next History', '<<history-next>>'),
None,
('_Interrupt Execution', '<<interrupt-execution>>'),
]),
],

('debug', [
'debug': [
('_Go to File/Line', '<<goto-file-line>>'),
('!_Debugger', '<<toggle-debugger>>'),
('_Stack Viewer', '<<open-stack-viewer>>'),
('!_Auto-open Stack Viewer', '<<toggle-jit-stack-viewer>>'),
]),
],

('options', [
'options': [
('Configure _IDLE', '<<open-config-dialog>>'),
None,
('Show _Code Context', '<<toggle-code-context>>'),
('Zoom Height', '<<zoom-height>>'),
]),
],

('window', [
]),
'window': [
],

('help', [
'help': [
('_About IDLE', '<<about-idle>>'),
None,
('_IDLE Help', '<<help>>'),
('Python _Docs', '<<python-docs>>'),
]),
]
],
}

if find_spec('turtledemo'):
menudefs[-1][1].append(('Turtle Demo', '<<open-turtle-demo>>'))
menudefs['help'].append(('Turtle Demo', '<<open-turtle-demo>>'))

default_keydefs = idleConf.GetCurrentKeySet()

Expand Down
8 changes: 4 additions & 4 deletions Lib/idlelib/zzdummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

class ZzDummy:

## menudefs = [
## ('format', [
## menudefs = {
## 'format': [
## ('Z in', '<<z-in>>'),
## ('Z out', '<<z-out>>'),
## ] )
## ]
## ]
## }

def __init__(self, editwin):
self.text = editwin.text
Expand Down