Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e92bf7

Browse files
committed
M Bindings.py
M EditorWindow.py M NEWS.txt M config-main.def M configDialog.py M configHandler.py M configHelpSourceEdit.py M configSectionNameDialog.py - Change default: IDLE now starts with Python Shell. - Removed the File Path from the Additional Help Sources scrolled list. - Add capability to access Additional Help Sources on the web if the Help File Path begins with //http or www. (Otherwise local path is validated, as before.) - Additional Help Sources were not being posted on the Help menu in the order entered. Implement sorting the list by [HelpFiles] 'option' number. - Add Browse button to New Help Source dialog. Arrange to start in Python/Doc if platform is Windows, otherwise start in current directory. - Put the Additional Help Sources directly on the Help menu instead of in an Extra Help cascade menu. Rearrange the Help menu so the Additional Help Sources come last. Update help.txt appropriately. - Fix Tk root pop-ups in configSectionNameDialog.py and configDialog.py
1 parent 50e9223 commit 8e92bf7

8 files changed

Lines changed: 164 additions & 92 deletions

File tree

Lib/idlelib/Bindings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@
6565
('!_Auto-open Stack Viewer', '<<toggle-jit-stack-viewer>>' ),
6666
]),
6767
('options', [
68-
('_Configure Idle...', '<<open-config-dialog>>'),
68+
('_Configure IDLE...', '<<open-config-dialog>>'),
6969
None,
7070
('Revert to _Default Settings', '<<revert-all-settings>>'),
7171
]),
7272
('help', [
73-
('_IDLE Help...', '<<help>>'),
74-
('Python _Documentation...', '<<python-docs>>'),
75-
('View IDLE _Readme...', '<<view-readme>>'),
73+
('_About IDLE', '<<about-idle>>'),
74+
('IDLE _Readme', '<<view-readme>>'),
7675
None,
77-
('_About IDLE...', '<<about-idle>>'),
76+
('_IDLE Help', '<<help>>'),
77+
('Python _Docs', '<<python-docs>>'),
7878
]),
7979
]
8080

Lib/idlelib/EditorWindow.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ def createmenubar(self):
247247
menudict[name] = menu = Menu(mbar, name=name)
248248
mbar.add_cascade(label=label, menu=menu, underline=underline)
249249
self.fill_menus()
250-
#create the ExtraHelp menu, if required
251-
self.ResetExtraHelpMenu()
250+
self.base_helpmenu_length = self.menudict['help'].index(END)
251+
self.reset_help_menu_entries()
252252

253253
def postwindowsmenu(self):
254254
# Only called when Windows menu exists
@@ -315,7 +315,8 @@ def python_docs(self, event=None):
315315
return "break"
316316

317317
def display_docs(self, url):
318-
url = os.path.normpath(url)
318+
if not (url.startswith('www') or url.startswith('http')):
319+
url = os.path.normpath(url)
319320
if sys.platform.count('win') or sys.platform.count('nt'):
320321
os.startfile(url)
321322
else:
@@ -530,29 +531,28 @@ def ResetKeybindings(self):
530531
menu.entryconfig(index,accelerator=accel)
531532
#print 'accel now:',accel,'\n'
532533

