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

Skip to content

Commit e7a161e

Browse files
committed
M configDialog.py
M configHelpSourceEdit.py 1. Attach configHelpSourceEdit error dialogs to parent to avoid Tk root pop-ups. 2. Make configHelpSourceEdit OK button the default and bind <Return>. 3. Reformat configHelpSourceEdit. 4. ConfigDialog.SaveAllChangedConfig() had a bug which caused additional help sources to be deleted when other config items were changed. 4. Uniform capitalization in configDialog. 5. Update configDialog doc string.
1 parent 9149aeb commit e7a161e

2 files changed

Lines changed: 97 additions & 82 deletions

File tree

Lib/idlelib/configDialog.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
"""
2-
configuration dialog
1+
"""IDLE Configuration Dialog: support user customization of IDLE by GUI
2+
3+
Customize font faces, sizes, and colorization attributes. Set indentation
4+
defaults. Customize keybindings. Colorization and keybindings can be
5+
saved as user defined sets. Select startup options including shell/editor
6+
and default window size. Define additional help sources.
7+
8+
Note that tab width in IDLE is currently fixed at eight due to Tk issues.
9+
Refer to comment in EditorWindow autoindent code for details.
10+
311
"""
412
from Tkinter import *
513
import tkMessageBox, tkColorChooser, tkFont
@@ -11,6 +19,7 @@
1119
from keybindingDialog import GetKeysDialog
1220
from configSectionNameDialog import GetCfgSectionNameDialog
1321
from configHelpSourceEdit import GetHelpSourceDialog
22+
1423
class ConfigDialog(Toplevel):
1524
"""
1625
configuration dialog for idle
@@ -336,11 +345,11 @@ def CreatePageGeneral(self):
336345
frameHelp=Frame(frame,borderwidth=2,relief=GROOVE)
337346
#frameRun
338347
labelRunTitle=Label(frameRun,text='Startup Preferences')
339-
labelRunChoiceTitle=Label(frameRun,text='On startup : ')
348+
labelRunChoiceTitle=Label(frameRun,text='On Startup : ')
340349
radioStartupEdit=Radiobutton(frameRun,variable=self.startupEdit,
341-
value=1,command=self.SetKeysType,text="open Edit Window")
350+
value=1,command=self.SetKeysType,text="Open Edit Window")
342351
radioStartupShell=Radiobutton(frameRun,variable=self.startupEdit,
343-
value=0,command=self.SetKeysType,text='open Shell Window')
352+
value=0,command=self.SetKeysType,text='Open Shell Window')
344353
#frameWinSize
345354
labelWinSizeTitle=Label(frameWinSize,text='Initial Window Size'+
346355
' (in characters)')
@@ -354,7 +363,7 @@ def CreatePageGeneral(self):
354363
labelHelpTitle=Label(frameHelp,text='Help Options')
355364
frameHelpList=Frame(frameHelp)
356365
frameHelpListButtons=Frame(frameHelpList)
357-
labelHelpListTitle=Label(frameHelpList,text='Additional (html) Help Sources:')
366+
labelHelpListTitle=Label(frameHelpList,text='Additional Help Sources:')
358367
scrollHelpList=Scrollbar(frameHelpList)
359368
self.listHelp=Listbox(frameHelpList,height=5,takefocus=FALSE,
360369
exportselection=FALSE)
@@ -840,11 +849,11 @@ def PaintThemeSample(self):
840849
apply(self.textHighlightSample.tag_config,(element,),colours)
841850
self.SetColourSample()
842851

843-
def OnCheckUserHelpBrowser(self):
844-
if self.userHelpBrowser.get():
845-
self.entryHelpBrowser.config(state=NORMAL)
846-
else:
847-
self.entryHelpBrowser.config(state=DISABLED)
852+
## def OnCheckUserHelpBrowser(self):
853+
## if self.userHelpBrowser.get():
854+
## self.entryHelpBrowser.config(state=NORMAL)
855+
## else:
856+
## self.entryHelpBrowser.config(state=DISABLED)
848857

849858
def HelpSourceSelected(self,event):
850859
self.SetHelpListButtonStates()
@@ -890,7 +899,7 @@ def HelpListItemRemove(self):
890899
self.SetHelpListButtonStates()
891900

892901
def UpdateUserHelpChangedItems(self):
893-
#clear and rebuild the HelpFiles secion in self.changedItems
902+
#clear and rebuild the HelpFiles section in self.changedItems
894903
if self.changedItems['main'].has_key('HelpFiles'):
895904
del(self.changedItems['main']['HelpFiles'])
896905
for num in range(1,len(self.userHelpList)+1):
@@ -1069,19 +1078,18 @@ def SetUserValue(self,configType,section,item,value):
10691078
return idleConf.userCfg[configType].SetOption(section,item,value)
10701079

