mirror of
https://github.com/python/cpython.git
synced 2025-11-01 22:21:35 +00:00
start of new config handling stuff
This commit is contained in:
parent
fa26f7cc39
commit
c11ccf35f4
6 changed files with 468 additions and 48 deletions
34
Lib/idlelib/config-extensions.def
Normal file
34
Lib/idlelib/config-extensions.def
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
# IDLE reads several config files to determine user preferences. This
|
||||||
|
# file is the default config file for idle extensions settings.
|
||||||
|
|
||||||
|
[SearchBinding]
|
||||||
|
enable=1
|
||||||
|
|
||||||
|
[AutoIndent]
|
||||||
|
enable=1
|
||||||
|
|
||||||
|
[AutoExpand]
|
||||||
|
enable=1
|
||||||
|
|
||||||
|
[FormatParagraph]
|
||||||
|
enable=1
|
||||||
|
|
||||||
|
[ZoomHeight]
|
||||||
|
enable=1
|
||||||
|
|
||||||
|
#[ScriptBinding] # disabled in favor of ExecBinding
|
||||||
|
#enable=0
|
||||||
|
|
||||||
|
[ExecBinding]
|
||||||
|
enable=1
|
||||||
|
|
||||||
|
[CallTips]
|
||||||
|
enable=1
|
||||||
|
|
||||||
|
[ParenMatch]
|
||||||
|
enable=0
|
||||||
|
style= expression
|
||||||
|
flash-delay= 500
|
||||||
|
bell= 1
|
||||||
|
hilite-foreground= black
|
||||||
|
hilite-background= #43cd80
|
||||||
56
Lib/idlelib/config-highlight.def
Normal file
56
Lib/idlelib/config-highlight.def
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
# IDLE reads several config files to determine user preferences. This
|
||||||
|
# file is the default config file for idle highlight theme settings.
|
||||||
|
|
||||||
|
[IDLE Classic Old - plain fonts]
|
||||||
|
normal-foreground= black
|
||||||
|
normal-background= white
|
||||||
|
normal-fontStyle= normal
|
||||||
|
keyword-foreground= #ff7700
|
||||||
|
keyword-fontStyle= normal
|
||||||
|
comment-foreground= #dd0000
|
||||||
|
comment-fontStyle= normal
|
||||||
|
string-foreground= #00aa00
|
||||||
|
string-fontStyle= normal
|
||||||
|
definition-foreground= #0000ff
|
||||||
|
definition-fontStyle= normal
|
||||||
|
hilite-foreground= #000068
|
||||||
|
hilite-background= #006868
|
||||||
|
hilite-fontStyle= normal
|
||||||
|
break-foreground= #ff7777
|
||||||
|
break-fontStyle= normal
|
||||||
|
hit-background= #000000
|
||||||
|
hit-foreground= #ffffff
|
||||||
|
hit-fontStyle= normal
|
||||||
|
cursor-background= black
|
||||||
|
error-background= #ff7777
|
||||||
|
#shell window
|
||||||
|
stdout-foreground= blue
|
||||||
|
stdout-fontStyle= normal
|
||||||
|
stderr-foreground= red
|
||||||
|
stderr-fontStyle= normal
|
||||||
|
console-foreground= #770000
|
||||||
|
console-fontStyle= normal
|
||||||
|
|
||||||
|
[IDLE Classic New]
|
||||||
|
normal-foreground= black
|
||||||
|
normal-background= white
|
||||||
|
normal-fontStyle= normal
|
||||||
|
keyword-foreground= #ff7700
|
||||||
|
keyword-fontStyle= bold
|
||||||
|
comment-foreground= #dd0000
|
||||||
|
comment-fontStyle= italic
|
||||||
|
string-foreground= #00aa00
|
||||||
|
string-fontStyle= normal
|
||||||
|
definition-foreground= #0000ff
|
||||||
|
definition-fontStyle= bold
|
||||||
|
hilite-foreground= #000068
|
||||||
|
hilite-background= #006868
|
||||||
|
break-foreground= #ff7777
|
||||||
|
hit-background= #000000
|
||||||
|
hit-foreground= #ffffff
|
||||||
|
cursor-background= black
|
||||||
|
error-background= #ff7777
|
||||||
|
#shell window
|
||||||
|
stdout-foreground= blue
|
||||||
|
stderr-foreground= red
|
||||||
|
console-foreground= #770000
|
||||||
58
Lib/idlelib/config-keys.def
Normal file
58
Lib/idlelib/config-keys.def
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
# IDLE reads several config files to determine user preferences. This
|
||||||
|
# file is the default config file for idle key binding settings.
|
||||||
|
|
||||||
|
[IDLE Classic - windows]
|
||||||
|
Copy= '<Control-c> <Control-C>'
|
||||||
|
Cut= '<Control-x> <Control-X>'
|
||||||
|
Paste= '<Control-v> <Control-V>'
|
||||||
|
beginning-of-line= '<Control-a> <Home>'
|
||||||
|
center-insert= '<Control-l>'
|
||||||
|
close-all-windows= '<Control-q>'
|
||||||
|
close-window= '<Alt-F4>'
|
||||||
|
dump-undo-state= '<Control-backslash>'
|
||||||
|
end-of-file= '<Control-d>'
|
||||||
|
python-docs= '<F1>'
|
||||||
|
history-next= '<Alt-n>'
|
||||||
|
history-previous= '<Alt-p>'
|
||||||
|
interrupt-execution= '<Control-c>'
|
||||||
|
open-class-browser= '<Alt-c>'
|
||||||
|
open-module= '<Alt-m>'
|
||||||
|
open-new-window= '<Control-n>'
|
||||||
|
open-window-from-file= '<Control-o>'
|
||||||
|
plain-newline-and-indent= '<Control-j>'
|
||||||
|
redo= '<Control-y>'
|
||||||
|
remove-selection= '<Escape>'
|
||||||
|
save-copy-of-window-as-file= '<Alt-Shift-s>'
|
||||||
|
save-window-as-file= '<Alt-s>'
|
||||||
|
save-window= '<Control-s>'
|
||||||
|
select-all= '<Alt-a>'
|
||||||
|
toggle-auto-coloring= '<Control-slash>'
|
||||||
|
undo= '<Control-z>'
|
||||||
|
|
||||||
|
[IDLE Classic - posix]
|
||||||
|
Copy= '<Alt-w> <Meta-w>'
|
||||||
|
Cut= '<Control-w>'
|
||||||
|
Paste= '<Control-y>'
|
||||||
|
beginning-of-line= '<Control-a> <Home>'
|
||||||
|
center-insert= '<Control-l>'
|
||||||
|
close-all-windows= '<Control-x><Control-c>'
|
||||||
|
close-window= '<Control-x><Control-0> <Control-x><Key-0>'
|
||||||
|
do-nothing= '<Control-x>'
|
||||||
|
dump-undo-state= '<Control-backslash>'
|
||||||
|
end-of-file= '<Control-d>'
|
||||||
|
help= '<F1>'
|
||||||
|
history-next= '<Alt-n> <Meta-n>'
|
||||||
|
history-previous= '<Alt-p> <Meta-p>'
|
||||||
|
interrupt-execution= '<Control-c>'
|
||||||
|
open-class-browser= '<Control-x><Control-b>'
|
||||||
|
open-module= '<Control-x><Control-m>'
|
||||||
|
open-new-window= '<Control-x><Control-n>'
|
||||||
|
open-window-from-file= '<Control-x><Control-f>'
|
||||||
|
plain-newline-and-indent= '<Control-j>'
|
||||||
|
redo= '<Alt-z> <Meta-z>'
|
||||||
|
save-copy-of-window-as-file= '<Control-x><w>'
|
||||||
|
save-window-as-file= '<Control-x><Control-w>'
|
||||||
|
save-window= '<Control-x><Control-s>'
|
||||||
|
select-all= '<Alt-a> <Meta-a>'
|
||||||
|
toggle-auto-coloring= '<Control-slash>'
|
||||||
|
undo= '<Control-z>'
|
||||||
63
Lib/idlelib/config-main.def
Normal file
63
Lib/idlelib/config-main.def
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
# IDLE reads several config files to determine user preferences. This
|
||||||
|
# file is the default config file for general idle settings.
|
||||||
|
#
|
||||||
|
# When IDLE starts, it will look in
|
||||||
|
# the following two sets of files, in order:
|
||||||
|
#
|
||||||
|
# default configuration
|
||||||
|
# ---------------------
|
||||||
|
# config-main.def the default general config file
|
||||||
|
# config-extensions.def the default extension config file
|
||||||
|
# config-highlight.def the default highlighting config file
|
||||||
|
# config-keys.def the default keybinding config file
|
||||||
|
#
|
||||||
|
# user configuration
|
||||||
|
# -------------------
|
||||||
|
# ~/.idlerc/idle-main.cfg the user general config file
|
||||||
|
# ~/.idlerc/idle-extensions.cfg the user extension config file
|
||||||
|
# ~/.idlerc/idle-highlight.cfg the user highlighting config file
|
||||||
|
# ~/.idlerc/idle-keys.cfg the user keybinding config file
|
||||||
|
# XXX what about Windows?
|
||||||
|
#
|
||||||
|
# Any options the user saves through the config dialog will be saved to
|
||||||
|
# the relevant user config file. Reverting any general setting to the
|
||||||
|
# default causes that entry to be wiped from the user file and re-read
|
||||||
|
# from the default file. User highlighting themes or keybinding sets are
|
||||||
|
# retained unless specifically deleted within the config dialog. Choosing
|
||||||
|
# one of the default themes or keysets just applies the relevant settings
|
||||||
|
# from the default file.
|
||||||
|
|
||||||
|
[General]
|
||||||
|
run-in-separate-process= 1
|
||||||
|
|
||||||
|
[EditorWindow]
|
||||||
|
width= 80
|
||||||
|
height= 24
|
||||||
|
font= courier
|
||||||
|
font-size= 12
|
||||||
|
|
||||||
|
[Indent]
|
||||||
|
use-spaces= 1
|
||||||
|
num-spaces= 4
|
||||||
|
tab-cols= 4
|
||||||
|
|
||||||
|
[Theme]
|
||||||
|
user= 0
|
||||||
|
name= "IDLE Classic New"
|
||||||
|
|
||||||
|
[Keys]
|
||||||
|
user= 0
|
||||||
|
name= "IDLE Classic - windows"
|
||||||
|
|
||||||
|
[RecentFiles]
|
||||||
|
1=
|
||||||
|
2=
|
||||||
|
3=
|
||||||
|
4=
|
||||||
|
5=
|
||||||
|
6=
|
||||||
|
7=
|
||||||
|
8=
|
||||||
|
9=
|
||||||
|
10=
|
||||||
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
from Tkinter import *
|
from Tkinter import *
|
||||||
import tkMessageBox, tkColorChooser, tkFont
|
import tkMessageBox, tkColorChooser, tkFont
|
||||||
|
|
||||||
import IdleConf
|
from configHandler import idleConf
|
||||||
|
|
||||||
class ConfigDialog(Toplevel):
|
class ConfigDialog(Toplevel):
|
||||||
"""
|
"""
|
||||||
|
|
@ -24,10 +24,7 @@ def __init__(self,parent,title,configDict):
|
||||||
self.configure(borderwidth=5)
|
self.configure(borderwidth=5)
|
||||||
self.geometry("+%d+%d" % (parent.winfo_rootx()+20,
|
self.geometry("+%d+%d" % (parent.winfo_rootx()+20,
|
||||||
parent.winfo_rooty()+30))
|
parent.winfo_rooty()+30))
|
||||||
self.LoadConfig()
|
#self.LoadConfig()
|
||||||
#elguavas - config placeholders til config stuff completed
|
|
||||||
self.bg=self.cget('bg')
|
|
||||||
self.fg=None
|
|
||||||
|
|
||||||
self.CreateWidgets()
|
self.CreateWidgets()
|
||||||
self.resizable(height=FALSE,width=FALSE)
|
self.resizable(height=FALSE,width=FALSE)
|
||||||
|
|
@ -45,19 +42,9 @@ def __init__(self,parent,title,configDict):
|
||||||
self.bind('<Alt-h>',self.ChangePageBinding)
|
self.bind('<Alt-h>',self.ChangePageBinding)
|
||||||
self.bind('<Alt-k>',self.ChangePageBinding)
|
self.bind('<Alt-k>',self.ChangePageBinding)
|
||||||
self.bind('<Alt-g>',self.ChangePageBinding)
|
self.bind('<Alt-g>',self.ChangePageBinding)
|
||||||
|
#self.LoadOptMenuHighlightTarget()
|
||||||
self.wait_window()
|
self.wait_window()
|
||||||
|
|
||||||
def LoadConfig(self):
|
|
||||||
#self.configParser=IdleConf.idleconf
|
|
||||||
#self.loadedConfig={}
|
|
||||||
#self.workingConfig={}
|
|
||||||
#for key in .keys():
|
|
||||||
#print self.configParser.getsection('Colors').options()
|
|
||||||
self.workingTestColours={
|
|
||||||
'Foo-Bg': '#ffffff',
|
|
||||||
'Foo-Fg': '#000000',
|
|
||||||
'Bar-Bg': '#777777'}
|
|
||||||
|
|
||||||
def Cancel(self):
|
def Cancel(self):
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
||||||
|
|
@ -134,17 +121,7 @@ def GetColour(self):
|
||||||
self.frameHighlightSample.update() #redraw after dialog
|
self.frameHighlightSample.update() #redraw after dialog
|
||||||
self.labelTestSample.update()
|
self.labelTestSample.update()
|
||||||
|
|
||||||
def __LoadFontList(self):
|
def SetFontSample(self,event):
|
||||||
fonts=list(tkFont.families(self))
|
|
||||||
fonts.sort()
|
|
||||||
for font in fonts:
|
|
||||||
self.listFontName.insert(END,font)
|
|
||||||
currentFontIndex=fonts.index('courier')
|
|
||||||
self.listFontName.see(currentFontIndex)
|
|
||||||
self.listFontName.select_set(currentFontIndex)
|
|
||||||
self.fontSize.set('12')
|
|
||||||
|
|
||||||
def __SetFontSample(self,event):
|
|
||||||
self.newFont.config(size=self.fontSize.get(),weight=NORMAL,
|
self.newFont.config(size=self.fontSize.get(),weight=NORMAL,
|
||||||
family=self.listFontName.get(self.listFontName.curselection()[0]))
|
family=self.listFontName.get(self.listFontName.curselection()[0]))
|
||||||
|
|
||||||
|
|
@ -167,13 +144,14 @@ def CreateWidgets(self):
|
||||||
pageButtonNames=('Fonts/Tabs','Highlighting','Keys','General')
|
pageButtonNames=('Fonts/Tabs','Highlighting','Keys','General')
|
||||||
self.pageButtons=[]
|
self.pageButtons=[]
|
||||||
buttonValue=0
|
buttonValue=0
|
||||||
|
buttonSelColour=framePageButtons.cget('bg')
|
||||||
for name in pageButtonNames:
|
for name in pageButtonNames:
|
||||||
buttonFrame=Frame(framePageButtons,borderwidth=2,relief=RIDGE)
|
buttonFrame=Frame(framePageButtons,borderwidth=2,relief=RIDGE)
|
||||||
buttonFrame.pack(side=LEFT)
|
buttonFrame.pack(side=LEFT)
|
||||||
button = Radiobutton(buttonFrame,command=self.ChangePage,
|
button = Radiobutton(buttonFrame,command=self.ChangePage,
|
||||||
value=buttonValue,padx=5,pady=5,takefocus=FALSE,underline=0,
|
value=buttonValue,padx=5,pady=5,takefocus=FALSE,underline=0,
|
||||||
indicatoron=FALSE,highlightthickness=0,variable=self.pageNum,
|
indicatoron=FALSE,highlightthickness=0,variable=self.pageNum,
|
||||||
selectcolor=self.bg,borderwidth=0,text=name)
|
selectcolor=buttonSelColour,borderwidth=0,text=name)
|
||||||
button.pack()
|
button.pack()
|
||||||
button.lift()
|
button.lift()
|
||||||
self.pageButtons.append(button)
|
self.pageButtons.append(button)
|
||||||
|
|
@ -216,21 +194,20 @@ def CreatePageFontTab(self):
|
||||||
text='Font :')
|
text='Font :')
|
||||||
self.listFontName=Listbox(frameFontName,height=5,takefocus=FALSE,
|
self.listFontName=Listbox(frameFontName,height=5,takefocus=FALSE,
|
||||||
exportselection=FALSE)
|
exportselection=FALSE)
|
||||||
self.listFontName.bind('<<ListboxSelect>>',self.__SetFontSample)
|
self.listFontName.bind('<<ListboxSelect>>',self.SetFontSample)
|
||||||
scrollFont=Scrollbar(frameFontName)
|
scrollFont=Scrollbar(frameFontName)
|
||||||
self.__LoadFontList()
|
self.LoadFontList()
|
||||||
scrollFont.config(command=self.listFontName.yview)
|
scrollFont.config(command=self.listFontName.yview)
|
||||||
self.listFontName.config(yscrollcommand=scrollFont.set)
|
self.listFontName.config(yscrollcommand=scrollFont.set)
|
||||||
labelFontSizeTitle=Label(frameFontSize,text='Size :')
|
labelFontSizeTitle=Label(frameFontSize,text='Size :')
|
||||||
sizes=('10','11','12','13','14','16','18','20','22')
|
sizes=('10','11','12','13','14','16','18','20','22')
|
||||||
args=(frameFontSize,self.fontSize)+sizes
|
args=(frameFontSize,self.fontSize)+sizes
|
||||||
keyArgs={'command':self.__SetFontSample}
|
keyArgs={'command':self.SetFontSample}
|
||||||
optFontSize=apply(OptionMenu,args,keyArgs)
|
optFontSize=apply(OptionMenu,args,keyArgs)
|
||||||
#optFontSize.bind('<<MenuSelect>>',self.__SetFontSample)
|
#optFontSize.bind('<<MenuSelect>>',self.SetFontSample)
|
||||||
frameFontSample=Frame(frameFont,relief=SOLID,borderwidth=1,
|
frameFontSample=Frame(frameFont,relief=SOLID,borderwidth=1)
|
||||||
bg=self.workingTestColours['Foo-Bg'])
|
self.labelFontSample=Label(frameFontSample,
|
||||||
self.labelFontSample=Label(frameFontSample,bg=self.workingTestColours['Foo-Bg'],
|
text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]',
|
||||||
fg='#000000',text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]',
|
|
||||||
justify=LEFT,font=self.newFont)
|
justify=LEFT,font=self.newFont)
|
||||||
#frameIndent
|
#frameIndent
|
||||||
labelIndentTitle=Label(frameIndent,text='Set Indentation Defaults')
|
labelIndentTitle=Label(frameIndent,text='Set Indentation Defaults')
|
||||||
|
|
@ -299,18 +276,16 @@ def CreatePageHighlight(self):
|
||||||
frameCustom=Frame(frame,borderwidth=2,relief=GROOVE)
|
frameCustom=Frame(frame,borderwidth=2,relief=GROOVE)
|
||||||
frameTheme=Frame(frame,borderwidth=2,relief=GROOVE)
|
frameTheme=Frame(frame,borderwidth=2,relief=GROOVE)
|
||||||
#frameCustom
|
#frameCustom
|
||||||
frameTarget=Frame(frameCustom)
|
self.frameHighlightTarget=Frame(frameCustom)
|
||||||
self.frameHighlightSample=Frame(frameCustom,relief=SOLID,borderwidth=1,
|
self.frameHighlightSample=Frame(frameCustom,relief=SOLID,
|
||||||
bg=self.workingTestColours['Foo-Bg'],cursor='hand2')
|
borderwidth=1,cursor='hand2')
|
||||||
frameSet=Frame(frameCustom)
|
frameSet=Frame(frameCustom)
|
||||||
self.frameColourSet=Frame(frameSet,relief=SOLID,borderwidth=1,
|
self.frameColourSet=Frame(frameSet,relief=SOLID,borderwidth=1)
|
||||||
bg=self.workingTestColours['Foo-Bg'])
|
|
||||||
frameFontSet=Frame(frameSet)
|
frameFontSet=Frame(frameSet)
|
||||||
labelCustomTitle=Label(frameCustom,text='Set Custom Highlighting')
|
labelCustomTitle=Label(frameCustom,text='Set Custom Highlighting')
|
||||||
labelTargetTitle=Label(frameTarget,text='for : ')
|
labelTargetTitle=Label(self.frameHighlightTarget,text='for : ')
|
||||||
optMenuTarget=OptionMenu(frameTarget,
|
self.optMenuHighlightTarget=OptionMenu(self.frameHighlightTarget,
|
||||||
self.highlightTarget,'normal text background','test target interface item 2')
|
self.highlightTarget,'normal text background','test target interface item 2')
|
||||||
self.highlightTarget.set('normal text background')
|
|
||||||
buttonSetColour=Button(self.frameColourSet,text='Set Colour',
|
buttonSetColour=Button(self.frameColourSet,text='Set Colour',
|
||||||
command=self.GetColour)
|
command=self.GetColour)
|
||||||
labelFontTitle=Label(frameFontSet,text='Set Font Style')
|
labelFontTitle=Label(frameFontSet,text='Set Font Style')
|
||||||
|
|
@ -322,8 +297,7 @@ def CreatePageHighlight(self):
|
||||||
text='#when finished, this\n#sample area will\n#be interactive\n'+
|
text='#when finished, this\n#sample area will\n#be interactive\n'+
|
||||||
'def Ahem(foo,bar):\n '+
|
'def Ahem(foo,bar):\n '+
|
||||||
'"""'+'doc hazard'+'"""'+
|
'"""'+'doc hazard'+'"""'+
|
||||||
'\n test=foo\n text=bar\n return',
|
'\n test=foo\n text=bar\n return')
|
||||||
bg=self.workingTestColours['Foo-Bg'])
|
|
||||||
buttonSaveCustomTheme=Button(frameCustom,
|
buttonSaveCustomTheme=Button(frameCustom,
|
||||||
text='Save as a Custom Theme')
|
text='Save as a Custom Theme')
|
||||||
#frameTheme
|
#frameTheme
|
||||||
|
|
@ -350,13 +324,13 @@ def CreatePageHighlight(self):
|
||||||
frameTheme.pack(side=LEFT,padx=5,pady=10,fill=Y)
|
frameTheme.pack(side=LEFT,padx=5,pady=10,fill=Y)
|
||||||
#frameCustom
|
#frameCustom
|
||||||
labelCustomTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
|
labelCustomTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
|
||||||
frameTarget.pack(side=TOP,padx=5,pady=5,fill=X)
|
self.frameHighlightTarget.pack(side=TOP,padx=5,pady=5,fill=X)
|
||||||
self.frameHighlightSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
|
self.frameHighlightSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
|
||||||
frameSet.pack(side=TOP,fill=X)
|
frameSet.pack(side=TOP,fill=X)
|
||||||
self.frameColourSet.pack(side=LEFT,padx=5,pady=5,fill=BOTH)
|
self.frameColourSet.pack(side=LEFT,padx=5,pady=5,fill=BOTH)
|
||||||
frameFontSet.pack(side=RIGHT,padx=5,pady=5,anchor=W)
|
frameFontSet.pack(side=RIGHT,padx=5,pady=5,anchor=W)
|
||||||
labelTargetTitle.pack(side=LEFT,anchor=E)
|
labelTargetTitle.pack(side=LEFT,anchor=E)
|
||||||
optMenuTarget.pack(side=RIGHT,anchor=W,expand=TRUE,fill=X)
|
self.optMenuHighlightTarget.pack(side=RIGHT,anchor=W,expand=TRUE,fill=X)
|
||||||
buttonSetColour.pack(expand=TRUE,fill=BOTH,padx=10,pady=10)
|
buttonSetColour.pack(expand=TRUE,fill=BOTH,padx=10,pady=10)
|
||||||
labelFontTitle.pack(side=TOP,anchor=W)
|
labelFontTitle.pack(side=TOP,anchor=W)
|
||||||
checkFontBold.pack(side=LEFT,anchor=W,pady=2)
|
checkFontBold.pack(side=LEFT,anchor=W,pady=2)
|
||||||
|
|
@ -529,6 +503,68 @@ def CreatePageGeneral(self):
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
|
|
||||||
|
def LoadFontList(self):
|
||||||
|
fonts=list(tkFont.families(self))
|
||||||
|
fonts.sort()
|
||||||
|
for font in fonts:
|
||||||
|
self.listFontName.insert(END,font)
|
||||||
|
currentFontIndex=fonts.index('courier')
|
||||||
|
self.listFontName.see(currentFontIndex)
|
||||||
|
self.listFontName.select_set(currentFontIndex)
|
||||||
|
self.fontSize.set('12')
|
||||||
|
|
||||||
|
#def LoadOptionMenu(self, optMenu, optList, optVar, optVal=None,
|
||||||
|
# command=None):
|
||||||
|
def LoadOptionMenu(self, optMenu, optVar, optVal=None, command=None):
|
||||||
|
"""
|
||||||
|
Load the relevant list of values into an OptionMenu and set
|
||||||
|
selected value if required.
|
||||||
|
"""
|
||||||
|
params={'cfg':None,
|
||||||
|
'section':None,
|
||||||
|
'optList':None,
|
||||||
|
'optVar':None,
|
||||||
|
'optVal':None,
|
||||||
|
'command':None}
|
||||||
|
if optMenu == self.optMenuHighlightTarget:
|
||||||
|
params['cfg']=idleConf.userCfg['highlight']
|
||||||
|
# if
|
||||||
|
# params['section']=idleconf.userCfg['main'].GetDef('EditorWindow',
|
||||||
|
# 'theme')
|
||||||
|
#
|
||||||
|
# params['optVar']=self.HighlightTarget
|
||||||
|
# params['optList']=idleconf.defaultCfg['main'].options(params.Section)
|
||||||
|
# else: # a default theme
|
||||||
|
# pass
|
||||||
|
#params.optList=idleConf
|
||||||
|
|
||||||
|
|
||||||
|
#if not params.optVar.get(): #no value set yet (initial load)
|
||||||
|
# params.optVal=
|
||||||
|
|
||||||
|
#if params.section: #we're asking to load a list of option names
|
||||||
|
# optList=params.cfg
|
||||||
|
#elif optMenu == xx:
|
||||||
|
#else:
|
||||||
|
|
||||||
|
#if self.HighlightTarget.get(): #if there was a value set (reload)
|
||||||
|
# params.optVal=self.HighlightTarget.get()
|
||||||
|
#else: #no value set yet (initial load)
|
||||||
|
#if not params.optVar.get(): #no value set yet (initial load)
|
||||||
|
|
||||||
|
menu=optMenu['menu']
|
||||||
|
print menu
|
||||||
|
menu.delete(0,END)
|
||||||
|
for item in optList:
|
||||||
|
menu.add_command(label=item,command=command)
|
||||||
|
if optVal:
|
||||||
|
optVar.set(optVal)
|
||||||
|
elif optList:
|
||||||
|
optVar.set(optList[0])
|
||||||
|
|
||||||
|
def SaveConfigs(self):
|
||||||
|
pass
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#test the dialog
|
#test the dialog
|
||||||
root=Tk()
|
root=Tk()
|
||||||
|
|
|
||||||
173
Lib/idlelib/configHandler.py
Normal file
173
Lib/idlelib/configHandler.py
Normal file
|
|
@ -0,0 +1,173 @@
|
||||||
|
##---------------------------------------------------------------------------##
|
||||||
|
##
|
||||||
|
## idle - configuration data handler, based on and replacing IdleConfig.py
|
||||||
|
## elguavas
|
||||||
|
##
|
||||||
|
##---------------------------------------------------------------------------##
|
||||||
|
"""Provides access to configuration information"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from ConfigParser import ConfigParser, NoOptionError, NoSectionError
|
||||||
|
|
||||||
|
class IdleConfParser(ConfigParser):
|
||||||
|
"""
|
||||||
|
A ConfigParser specialised for idle configuration file handling
|
||||||
|
"""
|
||||||
|
def __init__(self, cfgFile, cfgDefaults=None):
|
||||||
|
"""
|
||||||
|
cfgFile - string, fully specified configuration file name
|
||||||
|
"""
|
||||||
|
self.file=cfgFile
|
||||||
|
ConfigParser.__init__(self,defaults=cfgDefaults)
|
||||||
|
|
||||||
|
def GetInt(self, section, option):
|
||||||
|
"""
|
||||||
|
Get an option value as an integer
|
||||||
|
"""
|
||||||
|
return self.Get(section, option, type='int')
|
||||||
|
|
||||||
|
def GetBool(self, section, option):
|
||||||
|
"""
|
||||||
|
Get an option value as a boolean
|
||||||
|
"""
|
||||||
|
return self.Get(section, option, type='bool')
|
||||||
|
|
||||||
|
def Get(self, section, option, raw=0, vars=None, default=None,
|
||||||
|
type=None):
|
||||||
|
"""
|
||||||
|
Get an option value for given section/option or return default.
|
||||||
|
If type is specified, return as type.
|
||||||
|
"""
|
||||||
|
if type=='bool': getVal=self.getbool
|
||||||
|
elif type=='int': getVal=self.getint
|
||||||
|
else: getVal=self.get
|
||||||
|
if self.has_option(section,option):
|
||||||
|
return getVal(section, option, raw, vars)
|
||||||
|
else:
|
||||||
|
return default
|
||||||
|
|
||||||
|
def GetSectionList(self):
|
||||||
|
# only provided for consistency
|
||||||
|
return self.sections()
|
||||||
|
|
||||||
|
def GetOptionList(self,section):
|
||||||
|
"""
|
||||||
|
Get an option list for given section
|
||||||
|
"""
|
||||||
|
if self.has_section:
|
||||||
|
return self.options(section)
|
||||||
|
else: #return a default value
|
||||||
|
return []
|
||||||
|
|
||||||
|
def GetHighlight(self, theme, element):
|
||||||
|
fore = self.Get(theme, element + "-foreground")
|
||||||
|
back = self.Get(theme, element + "-background")
|
||||||
|
style = self.Ge(theme, element + "-fontStyle", default='')
|
||||||
|
return {"fg": fore,
|
||||||
|
"bg": back,
|
||||||
|
"fStyle": style}
|
||||||
|
|
||||||
|
def Load(self):
|
||||||
|
"""
|
||||||
|
Load the configuration file from disk
|
||||||
|
"""
|
||||||
|
self.read(self.file)
|
||||||
|
|
||||||
|
class IdleUserConfParser(IdleConfParser):
|
||||||
|
"""
|
||||||
|
IdleConfigParser specialised for user configuration handling
|
||||||
|
"""
|
||||||
|
def Save(self):
|
||||||
|
"""
|
||||||
|
write loaded user configuration file back to disk
|
||||||
|
"""
|
||||||
|
# this is a user config, it can be written to disk
|
||||||
|
self.write()
|
||||||
|
|
||||||
|
class IdleConf:
|
||||||
|
"""
|
||||||
|
holds config parsers for all idle config files:
|
||||||
|
default config files
|
||||||
|
(idle install dir)/config-main.def
|
||||||
|
(idle install dir)/config-extensions.def
|
||||||
|
(idle install dir)/config-highlight.def
|
||||||
|
(idle install dir)/config-keys.def
|
||||||
|
user config files
|
||||||
|
(user home dir)/.idlerc/idle-main.cfg
|
||||||
|
(user home dir)/.idlerc/idle-extensions.cfg
|
||||||
|
(user home dir)/.idlerc/idle-highlight.cfg
|
||||||
|
(user home dir)/.idlerc/idle-keys.cfg
|
||||||
|
"""
|
||||||
|
def __init__(self):
|
||||||
|
self.defaultCfg={}
|
||||||
|
self.userCfg={}
|
||||||
|
self.cfg={}
|
||||||
|
self.CreateConfigHandlers()
|
||||||
|
self.LoadCfgFiles()
|
||||||
|
#self.LoadCfg()
|
||||||
|
|
||||||
|
def CreateConfigHandlers(self):
|
||||||
|
"""
|
||||||
|
set up a dictionary config parsers for default and user
|
||||||
|
configurations respectively
|
||||||
|
"""
|
||||||
|
#build idle install path
|
||||||
|
if __name__ != '__main__': # we were imported
|
||||||
|
idledir=os.path.dirname(__file__)
|
||||||
|
else: # we were exec'ed (for testing only)
|
||||||
|
idledir=os.path.abspath(sys.path[0])
|
||||||
|
#print idledir
|
||||||
|
try: #build user home path
|
||||||
|
userdir = os.environ['HOME'] #real home directory
|
||||||
|
except KeyError:
|
||||||
|
userdir = os.getcwd() #hack for os'es without real homedirs
|
||||||
|
userdir=os.path.join(userdir,'.idlerc')
|
||||||
|
#print userdir
|
||||||
|
if not os.path.exists(userdir):
|
||||||
|
os.mkdir(userdir)
|
||||||
|
configTypes=('main','extensions','highlight','keys')
|
||||||
|
defCfgFiles={}
|
||||||
|
usrCfgFiles={}
|
||||||
|
for cfgType in configTypes: #build config file names
|
||||||
|
defCfgFiles[cfgType]=os.path.join(idledir,'config-'+cfgType+'.def')
|
||||||
|
usrCfgFiles[cfgType]=os.path.join(userdir,'idle-'+cfgType+'.cfg')
|
||||||
|
for cfgType in configTypes: #create config parsers
|
||||||
|
self.defaultCfg[cfgType]=IdleConfParser(defCfgFiles[cfgType])
|
||||||
|
self.userCfg[cfgType]=IdleUserConfParser(usrCfgFiles[cfgType])
|
||||||
|
|
||||||
|
def LoadCfgFiles(self):
|
||||||
|
"""
|
||||||
|
load all configuration files.
|
||||||
|
"""
|
||||||
|
for key in self.defaultCfg.keys():
|
||||||
|
self.defaultCfg[key].Load()
|
||||||
|
self.userCfg[key].Load() #same keys
|
||||||
|
|
||||||
|
def SaveUserCfgFiles(self):
|
||||||
|
"""
|
||||||
|
write all loaded user configuration files back to disk
|
||||||
|
"""
|
||||||
|
for key in self.userCfg.keys():
|
||||||
|
self.userCfg[key].Save()
|
||||||
|
|
||||||
|
idleConf=IdleConf()
|
||||||
|
|
||||||
|
### module test
|
||||||
|
if __name__ == '__main__':
|
||||||
|
def dumpCfg(cfg):
|
||||||
|
print '\n',cfg,'\n'
|
||||||
|
for key in cfg.keys():
|
||||||
|
sections=cfg[key].sections()
|
||||||
|
print key
|
||||||
|
print sections
|
||||||
|
for section in sections:
|
||||||
|
options=cfg[key].options(section)
|
||||||
|
print section
|
||||||
|
print options
|
||||||
|
for option in options:
|
||||||
|
print option, '=', cfg[key].Get(section,option)
|
||||||
|
dumpCfg(idleConf.defaultCfg)
|
||||||
|
dumpCfg(idleConf.userCfg)
|
||||||
|
print idleConf.userCfg['main'].Get('Theme','name')
|
||||||
|
#print idleConf.userCfg['highlight'].GetDefHighlight('Foo','normal')
|
||||||
Loading…
Add table
Add a link
Reference in a new issue