diff --git a/Doc/library/idle.rst b/Doc/library/idle.rst index 0bd248c22b1..7375679ea2e 100644 --- a/Doc/library/idle.rst +++ b/Doc/library/idle.rst @@ -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 ` 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 ` subsection below for more on Help menu + choices. .. index:: single: Cut diff --git a/Lib/idlelib/configdialog.py b/Lib/idlelib/configdialog.py index df216582fe6..5fea56c6904 100644 --- a/Lib/idlelib/configdialog.py +++ b/Lib/idlelib/configdialog.py @@ -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), diff --git a/Lib/idlelib/help.html b/Lib/idlelib/help.html index 0754f2453ba..cdcd0459cf5 100644 --- a/Lib/idlelib/help.html +++ b/Lib/idlelib/help.html @@ -363,9 +363,12 @@ and open docs.python.org showing the latest Python documentation.

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 Help sources subsection below +

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 Help sources subsection below for more on Help menu choices.

+

Context MenusΒΆ

diff --git a/Lib/idlelib/idle_test/test_query.py b/Lib/idlelib/idle_test/test_query.py index f957585190d..68d955a1321 100644 --- a/Lib/idlelib/idle_test/test_query.py +++ b/Lib/idlelib/idle_test/test_query.py @@ -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. diff --git a/Lib/idlelib/query.py b/Lib/idlelib/query.py index 097e6e61e35..bbd992440f6 100644 --- a/Lib/idlelib/query.py +++ b/Lib/idlelib/query.py @@ -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) diff --git a/Misc/NEWS.d/next/IDLE/2019-11-08-14-29-24.bpo-27465.RUKMNw.rst b/Misc/NEWS.d/next/IDLE/2019-11-08-14-29-24.bpo-27465.RUKMNw.rst new file mode 100644 index 00000000000..7e8f168e438 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2019-11-08-14-29-24.bpo-27465.RUKMNw.rst @@ -0,0 +1,2 @@ +Additional help sources added to IDLE's help menu are now sorted and must be +unique.