533-
def ResetExtraHelpMenu(self):
534-
"Load or update the Extra Help menu if required"
535-
menuList=idleConf.GetAllExtraHelpSourcesList()
536-
helpMenu=self.menudict['help']
537-
cascadeIndex=helpMenu.index(END)-1
538-
if menuList:
539-
if not hasattr(self,'menuExtraHelp'):
540-
self.menuExtraHelp=Menu(self.menubar)
541-
helpMenu.insert_cascade(cascadeIndex,label='Extra Help',
542-
underline=1,menu=self.menuExtraHelp)
543-
self.menuExtraHelp.delete(1,END)
544-
for menuItem in menuList:
545-
self.menuExtraHelp.add_command(label=menuItem[0],
546-
command=self.__DisplayExtraHelpCallback(menuItem[1]))
547-
else: #no extra help items
548-
if hasattr(self,'menuExtraHelp'):
549-
helpMenu.delete(cascadeIndex-1)
550-
del(self.menuExtraHelp)
551-
552-
def __DisplayExtraHelpCallback(self,helpFile):
553-
def DisplayExtraHelp(helpFile=helpFile):
554-
self.display_docs(helpFile)
555-
return DisplayExtraHelp
534+
def reset_help_menu_entries(self):
535+
"Update the additional help entries on the Help menu"
536+
help_list = idleConf.GetAllExtraHelpSourcesList()
537+
helpmenu = self.menudict['help']
538+
# first delete the extra help entries, if any
539+
helpmenu_length = helpmenu.index(END)
540+
if helpmenu_length > self.base_helpmenu_length:
541+
helpmenu.delete((self.base_helpmenu_length + 1), helpmenu_length)
542+
# then rebuild them
543+
if help_list:
544+
helpmenu.add_separator()
545+
for entry in help_list:
546+
cmd = self.__extra_help_callback(entry[1])
547+
helpmenu.add_command(label=entry[0], command=cmd)
548+
# and update the menu dictionary
549+
self.menudict['help'] = helpmenu
550+
551+
def __extra_help_callback(self, helpfile):
552+
"Create a callback with the helpfile value frozen at definition time"
553+
def display_extra_help(helpfile=helpfile):
554+
self.display_docs(helpfile)
555+
return display_extra_help
556556

557557
def UpdateRecentFilesList(self,newFile=None):
558558
"Load or update the recent files list, and menu if required"

Lib/idlelib/NEWS.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ What's New in IDLEfork 0.9 Alpha 2?
77

88
*Release date: XX-XXX-2003*
99

10+
- Change default: IDLE now starts with Python Shell.
11+
12+
- Removed the File Path from the Additional Help Sources scrolled list.
13+
14+
- Add capability to access Additional Help Sources on the web if the
15+
Help File Path begins with //http or www. (Otherwise local path is
16+
validated, as before.)
17+
18+
- Additional Help Sources were not being posted on the Help menu in the
19+
order entered. Implement sorting the list by [HelpFiles] 'option'
20+
number.
21+
22+
- Add Browse button to New Help Source dialog. Arrange to start in
23+
Python/Doc if platform is Windows, otherwise start in current directory.
24+
25+
- Put the Additional Help Sources directly on the Help menu instead of in
26+
an Extra Help cascade menu. Rearrange the Help menu so the Additional
27+
Help Sources come last. Update help.txt appropriately.
28+
29+
- Fix Tk root pop-ups in configSectionNameDialog.py and configDialog.py
30+
1031
- Uniform capitalization in General tab of ConfigDialog, update the doc string.
1132

1233
- Fix bug in ConfigDialog where SaveAllChangedConfig() was unexpectedly

Lib/idlelib/config-main.def

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,21 @@
2525
# retained unless specifically deleted within the config dialog. Choosing
2626
# one of the default themes or keysets just applies the relevant settings
2727
# from the default file.
28+
#
29+
# Additional help sources are listed in the [HelpFiles] section and must be
30+
# viewable by a web browser (or the Windows Help viewer in the case of .chm
31+
# files). These sources will be listed on the Help menu. The pattern is
32+
# <sequence_number = menu item;/path/to/help/source>
33+
# You can't use a semi-colon in a menu item or path. The path will be platform
34+
# specific because of path separators, drive specs etc.
35+
#
36+
# It is best to use the Configuration GUI to set up additional help sources!
37+
# Example:
38+
#1 = My Extra Help Source;/usr/share/doc/foo/index.html
39+
#2 = Another Help Source;/path/to/another.pdf
2840

2941
[General]
30-
editor-on-startup= 1
42+
editor-on-startup= 0
3143
print-command-posix=lpr %s
3244
print-command-win=start /min notepad /p %s
3345

@@ -51,22 +63,3 @@ default= 1
5163
name= IDLE Classic Windows
5264

5365
[HelpFiles]
54-
#additional help sources, must be viewable by an html browser
55-
#will be listed on the Help/Other Help menu
56-
#option names are the sequence number of the option
57-
#values take the form: menu item;/path/to/help/source
58-
#obviously you can't use a semi-colon in a menu item or path and the path will
59-
#be platform specific because of path separators, drive specs etc.
60-
#eg.:
61-
#1= My Extra Help Source;/usr/share/doc/foo/index.html
62-
#2= Another Help Source;/path/to/another.html
63-
64-
#[RecentFiles]
65-
#this section will only be present in the user config file idle-main.cfg
66-
#where it will record the most recently openned files in the form
67-
#IndexNum= /full/path/of/file , for display on the File/Recent Files menu
68-
#it is present here for reference only
69-
#eg.:
70-
#1=/most/recently/openned/file
71-
#2=/next/most/recently/openned/file
72-
#etc.