10711080
def SaveAllChangedConfigs(self):
1072-
"""
1073-
save all configuration changes to user config files.
1074-
"""
1075-
#this section gets completely replaced
1076-
idleConf.userCfg['main'].remove_section('HelpFiles')
1081+
"Save configuration changes to the user config file."
10771082
idleConf.userCfg['main'].Save()
10781083
for configType in self.changedItems.keys():
1079-
cfgTypeHasChanges=0
1084+
cfgTypeHasChanges = False
10801085
for section in self.changedItems[configType].keys():
1086+
if section == 'HelpFiles':
1087+
#this section gets completely replaced
1088+
idleConf.userCfg['main'].remove_section('HelpFiles')
10811089
for item in self.changedItems[configType][section].keys():
1082-
value=self.changedItems[configType][section][item]
1090+
value = self.changedItems[configType][section][item]
10831091
if self.SetUserValue(configType,section,item,value):
1084-
cfgTypeHasChanges=1
1092+
cfgTypeHasChanges = True
10851093
if cfgTypeHasChanges:
10861094
idleConf.userCfg[configType].Save()
10871095
self.ResetChangedItems() #clear the changed items dict
Lines changed: 69 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,126 @@
1-
"""
2-
Dialog that allows user to specify or edit the parameters for a user configured
3-
help source.
4-
"""
1+
"Dialog to specify or edit the parameters for a user configured help source."
2+
53
from Tkinter import *
64
import tkMessageBox
75
import os
86

97
class GetHelpSourceDialog(Toplevel):
10-
def __init__(self,parent,title,menuItem='',filePath=''):
8+
def __init__(self, parent, title, menuItem='', filePath=''):
119
"""
1210
menuItem - string, the menu item to edit, if any
1311
filePath - string, the help file path to edit, if any
1412
"""
1513
Toplevel.__init__(self, parent)
1614
self.configure(borderwidth=5)
17-
self.resizable(height=FALSE,width=FALSE)
15+
self.resizable(height=FALSE, width=FALSE)
1816
self.title(title)
1917
self.transient(parent)
2018
self.grab_set()
2119
self.protocol("WM_DELETE_WINDOW", self.Cancel)
2220
self.parent = parent
23-
self.result=None
21+
self.result = None
2422
self.CreateWidgets()
2523
self.menu.set(menuItem)
2624
self.path.set(filePath)
2725
self.withdraw() #hide while setting geometry
28-
self.update_idletasks()
2926
#needs to be done here so that the winfo_reqwidth is valid
27+
self.update_idletasks()
28+
#centre dialog over parent:
3029
self.geometry("+%d+%d" %
31-
((parent.winfo_rootx()+((parent.winfo_width()/2)
32-
-(self.winfo_reqwidth()/2)),
33-
parent.winfo_rooty()+((parent.winfo_height()/2)
34-
-(self.winfo_reqheight()/2)) )) ) #centre dialog over parent
30+
((parent.winfo_rootx() + ((parent.winfo_width()/2)
31+
-(self.winfo_reqwidth()/2)),
32+
parent.winfo_rooty() + ((parent.winfo_height()/2)
33+
-(self.winfo_reqheight()/2)))))
3534
self.deiconify() #geometry set, unhide
35+
self.bind('<Return>', self.Ok)
3636
self.wait_window()
3737

