bpo-27465: Make IDLE help source menu entries unique and sorted

This commit is contained in:
Zackery Spytz 2019-11-08 14:32:50 -07:00
parent fc6b1bf869
commit ae75a0b10b
6 changed files with 39 additions and 6 deletions

View File

@ -340,9 +340,14 @@ Python Docs
Turtle Demo
Run the turtledemo module with example Python code and turtle drawings.
Additional help sources may be added here with the Configure IDLE dialog under
the General tab. See the :ref:`Help sources <help-sources>` subsection below
for more on Help menu choices.
Additional help sources
Menu items for display here are added on the General tab of Options =>
Configure IDLE. Menu entries should be unique (new in 3.9) and will be
sorted. Documents can be located either on the current machine or on the
internet. The allowed file types may depend on the system. Local file
paths are checked when submitted; internet addresses are not. See the
:ref:`Help sources <help-sources>` subsection below for more on Help menu
choices.
.. index::
single: Cut

View File

@ -2103,6 +2103,10 @@ class GenPage(Frame):
# Set additional help sources.
self.user_helplist = idleConf.GetAllExtraHelpSourcesList()
self.set_additional_help_sources()
def set_additional_help_sources(self):
self.user_helplist.sort(key=lambda x: x[0])
self.helplist.delete(0, 'end')
for help_item in self.user_helplist:
self.helplist.insert(END, help_item[0])
@ -2131,7 +2135,9 @@ class GenPage(Frame):
Query for name and location of new help sources and add
them to the list.
"""
help_source = HelpSource(self, 'New Help Source').result
used_names = idleConf.GetExtraHelpSourceList('user')
help_source = HelpSource(self, 'New Help Source',
used_names=[item[0] for item in used_names]).result
if help_source:
self.user_helplist.append(help_source)
self.helplist.insert(END, help_source[0])
@ -2145,10 +2151,12 @@ class GenPage(Frame):
"""
item_index = self.helplist.index(ANCHOR)
help_source = self.user_helplist[item_index]
used_names = idleConf.GetExtraHelpSourceList('user')
new_help_source = HelpSource(
self, 'Edit Help Source',
menuitem=help_source[0],
filepath=help_source[1],
used_names=[item[0] for item in used_names]
).result
if new_help_source and new_help_source != help_source:
self.user_helplist[item_index] = new_help_source
@ -2171,6 +2179,7 @@ class GenPage(Frame):
def update_help_changes(self):
"Clear and rebuild the HelpFiles section in changes"
changes['main']['HelpFiles'] = {}
self.set_additional_help_sources()
for num in range(1, len(self.user_helplist) + 1):
changes.add_option(
'main', 'HelpFiles', str(num),

View File

@ -363,9 +363,12 @@ and open docs.python.org showing the latest Python documentation.</p>
<dt>Turtle Demo</dt><dd><p>Run the turtledemo module with example Python code and turtle drawings.</p>
</dd>
</dl>
<p>Additional help sources may be added here with the Configure IDLE dialog under
the General tab. See the <a class="reference internal" href="#help-sources"><span class="std std-ref">Help sources</span></a> subsection below
<dt>Additional help sources</dt><dd><p>Menu items for display here are added on the General tab of Options => Configure IDLE.
Menu entries should be unique (new in 3.9) and will be sorted. Documents can be located either on the current machine or on the internet.
The allowed file types may depend on the system. Local file paths are checked when submitted; internet addresses are not.
See the <a class="reference internal" href="#help-sources"><span class="std std-ref">Help sources</span></a> subsection below
for more on Help menu choices.</p>
</dd>
</div>
<div class="section" id="context-menus">
<span id="index-4"></span><h3>Context Menus<a class="headerlink" href="#context-menus" title="Permalink to this headline"></a></h3>

View File

@ -217,10 +217,14 @@ class HelpsourceEntryokTest(unittest.TestCase):
entry_ok = query.HelpSource.entry_ok
entry_error = {}
path_error = {}
def __init__(self, used_names={}):
self.used_names = used_names
def item_ok(self):
return self.name
def path_ok(self):
return self.path
def showerror(self, message):
self.entry_error['text'] = message
def test_entry_ok_helpsource(self):
dialog = self.Dummy_HelpSource()
@ -232,6 +236,13 @@ class HelpsourceEntryokTest(unittest.TestCase):
dialog.name, dialog.path = name, path
self.assertEqual(dialog.entry_ok(), result)
def test_entry_ok_helpsource_duplicate(self):
name = 'help1'
dialog = self.Dummy_HelpSource({name})
dialog.name, dialog.path = name, 'doc.txt'
self.assertEqual(dialog.entry_ok(), None)
self.assertIn('in use', dialog.entry_error['text'])
# 2 CustomRun test classes each test one method.

View File

@ -314,6 +314,9 @@ class HelpSource(Query):
self.entry_error['text'] = ''
self.path_error['text'] = ''
name = self.item_ok()
if name in self.used_names:
self.showerror('name is already in use.')
return None
path = self.path_ok()
return None if name is None or path is None else (name, path)

View File

@ -0,0 +1,2 @@
Additional help sources added to IDLE's help menu are now sorted and must be
unique.