Lib/idlelib/configDialog.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,8 @@ def LoadKeysList(self,keySetName):
677677
def DeleteCustomKeys(self):
678678
keySetName=self.customKeys.get()
679679
if not tkMessageBox.askyesno('Delete Key Set','Are you sure you wish '+
680-
'to delete the key set '+`keySetName`+' ?'):
680+
'to delete the key set '+`keySetName`+' ?',
681+
parent=self):
681682
return
682683
#remove key set from config
683684
idleConf.userCfg['keys'].remove_section(keySetName)
@@ -703,7 +704,8 @@ def DeleteCustomKeys(self):
703704
def DeleteCustomTheme(self):
704705
themeName=self.customTheme.get()
705706
if not tkMessageBox.askyesno('Delete Theme','Are you sure you wish '+
706-
'to delete the theme '+`themeName`+' ?'):
707+
'to delete the theme '+`themeName`+' ?',
708+
parent=self):
707709
return
708710
#remove theme from config
709711
idleConf.userCfg['highlight'].remove_section(themeName)
@@ -874,7 +876,7 @@ def HelpListItemAdd(self):
874876
helpSource=GetHelpSourceDialog(self,'New Help Source').result
875877
if helpSource:
876878
self.userHelpList.append( (helpSource[0],helpSource[1]) )
877-
self.listHelp.insert(END,helpSource[0]+' '+helpSource[1])
879+
self.listHelp.insert(END,helpSource[0])
878880
self.UpdateUserHelpChangedItems()
879881
self.SetHelpListButtonStates()
880882

@@ -887,7 +889,7 @@ def HelpListItemEdit(self):
887889
return #no changes
888890
self.userHelpList[itemIndex]=newHelpSource
889891
self.listHelp.delete(itemIndex)
890-
self.listHelp.insert(itemIndex,newHelpSource[0]+' '+newHelpSource[1])
892+
self.listHelp.insert(itemIndex,newHelpSource[0])
891893
self.UpdateUserHelpChangedItems()
892894
self.SetHelpListButtonStates()
893895

@@ -899,12 +901,11 @@ def HelpListItemRemove(self):
899901
self.SetHelpListButtonStates()
900902

901903
def UpdateUserHelpChangedItems(self):
902-
#clear and rebuild the HelpFiles section in self.changedItems
903-
if self.changedItems['main'].has_key('HelpFiles'):
904-
del(self.changedItems['main']['HelpFiles'])
904+
"Clear and rebuild the HelpFiles section in self.changedItems"
905+
self.changedItems['main']['HelpFiles'] = {}
905906
for num in range(1,len(self.userHelpList)+1):
906907
self.AddChangedItem('main','HelpFiles',str(num),
907-
string.join(self.userHelpList[num-1],';'))
908+
string.join(self.userHelpList[num-1][:2],';'))
908909

909910
def LoadFontCfg(self):
910911
##base editor font selection list
@@ -1019,10 +1020,10 @@ def LoadGeneralCfg(self):
10191020
#initial window size
10201021
self.winWidth.set(idleConf.GetOption('main','EditorWindow','width'))
10211022
self.winHeight.set(idleConf.GetOption('main','EditorWindow','height'))
1022-
#help browsing
1023-
self.userHelpList=idleConf.GetExtraHelpSourceList('user')
1023+
# additional help sources
1024+
self.userHelpList = idleConf.GetAllExtraHelpSourcesList()
10241025
for helpItem in self.userHelpList:
1025-
self.listHelp.insert(END,helpItem[0]+' '+helpItem[1])
1026+
self.listHelp.insert(END,helpItem[0])
10261027
self.SetHelpListButtonStates()
10271028
#self.userHelpBrowser.set(idleConf.GetOption('main','General',
10281029
# 'user-help-browser',default=0,type='bool'))
@@ -1086,6 +1087,7 @@ def SaveAllChangedConfigs(self):
10861087
if section == 'HelpFiles':
10871088
#this section gets completely replaced
10881089
idleConf.userCfg['main'].remove_section('HelpFiles')
1090+
cfgTypeHasChanges = True
10891091
for item in self.changedItems[configType][section].keys():
10901092
value = self.changedItems[configType][section][item]
10911093
if self.SetUserValue(configType,section,item,value):
@@ -1107,7 +1109,7 @@ def ActivateConfigChanges(self):
11071109
instance.ResetColorizer()
11081110
instance.ResetFont()
11091111
instance.ResetKeybindings()
1110-
instance.ResetExtraHelpMenu()
1112+
instance.reset_help_menu_entries()
11111113