3838
def CreateWidgets(self):
39-
self.menu=StringVar(self)
40-
self.path=StringVar(self)
41-
self.fontSize=StringVar(self)
42-
self.frameMain = Frame(self,borderwidth=2,relief=SUNKEN)
43-
self.frameMain.pack(side=TOP,expand=TRUE,fill=BOTH)
44-
labelMenu=Label(self.frameMain,anchor=W,justify=LEFT,
45-
text='Menu Item:')
46-
self.entryMenu=Entry(self.frameMain,textvariable=self.menu,width=30)
39+
self.menu = StringVar(self)
40+
self.path = StringVar(self)
41+
self.fontSize = StringVar(self)
42+
self.frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
43+
self.frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
44+
labelMenu = Label(self.frameMain, anchor=W, justify=LEFT,
45+
text='Menu Item:')
46+
self.entryMenu = Entry(self.frameMain, textvariable=self.menu,
47+
width=30)
4748
self.entryMenu.focus_set()
48-
labelPath=Label(self.frameMain,anchor=W,justify=LEFT,
49-
text='Help File Path:')
50-
self.entryPath=Entry(self.frameMain,textvariable=self.path,width=40)
49+
labelPath = Label(self.frameMain, anchor=W, justify=LEFT,
50+
text='Help File Path:')
51+
self.entryPath = Entry(self.frameMain, textvariable=self.path,
52+
width=40)
5153
self.entryMenu.focus_set()
52-
labelMenu.pack(anchor=W,padx=5,pady=3)
53-
self.entryMenu.pack(anchor=W,padx=5,pady=3)
54-
labelPath.pack(anchor=W,padx=5,pady=3)
55-
self.entryPath.pack(anchor=W,padx=5,pady=3)
56-
frameButtons=Frame(self)
57-
frameButtons.pack(side=BOTTOM,fill=X)
58-
self.buttonOk = Button(frameButtons,text='Ok',
59-
width=8,command=self.Ok)
60-
self.buttonOk.grid(row=0,column=0,padx=5,pady=5)
61-
self.buttonCancel = Button(frameButtons,text='Cancel',
62-
width=8,command=self.Cancel)
63-
self.buttonCancel.grid(row=0,column=1,padx=5,pady=5)
54+
labelMenu.pack(anchor=W, padx=5, pady=3)
55+
self.entryMenu.pack(anchor=W, padx=5, pady=3)
56+
labelPath.pack(anchor=W, padx=5, pady=3)
57+
self.entryPath.pack(anchor=W, padx=5, pady=3)
58+
frameButtons = Frame(self)
59+
frameButtons.pack(side=BOTTOM, fill=X)
60+
self.buttonOk = Button(frameButtons, text='OK',
61+
width=8, default=ACTIVE, command=self.Ok)
62+
self.buttonOk.grid(row=0, column=0, padx=5,pady=5)
63+
self.buttonOk.bind('<Return>', self.Ok)
64+
#self.buttonOk.focus()
65+
self.buttonCancel = Button(frameButtons, text='Cancel',
66+
width=8, command=self.Cancel)
67+
self.buttonCancel.grid(row=0, column=1, padx=5, pady=5)
6468

6569
def MenuOk(self):
66-
#simple validity check for a sensible
67-
#menu item name
68-
menuOk=1
69-
menu=self.menu.get()
70+
"Simple validity check for a sensible menu item name"
71+
menuOk = True
72+
menu = self.menu.get()
7073
menu.strip()
71-
if not menu: #no menu item specified
74+
if not menu:
7275
tkMessageBox.showerror(title='Menu Item Error',
73-
message='No menu item specified.')
76+
message='No menu item specified',
77+
parent=self)
7478
self.entryMenu.focus_set()
75-
menuOk=0
76-
elif len(menu)>30: #menu item name too long
79+
menuOk = False
80+
elif len(menu) > 30:
7781
tkMessageBox.showerror(title='Menu Item Error',
78-
message='Menu item too long. It should be no more '+
79-
'than 30 characters.')
82+
message='Menu item too long:'
83+
'\nLimit 30 characters.',
84+
parent=self)
8085
self.entryMenu.focus_set()
81-
menuOk=0
86+
menuOk = False
8287
return menuOk
8388

8489
def PathOk(self):
85-
#simple validity check for menu file path
86-
pathOk=1
87-
path=self.path.get()
90+
"Simple validity check for menu file path"
91+
pathOk = True
92+
path = self.path.get()
8893
path.strip()
8994
if not path: #no path specified
9095
tkMessageBox.showerror(title='File Path Error',
91-
message='No help file path specified.')
96+
message='No help file path specified.',
97+
parent=self)
9298
self.entryPath.focus_set()
93-
pathOk=0
99+
pathOk = False
94100
elif not os.path.exists(path):
95101
tkMessageBox.showerror(title='File Path Error',
96-
message='Help file path does not exist.')
102+
message='Help file path does not exist.',
103+
parent=self)
97104
self.entryPath.focus_set()
98-
pathOk=0
105+
pathOk = False
99106
return pathOk
100107

101108
def Ok(self, event=None):
102-
if self.MenuOk():
103-
if self.PathOk():
104-
self.result=( self.menu.get().strip(),self.path.get().strip() )
105-
self.destroy()
109+
if self.MenuOk() and self.PathOk():
110+
self.result = (self.menu.get().strip(),
111+
self.path.get().strip())
112+
self.destroy()
106113

107114
def Cancel(self, event=None):
108-
self.result=None
115+
self.result = None
109116
self.destroy()
110117

111118
if __name__ == '__main__':
112119
#test the dialog
113-
root=Tk()
120+
root = Tk()
114121
def run():
115-
keySeq=''
116-
dlg=GetHelpSourceDialog(root,'Get Help Source')
122+
keySeq = ''
123+
dlg = GetHelpSourceDialog(root, 'Get Help Source')
117124
print dlg.result
118-
Button(root,text='Dialog',command=run).pack()
125+
Button(root,text='Dialog', command=run).pack()
119126
root.mainloop()

0 commit comments

Comments
 (0)