blob: af3e98aeb9a5ffc03c973e15cd120abc8e7096a6 [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.
9Refer to comment in EditorWindow autoindent code for details.
10
Steven M. Gava44d3d1a2001-07-31 06:59:02 +000011"""
12from Tkinter import *
Steven M. Gavac01e30f2001-08-11 15:48:13 +000013import tkMessageBox, tkColorChooser, tkFont
Steven M. Gava052937f2002-02-11 02:20:53 +000014import string, copy
Steven M. Gava44d3d1a2001-07-31 06:59:02 +000015
Steven M. Gavac11ccf32001-09-24 09:43:17 +000016from configHandler import idleConf
Steven M. Gava485f7b62001-10-26 06:47:09 +000017from dynOptionMenuWidget import DynOptionMenu
Steven M. Gava2d4e03b2001-12-05 07:54:07 +000018from tabpage import TabPageSet
Steven M. Gavafacfc092002-01-19 00:29:54 +000019from keybindingDialog import GetKeysDialog
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +000020from configSectionNameDialog import GetCfgSectionNameDialog
Steven M. Gava085eb1b2002-02-05 04:52:32 +000021from configHelpSourceEdit import GetHelpSourceDialog
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +000022
Steven M. Gava44d3d1a2001-07-31 06:59:02 +000023class ConfigDialog(Toplevel):
Steven M. Gava44d3d1a2001-07-31 06:59:02 +000024 """
Steven M. Gavad721c482001-07-31 10:46:53 +000025 configuration dialog for idle
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000026 """
Steven M. Gava3b55a892001-11-21 05:56:26 +000027 def __init__(self,parent,title):
Steven M. Gavad721c482001-07-31 10:46:53 +000028 Toplevel.__init__(self, parent)
29 self.configure(borderwidth=5)
30 self.geometry("+%d+%d" % (parent.winfo_rootx()+20,
31 parent.winfo_rooty()+30))
Steven M. Gava9dd16b32001-11-03 14:54:25 +000032 #Theme Elements. Each theme element key is it's display name.
33 #The first value of the tuple is the sample area tag name.
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000034 #The second value is the display name list sort index.
Steven M. Gavaad4f5322002-01-03 12:05:17 +000035 self.themeElements={'Normal Text':('normal','00'),
36 'Python Keywords':('keyword','01'),
37 'Python Definitions':('definition','02'),
38 'Python Comments':('comment','03'),
39 'Python Strings':('string','04'),
40 'Selected Text':('hilite','05'),
41 'Found Text':('hit','06'),
42 'Cursor':('cursor','07'),
43 'Error Text':('error','08'),
44 'Shell Normal Text':('console','09'),
45 'Shell Stdout Text':('stdout','10'),
46 'Shell Stderr Text':('stderr','11')}
Steven M. Gavaa498af22002-02-01 01:33:36 +000047 self.ResetChangedItems() #load initial values in changed items dict
Steven M. Gavad721c482001-07-31 10:46:53 +000048 self.CreateWidgets()
49 self.resizable(height=FALSE,width=FALSE)
Steven M. Gavad721c482001-07-31 10:46:53 +000050 self.transient(parent)
51 self.grab_set()
52 self.protocol("WM_DELETE_WINDOW", self.Cancel)
53 self.parent = parent
Steven M. Gava2d4e03b2001-12-05 07:54:07 +000054 self.tabPages.focus_set()
Steven M. Gavad721c482001-07-31 10:46:53 +000055 #key bindings for this dialog
Steven M. Gava5f28e8f2002-01-21 06:38:21 +000056 #self.bind('<Escape>',self.Cancel) #dismiss dialog, no save
57 #self.bind('<Alt-a>',self.Apply) #apply changes, save
58 #self.bind('<F1>',self.Help) #context help
Steven M. Gava429a86a2001-10-23 10:42:12 +000059 self.LoadConfigs()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000060 self.AttachVarCallbacks() #avoid callbacks during LoadConfigs
Steven M. Gavad721c482001-07-31 10:46:53 +000061 self.wait_window()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000062
Steven M. Gavad721c482001-07-31 10:46:53 +000063 def CreateWidgets(self):
Steven M. Gava2d4e03b2001-12-05 07:54:07 +000064 self.tabPages = TabPageSet(self,
65 pageNames=['Fonts/Tabs','Highlighting','Keys','General'])
Steven M. Gavaad4f5322002-01-03 12:05:17 +000066 self.tabPages.ChangePage()#activates default (first) page
Steven M. Gavad721c482001-07-31 10:46:53 +000067 frameActionButtons = Frame(self)
Steven M. Gavad721c482001-07-31 10:46:53 +000068 #action buttons
Steven M. Gava952d0a52001-08-03 04:43:44 +000069 self.buttonHelp = Button(frameActionButtons,text='Help',
70 command=self.Help,takefocus=FALSE)
Steven M. Gavac01e30f2001-08-11 15:48:13 +000071 self.buttonOk = Button(frameActionButtons,text='Ok',
72 command=self.Ok,takefocus=FALSE)
73 self.buttonApply = Button(frameActionButtons,text='Apply',
Steven M. Gava5f28e8f2002-01-21 06:38:21 +000074 command=self.Apply,takefocus=FALSE)
Steven M. Gavad721c482001-07-31 10:46:53 +000075 self.buttonCancel = Button(frameActionButtons,text='Cancel',
76 command=self.Cancel,takefocus=FALSE)
Steven M. Gava2d4e03b2001-12-05 07:54:07 +000077 self.CreatePageFontTab()
78 self.CreatePageHighlight()
79 self.CreatePageKeys()
80 self.CreatePageGeneral()
Steven M. Gavac01e30f2001-08-11 15:48:13 +000081 self.buttonHelp.pack(side=RIGHT,padx=5,pady=5)
82 self.buttonOk.pack(side=LEFT,padx=5,pady=5)
83 self.buttonApply.pack(side=LEFT,padx=5,pady=5)
Steven M. Gavad721c482001-07-31 10:46:53 +000084 self.buttonCancel.pack(side=LEFT,padx=5,pady=5)
85 frameActionButtons.pack(side=BOTTOM)
Steven M. Gava2d4e03b2001-12-05 07:54:07 +000086 self.tabPages.pack(side=TOP,expand=TRUE,fill=BOTH)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000087
Steven M. Gava60fc7072001-08-04 13:58:22 +000088 def CreatePageFontTab(self):
Steven M. Gavaf213ccb2001-08-05 08:00:28 +000089 #tkVars
Steven M. Gava3b55a892001-11-21 05:56:26 +000090 self.fontSize=StringVar(self)
Steven M. Gavac112cd82002-01-22 05:56:40 +000091 self.fontBold=BooleanVar(self)
92 self.fontName=StringVar(self)
Steven M. Gava3b55a892001-11-21 05:56:26 +000093 self.spaceNum=IntVar(self)
Steven M. Gava9d142ad2002-03-12 02:33:52 +000094 #self.tabCols=IntVar(self)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000095 self.indentBySpaces=BooleanVar(self)
Kurt B. Kaiser05391692003-05-26 20:35:53 +000096 self.editFont=tkFont.Font(self,('courier',10,'normal'))
Steven M. Gavaf213ccb2001-08-05 08:00:28 +000097 ##widget creation
98 #body frame
Steven M. Gava2d4e03b2001-12-05 07:54:07 +000099 frame=self.tabPages.pages['Fonts/Tabs']['page']
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000100 #body section frames
101 frameFont=Frame(frame,borderwidth=2,relief=GROOVE)
102 frameIndent=Frame(frame,borderwidth=2,relief=GROOVE)
103 #frameFont
104 labelFontTitle=Label(frameFont,text='Set Base Editor Font')
105 frameFontName=Frame(frameFont)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000106 frameFontParam=Frame(frameFont)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000107 labelFontNameTitle=Label(frameFontName,justify=LEFT,
Steven M. Gavac01e30f2001-08-11 15:48:13 +0000108 text='Font :')
109 self.listFontName=Listbox(frameFontName,height=5,takefocus=FALSE,
110 exportselection=FALSE)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000111 self.listFontName.bind('<ButtonRelease-1>',self.OnListFontButtonRelease)
Steven M. Gavac01e30f2001-08-11 15:48:13 +0000112 scrollFont=Scrollbar(frameFontName)
Steven M. Gavac01e30f2001-08-11 15:48:13 +0000113 scrollFont.config(command=self.listFontName.yview)
114 self.listFontName.config(yscrollcommand=scrollFont.set)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000115 labelFontSizeTitle=Label(frameFontParam,text='Size :')
116 self.optMenuFontSize=DynOptionMenu(frameFontParam,self.fontSize,None,
Steven M. Gavac112cd82002-01-22 05:56:40 +0000117 command=self.SetFontSample)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000118 checkFontBold=Checkbutton(frameFontParam,variable=self.fontBold,
Steven M. Gavac112cd82002-01-22 05:56:40 +0000119 onvalue=1,offvalue=0,text='Bold',command=self.SetFontSample)
Steven M. Gavac11ccf32001-09-24 09:43:17 +0000120 frameFontSample=Frame(frameFont,relief=SOLID,borderwidth=1)
121 self.labelFontSample=Label(frameFontSample,
122 text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]',
Steven M. Gava429a86a2001-10-23 10:42:12 +0000123 justify=LEFT,font=self.editFont)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000124 #frameIndent
125 labelIndentTitle=Label(frameIndent,text='Set Indentation Defaults')
126 frameIndentType=Frame(frameIndent)
127 frameIndentSize=Frame(frameIndent)
128 labelIndentTypeTitle=Label(frameIndentType,
129 text='Choose indentation type :')
Steven M. Gavac112cd82002-01-22 05:56:40 +0000130 radioUseSpaces=Radiobutton(frameIndentType,variable=self.indentBySpaces,
Steven M. Gava429a86a2001-10-23 10:42:12 +0000131 value=1,text='Tab key inserts spaces')
Steven M. Gavac112cd82002-01-22 05:56:40 +0000132 radioUseTabs=Radiobutton(frameIndentType,variable=self.indentBySpaces,
Steven M. Gava429a86a2001-10-23 10:42:12 +0000133 value=0,text='Tab key inserts tabs')
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000134 labelIndentSizeTitle=Label(frameIndentSize,
135 text='Choose indentation size :')
136 labelSpaceNumTitle=Label(frameIndentSize,justify=LEFT,
Kurt B. Kaiser39df7c42002-09-14 02:58:07 +0000137 text='indent width')
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000138 self.scaleSpaceNum=Scale(frameIndentSize,variable=self.spaceNum,
Kurt B. Kaiser39df7c42002-09-14 02:58:07 +0000139 orient='horizontal',tickinterval=2,from_=2,to=16)
Steven M. Gava63f67142002-03-12 00:52:42 +0000140 #labeltabColsTitle=Label(frameIndentSize,justify=LEFT,
141 # text='when tab key inserts tabs,\ncolumns per tab')
142 #self.scaleTabCols=Scale(frameIndentSize,variable=self.tabCols,
143 # orient='horizontal',tickinterval=2,from_=2,to=8)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000144 #widget packing
145 #body
Steven M. Gavac01e30f2001-08-11 15:48:13 +0000146 frameFont.pack(side=LEFT,padx=5,pady=10,expand=TRUE,fill=BOTH)
147 frameIndent.pack(side=LEFT,padx=5,pady=10,fill=Y)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000148 #frameFont
149 labelFontTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000150 frameFontName.pack(side=TOP,padx=5,pady=5,fill=X)
151 frameFontParam.pack(side=TOP,padx=5,pady=5,fill=X)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000152 labelFontNameTitle.pack(side=TOP,anchor=W)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000153 self.listFontName.pack(side=LEFT,expand=TRUE,fill=X)
Steven M. Gavac01e30f2001-08-11 15:48:13 +0000154 scrollFont.pack(side=LEFT,fill=Y)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000155 labelFontSizeTitle.pack(side=LEFT,anchor=W)
156 self.optMenuFontSize.pack(side=LEFT,anchor=W)
157 checkFontBold.pack(side=LEFT,anchor=W,padx=20)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000158 frameFontSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
Steven M. Gavac01e30f2001-08-11 15:48:13 +0000159 self.labelFontSample.pack(expand=TRUE,fill=BOTH)
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000160 #frameIndent
161 labelIndentTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
162 frameIndentType.pack(side=TOP,padx=5,fill=X)
163 frameIndentSize.pack(side=TOP,padx=5,pady=5,fill=BOTH)
164 labelIndentTypeTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
165 radioUseSpaces.pack(side=TOP,anchor=W,padx=5)
166 radioUseTabs.pack(side=TOP,anchor=W,padx=5)
167 labelIndentSizeTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
168 labelSpaceNumTitle.pack(side=TOP,anchor=W,padx=5)
169 self.scaleSpaceNum.pack(side=TOP,padx=5,fill=X)
Steven M. Gava63f67142002-03-12 00:52:42 +0000170 #labeltabColsTitle.pack(side=TOP,anchor=W,padx=5)
171 #self.scaleTabCols.pack(side=TOP,padx=5,fill=X)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000172 return frame
173
174 def CreatePageHighlight(self):
Steven M. Gava3b55a892001-11-21 05:56:26 +0000175 self.builtinTheme=StringVar(self)
176 self.customTheme=StringVar(self)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000177 self.fgHilite=BooleanVar(self)
Steven M. Gava3b55a892001-11-21 05:56:26 +0000178 self.colour=StringVar(self)
179 self.fontName=StringVar(self)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000180 self.themeIsBuiltin=BooleanVar(self)
Steven M. Gava3b55a892001-11-21 05:56:26 +0000181 self.highlightTarget=StringVar(self)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000182 ##widget creation
183 #body frame
Steven M. Gava2d4e03b2001-12-05 07:54:07 +0000184 frame=self.tabPages.pages['Highlighting']['page']
Steven M. Gava952d0a52001-08-03 04:43:44 +0000185 #body section frames
186 frameCustom=Frame(frame,borderwidth=2,relief=GROOVE)
187 frameTheme=Frame(frame,borderwidth=2,relief=GROOVE)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000188 #frameCustom
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000189 self.textHighlightSample=Text(frameCustom,relief=SOLID,borderwidth=1,
Steven M. Gavab77d3432002-03-02 07:16:21 +0000190 font=('courier',12,''),cursor='hand2',width=21,height=10,
191 takefocus=FALSE,highlightthickness=0,wrap=NONE)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000192 text=self.textHighlightSample
193 text.bind('<Double-Button-1>',lambda e: 'break')
194 text.bind('<B1-Motion>',lambda e: 'break')
Steven M. Gava052937f2002-02-11 02:20:53 +0000195 textAndTags=(('#you can click here','comment'),('\n','normal'),
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000196 ('#to choose items','comment'),('\n','normal'),('def','keyword'),
197 (' ','normal'),('func','definition'),('(param):','normal'),
198 ('\n ','normal'),('"""string"""','string'),('\n var0 = ','normal'),
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000199 ("'string'",'string'),('\n var1 = ','normal'),("'selected'",'hilite'),
200 ('\n var2 = ','normal'),("'found'",'hit'),('\n\n','normal'),
Steven M. Gava99300612001-11-04 07:03:08 +0000201 (' error ','error'),(' ','normal'),('cursor |','cursor'),
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000202 ('\n ','normal'),('shell','console'),(' ','normal'),('stdout','stdout'),
203 (' ','normal'),('stderr','stderr'),('\n','normal'))
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000204 for txTa in textAndTags:
205 text.insert(END,txTa[0],txTa[1])
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000206 for element in self.themeElements.keys():
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000207 text.tag_bind(self.themeElements[element][0],'<ButtonPress-1>',
208 lambda event,elem=element: event.widget.winfo_toplevel()
209 .highlightTarget.set(elem))
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000210 text.config(state=DISABLED)
211 self.frameColourSet=Frame(frameCustom,relief=SOLID,borderwidth=1)
Steven M. Gava7c017862001-10-29 11:19:46 +0000212 frameFgBg=Frame(frameCustom)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000213 labelCustomTitle=Label(frameCustom,text='Set Custom Highlighting')
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000214 buttonSetColour=Button(self.frameColourSet,text='Choose Colour for :',
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000215 command=self.GetColour,highlightthickness=0)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000216 self.optMenuHighlightTarget=DynOptionMenu(self.frameColourSet,
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000217 self.highlightTarget,None,highlightthickness=0)#,command=self.SetHighlightTargetBinding
Steven M. Gava7c017862001-10-29 11:19:46 +0000218 self.radioFg=Radiobutton(frameFgBg,variable=self.fgHilite,
Steven M. Gava3b55a892001-11-21 05:56:26 +0000219 value=1,text='Foreground',command=self.SetColourSampleBinding)
Steven M. Gava7c017862001-10-29 11:19:46 +0000220 self.radioBg=Radiobutton(frameFgBg,variable=self.fgHilite,
Steven M. Gava3b55a892001-11-21 05:56:26 +0000221 value=0,text='Background',command=self.SetColourSampleBinding)
Steven M. Gava7c017862001-10-29 11:19:46 +0000222 self.fgHilite.set(1)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000223 buttonSaveCustomTheme=Button(frameCustom,
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000224 text='Save as New Custom Theme',command=self.SaveAsNewTheme)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000225 #frameTheme
Steven M. Gava952d0a52001-08-03 04:43:44 +0000226 labelThemeTitle=Label(frameTheme,text='Select a Highlighting Theme')
227 labelTypeTitle=Label(frameTheme,text='Select : ')
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000228 self.radioThemeBuiltin=Radiobutton(frameTheme,variable=self.themeIsBuiltin,
229 value=1,command=self.SetThemeType,text='a Built-in Theme')
230 self.radioThemeCustom=Radiobutton(frameTheme,variable=self.themeIsBuiltin,
231 value=0,command=self.SetThemeType,text='a Custom Theme')
Steven M. Gava41a85322001-10-29 08:05:34 +0000232 self.optMenuThemeBuiltin=DynOptionMenu(frameTheme,
Steven M. Gava7c017862001-10-29 11:19:46 +0000233 self.builtinTheme,None,command=None)
Steven M. Gava41a85322001-10-29 08:05:34 +0000234 self.optMenuThemeCustom=DynOptionMenu(frameTheme,
Steven M. Gava7c017862001-10-29 11:19:46 +0000235 self.customTheme,None,command=None)
Steven M. Gava49745752002-02-18 01:43:11 +0000236 self.buttonDeleteCustomTheme=Button(frameTheme,text='Delete Custom Theme',
237 command=self.DeleteCustomTheme)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000238 ##widget packing
239 #body
Steven M. Gava60fc7072001-08-04 13:58:22 +0000240 frameCustom.pack(side=LEFT,padx=5,pady=10,expand=TRUE,fill=BOTH)
241 frameTheme.pack(side=LEFT,padx=5,pady=10,fill=Y)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000242 #frameCustom
243 labelCustomTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000244 self.frameColourSet.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=X)
Steven M. Gava7c017862001-10-29 11:19:46 +0000245 frameFgBg.pack(side=TOP,padx=5,pady=0)
Steven M. Gavae16d94b2001-11-03 05:07:28 +0000246 self.textHighlightSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,
247 fill=BOTH)
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000248 buttonSetColour.pack(side=TOP,expand=TRUE,fill=X,padx=8,pady=4)
249 self.optMenuHighlightTarget.pack(side=TOP,expand=TRUE,fill=X,padx=8,pady=3)
Steven M. Gava7c017862001-10-29 11:19:46 +0000250 self.radioFg.pack(side=LEFT,anchor=E)
251 self.radioBg.pack(side=RIGHT,anchor=W)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000252 buttonSaveCustomTheme.pack(side=BOTTOM,fill=X,padx=5,pady=5)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000253 #frameTheme
Steven M. Gava952d0a52001-08-03 04:43:44 +0000254 labelThemeTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
255 labelTypeTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
Steven M. Gava41a85322001-10-29 08:05:34 +0000256 self.radioThemeBuiltin.pack(side=TOP,anchor=W,padx=5)
257 self.radioThemeCustom.pack(side=TOP,anchor=W,padx=5,pady=2)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000258 self.optMenuThemeBuiltin.pack(side=TOP,fill=X,padx=5,pady=5)
259 self.optMenuThemeCustom.pack(side=TOP,fill=X,anchor=W,padx=5,pady=5)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000260 self.buttonDeleteCustomTheme.pack(side=TOP,fill=X,padx=5,pady=5)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000261 return frame
262
263 def CreatePageKeys(self):
Steven M. Gava60fc7072001-08-04 13:58:22 +0000264 #tkVars
Steven M. Gava3b55a892001-11-21 05:56:26 +0000265 self.bindingTarget=StringVar(self)
266 self.builtinKeys=StringVar(self)
267 self.customKeys=StringVar(self)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000268 self.keysAreBuiltin=BooleanVar(self)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000269 self.keyBinding=StringVar(self)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000270 ##widget creation
271 #body frame
Steven M. Gava2d4e03b2001-12-05 07:54:07 +0000272 frame=self.tabPages.pages['Keys']['page']
Steven M. Gava60fc7072001-08-04 13:58:22 +0000273 #body section frames
274 frameCustom=Frame(frame,borderwidth=2,relief=GROOVE)
275 frameKeySets=Frame(frame,borderwidth=2,relief=GROOVE)
276 #frameCustom
277 frameTarget=Frame(frameCustom)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000278 labelCustomTitle=Label(frameCustom,text='Set Custom Key Bindings')
Steven M. Gavafacfc092002-01-19 00:29:54 +0000279 labelTargetTitle=Label(frameTarget,text='Action - Key(s)')
280 scrollTargetY=Scrollbar(frameTarget)
281 scrollTargetX=Scrollbar(frameTarget,orient=HORIZONTAL)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000282 self.listBindings=Listbox(frameTarget,takefocus=FALSE,
283 exportselection=FALSE)
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000284 self.listBindings.bind('<ButtonRelease-1>',self.KeyBindingSelected)
Steven M. Gavafacfc092002-01-19 00:29:54 +0000285 scrollTargetY.config(command=self.listBindings.yview)
286 scrollTargetX.config(command=self.listBindings.xview)
287 self.listBindings.config(yscrollcommand=scrollTargetY.set)
288 self.listBindings.config(xscrollcommand=scrollTargetX.set)
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000289 self.buttonNewKeys=Button(frameCustom,text='Get New Keys for Selection',
290 command=self.GetNewKeys,state=DISABLED)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000291 buttonSaveCustomKeys=Button(frameCustom,
292 text='Save as New Custom Key Set',command=self.SaveAsNewKeySet)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000293 #frameKeySets
Steven M. Gavaf213ccb2001-08-05 08:00:28 +0000294 labelKeysTitle=Label(frameKeySets,text='Select a Key Set')
Steven M. Gava60fc7072001-08-04 13:58:22 +0000295 labelTypeTitle=Label(frameKeySets,text='Select : ')
Steven M. Gava052937f2002-02-11 02:20:53 +0000296 self.radioKeysBuiltin=Radiobutton(frameKeySets,variable=self.keysAreBuiltin,
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000297 value=1,command=self.SetKeysType,text='a Built-in Key Set')
Steven M. Gava052937f2002-02-11 02:20:53 +0000298 self.radioKeysCustom=Radiobutton(frameKeySets,variable=self.keysAreBuiltin,
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000299 value=0,command=self.SetKeysType,text='a Custom Key Set')
Steven M. Gava41a85322001-10-29 08:05:34 +0000300 self.optMenuKeysBuiltin=DynOptionMenu(frameKeySets,
301 self.builtinKeys,None,command=None)
302 self.optMenuKeysCustom=DynOptionMenu(frameKeySets,
303 self.customKeys,None,command=None)
Steven M. Gava49745752002-02-18 01:43:11 +0000304 self.buttonDeleteCustomKeys=Button(frameKeySets,text='Delete Custom Key Set',
305 command=self.DeleteCustomKeys)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000306 ##widget packing
307 #body
308 frameCustom.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH)
309 frameKeySets.pack(side=LEFT,padx=5,pady=5,fill=Y)
310 #frameCustom
311 labelCustomTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000312 buttonSaveCustomKeys.pack(side=BOTTOM,fill=X,padx=5,pady=5)
313 self.buttonNewKeys.pack(side=BOTTOM,fill=X,padx=5,pady=5)
Steven M. Gavafacfc092002-01-19 00:29:54 +0000314 frameTarget.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH)
315 #frame target
316 frameTarget.columnconfigure(0,weight=1)
317 frameTarget.rowconfigure(1,weight=1)
318 labelTargetTitle.grid(row=0,column=0,columnspan=2,sticky=W)
319 self.listBindings.grid(row=1,column=0,sticky=NSEW)
320 scrollTargetY.grid(row=1,column=1,sticky=NS)
321 scrollTargetX.grid(row=2,column=0,sticky=EW)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000322 #frameKeySets
323 labelKeysTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
324 labelTypeTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
Steven M. Gava41a85322001-10-29 08:05:34 +0000325 self.radioKeysBuiltin.pack(side=TOP,anchor=W,padx=5)
326 self.radioKeysCustom.pack(side=TOP,anchor=W,padx=5,pady=2)
Steven M. Gava60fc7072001-08-04 13:58:22 +0000327 self.optMenuKeysBuiltin.pack(side=TOP,fill=X,padx=5,pady=5)
328 self.optMenuKeysCustom.pack(side=TOP,fill=X,anchor=W,padx=5,pady=5)
329 self.buttonDeleteCustomKeys.pack(side=TOP,fill=X,padx=5,pady=5)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000330 return frame
331
332 def CreatePageGeneral(self):
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000333 #tkVars
334 self.winWidth=StringVar(self)
Steven M. Gava3b55a892001-11-21 05:56:26 +0000335 self.winHeight=StringVar(self)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000336 self.startupEdit=IntVar(self)
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000337 self.autoSave=IntVar(self)
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000338 self.encoding=StringVar(self)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000339 self.userHelpBrowser=BooleanVar(self)
340 self.helpBrowser=StringVar(self)
Steven M. Gava230e5782001-08-07 03:28:25 +0000341 #widget creation
342 #body
Steven M. Gava2d4e03b2001-12-05 07:54:07 +0000343 frame=self.tabPages.pages['General']['page']
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000344 #body section frames
Steven M. Gava230e5782001-08-07 03:28:25 +0000345 frameRun=Frame(frame,borderwidth=2,relief=GROOVE)
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000346 frameSave=Frame(frame,borderwidth=2,relief=GROOVE)
Steven M. Gava230e5782001-08-07 03:28:25 +0000347 frameWinSize=Frame(frame,borderwidth=2,relief=GROOVE)
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000348 frameEncoding=Frame(frame,borderwidth=2,relief=GROOVE)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000349 frameHelp=Frame(frame,borderwidth=2,relief=GROOVE)
Steven M. Gava230e5782001-08-07 03:28:25 +0000350 #frameRun
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000351 labelRunTitle=Label(frameRun,text='Startup Preferences')
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000352 labelRunChoiceTitle=Label(frameRun,text='At Startup')
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000353 radioStartupEdit=Radiobutton(frameRun,variable=self.startupEdit,
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +0000354 value=1,command=self.SetKeysType,text="Open Edit Window")
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000355 radioStartupShell=Radiobutton(frameRun,variable=self.startupEdit,
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +0000356 value=0,command=self.SetKeysType,text='Open Shell Window')
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000357 #frameSave
358 labelSaveTitle=Label(frameSave,text='Autosave Preference')
359 labelRunSaveTitle=Label(frameSave,text='At Start of Run (F5) ')
360 radioSaveAsk=Radiobutton(frameSave,variable=self.autoSave,
361 value=0,command=self.SetKeysType,text="Prompt to Save")
362 radioSaveAuto=Radiobutton(frameSave,variable=self.autoSave,
363 value=1,command=self.SetKeysType,text='No Prompt')
Steven M. Gava230e5782001-08-07 03:28:25 +0000364 #frameWinSize
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000365 labelWinSizeTitle=Label(frameWinSize,text='Initial Window Size'+
366 ' (in characters)')
Steven M. Gava230e5782001-08-07 03:28:25 +0000367 labelWinWidthTitle=Label(frameWinSize,text='Width')
368 entryWinWidth=Entry(frameWinSize,textvariable=self.winWidth,
369 width=3)
370 labelWinHeightTitle=Label(frameWinSize,text='Height')
371 entryWinHeight=Entry(frameWinSize,textvariable=self.winHeight,
372 width=3)
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000373 #frameEncoding
374 labelEncodingTitle=Label(frameEncoding,text="Default Source Encoding")
375 radioEncLocale=Radiobutton(frameEncoding,variable=self.encoding,
376 value="locale",text="Locale-defined")
377 radioEncUTF8=Radiobutton(frameEncoding,variable=self.encoding,
378 value="utf-8",text="UTF-8")
379 radioEncNone=Radiobutton(frameEncoding,variable=self.encoding,
380 value="none",text="None")
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000381 #frameHelp
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000382 ##labelHelpTitle=Label(frameHelp,text='Help Options')
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000383 frameHelpList=Frame(frameHelp)
384 frameHelpListButtons=Frame(frameHelpList)
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +0000385 labelHelpListTitle=Label(frameHelpList,text='Additional Help Sources:')
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000386 scrollHelpList=Scrollbar(frameHelpList)
387 self.listHelp=Listbox(frameHelpList,height=5,takefocus=FALSE,
388 exportselection=FALSE)
389 scrollHelpList.config(command=self.listHelp.yview)
390 self.listHelp.config(yscrollcommand=scrollHelpList.set)
391 self.listHelp.bind('<ButtonRelease-1>',self.HelpSourceSelected)
392 self.buttonHelpListEdit=Button(frameHelpListButtons,text='Edit',
393 state=DISABLED,width=8,command=self.HelpListItemEdit)
394 self.buttonHelpListAdd=Button(frameHelpListButtons,text='Add',
395 width=8,command=self.HelpListItemAdd)
396 self.buttonHelpListRemove=Button(frameHelpListButtons,text='Remove',
397 state=DISABLED,width=8,command=self.HelpListItemRemove)
Steven M. Gava0c5bc8c2002-03-27 02:25:44 +0000398 # the following is better handled by the BROWSER environment
399 # variable under unix/linux
400 #checkHelpBrowser=Checkbutton(frameHelp,variable=self.userHelpBrowser,
401 # onvalue=1,offvalue=0,text='user specified (html) help browser:',
402 # command=self.OnCheckUserHelpBrowser)
403 #self.entryHelpBrowser=Entry(frameHelp,textvariable=self.helpBrowser,
404 # width=40)
Steven M. Gava230e5782001-08-07 03:28:25 +0000405 #widget packing
406 #body
407 frameRun.pack(side=TOP,padx=5,pady=5,fill=X)
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000408 frameSave.pack(side=TOP,padx=5,pady=5,fill=X)
Steven M. Gava230e5782001-08-07 03:28:25 +0000409 frameWinSize.pack(side=TOP,padx=5,pady=5,fill=X)
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000410 frameEncoding.pack(side=TOP,padx=5,pady=5,fill=X)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000411 frameHelp.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
Steven M. Gava230e5782001-08-07 03:28:25 +0000412 #frameRun
413 labelRunTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
414 labelRunChoiceTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000415 radioStartupShell.pack(side=RIGHT,anchor=W,padx=5,pady=5)
416 radioStartupEdit.pack(side=RIGHT,anchor=W,padx=5,pady=5)
417 #frameSave
418 labelSaveTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
419 labelRunSaveTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
420 radioSaveAuto.pack(side=RIGHT,anchor=W,padx=5,pady=5)
421 radioSaveAsk.pack(side=RIGHT,anchor=W,padx=5,pady=5)
Steven M. Gava230e5782001-08-07 03:28:25 +0000422 #frameWinSize
Steven M. Gavafacfc092002-01-19 00:29:54 +0000423 labelWinSizeTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
424 entryWinHeight.pack(side=RIGHT,anchor=E,padx=10,pady=5)
425 labelWinHeightTitle.pack(side=RIGHT,anchor=E,pady=5)
426 entryWinWidth.pack(side=RIGHT,anchor=E,padx=10,pady=5)
427 labelWinWidthTitle.pack(side=RIGHT,anchor=E,pady=5)
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000428 #frameEncoding
429 labelEncodingTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
430 radioEncNone.pack(side=RIGHT,anchor=E,pady=5)
431 radioEncUTF8.pack(side=RIGHT,anchor=E,pady=5)
432 radioEncLocale.pack(side=RIGHT,anchor=E,pady=5)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000433 #frameHelp
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000434 ##labelHelpTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000435 frameHelpListButtons.pack(side=RIGHT,padx=5,pady=5,fill=Y)
436 frameHelpList.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
437 labelHelpListTitle.pack(side=TOP,anchor=W)
438 scrollHelpList.pack(side=RIGHT,anchor=W,fill=Y)
439 self.listHelp.pack(side=LEFT,anchor=E,expand=TRUE,fill=BOTH)
440 self.buttonHelpListEdit.pack(side=TOP,anchor=W,pady=5)
441 self.buttonHelpListAdd.pack(side=TOP,anchor=W)
442 self.buttonHelpListRemove.pack(side=TOP,anchor=W,pady=5)
Steven M. Gava0c5bc8c2002-03-27 02:25:44 +0000443 #checkHelpBrowser.pack(side=TOP,anchor=W,padx=5)
444 #self.entryHelpBrowser.pack(side=TOP,anchor=W,padx=5,pady=5)
Steven M. Gava952d0a52001-08-03 04:43:44 +0000445 return frame
446
Steven M. Gavac112cd82002-01-22 05:56:40 +0000447 def AttachVarCallbacks(self):
448 self.fontSize.trace_variable('w',self.VarChanged_fontSize)
449 self.fontName.trace_variable('w',self.VarChanged_fontName)
450 self.fontBold.trace_variable('w',self.VarChanged_fontBold)
451 self.spaceNum.trace_variable('w',self.VarChanged_spaceNum)
Steven M. Gava9d142ad2002-03-12 02:33:52 +0000452 #self.tabCols.trace_variable('w',self.VarChanged_tabCols)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000453 self.indentBySpaces.trace_variable('w',self.VarChanged_indentBySpaces)
454 self.colour.trace_variable('w',self.VarChanged_colour)
Steven M. Gava052937f2002-02-11 02:20:53 +0000455 self.builtinTheme.trace_variable('w',self.VarChanged_builtinTheme)
456 self.customTheme.trace_variable('w',self.VarChanged_customTheme)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000457 self.themeIsBuiltin.trace_variable('w',self.VarChanged_themeIsBuiltin)
Steven M. Gava052937f2002-02-11 02:20:53 +0000458 self.highlightTarget.trace_variable('w',self.VarChanged_highlightTarget)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000459 self.keyBinding.trace_variable('w',self.VarChanged_keyBinding)
Steven M. Gava052937f2002-02-11 02:20:53 +0000460 self.builtinKeys.trace_variable('w',self.VarChanged_builtinKeys)
461 self.customKeys.trace_variable('w',self.VarChanged_customKeys)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000462 self.keysAreBuiltin.trace_variable('w',self.VarChanged_keysAreBuiltin)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000463 self.winWidth.trace_variable('w',self.VarChanged_winWidth)
464 self.winHeight.trace_variable('w',self.VarChanged_winHeight)
465 self.startupEdit.trace_variable('w',self.VarChanged_startupEdit)
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000466 self.autoSave.trace_variable('w',self.VarChanged_autoSave)
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000467 self.encoding.trace_variable('w',self.VarChanged_encoding)
Steven M. Gava052937f2002-02-11 02:20:53 +0000468
Steven M. Gavac112cd82002-01-22 05:56:40 +0000469 def VarChanged_fontSize(self,*params):
470 value=self.fontSize.get()
471 self.AddChangedItem('main','EditorWindow','font-size',value)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000472
Steven M. Gavac112cd82002-01-22 05:56:40 +0000473 def VarChanged_fontName(self,*params):
474 value=self.fontName.get()
475 self.AddChangedItem('main','EditorWindow','font',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000476
477 def VarChanged_fontBold(self,*params):
478 value=self.fontBold.get()
479 self.AddChangedItem('main','EditorWindow','font-bold',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000480
481 def VarChanged_indentBySpaces(self,*params):
482 value=self.indentBySpaces.get()
483 self.AddChangedItem('main','Indent','use-spaces',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000484
485 def VarChanged_spaceNum(self,*params):
486 value=self.spaceNum.get()
487 self.AddChangedItem('main','Indent','num-spaces',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000488
Steven M. Gava9d142ad2002-03-12 02:33:52 +0000489 #def VarChanged_tabCols(self,*params):
490 # value=self.tabCols.get()
491 # self.AddChangedItem('main','Indent','tab-cols',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000492
493 def VarChanged_colour(self,*params):
Steven M. Gava052937f2002-02-11 02:20:53 +0000494 self.OnNewColourSet()
495
496 def VarChanged_builtinTheme(self,*params):
497 value=self.builtinTheme.get()
498 self.AddChangedItem('main','Theme','name',value)
499 self.PaintThemeSample()
500
501 def VarChanged_customTheme(self,*params):
502 value=self.customTheme.get()
Steven M. Gava49745752002-02-18 01:43:11 +0000503 if value != '- no custom themes -':
504 self.AddChangedItem('main','Theme','name',value)
505 self.PaintThemeSample()
Steven M. Gava052937f2002-02-11 02:20:53 +0000506
507 def VarChanged_themeIsBuiltin(self,*params):
508 value=self.themeIsBuiltin.get()
509 self.AddChangedItem('main','Theme','default',value)
Steven M. Gavaf31eec02002-03-05 00:25:58 +0000510 if value:
511 self.VarChanged_builtinTheme()
512 else:
513 self.VarChanged_customTheme()
Steven M. Gava052937f2002-02-11 02:20:53 +0000514
515 def VarChanged_highlightTarget(self,*params):
516 self.SetHighlightTarget()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000517
Steven M. Gavac112cd82002-01-22 05:56:40 +0000518 def VarChanged_keyBinding(self,*params):
Steven M. Gavabbf5ef52002-01-22 11:35:50 +0000519 value=self.keyBinding.get()
520 keySet=self.customKeys.get()
521 event=self.listBindings.get(ANCHOR).split()[0]
Steven M. Gavaa498af22002-02-01 01:33:36 +0000522 if idleConf.IsCoreBinding(event):
523 #this is a core keybinding
524 self.AddChangedItem('keys',keySet,event,value)
525 else: #this is an extension key binding
526 extName=idleConf.GetExtnNameForEvent(event)
527 extKeybindSection=extName+'_cfgBindings'
528 self.AddChangedItem('extensions',extKeybindSection,event,value)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000529
Steven M. Gava052937f2002-02-11 02:20:53 +0000530 def VarChanged_builtinKeys(self,*params):
531 value=self.builtinKeys.get()
532 self.AddChangedItem('main','Keys','name',value)
533 self.LoadKeysList(value)
534
535 def VarChanged_customKeys(self,*params):
536 value=self.customKeys.get()
Steven M. Gava49745752002-02-18 01:43:11 +0000537 if value != '- no custom keys -':
538 self.AddChangedItem('main','Keys','name',value)
539 self.LoadKeysList(value)
Steven M. Gava052937f2002-02-11 02:20:53 +0000540
541 def VarChanged_keysAreBuiltin(self,*params):
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000542 value=self.keysAreBuiltin.get()
Steven M. Gava052937f2002-02-11 02:20:53 +0000543 self.AddChangedItem('main','Keys','default',value)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000544 if value:
Steven M. Gavaf31eec02002-03-05 00:25:58 +0000545 self.VarChanged_builtinKeys()
Steven M. Gava052937f2002-02-11 02:20:53 +0000546 else:
Steven M. Gavaf31eec02002-03-05 00:25:58 +0000547 self.VarChanged_customKeys()
Steven M. Gava052937f2002-02-11 02:20:53 +0000548
Steven M. Gavac112cd82002-01-22 05:56:40 +0000549 def VarChanged_winWidth(self,*params):
Steven M. Gavabbf5ef52002-01-22 11:35:50 +0000550 value=self.winWidth.get()
551 self.AddChangedItem('main','EditorWindow','width',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000552
553 def VarChanged_winHeight(self,*params):
Steven M. Gavabbf5ef52002-01-22 11:35:50 +0000554 value=self.winHeight.get()
555 self.AddChangedItem('main','EditorWindow','height',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000556
557 def VarChanged_startupEdit(self,*params):
Steven M. Gavabbf5ef52002-01-22 11:35:50 +0000558 value=self.startupEdit.get()
559 self.AddChangedItem('main','General','editor-on-startup',value)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000560
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +0000561 def VarChanged_autoSave(self,*params):
562 value=self.autoSave.get()
563 self.AddChangedItem('main','General','autosave',value)
564
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000565 def VarChanged_encoding(self,*params):
566 value=self.encoding.get()
567 self.AddChangedItem('main','EditorWindow','encoding',value)
568
Steven M. Gavaa498af22002-02-01 01:33:36 +0000569 def ResetChangedItems(self):
Steven M. Gavab77d3432002-03-02 07:16:21 +0000570 #When any config item is changed in this dialog, an entry
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000571 #should be made in the relevant section (config type) of this
572 #dictionary. The key should be the config file section name and the
Steven M. Gavaa498af22002-02-01 01:33:36 +0000573 #value a dictionary, whose key:value pairs are item=value pairs for
574 #that config file section.
575 self.changedItems={'main':{},'highlight':{},'keys':{},'extensions':{}}
576
Steven M. Gavac112cd82002-01-22 05:56:40 +0000577 def AddChangedItem(self,type,section,item,value):
Steven M. Gava2d7bb3f2002-01-29 08:35:29 +0000578 value=str(value) #make sure we use a string
Steven M. Gavac112cd82002-01-22 05:56:40 +0000579 if not self.changedItems[type].has_key(section):
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000580 self.changedItems[type][section]={}
Steven M. Gavac112cd82002-01-22 05:56:40 +0000581 self.changedItems[type][section][item]=value
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000582
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000583 def GetDefaultItems(self):
584 dItems={'main':{},'highlight':{},'keys':{},'extensions':{}}
585 for configType in dItems.keys():
586 sections=idleConf.GetSectionList('default',configType)
587 for section in sections:
588 dItems[configType][section]={}
589 options=idleConf.defaultCfg[configType].GetOptionList(section)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000590 for option in options:
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000591 dItems[configType][section][option]=(
592 idleConf.defaultCfg[configType].Get(section,option))
593 return dItems
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000594
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000595 def SetThemeType(self):
596 if self.themeIsBuiltin.get():
597 self.optMenuThemeBuiltin.config(state=NORMAL)
598 self.optMenuThemeCustom.config(state=DISABLED)
599 self.buttonDeleteCustomTheme.config(state=DISABLED)
600 else:
601 self.optMenuThemeBuiltin.config(state=DISABLED)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000602 self.radioThemeCustom.config(state=NORMAL)
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000603 self.optMenuThemeCustom.config(state=NORMAL)
604 self.buttonDeleteCustomTheme.config(state=NORMAL)
605
606 def SetKeysType(self):
Steven M. Gava052937f2002-02-11 02:20:53 +0000607 if self.keysAreBuiltin.get():
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000608 self.optMenuKeysBuiltin.config(state=NORMAL)
609 self.optMenuKeysCustom.config(state=DISABLED)
610 self.buttonDeleteCustomKeys.config(state=DISABLED)
611 else:
612 self.optMenuKeysBuiltin.config(state=DISABLED)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000613 self.radioKeysCustom.config(state=NORMAL)
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000614 self.optMenuKeysCustom.config(state=NORMAL)
615 self.buttonDeleteCustomKeys.config(state=NORMAL)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000616
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000617 def GetNewKeys(self):
618 listIndex=self.listBindings.index(ANCHOR)
619 binding=self.listBindings.get(listIndex)
620 bindName=binding.split()[0] #first part, up to first space
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000621 if self.keysAreBuiltin.get():
Steven M. Gavae28ee752002-02-11 03:45:22 +0000622 currentKeySetName=self.builtinKeys.get()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000623 else:
Steven M. Gavae28ee752002-02-11 03:45:22 +0000624 currentKeySetName=self.customKeys.get()
625 currentBindings=idleConf.GetCurrentKeySet()
626 if currentKeySetName in self.changedItems['keys'].keys(): #unsaved changes
627 keySetChanges=self.changedItems['keys'][currentKeySetName]
628 for event in keySetChanges.keys():
629 currentBindings[event]=keySetChanges[event].split()
630 currentKeySequences=currentBindings.values()
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000631 newKeys=GetKeysDialog(self,'Get New Keys',bindName,
632 currentKeySequences).result
633 if newKeys: #new keys were specified
Steven M. Gava052937f2002-02-11 02:20:53 +0000634 if self.keysAreBuiltin.get(): #current key set is a built-in
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000635 message=('Your changes will be saved as a new Custom Key Set. '+
636 'Enter a name for your new Custom Key Set below.')
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000637 newKeySet=self.GetNewKeysName(message)
638 if not newKeySet: #user cancelled custom key set creation
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000639 self.listBindings.select_set(listIndex)
640 self.listBindings.select_anchor(listIndex)
641 return
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000642 else: #create new custom key set based on previously active key set
643 self.CreateNewKeySet(newKeySet)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000644 self.listBindings.delete(listIndex)
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000645 self.listBindings.insert(listIndex,bindName+' - '+newKeys)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000646 self.listBindings.select_set(listIndex)
647 self.listBindings.select_anchor(listIndex)
Steven M. Gava052937f2002-02-11 02:20:53 +0000648 self.keyBinding.set(newKeys)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000649 else:
650 self.listBindings.select_set(listIndex)
651 self.listBindings.select_anchor(listIndex)
652
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000653 def GetNewKeysName(self,message):
Steven M. Gava49745752002-02-18 01:43:11 +0000654 usedNames=(idleConf.GetSectionList('user','keys')+
655 idleConf.GetSectionList('default','keys'))
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000656 newKeySet=GetCfgSectionNameDialog(self,'New Custom Key Set',
657 message,usedNames).result
658 return newKeySet
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000659
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000660 def SaveAsNewKeySet(self):
661 newKeysName=self.GetNewKeysName('New Key Set Name:')
662 if newKeysName:
663 self.CreateNewKeySet(newKeysName)
664
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000665 def KeyBindingSelected(self,event):
666 self.buttonNewKeys.config(state=NORMAL)
667
668 def CreateNewKeySet(self,newKeySetName):
669 #creates new custom key set based on the previously active key set,
670 #and makes the new key set active
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000671 if self.keysAreBuiltin.get():
Steven M. Gava052937f2002-02-11 02:20:53 +0000672 prevKeySetName=self.builtinKeys.get()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000673 else:
Steven M. Gava052937f2002-02-11 02:20:53 +0000674 prevKeySetName=self.customKeys.get()
Steven M. Gava052937f2002-02-11 02:20:53 +0000675 prevKeys=idleConf.GetCoreKeys(prevKeySetName)
Steven M. Gava052937f2002-02-11 02:20:53 +0000676 newKeys={}
677 for event in prevKeys.keys(): #add key set to changed items
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000678 eventName=event[2:-2] #trim off the angle brackets
Steven M. Gava052937f2002-02-11 02:20:53 +0000679 binding=string.join(prevKeys[event])
680 newKeys[eventName]=binding
Steven M. Gava052937f2002-02-11 02:20:53 +0000681 #handle any unsaved changes to prev key set
682 if prevKeySetName in self.changedItems['keys'].keys():
683 keySetChanges=self.changedItems['keys'][prevKeySetName]
684 for event in keySetChanges.keys():
685 newKeys[event]=keySetChanges[event]
Steven M. Gava052937f2002-02-11 02:20:53 +0000686 #save the new theme
687 self.SaveNewKeySet(newKeySetName,newKeys)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000688 #change gui over to the new key set
689 customKeyList=idleConf.GetSectionList('user','keys')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000690 customKeyList.sort()
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000691 self.optMenuKeysCustom.SetMenu(customKeyList,newKeySetName)
Steven M. Gava052937f2002-02-11 02:20:53 +0000692 self.keysAreBuiltin.set(0)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000693 self.SetKeysType()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000694
Steven M. Gava052937f2002-02-11 02:20:53 +0000695 def LoadKeysList(self,keySetName):
696 reselect=0
697 newKeySet=0
698 if self.listBindings.curselection():
699 reselect=1
700 listIndex=self.listBindings.index(ANCHOR)
Steven M. Gava052937f2002-02-11 02:20:53 +0000701 keySet=idleConf.GetKeySet(keySetName)
Steven M. Gava052937f2002-02-11 02:20:53 +0000702 bindNames=keySet.keys()
703 bindNames.sort()
704 self.listBindings.delete(0,END)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000705 for bindName in bindNames:
Steven M. Gava052937f2002-02-11 02:20:53 +0000706 key=string.join(keySet[bindName]) #make key(s) into a string
707 bindName=bindName[2:-2] #trim off the angle brackets
Steven M. Gava052937f2002-02-11 02:20:53 +0000708 if keySetName in self.changedItems['keys'].keys():
709 #handle any unsaved changes to this key set
710 if bindName in self.changedItems['keys'][keySetName].keys():
711 key=self.changedItems['keys'][keySetName][bindName]
Steven M. Gava052937f2002-02-11 02:20:53 +0000712 self.listBindings.insert(END, bindName+' - '+key)
Steven M. Gava052937f2002-02-11 02:20:53 +0000713 if reselect:
714 self.listBindings.see(listIndex)
715 self.listBindings.select_set(listIndex)
716 self.listBindings.select_anchor(listIndex)
717
Steven M. Gava49745752002-02-18 01:43:11 +0000718 def DeleteCustomKeys(self):
719 keySetName=self.customKeys.get()
720 if not tkMessageBox.askyesno('Delete Key Set','Are you sure you wish '+
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +0000721 'to delete the key set '+`keySetName`+' ?',
722 parent=self):
Steven M. Gava49745752002-02-18 01:43:11 +0000723 return
724 #remove key set from config
725 idleConf.userCfg['keys'].remove_section(keySetName)
726 if self.changedItems['keys'].has_key(keySetName):
727 del(self.changedItems['keys'][keySetName])
728 #write changes
729 idleConf.userCfg['keys'].Save()
730 #reload user key set list
731 itemList=idleConf.GetSectionList('user','keys')
732 itemList.sort()
733 if not itemList:
734 self.radioKeysCustom.config(state=DISABLED)
735 self.optMenuKeysCustom.SetMenu(itemList,'- no custom keys -')
736 else:
737 self.optMenuKeysCustom.SetMenu(itemList,itemList[0])
738 #revert to default key set
739 self.keysAreBuiltin.set(idleConf.defaultCfg['main'].Get('Keys','default'))
740 self.builtinKeys.set(idleConf.defaultCfg['main'].Get('Keys','name'))
741 #user can't back out of these changes, they must be applied now
742 self.Apply()
743 self.SetKeysType()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000744
Steven M. Gava49745752002-02-18 01:43:11 +0000745 def DeleteCustomTheme(self):
746 themeName=self.customTheme.get()
747 if not tkMessageBox.askyesno('Delete Theme','Are you sure you wish '+
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +0000748 'to delete the theme '+`themeName`+' ?',
749 parent=self):
Steven M. Gava49745752002-02-18 01:43:11 +0000750 return
751 #remove theme from config
752 idleConf.userCfg['highlight'].remove_section(themeName)
753 if self.changedItems['highlight'].has_key(themeName):
754 del(self.changedItems['highlight'][themeName])
755 #write changes
756 idleConf.userCfg['highlight'].Save()
757 #reload user theme list
758 itemList=idleConf.GetSectionList('user','highlight')
759 itemList.sort()
760 if not itemList:
761 self.radioThemeCustom.config(state=DISABLED)
762 self.optMenuThemeCustom.SetMenu(itemList,'- no custom themes -')
763 else:
764 self.optMenuThemeCustom.SetMenu(itemList,itemList[0])
765 #revert to default theme
766 self.themeIsBuiltin.set(idleConf.defaultCfg['main'].Get('Theme','default'))
767 self.builtinTheme.set(idleConf.defaultCfg['main'].Get('Theme','name'))
768 #user can't back out of these changes, they must be applied now
769 self.Apply()
770 self.SetThemeType()
771
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000772 def GetColour(self):
773 target=self.highlightTarget.get()
Steven M. Gava052937f2002-02-11 02:20:53 +0000774 prevColour=self.frameColourSet.cget('bg')
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000775 rgbTuplet, colourString = tkColorChooser.askcolor(parent=self,
Steven M. Gava052937f2002-02-11 02:20:53 +0000776 title='Pick new colour for : '+target,initialcolor=prevColour)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000777 if colourString and (colourString!=prevColour):
Steven M. Gava052937f2002-02-11 02:20:53 +0000778 #user didn't cancel, and they chose a new colour
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000779 if self.themeIsBuiltin.get(): #current theme is a built-in
780 message=('Your changes will be saved as a new Custom Theme. '+
781 'Enter a name for your new Custom Theme below.')
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000782 newTheme=self.GetNewThemeName(message)
783 if not newTheme: #user cancelled custom theme creation
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000784 return
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000785 else: #create new custom theme based on previously active theme
786 self.CreateNewTheme(newTheme)
Steven M. Gava052937f2002-02-11 02:20:53 +0000787 self.colour.set(colourString)
788 else: #current theme is user defined
789 self.colour.set(colourString)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000790
Steven M. Gava052937f2002-02-11 02:20:53 +0000791 def OnNewColourSet(self):
792 newColour=self.colour.get()
793 self.frameColourSet.config(bg=newColour)#set sample
794 if self.fgHilite.get(): plane='foreground'
795 else: plane='background'
796 sampleElement=self.themeElements[self.highlightTarget.get()][0]
797 apply(self.textHighlightSample.tag_config,
798 (sampleElement,),{plane:newColour})
799 theme=self.customTheme.get()
800 themeElement=sampleElement+'-'+plane
801 self.AddChangedItem('highlight',theme,themeElement,newColour)
Steven M. Gava052937f2002-02-11 02:20:53 +0000802
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000803 def GetNewThemeName(self,message):
Steven M. Gava49745752002-02-18 01:43:11 +0000804 usedNames=(idleConf.GetSectionList('user','highlight')+
805 idleConf.GetSectionList('default','highlight'))
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000806 newTheme=GetCfgSectionNameDialog(self,'New Custom Theme',
807 message,usedNames).result
808 return newTheme
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000809
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000810 def SaveAsNewTheme(self):
811 newThemeName=self.GetNewThemeName('New Theme Name:')
812 if newThemeName:
813 self.CreateNewTheme(newThemeName)
814
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000815 def CreateNewTheme(self,newThemeName):
816 #creates new custom theme based on the previously active theme,
817 #and makes the new theme active
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000818 if self.themeIsBuiltin.get():
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000819 themeType='default'
820 themeName=self.builtinTheme.get()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000821 else:
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000822 themeType='user'
823 themeName=self.customTheme.get()
824 newTheme=idleConf.GetThemeDict(themeType,themeName)
Steven M. Gava052937f2002-02-11 02:20:53 +0000825 #apply any of the old theme's unsaved changes to the new theme
826 if themeName in self.changedItems['highlight'].keys():
827 themeChanges=self.changedItems['highlight'][themeName]
828 for element in themeChanges.keys():
829 newTheme[element]=themeChanges[element]
830 #save the new theme
831 self.SaveNewTheme(newThemeName,newTheme)
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000832 #change gui over to the new theme
833 customThemeList=idleConf.GetSectionList('user','highlight')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000834 customThemeList.sort()
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +0000835 self.optMenuThemeCustom.SetMenu(customThemeList,newThemeName)
836 self.themeIsBuiltin.set(0)
837 self.SetThemeType()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000838
Steven M. Gavac112cd82002-01-22 05:56:40 +0000839 def OnListFontButtonRelease(self,event):
Kurt B. Kaiser05391692003-05-26 20:35:53 +0000840 font = self.listFontName.get(ANCHOR)
841 self.fontName.set(font.lower())
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000842 self.SetFontSample()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000843
Steven M. Gavac112cd82002-01-22 05:56:40 +0000844 def SetFontSample(self,event=None):
845 fontName=self.fontName.get()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000846 if self.fontBold.get():
Steven M. Gavac112cd82002-01-22 05:56:40 +0000847 fontWeight=tkFont.BOLD
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000848 else:
Steven M. Gavac112cd82002-01-22 05:56:40 +0000849 fontWeight=tkFont.NORMAL
850 self.editFont.config(size=self.fontSize.get(),
851 weight=fontWeight,family=fontName)
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000852
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000853 def SetHighlightTarget(self):
854 if self.highlightTarget.get()=='Cursor': #bg not possible
855 self.radioFg.config(state=DISABLED)
856 self.radioBg.config(state=DISABLED)
857 self.fgHilite.set(1)
858 else: #both fg and bg can be set
859 self.radioFg.config(state=NORMAL)
860 self.radioBg.config(state=NORMAL)
861 self.fgHilite.set(1)
862 self.SetColourSample()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000863
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000864 def SetColourSampleBinding(self,*args):
865 self.SetColourSample()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000866
Steven M. Gava5f28e8f2002-01-21 06:38:21 +0000867 def SetColourSample(self):
868 #set the colour smaple area
869 tag=self.themeElements[self.highlightTarget.get()][0]
870 if self.fgHilite.get(): plane='foreground'
871 else: plane='background'
872 colour=self.textHighlightSample.tag_cget(tag,plane)
873 self.frameColourSet.config(bg=colour)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000874
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000875 def PaintThemeSample(self):
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000876 if self.themeIsBuiltin.get(): #a default theme
Steven M. Gava99300612001-11-04 07:03:08 +0000877 theme=self.builtinTheme.get()
878 else: #a user theme
879 theme=self.customTheme.get()
Steven M. Gava052937f2002-02-11 02:20:53 +0000880 for elementTitle in self.themeElements.keys():
881 element=self.themeElements[elementTitle][0]
882 colours=idleConf.GetHighlight(theme,element)
883 if element=='cursor': #cursor sample needs special painting
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000884 colours['background']=idleConf.GetHighlight(theme,
Steven M. Gava0cae01c2002-01-04 07:53:06 +0000885 'normal', fgBg='bg')
Steven M. Gava052937f2002-02-11 02:20:53 +0000886 #handle any unsaved changes to this theme
887 if theme in self.changedItems['highlight'].keys():
888 themeDict=self.changedItems['highlight'][theme]
889 if themeDict.has_key(element+'-foreground'):
890 colours['foreground']=themeDict[element+'-foreground']
891 if themeDict.has_key(element+'-background'):
892 colours['background']=themeDict[element+'-background']
893 apply(self.textHighlightSample.tag_config,(element,),colours)
894 self.SetColourSample()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000895
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +0000896## def OnCheckUserHelpBrowser(self):
897## if self.userHelpBrowser.get():
898## self.entryHelpBrowser.config(state=NORMAL)
899## else:
900## self.entryHelpBrowser.config(state=DISABLED)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000901
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000902 def HelpSourceSelected(self,event):
903 self.SetHelpListButtonStates()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000904
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000905 def SetHelpListButtonStates(self):
906 if self.listHelp.size()<1: #no entries in list
907 self.buttonHelpListEdit.config(state=DISABLED)
908 self.buttonHelpListRemove.config(state=DISABLED)
909 else: #there are some entries
910 if self.listHelp.curselection(): #there currently is a selection
911 self.buttonHelpListEdit.config(state=NORMAL)
912 self.buttonHelpListRemove.config(state=NORMAL)
913 else: #there currently is not a selection
914 self.buttonHelpListEdit.config(state=DISABLED)
915 self.buttonHelpListRemove.config(state=DISABLED)
916
917 def HelpListItemAdd(self):
918 helpSource=GetHelpSourceDialog(self,'New Help Source').result
919 if helpSource:
920 self.userHelpList.append( (helpSource[0],helpSource[1]) )
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +0000921 self.listHelp.insert(END,helpSource[0])
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000922 self.UpdateUserHelpChangedItems()
923 self.SetHelpListButtonStates()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000924
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000925 def HelpListItemEdit(self):
926 itemIndex=self.listHelp.index(ANCHOR)
927 helpSource=self.userHelpList[itemIndex]
Steven M. Gava0c5bc8c2002-03-27 02:25:44 +0000928 newHelpSource=GetHelpSourceDialog(self,'Edit Help Source',
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000929 menuItem=helpSource[0],filePath=helpSource[1]).result
930 if (not newHelpSource) or (newHelpSource==helpSource):
931 return #no changes
932 self.userHelpList[itemIndex]=newHelpSource
933 self.listHelp.delete(itemIndex)
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +0000934 self.listHelp.insert(itemIndex,newHelpSource[0])
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000935 self.UpdateUserHelpChangedItems()
936 self.SetHelpListButtonStates()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000937
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000938 def HelpListItemRemove(self):
939 itemIndex=self.listHelp.index(ANCHOR)
940 del(self.userHelpList[itemIndex])
941 self.listHelp.delete(itemIndex)
942 self.UpdateUserHelpChangedItems()
943 self.SetHelpListButtonStates()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000944
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000945 def UpdateUserHelpChangedItems(self):
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +0000946 "Clear and rebuild the HelpFiles section in self.changedItems"
947 self.changedItems['main']['HelpFiles'] = {}
Steven M. Gava085eb1b2002-02-05 04:52:32 +0000948 for num in range(1,len(self.userHelpList)+1):
949 self.AddChangedItem('main','HelpFiles',str(num),
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +0000950 string.join(self.userHelpList[num-1][:2],';'))
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000951
Steven M. Gava429a86a2001-10-23 10:42:12 +0000952 def LoadFontCfg(self):
953 ##base editor font selection list
Steven M. Gavac11ccf32001-09-24 09:43:17 +0000954 fonts=list(tkFont.families(self))
955 fonts.sort()
956 for font in fonts:
957 self.listFontName.insert(END,font)
Steven M. Gava485f7b62001-10-26 06:47:09 +0000958 configuredFont=idleConf.GetOption('main','EditorWindow','font',
Steven M. Gava429a86a2001-10-23 10:42:12 +0000959 default='courier')
Kurt B. Kaiser05391692003-05-26 20:35:53 +0000960 lc_configuredFont = configuredFont.lower()
961 self.fontName.set(lc_configuredFont)
962 lc_fonts = [s.lower() for s in fonts]
963 if lc_configuredFont in lc_fonts:
964 currentFontIndex = lc_fonts.index(lc_configuredFont)
Steven M. Gava429a86a2001-10-23 10:42:12 +0000965 self.listFontName.see(currentFontIndex)
966 self.listFontName.select_set(currentFontIndex)
Steven M. Gavac112cd82002-01-22 05:56:40 +0000967 self.listFontName.select_anchor(currentFontIndex)
Steven M. Gava429a86a2001-10-23 10:42:12 +0000968 ##font size dropdown
Steven M. Gavac112cd82002-01-22 05:56:40 +0000969 fontSize=idleConf.GetOption('main','EditorWindow','font-size',
Kurt B. Kaiser05391692003-05-26 20:35:53 +0000970 default='10')
Chui Teya178cff2002-11-04 03:17:45 +0000971 self.optMenuFontSize.SetMenu(('7','8','9','10','11','12','13','14',
Steven M. Gava485f7b62001-10-26 06:47:09 +0000972 '16','18','20','22'),fontSize )
Steven M. Gavac112cd82002-01-22 05:56:40 +0000973 ##fontWeight
974 self.fontBold.set(idleConf.GetOption('main','EditorWindow',
975 'font-bold',default=0,type='bool'))
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000976 ##font sample
Steven M. Gava429a86a2001-10-23 10:42:12 +0000977 self.SetFontSample()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000978
Steven M. Gava429a86a2001-10-23 10:42:12 +0000979 def LoadTabCfg(self):
Steven M. Gava63f67142002-03-12 00:52:42 +0000980 ##indent type radiobuttons
Steven M. Gava485f7b62001-10-26 06:47:09 +0000981 spaceIndent=idleConf.GetOption('main','Indent','use-spaces',
Steven M. Gava429a86a2001-10-23 10:42:12 +0000982 default=1,type='bool')
Steven M. Gavac112cd82002-01-22 05:56:40 +0000983 self.indentBySpaces.set(spaceIndent)
Steven M. Gava429a86a2001-10-23 10:42:12 +0000984 ##indent sizes
Steven M. Gava485f7b62001-10-26 06:47:09 +0000985 spaceNum=idleConf.GetOption('main','Indent','num-spaces',
Steven M. Gava429a86a2001-10-23 10:42:12 +0000986 default=4,type='int')
Steven M. Gava63f67142002-03-12 00:52:42 +0000987 #tabCols=idleConf.GetOption('main','Indent','tab-cols',
988 # default=4,type='int')
Steven M. Gava429a86a2001-10-23 10:42:12 +0000989 self.spaceNum.set(spaceNum)
Steven M. Gava63f67142002-03-12 00:52:42 +0000990 #self.tabCols.set(tabCols)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000991
Steven M. Gava9dd16b32001-11-03 14:54:25 +0000992 def LoadThemeCfg(self):
Steven M. Gava41a85322001-10-29 08:05:34 +0000993 ##current theme type radiobutton
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000994 self.themeIsBuiltin.set(idleConf.GetOption('main','Theme','default',
Steven M. Gavac112cd82002-01-22 05:56:40 +0000995 type='bool',default=1))
Steven M. Gava41a85322001-10-29 08:05:34 +0000996 ##currently set theme
Steven M. Gavaad4f5322002-01-03 12:05:17 +0000997 currentOption=idleConf.CurrentTheme()
Steven M. Gava7c017862001-10-29 11:19:46 +0000998 ##load available theme option menus
Steven M. Gavad0342cd2001-11-04 11:53:10 +0000999 if self.themeIsBuiltin.get(): #default theme selected
Steven M. Gava41a85322001-10-29 08:05:34 +00001000 itemList=idleConf.GetSectionList('default','highlight')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +00001001 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +00001002 self.optMenuThemeBuiltin.SetMenu(itemList,currentOption)
1003 itemList=idleConf.GetSectionList('user','highlight')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +00001004 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +00001005 if not itemList:
1006 self.radioThemeCustom.config(state=DISABLED)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001007 self.customTheme.set('- no custom themes -')
Steven M. Gava41a85322001-10-29 08:05:34 +00001008 else:
1009 self.optMenuThemeCustom.SetMenu(itemList,itemList[0])
Steven M. Gava9dd16b32001-11-03 14:54:25 +00001010 else: #user theme selected
Steven M. Gava41a85322001-10-29 08:05:34 +00001011 itemList=idleConf.GetSectionList('user','highlight')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +00001012 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +00001013 self.optMenuThemeCustom.SetMenu(itemList,currentOption)
1014 itemList=idleConf.GetSectionList('default','highlight')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +00001015 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +00001016 self.optMenuThemeBuiltin.SetMenu(itemList,itemList[0])
Steven M. Gava7c017862001-10-29 11:19:46 +00001017 self.SetThemeType()
1018 ##load theme element option menu
Steven M. Gava9dd16b32001-11-03 14:54:25 +00001019 themeNames=self.themeElements.keys()
1020 themeNames.sort(self.__ThemeNameIndexCompare)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001021 self.optMenuHighlightTarget.SetMenu(themeNames,themeNames[0])
Steven M. Gava9dd16b32001-11-03 14:54:25 +00001022 self.PaintThemeSample()
Steven M. Gava0cae01c2002-01-04 07:53:06 +00001023 self.SetHighlightTarget()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001024
Steven M. Gava9dd16b32001-11-03 14:54:25 +00001025 def __ThemeNameIndexCompare(self,a,b):
1026 if self.themeElements[a][1]<self.themeElements[b][1]: return -1
1027 elif self.themeElements[a][1]==self.themeElements[b][1]: return 0
1028 else: return 1
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001029
Steven M. Gava9dd16b32001-11-03 14:54:25 +00001030 def LoadKeyCfg(self):
Steven M. Gava41a85322001-10-29 08:05:34 +00001031 ##current keys type radiobutton
Steven M. Gava052937f2002-02-11 02:20:53 +00001032 self.keysAreBuiltin.set(idleConf.GetOption('main','Keys','default',
Steven M. Gavac112cd82002-01-22 05:56:40 +00001033 type='bool',default=1))
Steven M. Gava41a85322001-10-29 08:05:34 +00001034 ##currently set keys
Steven M. Gavaad4f5322002-01-03 12:05:17 +00001035 currentOption=idleConf.CurrentKeys()
Steven M. Gava7c017862001-10-29 11:19:46 +00001036 ##load available keyset option menus
Steven M. Gava052937f2002-02-11 02:20:53 +00001037 if self.keysAreBuiltin.get(): #default theme selected
Steven M. Gava41a85322001-10-29 08:05:34 +00001038 itemList=idleConf.GetSectionList('default','keys')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +00001039 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +00001040 self.optMenuKeysBuiltin.SetMenu(itemList,currentOption)
1041 itemList=idleConf.GetSectionList('user','keys')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +00001042 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +00001043 if not itemList:
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001044 self.radioKeysCustom.config(state=DISABLED)
1045 self.customKeys.set('- no custom keys -')
Steven M. Gava41a85322001-10-29 08:05:34 +00001046 else:
1047 self.optMenuKeysCustom.SetMenu(itemList,itemList[0])
Steven M. Gavaa498af22002-02-01 01:33:36 +00001048 else: #user key set selected
Steven M. Gava41a85322001-10-29 08:05:34 +00001049 itemList=idleConf.GetSectionList('user','keys')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +00001050 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +00001051 self.optMenuKeysCustom.SetMenu(itemList,currentOption)
1052 itemList=idleConf.GetSectionList('default','keys')
Steven M. Gavaf9bb90e2002-01-24 06:02:50 +00001053 itemList.sort()
Steven M. Gava41a85322001-10-29 08:05:34 +00001054 self.optMenuKeysBuiltin.SetMenu(itemList,itemList[0])
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001055 self.SetKeysType()
Steven M. Gavafacfc092002-01-19 00:29:54 +00001056 ##load keyset element list
Steven M. Gava052937f2002-02-11 02:20:53 +00001057 keySetName=idleConf.CurrentKeys()
1058 self.LoadKeysList(keySetName)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001059
Steven M. Gavafacfc092002-01-19 00:29:54 +00001060 def LoadGeneralCfg(self):
Steven M. Gava5f28e8f2002-01-21 06:38:21 +00001061 #startup state
1062 self.startupEdit.set(idleConf.GetOption('main','General',
1063 'editor-on-startup',default=1,type='bool'))
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +00001064 #autosave state
1065 self.autoSave.set(idleConf.GetOption('main', 'General', 'autosave',
1066 default=0, type='bool'))
Steven M. Gavafacfc092002-01-19 00:29:54 +00001067 #initial window size
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001068 self.winWidth.set(idleConf.GetOption('main','EditorWindow','width'))
Steven M. Gavafacfc092002-01-19 00:29:54 +00001069 self.winHeight.set(idleConf.GetOption('main','EditorWindow','height'))
Kurt B. Kaisera053f332003-05-10 00:49:56 +00001070 # default source encoding
Kurt B. Kaiser6c638b62003-05-26 06:23:10 +00001071 self.encoding.set(idleConf.GetOption('main', 'EditorWindow',
1072 'encoding', default='none'))
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +00001073 # additional help sources
1074 self.userHelpList = idleConf.GetAllExtraHelpSourcesList()
Steven M. Gava085eb1b2002-02-05 04:52:32 +00001075 for helpItem in self.userHelpList:
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +00001076 self.listHelp.insert(END,helpItem[0])
Steven M. Gava085eb1b2002-02-05 04:52:32 +00001077 self.SetHelpListButtonStates()
Steven M. Gava0c5bc8c2002-03-27 02:25:44 +00001078 #self.userHelpBrowser.set(idleConf.GetOption('main','General',
1079 # 'user-help-browser',default=0,type='bool'))
1080 #self.helpBrowser.set(idleConf.GetOption('main','General',
1081 # 'user-help-browser-command',default=''))
1082 #self.OnCheckUserHelpBrowser()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001083
Steven M. Gava429a86a2001-10-23 10:42:12 +00001084 def LoadConfigs(self):
1085 """
1086 load configuration from default and user config files and populate
1087 the widgets on the config dialog pages.
1088 """
1089 ### fonts / tabs page
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001090 self.LoadFontCfg()
1091 self.LoadTabCfg()
Steven M. Gava429a86a2001-10-23 10:42:12 +00001092 ### highlighting page
Steven M. Gava9dd16b32001-11-03 14:54:25 +00001093 self.LoadThemeCfg()
Steven M. Gava429a86a2001-10-23 10:42:12 +00001094 ### keys page
Steven M. Gava9dd16b32001-11-03 14:54:25 +00001095 self.LoadKeyCfg()
Steven M. Gava429a86a2001-10-23 10:42:12 +00001096 ### general page
Steven M. Gavafacfc092002-01-19 00:29:54 +00001097 self.LoadGeneralCfg()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001098
Steven M. Gava052937f2002-02-11 02:20:53 +00001099 def SaveNewKeySet(self,keySetName,keySet):
1100 """
1101 save a newly created core key set.
1102 keySetName - string, the name of the new key set
1103 keySet - dictionary containing the new key set
1104 """
1105 if not idleConf.userCfg['keys'].has_section(keySetName):
1106 idleConf.userCfg['keys'].add_section(keySetName)
1107 for event in keySet.keys():
1108 value=keySet[event]
1109 idleConf.userCfg['keys'].SetOption(keySetName,event,value)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001110
Steven M. Gava052937f2002-02-11 02:20:53 +00001111 def SaveNewTheme(self,themeName,theme):
1112 """
1113 save a newly created theme.
1114 themeName - string, the name of the new theme
1115 theme - dictionary containing the new theme
1116 """
1117 if not idleConf.userCfg['highlight'].has_section(themeName):
1118 idleConf.userCfg['highlight'].add_section(themeName)
1119 for element in theme.keys():
1120 value=theme[element]
1121 idleConf.userCfg['highlight'].SetOption(themeName,element,value)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001122
Steven M. Gava2d7bb3f2002-01-29 08:35:29 +00001123 def SetUserValue(self,configType,section,item,value):
Steven M. Gava2d7bb3f2002-01-29 08:35:29 +00001124 if idleConf.defaultCfg[configType].has_option(section,item):
1125 if idleConf.defaultCfg[configType].Get(section,item)==value:
1126 #the setting equals a default setting, remove it from user cfg
1127 return idleConf.userCfg[configType].RemoveOption(section,item)
1128 #if we got here set the option
1129 return idleConf.userCfg[configType].SetOption(section,item,value)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001130
Steven M. Gava052937f2002-02-11 02:20:53 +00001131 def SaveAllChangedConfigs(self):
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +00001132 "Save configuration changes to the user config file."
Steven M. Gava0c5bc8c2002-03-27 02:25:44 +00001133 idleConf.userCfg['main'].Save()
Steven M. Gava5f28e8f2002-01-21 06:38:21 +00001134 for configType in self.changedItems.keys():
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +00001135 cfgTypeHasChanges = False
Steven M. Gava5f28e8f2002-01-21 06:38:21 +00001136 for section in self.changedItems[configType].keys():
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +00001137 if section == 'HelpFiles':
1138 #this section gets completely replaced
1139 idleConf.userCfg['main'].remove_section('HelpFiles')
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +00001140 cfgTypeHasChanges = True
Steven M. Gava5f28e8f2002-01-21 06:38:21 +00001141 for item in self.changedItems[configType][section].keys():
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +00001142 value = self.changedItems[configType][section][item]
Steven M. Gava2d7bb3f2002-01-29 08:35:29 +00001143 if self.SetUserValue(configType,section,item,value):
Kurt B. Kaisere7a161e2003-01-10 20:13:57 +00001144 cfgTypeHasChanges = True
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001145 if cfgTypeHasChanges:
1146 idleConf.userCfg[configType].Save()
Steven M. Gavaa498af22002-02-01 01:33:36 +00001147 self.ResetChangedItems() #clear the changed items dict
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001148
Steven M. Gava49745752002-02-18 01:43:11 +00001149 def ActivateConfigChanges(self):
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001150 #things that need to be done to make
Steven M. Gava49745752002-02-18 01:43:11 +00001151 #applied config changes dynamic:
Steven M. Gava49745752002-02-18 01:43:11 +00001152 #update editor/shell font and repaint
1153 #dynamically update indentation setttings
1154 #update theme and repaint
1155 #update keybindings and re-bind
1156 #update user help sources menu
Steven M. Gavab77d3432002-03-02 07:16:21 +00001157 winInstances=self.parent.instanceDict.keys()
1158 for instance in winInstances:
1159 instance.ResetColorizer()
Steven M. Gavab1585412002-03-12 00:21:56 +00001160 instance.ResetFont()
Steven M. Gavadbfe92c2002-03-18 02:38:44 +00001161 instance.ResetKeybindings()
Kurt B. Kaiser8e92bf72003-01-14 22:03:31 +00001162 instance.reset_help_menu_entries()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +00001163
Steven M. Gava5f28e8f2002-01-21 06:38:21 +00001164 def Cancel(self):
1165 self.destroy()
1166
1167 def Ok(self):
1168 self.Apply()
1169 self.destroy()
1170
1171 def Apply(self):
Steven M. Gava052937f2002-02-11 02:20:53 +00001172 self.SaveAllChangedConfigs()
Steven M. Gava49745752002-02-18 01:43:11 +00001173 self.ActivateConfigChanges()
Steven M. Gava5f28e8f2002-01-21 06:38:21 +00001174
1175 def Help(self):
Steven M. Gavac11ccf32001-09-24 09:43:17 +00001176 pass
1177
Steven M. Gava44d3d1a2001-07-31 06:59:02 +00001178if __name__ == '__main__':
Steven M. Gavad721c482001-07-31 10:46:53 +00001179 #test the dialog
1180 root=Tk()
1181 Button(root,text='Dialog',
Steven M. Gava3b55a892001-11-21 05:56:26 +00001182 command=lambda:ConfigDialog(root,'Settings')).pack()
Steven M. Gavaf31eec02002-03-05 00:25:58 +00001183 root.instanceDict={}
Steven M. Gavad721c482001-07-31 10:46:53 +00001184 root.mainloop()