Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 8 additions & 3 deletions Doc/library/idle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO giving more details here is counter-productive. That the menu items must be unique and sorted are rather minor, technical details. And I find this sentence to be stating the obvious: "The allowed file types may depend on the system." As for checking things when submitted, users will discover that themselves when using the feature, and I'm really not sure documenting it here is valuable.

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
Expand Down
11 changes: 10 additions & 1 deletion Lib/idlelib/configdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,10 @@ def load_general_cfg(self):

# Set additional help sources.
self.user_helplist = idleConf.GetAllExtraHelpSourcesList()
self.set_additional_help_sources()

def set_additional_help_sources(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this method should also be setting self.user_helplist = idleConf.GetAllExtraHelpSourcesList() rather than assuming it is set elsewhere before it is called.

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])
Expand Down Expand Up @@ -2131,7 +2135,9 @@ def helplist_item_add(self):
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])
Expand All @@ -2145,10 +2151,12 @@ def helplist_item_edit(self):
"""
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
Expand All @@ -2171,6 +2179,7 @@ def helplist_item_remove(self):
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),
Expand Down
7 changes: 5 additions & 2 deletions Lib/idlelib/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,12 @@ <h3>Help menu (Shell and Editor)<a class="headerlink" href="#help-menu-shell-and
<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>
Expand Down
11 changes: 11 additions & 0 deletions Lib/idlelib/idle_test/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,14 @@ class Dummy_HelpSource:
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()
Expand All @@ -232,6 +236,13 @@ def test_entry_ok_helpsource(self):
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.

Expand Down
3 changes: 3 additions & 0 deletions Lib/idlelib/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ def entry_ok(self):
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)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Additional help sources added to IDLE's help menu are now sorted and must be
unique.