bpo-27465: Make IDLE help source menu entries unique and sorted
This commit is contained in:
parent
fc6b1bf869
commit
ae75a0b10b
|
@ -340,9 +340,14 @@ Python Docs
|
||||||
Turtle Demo
|
Turtle Demo
|
||||||
Run the turtledemo module with example Python code and turtle drawings.
|
Run the turtledemo module with example Python code and turtle drawings.
|
||||||
|
|
||||||
Additional help sources may be added here with the Configure IDLE dialog under
|
Additional help sources
|
||||||
the General tab. See the :ref:`Help sources <help-sources>` subsection below
|
Menu items for display here are added on the General tab of Options =>
|
||||||
for more on Help menu choices.
|
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::
|
.. index::
|
||||||
single: Cut
|
single: Cut
|
||||||
|
|
|
@ -2103,6 +2103,10 @@ class GenPage(Frame):
|
||||||
|
|
||||||
# Set additional help sources.
|
# Set additional help sources.
|
||||||
self.user_helplist = idleConf.GetAllExtraHelpSourcesList()
|
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')
|
self.helplist.delete(0, 'end')
|
||||||
for help_item in self.user_helplist:
|
for help_item in self.user_helplist:
|
||||||
self.helplist.insert(END, help_item[0])
|
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
|
Query for name and location of new help sources and add
|
||||||
them to the list.
|
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:
|
if help_source:
|
||||||
self.user_helplist.append(help_source)
|
self.user_helplist.append(help_source)
|
||||||
self.helplist.insert(END, help_source[0])
|
self.helplist.insert(END, help_source[0])
|
||||||
|
@ -2145,10 +2151,12 @@ class GenPage(Frame):
|
||||||
"""
|
"""
|
||||||
item_index = self.helplist.index(ANCHOR)
|
item_index = self.helplist.index(ANCHOR)
|
||||||
help_source = self.user_helplist[item_index]
|
help_source = self.user_helplist[item_index]
|
||||||
|
used_names = idleConf.GetExtraHelpSourceList('user')
|
||||||
new_help_source = HelpSource(
|
new_help_source = HelpSource(
|
||||||
self, 'Edit Help Source',
|
self, 'Edit Help Source',
|
||||||
menuitem=help_source[0],
|
menuitem=help_source[0],
|
||||||
filepath=help_source[1],
|
filepath=help_source[1],
|
||||||
|
used_names=[item[0] for item in used_names]
|
||||||
).result
|
).result
|
||||||
if new_help_source and new_help_source != help_source:
|
if new_help_source and new_help_source != help_source:
|
||||||
self.user_helplist[item_index] = new_help_source
|
self.user_helplist[item_index] = new_help_source
|
||||||
|
@ -2171,6 +2179,7 @@ class GenPage(Frame):
|
||||||
def update_help_changes(self):
|
def update_help_changes(self):
|
||||||
"Clear and rebuild the HelpFiles section in changes"
|
"Clear and rebuild the HelpFiles section in changes"
|
||||||
changes['main']['HelpFiles'] = {}
|
changes['main']['HelpFiles'] = {}
|
||||||
|
self.set_additional_help_sources()
|
||||||
for num in range(1, len(self.user_helplist) + 1):
|
for num in range(1, len(self.user_helplist) + 1):
|
||||||
changes.add_option(
|
changes.add_option(
|
||||||
'main', 'HelpFiles', str(num),
|
'main', 'HelpFiles', str(num),
|
||||||
|
|
|
@ -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>
|
<dt>Turtle Demo</dt><dd><p>Run the turtledemo module with example Python code and turtle drawings.</p>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
<p>Additional help sources may be added here with the Configure IDLE dialog under
|
<dt>Additional help sources</dt><dd><p>Menu items for display here are added on the General tab of Options => Configure IDLE.
|
||||||
the General tab. See the <a class="reference internal" href="#help-sources"><span class="std std-ref">Help sources</span></a> subsection below
|
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>
|
for more on Help menu choices.</p>
|
||||||
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="context-menus">
|
<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>
|
<span id="index-4"></span><h3>Context Menus<a class="headerlink" href="#context-menus" title="Permalink to this headline">¶</a></h3>
|
||||||
|
|
|
@ -217,10 +217,14 @@ class HelpsourceEntryokTest(unittest.TestCase):
|
||||||
entry_ok = query.HelpSource.entry_ok
|
entry_ok = query.HelpSource.entry_ok
|
||||||
entry_error = {}
|
entry_error = {}
|
||||||
path_error = {}
|
path_error = {}
|
||||||
|
def __init__(self, used_names={}):
|
||||||
|
self.used_names = used_names
|
||||||
def item_ok(self):
|
def item_ok(self):
|
||||||
return self.name
|
return self.name
|
||||||
def path_ok(self):
|
def path_ok(self):
|
||||||
return self.path
|
return self.path
|
||||||
|
def showerror(self, message):
|
||||||
|
self.entry_error['text'] = message
|
||||||
|
|
||||||
def test_entry_ok_helpsource(self):
|
def test_entry_ok_helpsource(self):
|
||||||
dialog = self.Dummy_HelpSource()
|
dialog = self.Dummy_HelpSource()
|
||||||
|
@ -232,6 +236,13 @@ class HelpsourceEntryokTest(unittest.TestCase):
|
||||||
dialog.name, dialog.path = name, path
|
dialog.name, dialog.path = name, path
|
||||||
self.assertEqual(dialog.entry_ok(), result)
|
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.
|
# 2 CustomRun test classes each test one method.
|
||||||
|
|
||||||
|
|
|
@ -314,6 +314,9 @@ class HelpSource(Query):
|
||||||
self.entry_error['text'] = ''
|
self.entry_error['text'] = ''
|
||||||
self.path_error['text'] = ''
|
self.path_error['text'] = ''
|
||||||
name = self.item_ok()
|
name = self.item_ok()
|
||||||
|
if name in self.used_names:
|
||||||
|
self.showerror('name is already in use.')
|
||||||
|
return None
|
||||||
path = self.path_ok()
|
path = self.path_ok()
|
||||||
return None if name is None or path is None else (name, path)
|
return None if name is None or path is None else (name, path)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Additional help sources added to IDLE's help menu are now sorted and must be
|
||||||
|
unique.
|
Loading…
Reference in New Issue