5 import tkMessageBox
, tkColorChooser
, tkFont
7 from configHandler
import idleConf
8 from dynOptionMenuWidget
import DynOptionMenu
9 from tabpage
import TabPageSet
11 class ConfigDialog(Toplevel
):
13 configuration dialog for idle
15 def __init__(self
,parent
,title
):
16 Toplevel
.__init
__(self
, parent
)
17 self
.configure(borderwidth
=5)
18 self
.geometry("+%d+%d" % (parent
.winfo_rootx()+20,
19 parent
.winfo_rooty()+30))
20 #Theme Elements. Each theme element key is it's display name.
21 #The first value of the tuple is the sample area tag name.
22 #The second value is the display name list sort index.
23 #The third value indicates whether the element can have a foreground
24 #or background colour or both.
25 self
.themeElements
={'Normal Text':('normal','00','both'),
26 'Python Keywords':('keyword','01','both'),
27 'Python Definitions':('definition','02','both'),
28 'Python Comments':('comment','03','both'),
29 'Python Strings':('string','04','both'),
30 'Selected Text':('hilite','05','both'),
31 'Found Text':('hit','06','both'),
32 'Cursor':('cursor','07','fg'),
33 'Error Background':('error','08','bg'),
34 'Shell Foreground':('console','09','fg'),
35 'Shell Stdout Foreground':('stdout','10','fg'),
36 'Shell Stderr Foreground':('stderr','11','fg')}
38 self
.resizable(height
=FALSE
,width
=FALSE
)
39 self
.transient(parent
)
41 self
.protocol("WM_DELETE_WINDOW", self
.Cancel
)
43 self
.tabPages
.focus_set()
44 #key bindings for this dialog
45 self
.bind('<Escape>',self
.CancelBinding
) #dismiss dialog, no save
46 self
.bind('<Alt-a>',self
.ApplyBinding
) #apply changes, save
47 self
.bind('<F1>',self
.HelpBinding
) #context help
63 def CancelBinding(self
,event
):
66 def OkBinding(self
,event
):
69 def ApplyBinding(self
,event
):
72 def HelpBinding(self
,event
):
75 def SetThemeType(self
):
76 if self
.themeIsBuiltin
.get():
77 self
.optMenuThemeBuiltin
.config(state
=NORMAL
)
78 self
.optMenuThemeCustom
.config(state
=DISABLED
)
79 self
.buttonDeleteCustomTheme
.config(state
=DISABLED
)
81 self
.optMenuThemeBuiltin
.config(state
=DISABLED
)
82 self
.optMenuThemeCustom
.config(state
=NORMAL
)
83 self
.buttonDeleteCustomTheme
.config(state
=NORMAL
)
85 def SetKeysType(self
):
86 if self
.keysAreDefault
.get():
87 self
.optMenuKeysBuiltin
.config(state
=NORMAL
)
88 self
.optMenuKeysCustom
.config(state
=DISABLED
)
89 self
.buttonDeleteCustomKeys
.config(state
=DISABLED
)
91 self
.optMenuKeysBuiltin
.config(state
=DISABLED
)
92 self
.optMenuKeysCustom
.config(state
=NORMAL
)
93 self
.buttonDeleteCustomKeys
.config(state
=NORMAL
)
96 target
=self
.highlightTarget
.get()
97 rgbTuplet
, colourString
= tkColorChooser
.askcolor(parent
=self
,
98 title
='Pick new colour for : '+target
,
99 initialcolor
=self
.frameColourSet
.cget('bg'))
100 if colourString
: #user didn't cancel
101 self
.frameColourSet
.config(bg
=colourString
)#set sample
102 if self
.fgHilite
.get(): plane
='foreground'
103 else: plane
='background'
104 apply(self
.textHighlightSample
.tag_config
,
105 (self
.themeElements
[target
][0],),{plane
:colourString
})
107 def SetFontSampleBinding(self
,event
):
110 def SetFontSample(self
):
111 self
.editFont
.config(size
=self
.fontSize
.get(),weight
=NORMAL
,
112 family
=self
.listFontName
.get(self
.listFontName
.curselection()[0]))
114 def SetHighlightTargetBinding(self
,*args
):
115 self
.SetHighlightTarget()
117 def SetHighlightTarget(self
):
118 colourPlane
=self
.themeElements
[self
.highlightTarget
.get()][2]
119 if colourPlane
== 'bg':
120 self
.radioFg
.config(state
=DISABLED
)
121 self
.radioBg
.config(state
=DISABLED
)
123 elif colourPlane
== 'fg':
124 self
.radioFg
.config(state
=DISABLED
)
125 self
.radioBg
.config(state
=DISABLED
)
127 elif colourPlane
== 'both':
128 self
.radioFg
.config(state
=NORMAL
)
129 self
.radioBg
.config(state
=NORMAL
)
130 self
.fgHilite
.set(1) #default to setting foreground attribute
131 self
.SetColourSample()
133 def SetColourSampleBinding(self
,*args
):
134 self
.SetColourSample()
136 def SetColourSample(self
):
137 #set the colour smaple area
138 tag
=self
.themeElements
[self
.highlightTarget
.get()][0]
139 if self
.fgHilite
.get(): plane
='foreground'
140 else: plane
='background'
141 colour
=self
.textHighlightSample
.tag_cget(tag
,plane
)
142 self
.frameColourSet
.config(bg
=colour
)
144 def CreateWidgets(self
):
145 self
.tabPages
= TabPageSet(self
,
146 pageNames
=['Fonts/Tabs','Highlighting','Keys','General'])
147 frameActionButtons
= Frame(self
)
149 self
.buttonHelp
= Button(frameActionButtons
,text
='Help',
150 command
=self
.Help
,takefocus
=FALSE
)
151 self
.buttonOk
= Button(frameActionButtons
,text
='Ok',
152 command
=self
.Ok
,takefocus
=FALSE
)
153 self
.buttonApply
= Button(frameActionButtons
,text
='Apply',
154 command
=self
.Apply
,underline
=0,takefocus
=FALSE
)
155 self
.buttonCancel
= Button(frameActionButtons
,text
='Cancel',
156 command
=self
.Cancel
,takefocus
=FALSE
)
157 self
.CreatePageFontTab()
158 self
.CreatePageHighlight()
159 self
.CreatePageKeys()
160 self
.CreatePageGeneral()
161 self
.buttonHelp
.pack(side
=RIGHT
,padx
=5,pady
=5)
162 self
.buttonOk
.pack(side
=LEFT
,padx
=5,pady
=5)
163 self
.buttonApply
.pack(side
=LEFT
,padx
=5,pady
=5)
164 self
.buttonCancel
.pack(side
=LEFT
,padx
=5,pady
=5)
165 frameActionButtons
.pack(side
=BOTTOM
)
166 self
.tabPages
.pack(side
=TOP
,expand
=TRUE
,fill
=BOTH
)
169 def CreatePageFontTab(self
):
171 self
.fontSize
=StringVar(self
)
172 self
.fontBold
=StringVar(self
)
173 self
.spaceNum
=IntVar(self
)
174 self
.tabCols
=IntVar(self
)
175 self
.indentType
=IntVar(self
)
176 self
.editFont
=tkFont
.Font(self
,('courier',12,'normal'))
179 frame
=self
.tabPages
.pages
['Fonts/Tabs']['page']
181 frameFont
=Frame(frame
,borderwidth
=2,relief
=GROOVE
)
182 frameIndent
=Frame(frame
,borderwidth
=2,relief
=GROOVE
)
184 labelFontTitle
=Label(frameFont
,text
='Set Base Editor Font')
185 frameFontName
=Frame(frameFont
)
186 frameFontParam
=Frame(frameFont
)
187 labelFontNameTitle
=Label(frameFontName
,justify
=LEFT
,
189 self
.listFontName
=Listbox(frameFontName
,height
=5,takefocus
=FALSE
,
190 exportselection
=FALSE
)
191 self
.listFontName
.bind('<<ListboxSelect>>',self
.SetFontSampleBinding
)
192 scrollFont
=Scrollbar(frameFontName
)
193 scrollFont
.config(command
=self
.listFontName
.yview
)
194 self
.listFontName
.config(yscrollcommand
=scrollFont
.set)
195 labelFontSizeTitle
=Label(frameFontParam
,text
='Size :')
196 self
.optMenuFontSize
=DynOptionMenu(frameFontParam
,self
.fontSize
,None,
197 command
=self
.SetFontSampleBinding
)
198 checkFontBold
=Checkbutton(frameFontParam
,variable
=self
.fontBold
,
199 onvalue
='Bold',offvalue
='',text
='Bold')
200 frameFontSample
=Frame(frameFont
,relief
=SOLID
,borderwidth
=1)
201 self
.labelFontSample
=Label(frameFontSample
,
202 text
='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]',
203 justify
=LEFT
,font
=self
.editFont
)
205 labelIndentTitle
=Label(frameIndent
,text
='Set Indentation Defaults')
206 frameIndentType
=Frame(frameIndent
)
207 frameIndentSize
=Frame(frameIndent
)
208 labelIndentTypeTitle
=Label(frameIndentType
,
209 text
='Choose indentation type :')
210 radioUseSpaces
=Radiobutton(frameIndentType
,variable
=self
.indentType
,
211 value
=1,text
='Tab key inserts spaces')
212 radioUseTabs
=Radiobutton(frameIndentType
,variable
=self
.indentType
,
213 value
=0,text
='Tab key inserts tabs')
214 labelIndentSizeTitle
=Label(frameIndentSize
,
215 text
='Choose indentation size :')
216 labelSpaceNumTitle
=Label(frameIndentSize
,justify
=LEFT
,
217 text
='when tab key inserts spaces,\nspaces per tab')
218 self
.scaleSpaceNum
=Scale(frameIndentSize
,variable
=self
.spaceNum
,
219 orient
='horizontal',tickinterval
=2,from_
=2,to
=8)
220 labeltabColsTitle
=Label(frameIndentSize
,justify
=LEFT
,
221 text
='when tab key inserts tabs,\ncolumns per tab')
222 self
.scaleTabCols
=Scale(frameIndentSize
,variable
=self
.tabCols
,
223 orient
='horizontal',tickinterval
=2,from_
=2,to
=8)
226 frameFont
.pack(side
=LEFT
,padx
=5,pady
=10,expand
=TRUE
,fill
=BOTH
)
227 frameIndent
.pack(side
=LEFT
,padx
=5,pady
=10,fill
=Y
)
229 labelFontTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
230 frameFontName
.pack(side
=TOP
,padx
=5,pady
=5,fill
=X
)
231 frameFontParam
.pack(side
=TOP
,padx
=5,pady
=5,fill
=X
)
232 labelFontNameTitle
.pack(side
=TOP
,anchor
=W
)
233 self
.listFontName
.pack(side
=LEFT
,expand
=TRUE
,fill
=X
)
234 scrollFont
.pack(side
=LEFT
,fill
=Y
)
235 labelFontSizeTitle
.pack(side
=LEFT
,anchor
=W
)
236 self
.optMenuFontSize
.pack(side
=LEFT
,anchor
=W
)
237 checkFontBold
.pack(side
=LEFT
,anchor
=W
,padx
=20)
238 frameFontSample
.pack(side
=TOP
,padx
=5,pady
=5,expand
=TRUE
,fill
=BOTH
)
239 self
.labelFontSample
.pack(expand
=TRUE
,fill
=BOTH
)
241 labelIndentTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
242 frameIndentType
.pack(side
=TOP
,padx
=5,fill
=X
)
243 frameIndentSize
.pack(side
=TOP
,padx
=5,pady
=5,fill
=BOTH
)
244 labelIndentTypeTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
245 radioUseSpaces
.pack(side
=TOP
,anchor
=W
,padx
=5)
246 radioUseTabs
.pack(side
=TOP
,anchor
=W
,padx
=5)
247 labelIndentSizeTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
248 labelSpaceNumTitle
.pack(side
=TOP
,anchor
=W
,padx
=5)
249 self
.scaleSpaceNum
.pack(side
=TOP
,padx
=5,fill
=X
)
250 labeltabColsTitle
.pack(side
=TOP
,anchor
=W
,padx
=5)
251 self
.scaleTabCols
.pack(side
=TOP
,padx
=5,fill
=X
)
254 def CreatePageHighlight(self
):
255 self
.builtinTheme
=StringVar(self
)
256 self
.customTheme
=StringVar(self
)
257 self
.fgHilite
=IntVar(self
)
258 self
.colour
=StringVar(self
)
259 self
.fontName
=StringVar(self
)
260 self
.themeIsBuiltin
=IntVar(self
)
261 self
.highlightTarget
=StringVar(self
)
262 self
.highlightTarget
.trace_variable('w',self
.SetHighlightTargetBinding
)
265 frame
=self
.tabPages
.pages
['Highlighting']['page']
267 frameCustom
=Frame(frame
,borderwidth
=2,relief
=GROOVE
)
268 frameTheme
=Frame(frame
,borderwidth
=2,relief
=GROOVE
)
270 self
.textHighlightSample
=Text(frameCustom
,relief
=SOLID
,borderwidth
=1,
271 font
=('courier',12,''),cursor
='hand2',width
=10,height
=10,
272 takefocus
=FALSE
,highlightthickness
=0)
273 text
=self
.textHighlightSample
274 text
.bind('<Double-Button-1>',lambda e
: 'break')
275 text
.bind('<B1-Motion>',lambda e
: 'break')
276 textAndTags
=(('#you can click in here','comment'),('\n','normal'),
277 ('#to choose items','comment'),('\n','normal'),('def','keyword'),
278 (' ','normal'),('func','definition'),('(param):','normal'),
279 ('\n ','normal'),('"""string"""','string'),('\n var0 = ','normal'),
280 ("'string'",'string'),('\n var1 = ','normal'),("'selected'",'hilite'),
281 ('\n var2 = ','normal'),("'found'",'hit'),('\n\n','normal'),
282 (' error ','error'),(' ','normal'),('cursor |','cursor'),
283 ('\n ','normal'),('shell','console'),(' ','normal'),('stdout','stdout'),
284 (' ','normal'),('stderr','stderr'),('\n','normal'))
285 for txTa
in textAndTags
:
286 text
.insert(END
,txTa
[0],txTa
[1])
287 for element
in self
.themeElements
.keys():
288 text
.tag_bind(self
.themeElements
[element
][0],'<ButtonPress-1>',
289 lambda event
,elem
=element
: event
.widget
.winfo_toplevel()
290 .highlightTarget
.set(elem
))
291 text
.config(state
=DISABLED
)
292 self
.frameColourSet
=Frame(frameCustom
,relief
=SOLID
,borderwidth
=1)
293 frameFgBg
=Frame(frameCustom
)
294 labelCustomTitle
=Label(frameCustom
,text
='Set Custom Highlighting')
295 buttonSetColour
=Button(self
.frameColourSet
,text
='Choose Colour for :',
296 command
=self
.GetColour
,highlightthickness
=0)
297 self
.optMenuHighlightTarget
=DynOptionMenu(self
.frameColourSet
,
298 self
.highlightTarget
,None,highlightthickness
=0)#,command=self.SetHighlightTargetBinding
299 self
.radioFg
=Radiobutton(frameFgBg
,variable
=self
.fgHilite
,
300 value
=1,text
='Foreground',command
=self
.SetColourSampleBinding
)
301 self
.radioBg
=Radiobutton(frameFgBg
,variable
=self
.fgHilite
,
302 value
=0,text
='Background',command
=self
.SetColourSampleBinding
)
304 buttonSaveCustomTheme
=Button(frameCustom
,
305 text
='Save as a Custom Theme')
307 labelThemeTitle
=Label(frameTheme
,text
='Select a Highlighting Theme')
308 labelTypeTitle
=Label(frameTheme
,text
='Select : ')
309 self
.radioThemeBuiltin
=Radiobutton(frameTheme
,variable
=self
.themeIsBuiltin
,
310 value
=1,command
=self
.SetThemeType
,text
='a Built-in Theme')
311 self
.radioThemeCustom
=Radiobutton(frameTheme
,variable
=self
.themeIsBuiltin
,
312 value
=0,command
=self
.SetThemeType
,text
='a Custom Theme')
313 self
.optMenuThemeBuiltin
=DynOptionMenu(frameTheme
,
314 self
.builtinTheme
,None,command
=None)
315 self
.optMenuThemeCustom
=DynOptionMenu(frameTheme
,
316 self
.customTheme
,None,command
=None)
317 self
.buttonDeleteCustomTheme
=Button(frameTheme
,text
='Delete Custom Theme')
320 frameCustom
.pack(side
=LEFT
,padx
=5,pady
=10,expand
=TRUE
,fill
=BOTH
)
321 frameTheme
.pack(side
=LEFT
,padx
=5,pady
=10,fill
=Y
)
323 labelCustomTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
324 self
.frameColourSet
.pack(side
=TOP
,padx
=5,pady
=5,expand
=TRUE
,fill
=X
)
325 frameFgBg
.pack(side
=TOP
,padx
=5,pady
=0)
326 self
.textHighlightSample
.pack(side
=TOP
,padx
=5,pady
=5,expand
=TRUE
,
328 buttonSetColour
.pack(side
=TOP
,expand
=TRUE
,fill
=X
,padx
=8,pady
=4)
329 self
.optMenuHighlightTarget
.pack(side
=TOP
,expand
=TRUE
,fill
=X
,padx
=8,pady
=3)
330 self
.radioFg
.pack(side
=LEFT
,anchor
=E
)
331 self
.radioBg
.pack(side
=RIGHT
,anchor
=W
)
332 buttonSaveCustomTheme
.pack(side
=BOTTOM
,fill
=X
,padx
=5,pady
=5)
334 labelThemeTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
335 labelTypeTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
336 self
.radioThemeBuiltin
.pack(side
=TOP
,anchor
=W
,padx
=5)
337 self
.radioThemeCustom
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=2)
338 self
.optMenuThemeBuiltin
.pack(side
=TOP
,fill
=X
,padx
=5,pady
=5)
339 self
.optMenuThemeCustom
.pack(side
=TOP
,fill
=X
,anchor
=W
,padx
=5,pady
=5)
340 self
.buttonDeleteCustomTheme
.pack(side
=TOP
,fill
=X
,padx
=5,pady
=5)
343 def CreatePageKeys(self
):
345 self
.bindingTarget
=StringVar(self
)
346 self
.builtinKeys
=StringVar(self
)
347 self
.customKeys
=StringVar(self
)
348 self
.keyChars
=StringVar(self
)
349 self
.keyCtrl
=StringVar(self
)
350 self
.keyAlt
=StringVar(self
)
351 self
.keyShift
=StringVar(self
)
352 self
.keysAreDefault
=IntVar(self
)
355 frame
=self
.tabPages
.pages
['Keys']['page']
357 frameCustom
=Frame(frame
,borderwidth
=2,relief
=GROOVE
)
358 frameKeySets
=Frame(frame
,borderwidth
=2,relief
=GROOVE
)
360 frameTarget
=Frame(frameCustom
)
361 frameSet
=Frame(frameCustom
)
362 labelCustomTitle
=Label(frameCustom
,text
='Set Custom Key Bindings')
363 labelTargetTitle
=Label(frameTarget
,text
='Action')
364 scrollTarget
=Scrollbar(frameTarget
)
365 listTarget
=Listbox(frameTarget
)
366 scrollTarget
.config(command
=listTarget
.yview
)
367 listTarget
.config(yscrollcommand
=scrollTarget
.set)
368 labelKeyBindTitle
=Label(frameSet
,text
='Binding')
369 labelModifierTitle
=Label(frameSet
,text
='Modifier:')
370 checkCtrl
=Checkbutton(frameSet
,text
='Ctrl')
371 checkAlt
=Checkbutton(frameSet
,text
='Alt')
372 checkShift
=Checkbutton(frameSet
,text
='Shift')
373 labelKeyEntryTitle
=Label(frameSet
,text
='Key:')
374 entryKey
=Entry(frameSet
,width
=4)
375 buttonSaveCustomKeys
=Button(frameCustom
,text
='Save as a Custom Key Set')
377 labelKeysTitle
=Label(frameKeySets
,text
='Select a Key Set')
378 labelTypeTitle
=Label(frameKeySets
,text
='Select : ')
379 self
.radioKeysBuiltin
=Radiobutton(frameKeySets
,variable
=self
.keysAreDefault
,
380 value
=1,command
=self
.SetKeysType
,text
='a Built-in Key Set')
381 self
.radioKeysCustom
=Radiobutton(frameKeySets
,variable
=self
.keysAreDefault
,
382 value
=0,command
=self
.SetKeysType
,text
='a Custom Key Set')
383 self
.optMenuKeysBuiltin
=DynOptionMenu(frameKeySets
,
384 self
.builtinKeys
,None,command
=None)
385 self
.optMenuKeysCustom
=DynOptionMenu(frameKeySets
,
386 self
.customKeys
,None,command
=None)
387 self
.buttonDeleteCustomKeys
=Button(frameKeySets
,text
='Delete Custom Key Set')
390 frameCustom
.pack(side
=LEFT
,padx
=5,pady
=5,expand
=TRUE
,fill
=BOTH
)
391 frameKeySets
.pack(side
=LEFT
,padx
=5,pady
=5,fill
=Y
)
393 labelCustomTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
394 buttonSaveCustomKeys
.pack(side
=BOTTOM
,fill
=X
,padx
=5,pady
=5)
395 frameTarget
.pack(side
=LEFT
,padx
=5,pady
=5,fill
=Y
)
396 frameSet
.pack(side
=LEFT
,padx
=5,pady
=5,fill
=Y
)
397 labelTargetTitle
.pack(side
=TOP
,anchor
=W
)
398 scrollTarget
.pack(side
=RIGHT
,anchor
=W
,fill
=Y
)
399 listTarget
.pack(side
=TOP
,anchor
=W
,expand
=TRUE
,fill
=BOTH
)
400 labelKeyBindTitle
.pack(side
=TOP
,anchor
=W
)
401 labelModifierTitle
.pack(side
=TOP
,anchor
=W
,pady
=5)
402 checkCtrl
.pack(side
=TOP
,anchor
=W
)
403 checkAlt
.pack(side
=TOP
,anchor
=W
,pady
=2)
404 checkShift
.pack(side
=TOP
,anchor
=W
)
405 labelKeyEntryTitle
.pack(side
=TOP
,anchor
=W
,pady
=5)
406 entryKey
.pack(side
=TOP
,anchor
=W
)
408 labelKeysTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
409 labelTypeTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
410 self
.radioKeysBuiltin
.pack(side
=TOP
,anchor
=W
,padx
=5)
411 self
.radioKeysCustom
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=2)
412 self
.optMenuKeysBuiltin
.pack(side
=TOP
,fill
=X
,padx
=5,pady
=5)
413 self
.optMenuKeysCustom
.pack(side
=TOP
,fill
=X
,anchor
=W
,padx
=5,pady
=5)
414 self
.buttonDeleteCustomKeys
.pack(side
=TOP
,fill
=X
,padx
=5,pady
=5)
417 def CreatePageGeneral(self
):
419 self
.runType
=IntVar(self
)
420 self
.winWidth
=StringVar(self
)
421 self
.winHeight
=StringVar(self
)
422 self
.extState
=IntVar(self
)
425 frame
=self
.tabPages
.pages
['General']['page']
427 frameRun
=Frame(frame
,borderwidth
=2,relief
=GROOVE
)
428 frameWinSize
=Frame(frame
,borderwidth
=2,relief
=GROOVE
)
429 frameExt
=Frame(frame
,borderwidth
=2,relief
=GROOVE
)
431 labelRunTitle
=Label(frameRun
,text
='Run Preferences')
432 labelRunChoiceTitle
=Label(frameRun
,text
='Run code : ')
433 radioRunInternal
=Radiobutton(frameRun
,variable
=self
.runType
,
434 value
=0,command
=self
.SetKeysType
,text
="in IDLE's Process")
435 radioRunSeparate
=Radiobutton(frameRun
,variable
=self
.runType
,
436 value
=1,command
=self
.SetKeysType
,text
='in a Separate Process')
438 labelWinSizeTitle
=Label(frameWinSize
,text
='Initial Window Size')
439 buttonWinSizeSet
=Button(frameWinSize
,text
='Set to current window size')
440 labelWinWidthTitle
=Label(frameWinSize
,text
='Width')
441 entryWinWidth
=Entry(frameWinSize
,textvariable
=self
.winWidth
,
443 labelWinHeightTitle
=Label(frameWinSize
,text
='Height')
444 entryWinHeight
=Entry(frameWinSize
,textvariable
=self
.winHeight
,
447 frameExtList
=Frame(frameExt
)
448 frameExtSet
=Frame(frameExt
)
449 labelExtTitle
=Label(frameExt
,text
='Configure IDLE Extensions')
450 labelExtListTitle
=Label(frameExtList
,text
='Extension')
451 scrollExtList
=Scrollbar(frameExtList
)
452 listExt
=Listbox(frameExtList
,height
=5)
453 scrollExtList
.config(command
=listExt
.yview
)
454 listExt
.config(yscrollcommand
=scrollExtList
.set)
455 labelExtSetTitle
=Label(frameExtSet
,text
='Settings')
456 radioEnableExt
=Radiobutton(frameExtSet
,variable
=self
.extState
,
457 value
=1,text
="enable")
458 radioDisableExt
=Radiobutton(frameExtSet
,variable
=self
.extState
,
459 value
=0,text
="disable")
461 buttonExtConfig
=Button(frameExtSet
,text
='Configure')
465 frameRun
.pack(side
=TOP
,padx
=5,pady
=5,fill
=X
)
466 frameWinSize
.pack(side
=TOP
,padx
=5,pady
=5,fill
=X
)
467 frameExt
.pack(side
=TOP
,padx
=5,pady
=5,expand
=TRUE
,fill
=BOTH
)
469 labelRunTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
470 labelRunChoiceTitle
.pack(side
=LEFT
,anchor
=W
,padx
=5,pady
=5)
471 radioRunInternal
.pack(side
=LEFT
,anchor
=W
,padx
=5,pady
=5)
472 radioRunSeparate
.pack(side
=LEFT
,anchor
=W
,padx
=5,pady
=5)
474 labelWinSizeTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
475 buttonWinSizeSet
.pack(side
=LEFT
,anchor
=W
,padx
=5,pady
=5)
476 labelWinWidthTitle
.pack(side
=LEFT
,anchor
=W
,padx
=5,pady
=5)
477 entryWinWidth
.pack(side
=LEFT
,anchor
=W
,padx
=5,pady
=5)
478 labelWinHeightTitle
.pack(side
=LEFT
,anchor
=W
,padx
=5,pady
=5)
479 entryWinHeight
.pack(side
=LEFT
,anchor
=W
,padx
=5,pady
=5)
481 labelExtTitle
.pack(side
=TOP
,anchor
=W
,padx
=5,pady
=5)
482 frameExtSet
.pack(side
=RIGHT
,padx
=5,pady
=5,fill
=Y
)
483 frameExtList
.pack(side
=RIGHT
,padx
=5,pady
=5,expand
=TRUE
,fill
=BOTH
)
484 labelExtListTitle
.pack(side
=TOP
,anchor
=W
)
485 scrollExtList
.pack(side
=RIGHT
,anchor
=W
,fill
=Y
)
486 listExt
.pack(side
=LEFT
,anchor
=E
,expand
=TRUE
,fill
=BOTH
)
487 labelExtSetTitle
.pack(side
=TOP
,anchor
=W
)
488 radioEnableExt
.pack(side
=TOP
,anchor
=W
)
489 radioDisableExt
.pack(side
=TOP
,anchor
=W
)
490 buttonExtConfig
.pack(side
=TOP
,anchor
=W
,pady
=5)
494 def PaintThemeSample(self
):
495 if self
.themeIsBuiltin
.get(): #a default theme
496 theme
=self
.builtinTheme
.get()
498 theme
=self
.customTheme
.get()
499 for element
in self
.themeElements
.keys():
500 colours
=idleConf
.GetHighlight(theme
, self
.themeElements
[element
][0])
501 apply(self
.textHighlightSample
.tag_config
,
502 (self
.themeElements
[element
][0],),colours
)
504 def LoadFontCfg(self
):
505 ##base editor font selection list
506 fonts
=list(tkFont
.families(self
))
509 self
.listFontName
.insert(END
,font
)
510 configuredFont
=idleConf
.GetOption('main','EditorWindow','font',
512 if configuredFont
in fonts
:
513 currentFontIndex
=fonts
.index(configuredFont
)
514 self
.listFontName
.see(currentFontIndex
)
515 self
.listFontName
.select_set(currentFontIndex
)
517 fontSize
=idleConf
.GetOption('main','EditorWindow','font-size',default
='12')
518 self
.optMenuFontSize
.SetMenu(('10','11','12','13','14',
519 '16','18','20','22'),fontSize
)
523 def LoadTabCfg(self
):
524 ##indent type radibuttons
525 spaceIndent
=idleConf
.GetOption('main','Indent','use-spaces',
526 default
=1,type='bool')
527 self
.indentType
.set(spaceIndent
)
529 spaceNum
=idleConf
.GetOption('main','Indent','num-spaces',
530 default
=4,type='int')
531 tabCols
=idleConf
.GetOption('main','Indent','tab-cols',
532 default
=4,type='int')
533 self
.spaceNum
.set(spaceNum
)
534 self
.tabCols
.set(tabCols
)
536 def LoadThemeCfg(self
):
537 ##current theme type radiobutton
538 self
.themeIsBuiltin
.set(idleConf
.GetOption('main','Theme','default',
539 type='int',default
=1))
540 ##currently set theme
541 currentOption
=idleConf
.GetOption('main','Theme','name')
542 ##load available theme option menus
543 if self
.themeIsBuiltin
.get(): #default theme selected
544 itemList
=idleConf
.GetSectionList('default','highlight')
545 self
.optMenuThemeBuiltin
.SetMenu(itemList
,currentOption
)
546 itemList
=idleConf
.GetSectionList('user','highlight')
548 self
.radioThemeCustom
.config(state
=DISABLED
)
549 self
.customTheme
.set('- no custom themes -')
551 self
.optMenuThemeCustom
.SetMenu(itemList
,itemList
[0])
552 else: #user theme selected
553 itemList
=idleConf
.GetSectionList('user','highlight')
554 self
.optMenuThemeCustom
.SetMenu(itemList
,currentOption
)
555 itemList
=idleConf
.GetSectionList('default','highlight')
556 self
.optMenuThemeBuiltin
.SetMenu(itemList
,itemList
[0])
558 ##load theme element option menu
559 themeNames
=self
.themeElements
.keys()
560 themeNames
.sort(self
.__ThemeNameIndexCompare
)
561 self
.optMenuHighlightTarget
.SetMenu(themeNames
,themeNames
[0])
562 sampleBg
=idleConf
.GetHighlight(currentOption
,
563 self
.highlightTarget
.get())['background']
565 self
.frameColourSet
.config(bg
=sampleBg
)
566 self
.PaintThemeSample()
568 def __ThemeNameIndexCompare(self
,a
,b
):
569 if self
.themeElements
[a
][1]<self
.themeElements
[b
][1]: return -1
570 elif self
.themeElements
[a
][1]==self
.themeElements
[b
][1]: return 0
573 def LoadKeyCfg(self
):
574 ##current keys type radiobutton
575 self
.keysAreDefault
.set(idleConf
.GetOption('main','Keys','default',
576 type='int',default
=1))
578 currentOption
=idleConf
.GetOption('main','Keys','name')
579 ##load available keyset option menus
580 if self
.keysAreDefault
.get(): #default theme selected
581 itemList
=idleConf
.GetSectionList('default','keys')
582 self
.optMenuKeysBuiltin
.SetMenu(itemList
,currentOption
)
583 itemList
=idleConf
.GetSectionList('user','keys')
585 self
.radioKeysCustom
.config(state
=DISABLED
)
586 self
.customKeys
.set('- no custom keys -')
588 self
.optMenuKeysCustom
.SetMenu(itemList
,itemList
[0])
589 else: #user theme selected
590 itemList
=idleConf
.GetSectionList('user','keys')
591 self
.optMenuKeysCustom
.SetMenu(itemList
,currentOption
)
592 itemList
=idleConf
.GetSectionList('default','keys')
593 self
.optMenuKeysBuiltin
.SetMenu(itemList
,itemList
[0])
595 ##load keyset element option menu
597 def LoadConfigs(self
):
599 load configuration from default and user config files and populate
600 the widgets on the config dialog pages.
602 ### fonts / tabs page
605 ### highlighting page
612 def SaveConfigs(self
):
614 save configuration changes to user config files.
618 if __name__
== '__main__':
621 Button(root
,text
='Dialog',
622 command
=lambda:ConfigDialog(root
,'Settings')).pack()