11121114
def Cancel(self):
11131115
self.destroy()

Lib/idlelib/configHandler.py

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
"""Provides access to stored IDLE configuration information.
2+
3+
Refer to the comments at the beginning of config-main.def for a description of
4+
the available configuration files and the design implemented to update user
5+
configuration information. In particular, user configuration choices which
6+
duplicate the defaults will be removed from the user's configuration files,
7+
and if a file becomes empty, it will be deleted.
8+
9+
The contents of the user files may be altered using the Options/Configure IDLE
10+
menu to access the configuration GUI (configDialog.py), or manually.
11+
12+
Throughout this module there is an emphasis on returning useable defaults
13+
when a problem occurs in returning a requested configuration value back to
14+
idle. This is to allow IDLE to continue to function in spite of errors in
15+
the retrieval of config information. When a default is returned instead of
16+
a requested config value, a message is printed to stderr to aid in
17+
configuration problem notification and resolution.
18+
119
"""
2-
Provides access to stored idle configuration information.
3-
"""
4-
# Throughout this module there is an emphasis on returning useable defaults
5-
# when a problem occurs in returning a requested configuration value back to
6-
# idle. This is to allow idle to continue to function in spite of errors in
7-
# the retrieval of config information. When a default is returned instead of
8-
# a requested config value, a message is printed to stderr to aid in
9-
# configuration problem notification and resolution.
10-
11-
import os, sys, string
20+
import os
21+
import sys
22+
import string
1223
from ConfigParser import ConfigParser, NoOptionError, NoSectionError
1324

1425
class InvalidConfigType(Exception): pass
@@ -123,9 +134,11 @@ def RemoveFile(self):
123134
os.remove(self.file)
124135

125136
def Save(self):
126-
"""
127-
If config isn't empty, write file to disk. If config is empty,
128-
remove the file from disk if it exists.
137+
"""Update user configuration file.
138+
139+
Remove empty sections. If resulting config isn't empty, write the file
140+
to disk. If config is empty, remove the file from disk if it exists.
141+
129142
"""
130143
if not self.IsEmpty():
131144
cfgFile=open(self.file,'w')
@@ -555,11 +568,14 @@ def GetCoreKeys(self, keySetName=None):
555568
return keyBindings
556569

557570
def GetExtraHelpSourceList(self,configSet):
558-
"""
559-
Returns a list of tuples containing the details of any additional
560-
help sources configured in the requested configSet ('user' or 'default')
561-
, or an empty list if there are none. Returned tuples are of the form
562-
form (menu_item , path_to_help_file , option).
571+
"""Fetch list of extra help sources from a given configSet.
572+
573+
Valid configSets are 'user' or 'default'. Return a list of tuples of
574+
the form (menu_item , path_to_help_file , option), or return the empty
575+
list. 'option' is the sequence number of the help resource. 'option'
576+
values determine the position of the menu items on the Help menu,
577+
therefore the returned list must be sorted by 'option'.
578+
563579
"""
564580
helpSources=[]
565581
if configSet=='user':
@@ -580,8 +596,17 @@ def GetExtraHelpSourceList(self,configSet):
580596
helpPath=value[1].strip()
581597
if menuItem and helpPath: #neither are empty strings
582598
helpSources.append( (menuItem,helpPath,option) )
599+
helpSources.sort(self.__helpsort)
583600
return helpSources
584601

602+
def __helpsort(self, h1, h2):
603+
if int(h1[2]) < int(h2[2]):
604+
return -1
605+
elif int(h1[2]) > int(h2[2]):
606+
return 1
607+
else:
608+
return 0
609+
585610
def GetAllExtraHelpSourcesList(self):
586611
"""
587612
Returns a list of tuples containing the details of all additional help

0 commit comments

Comments
 (0)