blob: 8d3a49dff7e4a6e01338a4f53bb17a33b85614bd [file] [log] [blame]
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +00001"""IDLE Configuration Dialog: support user customization of IDLE by GUI
2
3Customize font faces, sizes, and colorization attributes. Set indentation
4defaults. Customize keybindings. Colorization and keybindings can be
5saved as user defined sets. Select startup options including shell/editor
6and default window size. Define additional help sources.
7
8Note that tab width in IDLE is currently fixed at eight due to Tk issues.
Kurt B. Kaiseracdef852005-01-31 03:34:26 +00009Refer to comments in EditorWindow autoindent code for details.
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +000010
Steven M. Gava44d3d1a2001-07-31 06:59:02 +000011"""
Georg Brandl6634bf22008-05-20 07:13:37 +000012from Tkinter import *
13import tkMessageBox, tkColorChooser, tkFont
Christian Heimesc5f05e42008-02-23 17:40:11 +000014import string
Steven M. Gava44d3d1a2001-07-31 06:59:02 +000015
Ezio Melotti4c6daf12010-08-02 20:40:20 +000016from idlelib.configHandler import idleConf
17from idlelib.dynOptionMenuWidget import DynOptionMenu
18from idlelib.tabbedpages import TabbedPageSet
19from idlelib.keybindingDialog import GetKeysDialog
20from idlelib.configSectionNameDialog import GetCfgSectionNameDialog
21from idlelib.configHelpSourceEdit import GetHelpSourceDialog
22from idlelib import macosxSupport
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +000023
Steven M. Gava44d3d1a2001-07-31 06:59:02 +000024class ConfigDialog(Toplevel):
Kurt B. Kaiseracdef852005-01-31 03:34:26 +000025
Steven M. Gava3b55a892001-11-21 05:56:26 +000026 def __init__(self,parent,title):
Steven M. Gavad721c482001-07-31 10:46:53 +000027 Toplevel.__init__(self, parent)
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +000028 self.wm_withdraw()
29
Steven M. Gavad721c482001-07-31 10:46:53 +000030 self.configure(borderwidth=5)
31 self.geometry("+%d+%d" % (parent.winfo_rootx()+20,
32 parent.winfo_rooty()+30))
Georg Brandl7eb4b7d2005-07-22 21:49:32 +000033 #Theme Elements. Each theme element key is its display name.
Steven M. Gava9dd16b32001-11-03 14:54:25 +000034 #The first value of the tuple is the sample area tag name.
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000035 #The second value is the display name list sort index.
Steven M. Gavaad4f5322002-01-03 12:05:17 +000036 self.themeElements={'Normal Text':('normal','00'),
37 'Python Keywords':('keyword','01'),
38 'Python Definitions':('definition','02'),
Kurt B. Kaiser73360a32004-03-08 18:15:31 +000039 'Python Builtins':('builtin', '03'),
40 'Python Comments':('comment','04'),
41 'Python Strings':('string','05'),
42 'Selected Text':('hilite','06'),
43 'Found Text':('hit','07'),
44 'Cursor':('cursor','08'),
45 'Error Text':('error','09'),
46 'Shell Normal Text':('console','10'),
47 'Shell Stdout Text':('stdout','11'),
48 'Shell Stderr Text':('stderr','12'),
49 }
Steven M. Gavaa498af22002-02-01 01:33:36 +000050 self.ResetChangedItems() #load initial values in changed items dict
Steven M. Gavad721c482001-07-31 10:46:53 +000051 self.CreateWidgets()
52 self.resizable(height=FALSE,width=FALSE)
Steven M. Gavad721c482001-07-31 10:46:53 +000053 self.transient(parent)
54 self.grab_set()
55 self.protocol("WM_DELETE_WINDOW", self.Cancel)
56 self.parent = parent
Steven M. Gava2d4e03b2001-12-05 07:54:07 +000057 self.tabPages.focus_set()
Steven M. Gavad721c482001-07-31 10:46:53 +000058 #key bindings for this dialog
Steven M. Gava5f28e8f2002-01-21 06:38:21 +000059 #self.bind('<Escape>',self.Cancel) #dismiss dialog, no save
60 #self.bind('<Alt-a>',self.Apply) #apply changes, save
61 #self.bind('<F1>',self.Help) #context help
Steven M. Gava429a86af2001-10-23 10:42:12 +000062 self.LoadConfigs()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000063 self.AttachVarCallbacks() #avoid callbacks during LoadConfigs
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +000064
65 self.wm_deiconify()
Steven M. Gavad721c482001-07-31 10:46:53 +000066 self.wait_window()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000067
Steven M. Gavad721c482001-07-31 10:46:53 +000068 def CreateWidgets(self):
Kurt B. Kaiser20172f92007-10-30 02:38:54 +000069 self.tabPages = TabbedPageSet(self,
70 page_names=['Fonts/Tabs','Highlighting','Keys','General'])
71 frameActionButtons = Frame(self,pady=2)
Steven M. Gavad721c482001-07-31 10:46:53 +000072 #action buttons
Ronald Oussorende3dfc12009-03-04 21:35:38 +000073 if macosxSupport.runningAsOSXApp():
74 # Changing the default padding on OSX results in unreadable
75 # text in the buttons
76 paddingArgs={}
77 else:
78 paddingArgs={'padx':6, 'pady':3}
79
Steven M. Gava952d0a52001-08-03 04:43:44 +000080 self.buttonHelp = Button(frameActionButtons,text='Help',
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +000081 command=self.Help,takefocus=FALSE,
Ronald Oussorende3dfc12009-03-04 21:35:38 +000082 **paddingArgs)
Steven M. Gavac01e30f2001-08-11 15:48:13 +000083 self.buttonOk = Button(frameActionButtons,text='Ok',
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +000084 command=self.Ok,takefocus=FALSE,
Ronald Oussorende3dfc12009-03-04 21:35:38 +000085 **paddingArgs)
Steven M. Gavac01e30f2001-08-11 15:48:13 +000086 self.buttonApply = Button(frameActionButtons,text='Apply',
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +000087 command=self.Apply,takefocus=FALSE,
Ronald Oussorende3dfc12009-03-04 21:35:38 +000088 **paddingArgs)
Steven M. Gavad721c482001-07-31 10:46:53 +000089 self.buttonCancel = Button(frameActionButtons,text='Cancel',
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +000090 command=self.Cancel,takefocus=FALSE,
Ronald Oussorende3dfc12009-03-04 21:35:38 +000091 **paddingArgs)
Steven M. Gava2d4e03b2001-12-05 07:54:07 +000092 self.CreatePageFontTab()
93 self.CreatePageHighlight()
94 self.CreatePageKeys()
95 self.CreatePageGeneral()
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +000096 self.buttonHelp.pack(side=RIGHT,padx=5)
97 self.buttonOk.pack(side=LEFT,padx=5)
98 self.buttonApply.pack(side=LEFT,padx=5)
99 self.buttonCancel.pack(side=LEFT,padx=5)
Steven M. Gavad721c482001-07-31 10:46:53 +0000100 frameActionButtons.pack(side=BOTTOM)
Kurt B. Kaiser28c7bcf2007-12-28 04:18:01 +0000101 Frame(self, height=2, borderwidth=0).pack(side=BOTTOM)
Steven M. Gava2d4e03b2001-12-05 07:54:07 +0000102 self.tabPages.pack(side=TOP,expand=TRUE,fill=BOTH)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000103
Steven M. Gava60fc7072001-08-04 13:58:22 +0000104 def CreatePageFontTab(self):
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000105 #tkVars
Steven M. Gava3b55a892001-11-21 05:56:26 +0000106 self.fontSize=StringVar(self)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000107 self.fontBold=BooleanVar(self)
108 self.fontName=StringVar(self)
Steven M. Gava3b55a892001-11-21 05:56:26 +0000109 self.spaceNum=IntVar(self)
Kurt B. Kaiser05391692003-05-26 20:35:53 +0000110 self.editFont=tkFont.Font(self,('courier',10,'normal'))
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000111 ##widget creation
112 #body frame
Kurt B. Kaiser20172f92007-10-30 02:38:54 +0000113 frame=self.tabPages.pages['Fonts/Tabs'].frame
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000114 #body section frames
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +0000115 frameFont=LabelFrame(frame,borderwidth=2,relief=GROOVE,
116 text=' Base Editor Font ')
117 frameIndent=LabelFrame(frame,borderwidth=2,relief=GROOVE,
118 text=' Indentation Width ')
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000119 #frameFont
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000120 frameFontName=Frame(frameFont)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000121 frameFontParam=Frame(frameFont)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000122 labelFontNameTitle=Label(frameFontName,justify=LEFT,
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +0000123 text='Font Face :')
Steven M. Gavac01e30f2001-08-11 15:48:13 +0000124 self.listFontName=Listbox(frameFontName,height=5,takefocus=FALSE,
125 exportselection=FALSE)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000126 self.listFontName.bind('<ButtonRelease-1>',self.OnListFontButtonRelease)
Steven M. Gavac01e30f2001-08-11 15:48:13 +0000127 scrollFont=Scrollbar(frameFontName)
Steven M. Gavac01e30f2001-08-11 15:48:13 +0000128 scrollFont.config(command=self.listFontName.yview)
129 self.listFontName.config(yscrollcommand=scrollFont.set)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000130 labelFontSizeTitle=Label(frameFontParam,text='Size :')
131 self.optMenuFontSize=DynOptionMenu(frameFontParam,self.fontSize,None,
Steven M. Gavac112cd82002-01-22 05:56:40 +0000132 command=self.SetFontSample)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000133 checkFontBold=Checkbutton(frameFontParam,variable=self.fontBold,
Steven M. Gavac112cd82002-01-22 05:56:40 +0000134 onvalue=1,offvalue=0,text='Bold',command=self.SetFontSample)
Steven M. Gavac11ccf32001-09-24 09:43:17 +0000135 frameFontSample=Frame(frameFont,relief=SOLID,borderwidth=1)
136 self.labelFontSample=Label(frameFontSample,
137 text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]',
Steven M. Gava429a86af2001-10-23 10:42:12 +0000138 justify=LEFT,font=self.editFont)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000139 #frameIndent
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000140 frameIndentSize=Frame(frameIndent)
Kurt B. Kaiseracdef852005-01-31 03:34:26 +0000141 labelSpaceNumTitle=Label(frameIndentSize, justify=LEFT,
142 text='Python Standard: 4 Spaces!')
143 self.scaleSpaceNum=Scale(frameIndentSize, variable=self.spaceNum,
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +0000144 orient='horizontal',
Kurt B. Kaiseracdef852005-01-31 03:34:26 +0000145 tickinterval=2, from_=2, to=16)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000146 #widget packing
147 #body
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +0000148 frameFont.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH)
149 frameIndent.pack(side=LEFT,padx=5,pady=5,fill=Y)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000150 #frameFont
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000151 frameFontName.pack(side=TOP,padx=5,pady=5,fill=X)
152 frameFontParam.pack(side=TOP,padx=5,pady=5,fill=X)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000153 labelFontNameTitle.pack(side=TOP,anchor=W)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000154 self.listFontName.pack(side=LEFT,expand=TRUE,fill=X)
Steven M. Gavac01e30f2001-08-11 15:48:13 +0000155 scrollFont.pack(side=LEFT,fill=Y)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000156 labelFontSizeTitle.pack(side=LEFT,anchor=W)
157 self.optMenuFontSize.pack(side=LEFT,anchor=W)
158 checkFontBold.pack(side=LEFT,anchor=W,padx=20)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000159 frameFontSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
Steven M. Gavac01e30f2001-08-11 15:48:13 +0000160 self.labelFontSample.pack(expand=TRUE,fill=BOTH)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000161 #frameIndent
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +0000162 frameIndentSize.pack(side=TOP,fill=X)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000163 labelSpaceNumTitle.pack(side=TOP,anchor=W,padx=5)
164 self.scaleSpaceNum.pack(side=TOP,padx=5,fill=X)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000165 return frame
166
167 def CreatePageHighlight(self):
Steven M. Gava3b55a892001-11-21 05:56:26 +0000168 self.builtinTheme=StringVar(self)
169 self.customTheme=StringVar(self)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000170 self.fgHilite=BooleanVar(self)
Steven M. Gava3b55a892001-11-21 05:56:26 +0000171 self.colour=StringVar(self)
172 self.fontName=StringVar(self)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000173 self.themeIsBuiltin=BooleanVar(self)
Steven M. Gava3b55a892001-11-21 05:56:26 +0000174 self.highlightTarget=StringVar(self)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000175 ##widget creation
176 #body frame
Kurt B. Kaiser20172f92007-10-30 02:38:54 +0000177 frame=self.tabPages.pages['Highlighting'].frame
Steven M. Gava952d0a52001-08-03 04:43:44 +0000178 #body section frames
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +0000179 frameCustom=LabelFrame(frame,borderwidth=2,relief=GROOVE,
180 text=' Custom Highlighting ')
181 frameTheme=LabelFrame(frame,borderwidth=2,relief=GROOVE,
182 text=' Highlighting Theme ')
Steven M. Gava952d0a52001-08-03 04:43:44 +0000183 #frameCustom
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000184 self.textHighlightSample=Text(frameCustom,relief=SOLID,borderwidth=1,
Steven M. Gavab77d3432002-03-02 07:16:21 +0000185 font=('courier',12,''),cursor='hand2',width=21,height=10,
186 takefocus=FALSE,highlightthickness=0,wrap=NONE)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000187 text=self.textHighlightSample
188 text.bind('<Double-Button-1>',lambda e: 'break')
189 text.bind('<B1-Motion>',lambda e: 'break')
Steven M. Gava052937f2002-02-11 02:20:53 +0000190 textAndTags=(('#you can click here','comment'),('\n','normal'),
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000191 ('#to choose items','comment'),('\n','normal'),('def','keyword'),
192 (' ','normal'),('func','definition'),('(param):','normal'),
193 ('\n ','normal'),('"""string"""','string'),('\n var0 = ','normal'),
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000194 ("'string'",'string'),('\n var1 = ','normal'),("'selected'",'hilite'),
Kurt B. Kaiser73360a32004-03-08 18:15:31 +0000195 ('\n var2 = ','normal'),("'found'",'hit'),
196 ('\n var3 = ','normal'),('list', 'builtin'), ('(','normal'),
197 ('None', 'builtin'),(')\n\n','normal'),
Steven M. Gava99300612001-11-04 07:03:08 +0000198 (' error ','error'),(' ','normal'),('cursor |','cursor'),
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000199 ('\n ','normal'),('shell','console'),(' ','normal'),('stdout','stdout'),
200 (' ','normal'),('stderr','stderr'),('\n','normal'))
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000201 for txTa in textAndTags:
202 text.insert(END,txTa[0],txTa[1])
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000203 for element in self.themeElements.keys():
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000204 text.tag_bind(self.themeElements[element][0],'<ButtonPress-1>',
205 lambda event,elem=element: event.widget.winfo_toplevel()
206 .highlightTarget.set(elem))
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000207 text.config(state=DISABLED)
208 self.frameColourSet=Frame(frameCustom,relief=SOLID,borderwidth=1)
Steven M. Gava7c017862001-10-29 11:19:46 +0000209 frameFgBg=Frame(frameCustom)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000210 buttonSetColour=Button(self.frameColourSet,text='Choose Colour for :',
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000211 command=self.GetColour,highlightthickness=0)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000212 self.optMenuHighlightTarget=DynOptionMenu(self.frameColourSet,
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000213 self.highlightTarget,None,highlightthickness=0)#,command=self.SetHighlightTargetBinding
Steven M. Gava7c017862001-10-29 11:19:46 +0000214 self.radioFg=Radiobutton(frameFgBg,variable=self.fgHilite,
Steven M. Gava3b55a892001-11-21 05:56:26 +0000215 value=1,text='Foreground',command=self.SetColourSampleBinding)
Steven M. Gava7c017862001-10-29 11:19:46 +0000216 self.radioBg=Radiobutton(frameFgBg,variable=self.fgHilite,
Steven M. Gava3b55a892001-11-21 05:56:26 +0000217 value=0,text='Background',command=self.SetColourSampleBinding)
Steven M. Gava7c017862001-10-29 11:19:46 +0000218 self.fgHilite.set(1)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000219 buttonSaveCustomTheme=Button(frameCustom,
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000220 text='Save as New Custom Theme',command=self.SaveAsNewTheme)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000221 #frameTheme
Steven M. Gava952d0a52001-08-03 04:43:44 +0000222 labelTypeTitle=Label(frameTheme,text='Select : ')
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000223 self.radioThemeBuiltin=Radiobutton(frameTheme,variable=self.themeIsBuiltin,
224 value=1,command=self.SetThemeType,text='a Built-in Theme')
225 self.radioThemeCustom=Radiobutton(frameTheme,variable=self.themeIsBuiltin,
226 value=0,command=self.SetThemeType,text='a Custom Theme')
Steven M. Gava41a85322001-10-29 08:05:34 +0000227 self.optMenuThemeBuiltin=DynOptionMenu(frameTheme,
Steven M. Gava7c017862001-10-29 11:19:46 +0000228 self.builtinTheme,None,command=None)
Steven M. Gava41a85322001-10-29 08:05:34 +0000229 self.optMenuThemeCustom=DynOptionMenu(frameTheme,
Steven M. Gava7c017862001-10-29 11:19:46 +0000230 self.customTheme,None,command=None)
Steven M. Gava49745752002-02-18 01:43:11 +0000231 self.buttonDeleteCustomTheme=Button(frameTheme,text='Delete Custom Theme',
232 command=self.DeleteCustomTheme)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000233 ##widget packing
234 #body
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +0000235 frameCustom.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH)
236 frameTheme.pack(side=LEFT,padx=5,pady=5,fill=Y)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000237 #frameCustom
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000238 self.frameColourSet.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=X)
Steven M. Gava7c017862001-10-29 11:19:46 +0000239 frameFgBg.pack(side=TOP,padx=5,pady=0)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000240 self.textHighlightSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,
241 fill=BOTH)
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000242 buttonSetColour.pack(side=TOP,expand=TRUE,fill=X,padx=8,pady=4)
243 self.optMenuHighlightTarget.pack(side=TOP,expand=TRUE,fill=X,padx=8,pady=3)
Steven M. Gava7c017862001-10-29 11:19:46 +0000244 self.radioFg.pack(side=LEFT,anchor=E)
245 self.radioBg.pack(side=RIGHT,anchor=W)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000246 buttonSaveCustomTheme.pack(side=BOTTOM,fill=X,padx=5,pady=5)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000247 #frameTheme
Steven M. Gava952d0a52001-08-03 04:43:44 +0000248 labelTypeTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
Steven M. Gava41a85322001-10-29 08:05:34 +0000249 self.radioThemeBuiltin.pack(side=TOP,anchor=W,padx=5)
250 self.radioThemeCustom.pack(side=TOP,anchor=W,padx=5,pady=2)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000251 self.optMenuThemeBuiltin.pack(side=TOP,fill=X,padx=5,pady=5)
252 self.optMenuThemeCustom.pack(side=TOP,fill=X,anchor=W,padx=5,pady=5)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000253 self.buttonDeleteCustomTheme.pack(side=TOP,fill=X,padx=5,pady=5)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000254 return frame
255
256 def CreatePageKeys(self):
Steven M. Gava60fc7072001-08-04 13:58:22 +0000257 #tkVars
Steven M. Gava3b55a892001-11-21 05:56:26 +0000258 self.bindingTarget=StringVar(self)
259 self.builtinKeys=StringVar(self)
260 self.customKeys=StringVar(self)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000261 self.keysAreBuiltin=BooleanVar(self)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000262 self.keyBinding=StringVar(self)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000263 ##widget creation
264 #body frame
Kurt B. Kaiser20172f92007-10-30 02:38:54 +0000265 frame=self.tabPages.pages['Keys'].frame
Steven M. Gava60fc7072001-08-04 13:58:22 +0000266 #body section frames
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +0000267 frameCustom=LabelFrame(frame,borderwidth=2,relief=GROOVE,
268 text=' Custom Key Bindings ')
269 frameKeySets=LabelFrame(frame,borderwidth=2,relief=GROOVE,
270 text=' Key Set ')
Steven M. Gava60fc7072001-08-04 13:58:22 +0000271 #frameCustom
272 frameTarget=Frame(frameCustom)
Steven M. Gavafacfc092002-01-19 00:29:54 +0000273 labelTargetTitle=Label(frameTarget,text='Action - Key(s)')
274 scrollTargetY=Scrollbar(frameTarget)
275 scrollTargetX=Scrollbar(frameTarget,orient=HORIZONTAL)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000276 self.listBindings=Listbox(frameTarget,takefocus=FALSE,
277 exportselection=FALSE)
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000278 self.listBindings.bind('<ButtonRelease-1>',self.KeyBindingSelected)
Steven M. Gavafacfc092002-01-19 00:29:54 +0000279 scrollTargetY.config(command=self.listBindings.yview)
280 scrollTargetX.config(command=self.listBindings.xview)
281 self.listBindings.config(yscrollcommand=scrollTargetY.set)
282 self.listBindings.config(xscrollcommand=scrollTargetX.set)
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000283 self.buttonNewKeys=Button(frameCustom,text='Get New Keys for Selection',
284 command=self.GetNewKeys,state=DISABLED)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000285 #frameKeySets
Kurt B. Kaiser28c7bcf2007-12-28 04:18:01 +0000286 frames = [Frame(frameKeySets, padx=2, pady=2, borderwidth=0)
287 for i in range(2)]
288 self.radioKeysBuiltin=Radiobutton(frames[0],variable=self.keysAreBuiltin,
289 value=1,command=self.SetKeysType,text='Use a Built-in Key Set')
290 self.radioKeysCustom=Radiobutton(frames[0],variable=self.keysAreBuiltin,
291 value=0,command=self.SetKeysType,text='Use a Custom Key Set')
292 self.optMenuKeysBuiltin=DynOptionMenu(frames[0],
Steven M. Gava41a85322001-10-29 08:05:34 +0000293 self.builtinKeys,None,command=None)
Kurt B. Kaiser28c7bcf2007-12-28 04:18:01 +0000294 self.optMenuKeysCustom=DynOptionMenu(frames[0],
Steven M. Gava41a85322001-10-29 08:05:34 +0000295 self.customKeys,None,command=None)
Kurt B. Kaiser28c7bcf2007-12-28 04:18:01 +0000296 self.buttonDeleteCustomKeys=Button(frames[1],text='Delete Custom Key Set',
Steven M. Gava49745752002-02-18 01:43:11 +0000297 command=self.DeleteCustomKeys)
Kurt B. Kaiser28c7bcf2007-12-28 04:18:01 +0000298 buttonSaveCustomKeys=Button(frames[1],
299 text='Save as New Custom Key Set',command=self.SaveAsNewKeySet)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000300 ##widget packing
301 #body
Kurt B. Kaiser28c7bcf2007-12-28 04:18:01 +0000302 frameCustom.pack(side=BOTTOM,padx=5,pady=5,expand=TRUE,fill=BOTH)
303 frameKeySets.pack(side=BOTTOM,padx=5,pady=5,fill=BOTH)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000304 #frameCustom
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000305 self.buttonNewKeys.pack(side=BOTTOM,fill=X,padx=5,pady=5)
Steven M. Gavafacfc092002-01-19 00:29:54 +0000306 frameTarget.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH)
307 #frame target
308 frameTarget.columnconfigure(0,weight=1)
309 frameTarget.rowconfigure(1,weight=1)
310 labelTargetTitle.grid(row=0,column=0,columnspan=2,sticky=W)
311 self.listBindings.grid(row=1,column=0,sticky=NSEW)
312 scrollTargetY.grid(row=1,column=1,sticky=NS)
313 scrollTargetX.grid(row=2,column=0,sticky=EW)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000314 #frameKeySets
Kurt B. Kaiser28c7bcf2007-12-28 04:18:01 +0000315 self.radioKeysBuiltin.grid(row=0, column=0, sticky=W+NS)
316 self.radioKeysCustom.grid(row=1, column=0, sticky=W+NS)
317 self.optMenuKeysBuiltin.grid(row=0, column=1, sticky=NSEW)
318 self.optMenuKeysCustom.grid(row=1, column=1, sticky=NSEW)
319 self.buttonDeleteCustomKeys.pack(side=LEFT,fill=X,expand=True,padx=2)
320 buttonSaveCustomKeys.pack(side=LEFT,fill=X,expand=True,padx=2)
321 frames[0].pack(side=TOP, fill=BOTH, expand=True)
322 frames[1].pack(side=TOP, fill=X, expand=True, pady=2)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000323 return frame
324
325 def CreatePageGeneral(self):
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000326 #tkVars
327 self.winWidth=StringVar(self)
Steven M. Gava3b55a892001-11-21 05:56:26 +0000328 self.winHeight=StringVar(self)
Raymond Hettinger4e49b832004-06-04 06:31:08 +0000329 self.paraWidth=StringVar(self)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000330 self.startupEdit=IntVar(self)
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000331 self.autoSave=IntVar(self)
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000332 self.encoding=StringVar(self)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000333 self.userHelpBrowser=BooleanVar(self)
334 self.helpBrowser=StringVar(self)
Steven M. Gava230e5782001-08-07 03:28:25 +0000335 #widget creation
336 #body
Kurt B. Kaiser20172f92007-10-30 02:38:54 +0000337 frame=self.tabPages.pages['General'].frame
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000338 #body section frames
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +0000339 frameRun=LabelFrame(frame,borderwidth=2,relief=GROOVE,
340 text=' Startup Preferences ')
341 frameSave=LabelFrame(frame,borderwidth=2,relief=GROOVE,
342 text=' Autosave Preferences ')
Steven M. Gava230e5782001-08-07 03:28:25 +0000343 frameWinSize=Frame(frame,borderwidth=2,relief=GROOVE)
Raymond Hettinger4e49b832004-06-04 06:31:08 +0000344 frameParaSize=Frame(frame,borderwidth=2,relief=GROOVE)
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000345 frameEncoding=Frame(frame,borderwidth=2,relief=GROOVE)
Kurt B. Kaisere3fde8f2007-10-04 03:11:12 +0000346 frameHelp=LabelFrame(frame,borderwidth=2,relief=GROOVE,
347 text=' Additional Help Sources ')
Steven M. Gava230e5782001-08-07 03:28:25 +0000348 #frameRun
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000349 labelRunChoiceTitle=Label(frameRun,text='At Startup')
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000350 radioStartupEdit=Radiobutton(frameRun,variable=self.startupEdit,
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +0000351 value=1,command=self.SetKeysType,text="Open Edit Window")
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000352 radioStartupShell=Radiobutton(frameRun,variable=self.startupEdit,
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +0000353 value=0,command=self.SetKeysType,text='Open Shell Window')
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000354 #frameSave
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000355 labelRunSaveTitle=Label(frameSave,text='At Start of Run (F5) ')
356 radioSaveAsk=Radiobutton(frameSave,variable=self.autoSave,
357 value=0,command=self.SetKeysType,text="Prompt to Save")
358 radioSaveAuto=Radiobutton(frameSave,variable=self.autoSave,
359 value=1,command=self.SetKeysType,text='No Prompt')
Steven M. Gava230e5782001-08-07 03:28:25 +0000360 #frameWinSize
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000361 labelWinSizeTitle=Label(frameWinSize,text='Initial Window Size'+
362 ' (in characters)')
Steven M. Gava230e5782001-08-07 03:28:25 +0000363 labelWinWidthTitle=Label(frameWinSize,text='Width')
364 entryWinWidth=Entry(frameWinSize,textvariable=self.winWidth,
365 width=3)
366 labelWinHeightTitle=Label(frameWinSize,text='Height')
367 entryWinHeight=Entry(frameWinSize,textvariable=self.winHeight,
368 width=3)
Raymond Hettinger4e49b832004-06-04 06:31:08 +0000369 #paragraphFormatWidth
370 labelParaWidthTitle=Label(frameParaSize,text='Paragraph reformat'+
371 ' width (in characters)')
372 entryParaWidth=Entry(frameParaSize,textvariable=self.paraWidth,
373 width=3)
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000374 #frameEncoding
375 labelEncodingTitle=Label(frameEncoding,text="Default Source Encoding")
376 radioEncLocale=Radiobutton(frameEncoding,variable=self.encoding,
377 value="locale",text="Locale-defined")
378 radioEncUTF8=Radiobutton(frameEncoding,variable=self.encoding,
379 value="utf-8",text="UTF-8")
380 radioEncNone=Radiobutton(frameEncoding,variable=self.encoding,
381 value="none",text="None")
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000382 #frameHelp
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000383 frameHelpList=Frame(frameHelp)
384 frameHelpListButtons=Frame(frameHelpList)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000385 scrollHelpList=Scrollbar(frameHelpList)
386 self.listHelp=Listbox(frameHelpList,height=5,takefocus=FALSE,
387 exportselection=FALSE)
388 scrollHelpList.config(command=self.listHelp.yview)
389 self.listHelp.config(yscrollcommand=scrollHelpList.set)
390 self.listHelp.bind('<ButtonRelease-1>',self.HelpSourceSelected)
391 self.buttonHelpListEdit=Button(frameHelpListButtons,text='Edit',
392 state=DISABLED,width=8,command=self.HelpListItemEdit)
393 self.buttonHelpListAdd=Button(frameHelpListButtons,text='Add',
394 width=8,command=self.HelpListItemAdd)
395 self.buttonHelpListRemove=Button(frameHelpListButtons,text='Remove',
396 state=DISABLED,width=8,command=self.HelpListItemRemove)
Steven M. Gava230e5782001-08-07 03:28:25 +0000397 #widget packing
398 #body
399 frameRun.pack(side=TOP,padx=5,pady=5,fill=X)
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000400 frameSave.pack(side=TOP,padx=5,pady=5,fill=X)
Steven M. Gava230e5782001-08-07 03:28:25 +0000401 frameWinSize.pack(side=TOP,padx=5,pady=5,fill=X)
Raymond Hettinger4e49b832004-06-04 06:31:08 +0000402 frameParaSize.pack(side=TOP,padx=5,pady=5,fill=X)
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000403 frameEncoding.pack(side=TOP,padx=5,pady=5,fill=X)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000404 frameHelp.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
Steven M. Gava230e5782001-08-07 03:28:25 +0000405 #frameRun
Steven M. Gava230e5782001-08-07 03:28:25 +0000406 labelRunChoiceTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000407 radioStartupShell.pack(side=RIGHT,anchor=W,padx=5,pady=5)
408 radioStartupEdit.pack(side=RIGHT,anchor=W,padx=5,pady=5)
409 #frameSave
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000410 labelRunSaveTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
411 radioSaveAuto.pack(side=RIGHT,anchor=W,padx=5,pady=5)
412 radioSaveAsk.pack(side=RIGHT,anchor=W,padx=5,pady=5)
Steven M. Gava230e5782001-08-07 03:28:25 +0000413 #frameWinSize
Steven M. Gavafacfc092002-01-19 00:29:54 +0000414 labelWinSizeTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
415 entryWinHeight.pack(side=RIGHT,anchor=E,padx=10,pady=5)
416 labelWinHeightTitle.pack(side=RIGHT,anchor=E,pady=5)
417 entryWinWidth.pack(side=RIGHT,anchor=E,padx=10,pady=5)
418 labelWinWidthTitle.pack(side=RIGHT,anchor=E,pady=5)
Raymond Hettinger4e49b832004-06-04 06:31:08 +0000419 #paragraphFormatWidth
420 labelParaWidthTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
421 entryParaWidth.pack(side=RIGHT,anchor=E,padx=10,pady=5)
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000422 #frameEncoding
423 labelEncodingTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
424 radioEncNone.pack(side=RIGHT,anchor=E,pady=5)
425 radioEncUTF8.pack(side=RIGHT,anchor=E,pady=5)
426 radioEncLocale.pack(side=RIGHT,anchor=E,pady=5)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000427 #frameHelp
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000428 frameHelpListButtons.pack(side=RIGHT,padx=5,pady=5,fill=Y)
429 frameHelpList.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000430 scrollHelpList.pack(side=RIGHT,anchor=W,fill=Y)
431 self.listHelp.pack(side=LEFT,anchor=E,expand=TRUE,fill=BOTH)
432 self.buttonHelpListEdit.pack(side=TOP,anchor=W,pady=5)
433 self.buttonHelpListAdd.pack(side=TOP,anchor=W)
434 self.buttonHelpListRemove.pack(side=TOP,anchor=W,pady=5)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000435 return frame
436
Steven M. Gavac112cd82002-01-22 05:56:40 +0000437 def AttachVarCallbacks(self):
438 self.fontSize.trace_variable('w',self.VarChanged_fontSize)
439 self.fontName.trace_variable('w',self.VarChanged_fontName)
440 self.fontBold.trace_variable('w',self.VarChanged_fontBold)
441 self.spaceNum.trace_variable('w',self.VarChanged_spaceNum)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000442 self.colour.trace_variable('w',self.VarChanged_colour)
Steven M. Gava052937f2002-02-11 02:20:53 +0000443 self.builtinTheme.trace_variable('w',self.VarChanged_builtinTheme)
444 self.customTheme.trace_variable('w',self.VarChanged_customTheme)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000445 self.themeIsBuiltin.trace_variable('w',self.VarChanged_themeIsBuiltin)
Steven M. Gava052937f2002-02-11 02:20:53 +0000446 self.highlightTarget.trace_variable('w',self.VarChanged_highlightTarget)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000447 self.keyBinding.trace_variable('w',self.VarChanged_keyBinding)
Steven M. Gava052937f2002-02-11 02:20:53 +0000448 self.builtinKeys.trace_variable('w',self.VarChanged_builtinKeys)
449 self.customKeys.trace_variable('w',self.VarChanged_customKeys)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000450 self.keysAreBuiltin.trace_variable('w',self.VarChanged_keysAreBuiltin)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000451 self.winWidth.trace_variable('w',self.VarChanged_winWidth)
452 self.winHeight.trace_variable('w',self.VarChanged_winHeight)
Raymond Hettinger4e49b832004-06-04 06:31:08 +0000453 self.paraWidth.trace_variable('w',self.VarChanged_paraWidth)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000454 self.startupEdit.trace_variable('w',self.VarChanged_startupEdit)
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000455 self.autoSave.trace_variable('w',self.VarChanged_autoSave)
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000456 self.encoding.trace_variable('w',self.VarChanged_encoding)
Steven M. Gava052937f2002-02-11 02:20:53 +0000457
Steven M. Gavac112cd82002-01-22 05:56:40 +0000458 def VarChanged_fontSize(self,*params):
459 value=self.fontSize.get()
460 self.AddChangedItem('main','EditorWindow','font-size',value)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000461
Steven M. Gavac112cd82002-01-22 05:56:40 +0000462 def VarChanged_fontName(self,*params):
463 value=self.fontName.get()
464 self.AddChangedItem('main','EditorWindow','font',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000465
466 def VarChanged_fontBold(self,*params):
467 value=self.fontBold.get()
468 self.AddChangedItem('main','EditorWindow','font-bold',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000469
Steven M. Gavac112cd82002-01-22 05:56:40 +0000470 def VarChanged_spaceNum(self,*params):
471 value=self.spaceNum.get()
472 self.AddChangedItem('main','Indent','num-spaces',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000473
Steven M. Gavac112cd82002-01-22 05:56:40 +0000474 def VarChanged_colour(self,*params):
Steven M. Gava052937f2002-02-11 02:20:53 +0000475 self.OnNewColourSet()
476
477 def VarChanged_builtinTheme(self,*params):
478 value=self.builtinTheme.get()
479 self.AddChangedItem('main','Theme','name',value)
480 self.PaintThemeSample()
481
482 def VarChanged_customTheme(self,*params):
483 value=self.customTheme.get()
Steven M. Gava49745752002-02-18 01:43:11 +0000484 if value != '- no custom themes -':
485 self.AddChangedItem('main','Theme','name',value)
486 self.PaintThemeSample()
Steven M. Gava052937f2002-02-11 02:20:53 +0000487
488 def VarChanged_themeIsBuiltin(self,*params):
489 value=self.themeIsBuiltin.get()
490 self.AddChangedItem('main','Theme','default',value)
Steven M. Gavaf31eec02002-03-05 00:25:58 +0000491 if value:
492 self.VarChanged_builtinTheme()
493 else:
494 self.VarChanged_customTheme()
Steven M. Gava052937f2002-02-11 02:20:53 +0000495
496 def VarChanged_highlightTarget(self,*params):
497 self.SetHighlightTarget()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000498
Steven M. Gavac112cd82002-01-22 05:56:40 +0000499 def VarChanged_keyBinding(self,*params):
Steven M. Gavabbf5ef52002-01-22 11:35:50 +0000500 value=self.keyBinding.get()
501 keySet=self.customKeys.get()
502 event=self.listBindings.get(ANCHOR).split()[0]
Steven M. Gavaa498af22002-02-01 01:33:36 +0000503 if idleConf.IsCoreBinding(event):
504 #this is a core keybinding
505 self.AddChangedItem('keys',keySet,event,value)
506 else: #this is an extension key binding
507 extName=idleConf.GetExtnNameForEvent(event)
508 extKeybindSection=extName+'_cfgBindings'
509 self.AddChangedItem('extensions',extKeybindSection,event,value)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000510
Steven M. Gava052937f2002-02-11 02:20:53 +0000511 def VarChanged_builtinKeys(self,*params):
512 value=self.builtinKeys.get()
513 self.AddChangedItem('main','Keys','name',value)
514 self.LoadKeysList(value)
515
516 def VarChanged_customKeys(self,*params):
517 value=self.customKeys.get()
Steven M. Gava49745752002-02-18 01:43:11 +0000518 if value != '- no custom keys -':
519 self.AddChangedItem('main','Keys','name',value)
520 self.LoadKeysList(value)
Steven M. Gava052937f2002-02-11 02:20:53 +0000521
522 def VarChanged_keysAreBuiltin(self,*params):
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000523 value=self.keysAreBuiltin.get()
Steven M. Gava052937f2002-02-11 02:20:53 +0000524 self.AddChangedItem('main','Keys','default',value)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000525 if value:
Steven M. Gavaf31eec02002-03-05 00:25:58 +0000526 self.VarChanged_builtinKeys()
Steven M. Gava052937f2002-02-11 02:20:53 +0000527 else:
Steven M. Gavaf31eec02002-03-05 00:25:58 +0000528 self.VarChanged_customKeys()
Steven M. Gava052937f2002-02-11 02:20:53 +0000529
Steven M. Gavac112cd82002-01-22 05:56:40 +0000530 def VarChanged_winWidth(self,*params):
Steven M. Gavabbf5ef52002-01-22 11:35:50 +0000531 value=self.winWidth.get()
532 self.AddChangedItem('main','EditorWindow','width',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000533
534 def VarChanged_winHeight(self,*params):
Steven M. Gavabbf5ef52002-01-22 11:35:50 +0000535 value=self.winHeight.get()
536 self.AddChangedItem('main','EditorWindow','height',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000537
Raymond Hettinger4e49b832004-06-04 06:31:08 +0000538 def VarChanged_paraWidth(self,*params):
539 value=self.paraWidth.get()
540 self.AddChangedItem('main','FormatParagraph','paragraph',value)
541
Steven M. Gavac112cd82002-01-22 05:56:40 +0000542 def VarChanged_startupEdit(self,*params):
Steven M. Gavabbf5ef52002-01-22 11:35:50 +0000543 value=self.startupEdit.get()
544 self.AddChangedItem('main','General','editor-on-startup',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000545
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000546 def VarChanged_autoSave(self,*params):
547 value=self.autoSave.get()
548 self.AddChangedItem('main','General','autosave',value)
549
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000550 def VarChanged_encoding(self,*params):
551 value=self.encoding.get()
552 self.AddChangedItem('main','EditorWindow','encoding',value)
553
Steven M. Gavaa498af22002-02-01 01:33:36 +0000554 def ResetChangedItems(self):
Steven M. Gavab77d3432002-03-02 07:16:21 +0000555 #When any config item is changed in this dialog, an entry
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000556 #should be made in the relevant section (config type) of this
557 #dictionary. The key should be the config file section name and the
Steven M. Gavaa498af22002-02-01 01:33:36 +0000558 #value a dictionary, whose key:value pairs are item=value pairs for
559 #that config file section.
560 self.changedItems={'main':{},'highlight':{},'keys':{},'extensions':{}}
561
Steven M. Gavac112cd82002-01-22 05:56:40 +0000562 def AddChangedItem(self,type,section,item,value):
Steven M. Gava2d7bb3f2002-01-29 08:35:29 +0000563 value=str(value) #make sure we use a string
Steven M. Gavac112cd82002-01-22 05:56:40 +0000564 if not self.changedItems[type].has_key(section):
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000565 self.changedItems[type][section]={}
Steven M. Gavac112cd82002-01-22 05:56:40 +0000566 self.changedItems[type][section][item]=value
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000567
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000568 def GetDefaultItems(self):
569 dItems={'main':{},'highlight':{},'keys':{},'extensions':{}}
570 for configType in dItems.keys():
571 sections=idleConf.GetSectionList('default',configType)
572 for section in sections:
573 dItems[configType][section]={}
574 options=idleConf.defaultCfg[configType].GetOptionList(section)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000575 for option in options:
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000576 dItems[configType][section][option]=(
577 idleConf.defaultCfg[configType].Get(section,option))
578 return dItems
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000579
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000580 def SetThemeType(self):
581 if self.themeIsBuiltin.get():
582 self.optMenuThemeBuiltin.config(state=NORMAL)
583 self.optMenuThemeCustom.config(state=DISABLED)
584 self.buttonDeleteCustomTheme.config(state=DISABLED)
585 else:
586 self.optMenuThemeBuiltin.config(state=DISABLED)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000587 self.radioThemeCustom.config(state=NORMAL)
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000588 self.optMenuThemeCustom.config(state=NORMAL)
589 self.buttonDeleteCustomTheme.config(state=NORMAL)
590
591 def SetKeysType(self):
Steven M. Gava052937f2002-02-11 02:20:53 +0000592 if self.keysAreBuiltin.get():
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000593 self.optMenuKeysBuiltin.config(state=NORMAL)
594 self.optMenuKeysCustom.config(state=DISABLED)
595 self.buttonDeleteCustomKeys.config(state=DISABLED)
596 else:
597 self.optMenuKeysBuiltin.config(state=DISABLED)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000598 self.radioKeysCustom.config(state=NORMAL)
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000599 self.optMenuKeysCustom.config(state=NORMAL)
600 self.buttonDeleteCustomKeys.config(state=NORMAL)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000601
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000602 def GetNewKeys(self):
603 listIndex=self.listBindings.index(ANCHOR)
604 binding=self.listBindings.get(listIndex)
605 bindName=binding.split()[0] #first part, up to first space
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000606 if self.keysAreBuiltin.get():
Steven M. Gavae28ee752002-02-11 03:45:22 +0000607 currentKeySetName=self.builtinKeys.get()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000608 else:
Steven M. Gavae28ee752002-02-11 03:45:22 +0000609 currentKeySetName=self.customKeys.get()
610 currentBindings=idleConf.GetCurrentKeySet()
611 if currentKeySetName in self.changedItems['keys'].keys(): #unsaved changes
612 keySetChanges=self.changedItems['keys'][currentKeySetName]
613 for event in keySetChanges.keys():
614 currentBindings[event]=keySetChanges[event].split()
615 currentKeySequences=currentBindings.values()
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000616 newKeys=GetKeysDialog(self,'Get New Keys',bindName,
617 currentKeySequences).result
618 if newKeys: #new keys were specified
Steven M. Gava052937f2002-02-11 02:20:53 +0000619 if self.keysAreBuiltin.get(): #current key set is a built-in
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000620 message=('Your changes will be saved as a new Custom Key Set. '+
621 'Enter a name for your new Custom Key Set below.')
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000622 newKeySet=self.GetNewKeysName(message)
623 if not newKeySet: #user cancelled custom key set creation
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000624 self.listBindings.select_set(listIndex)
625 self.listBindings.select_anchor(listIndex)
626 return
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000627 else: #create new custom key set based on previously active key set
628 self.CreateNewKeySet(newKeySet)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000629 self.listBindings.delete(listIndex)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000630 self.listBindings.insert(listIndex,bindName+' - '+newKeys)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000631 self.listBindings.select_set(listIndex)
632 self.listBindings.select_anchor(listIndex)
Steven M. Gava052937f2002-02-11 02:20:53 +0000633 self.keyBinding.set(newKeys)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000634 else:
635 self.listBindings.select_set(listIndex)
636 self.listBindings.select_anchor(listIndex)
637
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000638 def GetNewKeysName(self,message):
Steven M. Gava49745752002-02-18 01:43:11 +0000639 usedNames=(idleConf.GetSectionList('user','keys')+
640 idleConf.GetSectionList('default','keys'))
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000641 newKeySet=GetCfgSectionNameDialog(self,'New Custom Key Set',
642 message,usedNames).result
643 return newKeySet
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000644
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000645 def SaveAsNewKeySet(self):
646 newKeysName=self.GetNewKeysName('New Key Set Name:')
647 if newKeysName:
648 self.CreateNewKeySet(newKeysName)
649
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000650 def KeyBindingSelected(self,event):
651 self.buttonNewKeys.config(state=NORMAL)
652
653 def CreateNewKeySet(self,newKeySetName):
654 #creates new custom key set based on the previously active key set,
655 #and makes the new key set active
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000656 if self.keysAreBuiltin.get():
Steven M. Gava052937f2002-02-11 02:20:53 +0000657 prevKeySetName=self.builtinKeys.get()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000658 else:
Steven M. Gava052937f2002-02-11 02:20:53 +0000659 prevKeySetName=self.customKeys.get()
Steven M. Gava052937f2002-02-11 02:20:53 +0000660 prevKeys=idleConf.GetCoreKeys(prevKeySetName)
Steven M. Gava052937f2002-02-11 02:20:53 +0000661 newKeys={}
662 for event in prevKeys.keys(): #add key set to changed items
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000663 eventName=event[2:-2] #trim off the angle brackets
Steven M. Gava052937f2002-02-11 02:20:53 +0000664 binding=string.join(prevKeys[event])
665 newKeys[eventName]=binding
Steven M. Gava052937f2002-02-11 02:20:53 +0000666 #handle any unsaved changes to prev key set
667 if prevKeySetName in self.changedItems['keys'].keys():
668 keySetChanges=self.changedItems['keys'][prevKeySetName]
669 for event in keySetChanges.keys():
670 newKeys[event]=keySetChanges[event]
Steven M. Gava052937f2002-02-11 02:20:53 +0000671 #save the new theme
672 self.SaveNewKeySet(newKeySetName,newKeys)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000673 #change gui over to the new key set
674 customKeyList=idleConf.GetSectionList('user','keys')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000675 customKeyList.sort()
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000676 self.optMenuKeysCustom.SetMenu(customKeyList,newKeySetName)
Steven M. Gava052937f2002-02-11 02:20:53 +0000677 self.keysAreBuiltin.set(0)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000678 self.SetKeysType()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000679
Steven M. Gava052937f2002-02-11 02:20:53 +0000680 def LoadKeysList(self,keySetName):
681 reselect=0
682 newKeySet=0
683 if self.listBindings.curselection():
684 reselect=1
685 listIndex=self.listBindings.index(ANCHOR)
Steven M. Gava052937f2002-02-11 02:20:53 +0000686 keySet=idleConf.GetKeySet(keySetName)
Steven M. Gava052937f2002-02-11 02:20:53 +0000687 bindNames=keySet.keys()
688 bindNames.sort()
689 self.listBindings.delete(0,END)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000690 for bindName in bindNames:
Steven M. Gava052937f2002-02-11 02:20:53 +0000691 key=string.join(keySet[bindName]) #make key(s) into a string
692 bindName=bindName[2:-2] #trim off the angle brackets
Steven M. Gava052937f2002-02-11 02:20:53 +0000693 if keySetName in self.changedItems['keys'].keys():
694 #handle any unsaved changes to this key set
695 if bindName in self.changedItems['keys'][keySetName].keys():
696 key=self.changedItems['keys'][keySetName][bindName]
Steven M. Gava052937f2002-02-11 02:20:53 +0000697 self.listBindings.insert(END, bindName+' - '+key)
Steven M. Gava052937f2002-02-11 02:20:53 +0000698 if reselect:
699 self.listBindings.see(listIndex)
700 self.listBindings.select_set(listIndex)
701 self.listBindings.select_anchor(listIndex)
702
Steven M. Gava49745752002-02-18 01:43:11 +0000703 def DeleteCustomKeys(self):
704 keySetName=self.customKeys.get()
705 if not tkMessageBox.askyesno('Delete Key Set','Are you sure you wish '+
Walter Dörwald70a6b492004-02-12 17:35:32 +0000706 'to delete the key set %r ?' % (keySetName),
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +0000707 parent=self):
Steven M. Gava49745752002-02-18 01:43:11 +0000708 return
709 #remove key set from config
710 idleConf.userCfg['keys'].remove_section(keySetName)
711 if self.changedItems['keys'].has_key(keySetName):
712 del(self.changedItems['keys'][keySetName])
713 #write changes
714 idleConf.userCfg['keys'].Save()
715 #reload user key set list
716 itemList=idleConf.GetSectionList('user','keys')
717 itemList.sort()
718 if not itemList:
719 self.radioKeysCustom.config(state=DISABLED)
720 self.optMenuKeysCustom.SetMenu(itemList,'- no custom keys -')
721 else:
722 self.optMenuKeysCustom.SetMenu(itemList,itemList[0])
723 #revert to default key set
724 self.keysAreBuiltin.set(idleConf.defaultCfg['main'].Get('Keys','default'))
725 self.builtinKeys.set(idleConf.defaultCfg['main'].Get('Keys','name'))
726 #user can't back out of these changes, they must be applied now
727 self.Apply()
728 self.SetKeysType()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000729
Steven M. Gava49745752002-02-18 01:43:11 +0000730 def DeleteCustomTheme(self):
731 themeName=self.customTheme.get()
732 if not tkMessageBox.askyesno('Delete Theme','Are you sure you wish '+
Walter Dörwald70a6b492004-02-12 17:35:32 +0000733 'to delete the theme %r ?' % (themeName,),
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +0000734 parent=self):
Steven M. Gava49745752002-02-18 01:43:11 +0000735 return
736 #remove theme from config
737 idleConf.userCfg['highlight'].remove_section(themeName)
738 if self.changedItems['highlight'].has_key(themeName):
739 del(self.changedItems['highlight'][themeName])
740 #write changes
741 idleConf.userCfg['highlight'].Save()
742 #reload user theme list
743 itemList=idleConf.GetSectionList('user','highlight')
744 itemList.sort()
745 if not itemList:
746 self.radioThemeCustom.config(state=DISABLED)
747 self.optMenuThemeCustom.SetMenu(itemList,'- no custom themes -')
748 else:
749 self.optMenuThemeCustom.SetMenu(itemList,itemList[0])
750 #revert to default theme
751 self.themeIsBuiltin.set(idleConf.defaultCfg['main'].Get('Theme','default'))
752 self.builtinTheme.set(idleConf.defaultCfg['main'].Get('Theme','name'))
753 #user can't back out of these changes, they must be applied now
754 self.Apply()
755 self.SetThemeType()
756
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000757 def GetColour(self):
758 target=self.highlightTarget.get()
Steven M. Gava052937f2002-02-11 02:20:53 +0000759 prevColour=self.frameColourSet.cget('bg')
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000760 rgbTuplet, colourString = tkColorChooser.askcolor(parent=self,
Steven M. Gava052937f2002-02-11 02:20:53 +0000761 title='Pick new colour for : '+target,initialcolor=prevColour)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000762 if colourString and (colourString!=prevColour):
Steven M. Gava052937f2002-02-11 02:20:53 +0000763 #user didn't cancel, and they chose a new colour
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000764 if self.themeIsBuiltin.get(): #current theme is a built-in
765 message=('Your changes will be saved as a new Custom Theme. '+
766 'Enter a name for your new Custom Theme below.')
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000767 newTheme=self.GetNewThemeName(message)
768 if not newTheme: #user cancelled custom theme creation
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000769 return
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000770 else: #create new custom theme based on previously active theme
771 self.CreateNewTheme(newTheme)
Steven M. Gava052937f2002-02-11 02:20:53 +0000772 self.colour.set(colourString)
773 else: #current theme is user defined
774 self.colour.set(colourString)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000775
Steven M. Gava052937f2002-02-11 02:20:53 +0000776 def OnNewColourSet(self):
777 newColour=self.colour.get()
778 self.frameColourSet.config(bg=newColour)#set sample
779 if self.fgHilite.get(): plane='foreground'
780 else: plane='background'
781 sampleElement=self.themeElements[self.highlightTarget.get()][0]
Raymond Hettinger931237e2003-07-09 18:48:24 +0000782 self.textHighlightSample.tag_config(sampleElement, **{plane:newColour})
Steven M. Gava052937f2002-02-11 02:20:53 +0000783 theme=self.customTheme.get()
784 themeElement=sampleElement+'-'+plane
785 self.AddChangedItem('highlight',theme,themeElement,newColour)
Steven M. Gava052937f2002-02-11 02:20:53 +0000786
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000787 def GetNewThemeName(self,message):
Steven M. Gava49745752002-02-18 01:43:11 +0000788 usedNames=(idleConf.GetSectionList('user','highlight')+
789 idleConf.GetSectionList('default','highlight'))
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000790 newTheme=GetCfgSectionNameDialog(self,'New Custom Theme',
791 message,usedNames).result
792 return newTheme
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000793
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000794 def SaveAsNewTheme(self):
795 newThemeName=self.GetNewThemeName('New Theme Name:')
796 if newThemeName:
797 self.CreateNewTheme(newThemeName)
798
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000799 def CreateNewTheme(self,newThemeName):
800 #creates new custom theme based on the previously active theme,
801 #and makes the new theme active
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000802 if self.themeIsBuiltin.get():
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000803 themeType='default'
804 themeName=self.builtinTheme.get()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000805 else:
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000806 themeType='user'
807 themeName=self.customTheme.get()
808 newTheme=idleConf.GetThemeDict(themeType,themeName)
Steven M. Gava052937f2002-02-11 02:20:53 +0000809 #apply any of the old theme's unsaved changes to the new theme
810 if themeName in self.changedItems['highlight'].keys():
811 themeChanges=self.changedItems['highlight'][themeName]
812 for element in themeChanges.keys():
813 newTheme[element]=themeChanges[element]
814 #save the new theme
815 self.SaveNewTheme(newThemeName,newTheme)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000816 #change gui over to the new theme
817 customThemeList=idleConf.GetSectionList('user','highlight')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000818 customThemeList.sort()
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000819 self.optMenuThemeCustom.SetMenu(customThemeList,newThemeName)
820 self.themeIsBuiltin.set(0)
821 self.SetThemeType()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000822
Steven M. Gavac112cd82002-01-22 05:56:40 +0000823 def OnListFontButtonRelease(self,event):
Kurt B. Kaiser05391692003-05-26 20:35:53 +0000824 font = self.listFontName.get(ANCHOR)
825 self.fontName.set(font.lower())
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000826 self.SetFontSample()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000827
Steven M. Gavac112cd82002-01-22 05:56:40 +0000828 def SetFontSample(self,event=None):
829 fontName=self.fontName.get()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000830 if self.fontBold.get():
Steven M. Gavac112cd82002-01-22 05:56:40 +0000831 fontWeight=tkFont.BOLD
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000832 else:
Steven M. Gavac112cd82002-01-22 05:56:40 +0000833 fontWeight=tkFont.NORMAL
834 self.editFont.config(size=self.fontSize.get(),
835 weight=fontWeight,family=fontName)
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000836
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000837 def SetHighlightTarget(self):
838 if self.highlightTarget.get()=='Cursor': #bg not possible
839 self.radioFg.config(state=DISABLED)
840 self.radioBg.config(state=DISABLED)
841 self.fgHilite.set(1)
842 else: #both fg and bg can be set
843 self.radioFg.config(state=NORMAL)
844 self.radioBg.config(state=NORMAL)
845 self.fgHilite.set(1)
846 self.SetColourSample()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000847
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000848 def SetColourSampleBinding(self,*args):
849 self.SetColourSample()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000850
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000851 def SetColourSample(self):
852 #set the colour smaple area
853 tag=self.themeElements[self.highlightTarget.get()][0]
854 if self.fgHilite.get(): plane='foreground'
855 else: plane='background'
856 colour=self.textHighlightSample.tag_cget(tag,plane)
857 self.frameColourSet.config(bg=colour)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000858
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000859 def PaintThemeSample(self):
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000860 if self.themeIsBuiltin.get(): #a default theme
Steven M. Gava99300612001-11-04 07:03:08 +0000861 theme=self.builtinTheme.get()
862 else: #a user theme
863 theme=self.customTheme.get()
Steven M. Gava052937f2002-02-11 02:20:53 +0000864 for elementTitle in self.themeElements.keys():
865 element=self.themeElements[elementTitle][0]
866 colours=idleConf.GetHighlight(theme,element)
867 if element=='cursor': #cursor sample needs special painting
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000868 colours['background']=idleConf.GetHighlight(theme,
Steven M. Gava0cae01c2002-01-04 07:53:06 +0000869 'normal', fgBg='bg')
Steven M. Gava052937f2002-02-11 02:20:53 +0000870 #handle any unsaved changes to this theme
871 if theme in self.changedItems['highlight'].keys():
872 themeDict=self.changedItems['highlight'][theme]
873 if themeDict.has_key(element+'-foreground'):
874 colours['foreground']=themeDict[element+'-foreground']
875 if themeDict.has_key(element+'-background'):
876 colours['background']=themeDict[element+'-background']
Raymond Hettinger931237e2003-07-09 18:48:24 +0000877 self.textHighlightSample.tag_config(element, **colours)
Steven M. Gava052937f2002-02-11 02:20:53 +0000878 self.SetColourSample()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000879
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000880 def HelpSourceSelected(self,event):
881 self.SetHelpListButtonStates()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000882
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000883 def SetHelpListButtonStates(self):
884 if self.listHelp.size()<1: #no entries in list
885 self.buttonHelpListEdit.config(state=DISABLED)
886 self.buttonHelpListRemove.config(state=DISABLED)
887 else: #there are some entries
888 if self.listHelp.curselection(): #there currently is a selection
889 self.buttonHelpListEdit.config(state=NORMAL)
890 self.buttonHelpListRemove.config(state=NORMAL)
891 else: #there currently is not a selection
892 self.buttonHelpListEdit.config(state=DISABLED)
893 self.buttonHelpListRemove.config(state=DISABLED)
894
895 def HelpListItemAdd(self):
896 helpSource=GetHelpSourceDialog(self,'New Help Source').result
897 if helpSource:
898 self.userHelpList.append( (helpSource[0],helpSource[1]) )
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +0000899 self.listHelp.insert(END,helpSource[0])
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000900 self.UpdateUserHelpChangedItems()
901 self.SetHelpListButtonStates()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000902
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000903 def HelpListItemEdit(self):
904 itemIndex=self.listHelp.index(ANCHOR)
905 helpSource=self.userHelpList[itemIndex]
Steven M. Gava0c5bc8c2002-03-27 02:25:44 +0000906 newHelpSource=GetHelpSourceDialog(self,'Edit Help Source',
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000907 menuItem=helpSource[0],filePath=helpSource[1]).result
908 if (not newHelpSource) or (newHelpSource==helpSource):
909 return #no changes
910 self.userHelpList[itemIndex]=newHelpSource
911 self.listHelp.delete(itemIndex)
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +0000912 self.listHelp.insert(itemIndex,newHelpSource[0])
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000913 self.UpdateUserHelpChangedItems()
914 self.SetHelpListButtonStates()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000915
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000916 def HelpListItemRemove(self):
917 itemIndex=self.listHelp.index(ANCHOR)
918 del(self.userHelpList[itemIndex])
919 self.listHelp.delete(itemIndex)
920 self.UpdateUserHelpChangedItems()
921 self.SetHelpListButtonStates()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000922
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000923 def UpdateUserHelpChangedItems(self):
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +0000924 "Clear and rebuild the HelpFiles section in self.changedItems"
925 self.changedItems['main']['HelpFiles'] = {}
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000926 for num in range(1,len(self.userHelpList)+1):
927 self.AddChangedItem('main','HelpFiles',str(num),
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +0000928 string.join(self.userHelpList[num-1][:2],';'))
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000929
Steven M. Gava429a86af2001-10-23 10:42:12 +0000930 def LoadFontCfg(self):
931 ##base editor font selection list
Steven M. Gavac11ccf32001-09-24 09:43:17 +0000932 fonts=list(tkFont.families(self))
933 fonts.sort()
934 for font in fonts:
935 self.listFontName.insert(END,font)
Steven M. Gava485f7b62001-10-26 06:47:09 +0000936 configuredFont=idleConf.GetOption('main','EditorWindow','font',
Steven M. Gava429a86af2001-10-23 10:42:12 +0000937 default='courier')
Kurt B. Kaiser05391692003-05-26 20:35:53 +0000938 lc_configuredFont = configuredFont.lower()
939 self.fontName.set(lc_configuredFont)
940 lc_fonts = [s.lower() for s in fonts]
941 if lc_configuredFont in lc_fonts:
942 currentFontIndex = lc_fonts.index(lc_configuredFont)
Steven M. Gava429a86af2001-10-23 10:42:12 +0000943 self.listFontName.see(currentFontIndex)
944 self.listFontName.select_set(currentFontIndex)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000945 self.listFontName.select_anchor(currentFontIndex)
Steven M. Gava429a86af2001-10-23 10:42:12 +0000946 ##font size dropdown
Steven M. Gavac112cd82002-01-22 05:56:40 +0000947 fontSize=idleConf.GetOption('main','EditorWindow','font-size',
Kurt B. Kaiser05391692003-05-26 20:35:53 +0000948 default='10')
Chui Teya178cff2002-11-04 03:17:45 +0000949 self.optMenuFontSize.SetMenu(('7','8','9','10','11','12','13','14',
Steven M. Gava485f7b62001-10-26 06:47:09 +0000950 '16','18','20','22'),fontSize )
Steven M. Gavac112cd82002-01-22 05:56:40 +0000951 ##fontWeight
952 self.fontBold.set(idleConf.GetOption('main','EditorWindow',
953 'font-bold',default=0,type='bool'))
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000954 ##font sample
Steven M. Gava429a86af2001-10-23 10:42:12 +0000955 self.SetFontSample()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000956
Steven M. Gava429a86af2001-10-23 10:42:12 +0000957 def LoadTabCfg(self):
Steven M. Gava429a86af2001-10-23 10:42:12 +0000958 ##indent sizes
Steven M. Gava485f7b62001-10-26 06:47:09 +0000959 spaceNum=idleConf.GetOption('main','Indent','num-spaces',
Steven M. Gava429a86af2001-10-23 10:42:12 +0000960 default=4,type='int')
Steven M. Gava429a86af2001-10-23 10:42:12 +0000961 self.spaceNum.set(spaceNum)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000962
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000963 def LoadThemeCfg(self):
Steven M. Gava41a85322001-10-29 08:05:34 +0000964 ##current theme type radiobutton
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000965 self.themeIsBuiltin.set(idleConf.GetOption('main','Theme','default',
Steven M. Gavac112cd82002-01-22 05:56:40 +0000966 type='bool',default=1))
Steven M. Gava41a85322001-10-29 08:05:34 +0000967 ##currently set theme
Steven M. Gavaad4f5322002-01-03 12:05:17 +0000968 currentOption=idleConf.CurrentTheme()
Steven M. Gava7c017862001-10-29 11:19:46 +0000969 ##load available theme option menus
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000970 if self.themeIsBuiltin.get(): #default theme selected
Steven M. Gava41a85322001-10-29 08:05:34 +0000971 itemList=idleConf.GetSectionList('default','highlight')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000972 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +0000973 self.optMenuThemeBuiltin.SetMenu(itemList,currentOption)
974 itemList=idleConf.GetSectionList('user','highlight')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000975 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +0000976 if not itemList:
977 self.radioThemeCustom.config(state=DISABLED)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000978 self.customTheme.set('- no custom themes -')
Steven M. Gava41a85322001-10-29 08:05:34 +0000979 else:
980 self.optMenuThemeCustom.SetMenu(itemList,itemList[0])
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000981 else: #user theme selected
Steven M. Gava41a85322001-10-29 08:05:34 +0000982 itemList=idleConf.GetSectionList('user','highlight')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000983 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +0000984 self.optMenuThemeCustom.SetMenu(itemList,currentOption)
985 itemList=idleConf.GetSectionList('default','highlight')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000986 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +0000987 self.optMenuThemeBuiltin.SetMenu(itemList,itemList[0])
Steven M. Gava7c017862001-10-29 11:19:46 +0000988 self.SetThemeType()
989 ##load theme element option menu
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000990 themeNames=self.themeElements.keys()
Ezio Melotti4c6daf12010-08-02 20:40:20 +0000991 themeNames.sort(key=lambda x: self.themeElements[x][1])
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000992 self.optMenuHighlightTarget.SetMenu(themeNames,themeNames[0])
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000993 self.PaintThemeSample()
Steven M. Gava0cae01c2002-01-04 07:53:06 +0000994 self.SetHighlightTarget()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000995
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000996 def LoadKeyCfg(self):
Steven M. Gava41a85322001-10-29 08:05:34 +0000997 ##current keys type radiobutton
Steven M. Gava052937f2002-02-11 02:20:53 +0000998 self.keysAreBuiltin.set(idleConf.GetOption('main','Keys','default',
Steven M. Gavac112cd82002-01-22 05:56:40 +0000999 type='bool',default=1))
Steven M. Gava41a85322001-10-29 08:05:34 +00001000 ##currently set keys
Steven M. Gavaad4f5322002-01-03 12:05:17 +00001001 currentOption=idleConf.CurrentKeys()
Steven M. Gava7c017862001-10-29 11:19:46 +00001002 ##load available keyset option menus
Steven M. Gava052937f2002-02-11 02:20:53 +00001003 if self.keysAreBuiltin.get(): #default theme selected
Steven M. Gava41a85322001-10-29 08:05:34 +00001004 itemList=idleConf.GetSectionList('default','keys')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +00001005 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +00001006 self.optMenuKeysBuiltin.SetMenu(itemList,currentOption)
1007 itemList=idleConf.GetSectionList('user','keys')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +00001008 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +00001009 if not itemList:
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001010 self.radioKeysCustom.config(state=DISABLED)
1011 self.customKeys.set('- no custom keys -')
Steven M. Gava41a85322001-10-29 08:05:34 +00001012 else:
1013 self.optMenuKeysCustom.SetMenu(itemList,itemList[0])
Steven M. Gavaa498af22002-02-01 01:33:36 +00001014 else: #user key set selected
Steven M. Gava41a85322001-10-29 08:05:34 +00001015 itemList=idleConf.GetSectionList('user','keys')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +00001016 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +00001017 self.optMenuKeysCustom.SetMenu(itemList,currentOption)
1018 itemList=idleConf.GetSectionList('default','keys')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +00001019 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +00001020 self.optMenuKeysBuiltin.SetMenu(itemList,itemList[0])
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001021 self.SetKeysType()
Steven M. Gavafacfc092002-01-19 00:29:54 +00001022 ##load keyset element list
Steven M. Gava052937f2002-02-11 02:20:53 +00001023 keySetName=idleConf.CurrentKeys()
1024 self.LoadKeysList(keySetName)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001025
Steven M. Gavafacfc092002-01-19 00:29:54 +00001026 def LoadGeneralCfg(self):
Steven M. Gava5f28e8f2002-01-21 06:38:21 +00001027 #startup state
1028 self.startupEdit.set(idleConf.GetOption('main','General',
1029 'editor-on-startup',default=1,type='bool'))
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +00001030 #autosave state
1031 self.autoSave.set(idleConf.GetOption('main', 'General', 'autosave',
1032 default=0, type='bool'))
Steven M. Gavafacfc092002-01-19 00:29:54 +00001033 #initial window size
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001034 self.winWidth.set(idleConf.GetOption('main','EditorWindow','width'))
Steven M. Gavafacfc092002-01-19 00:29:54 +00001035 self.winHeight.set(idleConf.GetOption('main','EditorWindow','height'))
Raymond Hettinger4e49b832004-06-04 06:31:08 +00001036 #initial paragraph reformat size
1037 self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph'))
Kurt B. Kaisera053f332003-05-10 00:49:56 +00001038 # default source encoding
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +00001039 self.encoding.set(idleConf.GetOption('main', 'EditorWindow',
1040 'encoding', default='none'))
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +00001041 # additional help sources
1042 self.userHelpList = idleConf.GetAllExtraHelpSourcesList()
Steven M. Gava085eb1b2002-02-05 04:52:32 +00001043 for helpItem in self.userHelpList:
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +00001044 self.listHelp.insert(END,helpItem[0])
Steven M. Gava085eb1b2002-02-05 04:52:32 +00001045 self.SetHelpListButtonStates()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001046
Steven M. Gava429a86af2001-10-23 10:42:12 +00001047 def LoadConfigs(self):
1048 """
1049 load configuration from default and user config files and populate
1050 the widgets on the config dialog pages.
1051 """
1052 ### fonts / tabs page
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001053 self.LoadFontCfg()
1054 self.LoadTabCfg()
Steven M. Gava429a86af2001-10-23 10:42:12 +00001055 ### highlighting page
Steven M. Gava9dd16b32001-11-03 14:54:25 +00001056 self.LoadThemeCfg()
Steven M. Gava429a86af2001-10-23 10:42:12 +00001057 ### keys page
Steven M. Gava9dd16b32001-11-03 14:54:25 +00001058 self.LoadKeyCfg()
Steven M. Gava429a86af2001-10-23 10:42:12 +00001059 ### general page
Steven M. Gavafacfc092002-01-19 00:29:54 +00001060 self.LoadGeneralCfg()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001061
Steven M. Gava052937f2002-02-11 02:20:53 +00001062 def SaveNewKeySet(self,keySetName,keySet):
1063 """
1064 save a newly created core key set.
1065 keySetName - string, the name of the new key set
1066 keySet - dictionary containing the new key set
1067 """
1068 if not idleConf.userCfg['keys'].has_section(keySetName):
1069 idleConf.userCfg['keys'].add_section(keySetName)
1070 for event in keySet.keys():
1071 value=keySet[event]
1072 idleConf.userCfg['keys'].SetOption(keySetName,event,value)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001073
Steven M. Gava052937f2002-02-11 02:20:53 +00001074 def SaveNewTheme(self,themeName,theme):
1075 """
1076 save a newly created theme.
1077 themeName - string, the name of the new theme
1078 theme - dictionary containing the new theme
1079 """
1080 if not idleConf.userCfg['highlight'].has_section(themeName):
1081 idleConf.userCfg['highlight'].add_section(themeName)
1082 for element in theme.keys():
1083 value=theme[element]
1084 idleConf.userCfg['highlight'].SetOption(themeName,element,value)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001085
Steven M. Gava2d7bb3f2002-01-29 08:35:29 +00001086 def SetUserValue(self,configType,section,item,value):
Steven M. Gava2d7bb3f2002-01-29 08:35:29 +00001087 if idleConf.defaultCfg[configType].has_option(section,item):
1088 if idleConf.defaultCfg[configType].Get(section,item)==value:
1089 #the setting equals a default setting, remove it from user cfg
1090 return idleConf.userCfg[configType].RemoveOption(section,item)
1091 #if we got here set the option
1092 return idleConf.userCfg[configType].SetOption(section,item,value)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001093
Steven M. Gava052937f2002-02-11 02:20:53 +00001094 def SaveAllChangedConfigs(self):
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +00001095 "Save configuration changes to the user config file."
Steven M. Gava0c5bc8c2002-03-27 02:25:44 +00001096 idleConf.userCfg['main'].Save()
Steven M. Gava5f28e8f2002-01-21 06:38:21 +00001097 for configType in self.changedItems.keys():
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +00001098 cfgTypeHasChanges = False
Steven M. Gava5f28e8f2002-01-21 06:38:21 +00001099 for section in self.changedItems[configType].keys():
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +00001100 if section == 'HelpFiles':
1101 #this section gets completely replaced
1102 idleConf.userCfg['main'].remove_section('HelpFiles')
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +00001103 cfgTypeHasChanges = True
Steven M. Gava5f28e8f2002-01-21 06:38:21 +00001104 for item in self.changedItems[configType][section].keys():
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +00001105 value = self.changedItems[configType][section][item]
Steven M. Gava2d7bb3f2002-01-29 08:35:29 +00001106 if self.SetUserValue(configType,section,item,value):
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +00001107 cfgTypeHasChanges = True
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001108 if cfgTypeHasChanges:
1109 idleConf.userCfg[configType].Save()
Kurt B. Kaiser5acdf932004-11-16 21:28:36 +00001110 for configType in ['keys', 'highlight']:
1111 # save these even if unchanged!
1112 idleConf.userCfg[configType].Save()
Steven M. Gavaa498af22002-02-01 01:33:36 +00001113 self.ResetChangedItems() #clear the changed items dict
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001114
Kurt B. Kaiserb1754452005-11-18 22:05:48 +00001115 def DeactivateCurrentConfig(self):
1116 #Before a config is saved, some cleanup of current
1117 #config must be done - remove the previous keybindings
1118 winInstances=self.parent.instance_dict.keys()
1119 for instance in winInstances:
1120 instance.RemoveKeybindings()
1121
Steven M. Gava49745752002-02-18 01:43:11 +00001122 def ActivateConfigChanges(self):
Kurt B. Kaiseracdef852005-01-31 03:34:26 +00001123 "Dynamically apply configuration changes"
Kurt B. Kaisercf6f1b62004-04-11 03:16:07 +00001124 winInstances=self.parent.instance_dict.keys()
Steven M. Gavab77d3432002-03-02 07:16:21 +00001125 for instance in winInstances:
1126 instance.ResetColorizer()
Steven M. Gavab1585412002-03-12 00:21:56 +00001127 instance.ResetFont()
Kurt B. Kaiseracdef852005-01-31 03:34:26 +00001128 instance.set_notabs_indentwidth()
Kurt B. Kaiserb1754452005-11-18 22:05:48 +00001129 instance.ApplyKeybindings()
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +00001130 instance.reset_help_menu_entries()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001131
Steven M. Gava5f28e8f2002-01-21 06:38:21 +00001132 def Cancel(self):
1133 self.destroy()
1134
1135 def Ok(self):
1136 self.Apply()
1137 self.destroy()
1138
1139 def Apply(self):
Kurt B. Kaiserb1754452005-11-18 22:05:48 +00001140 self.DeactivateCurrentConfig()
Steven M. Gava052937f2002-02-11 02:20:53 +00001141 self.SaveAllChangedConfigs()
Steven M. Gava49745752002-02-18 01:43:11 +00001142 self.ActivateConfigChanges()
Steven M. Gava5f28e8f2002-01-21 06:38:21 +00001143
1144 def Help(self):
Steven M. Gavac11ccf32001-09-24 09:43:17 +00001145 pass
1146
Steven M. Gava44d3d1a2001-07-31 06:59:02 +00001147if __name__ == '__main__':
Steven M. Gavad721c482001-07-31 10:46:53 +00001148 #test the dialog
1149 root=Tk()
1150 Button(root,text='Dialog',
Steven M. Gava3b55a892001-11-21 05:56:26 +00001151 command=lambda:ConfigDialog(root,'Settings')).pack()
Kurt B. Kaisercf6f1b62004-04-11 03:16:07 +00001152 root.instance_dict={}
Steven M. Gavad721c482001-07-31 10:46:53 +00001153 root.mainloop()