[Idle-dev] CVS: idle config-extensions.def,NONE,1.1 config-highlight.def,NONE,1.1 config-keys.def,NONE,1.1 config-main.def,NONE,1.1 configHandler.py,NONE,1.1 configDialog.py,1.9,1.10
Stephen M. Gava
elguavas@users.sourceforge.net
Mon, 24 Sep 2001 02:43:20 -0700
Update of /cvsroot/idlefork/idle
In directory usw-pr-cvs1:/tmp/cvs-serv24813
Modified Files:
configDialog.py
Added Files:
config-extensions.def config-highlight.def config-keys.def
config-main.def configHandler.py
Log Message:
start of new config handling stuff
--- NEW FILE: config-extensions.def ---
# 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
--- NEW FILE: config-highlight.def ---
# 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
--- NEW FILE: config-keys.def ---
# 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>'
--- NEW FILE: config-main.def ---
# 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=
--- NEW FILE: configHandler.py ---
##---------------------------------------------------------------------------##
##
## 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')
Index: configDialog.py
===================================================================
RCS file: /cvsroot/idlefork/idle/configDialog.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** configDialog.py 2001/08/13 04:36:58 1.9
--- configDialog.py 2001/09/24 09:43:17 1.10
***************
*** 11,15 ****
import tkMessageBox, tkColorChooser, tkFont
! import IdleConf
class ConfigDialog(Toplevel):
--- 11,15 ----
import tkMessageBox, tkColorChooser, tkFont
! from configHandler import idleConf
class ConfigDialog(Toplevel):
***************
*** 25,32 ****
self.geometry("+%d+%d" % (parent.winfo_rootx()+20,
parent.winfo_rooty()+30))
! self.LoadConfig()
! #elguavas - config placeholders til config stuff completed
! self.bg=self.cget('bg')
! self.fg=None
self.CreateWidgets()
--- 25,29 ----
self.geometry("+%d+%d" % (parent.winfo_rootx()+20,
parent.winfo_rooty()+30))
! #self.LoadConfig()
self.CreateWidgets()
***************
*** 46,62 ****
self.bind('<Alt-k>',self.ChangePageBinding)
self.bind('<Alt-g>',self.ChangePageBinding)
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):
self.destroy()
--- 43,49 ----
self.bind('<Alt-k>',self.ChangePageBinding)
self.bind('<Alt-g>',self.ChangePageBinding)
+ #self.LoadOptMenuHighlightTarget()
self.wait_window()
def Cancel(self):
self.destroy()
***************
*** 135,149 ****
self.labelTestSample.update()
! 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 __SetFontSample(self,event):
self.newFont.config(size=self.fontSize.get(),weight=NORMAL,
family=self.listFontName.get(self.listFontName.curselection()[0]))
--- 122,126 ----
self.labelTestSample.update()
! def SetFontSample(self,event):
self.newFont.config(size=self.fontSize.get(),weight=NORMAL,
family=self.listFontName.get(self.listFontName.curselection()[0]))
***************
*** 168,171 ****
--- 145,149 ----
self.pageButtons=[]
buttonValue=0
+ buttonSelColour=framePageButtons.cget('bg')
for name in pageButtonNames:
buttonFrame=Frame(framePageButtons,borderwidth=2,relief=RIDGE)
***************
*** 174,178 ****
value=buttonValue,padx=5,pady=5,takefocus=FALSE,underline=0,
indicatoron=FALSE,highlightthickness=0,variable=self.pageNum,
! selectcolor=self.bg,borderwidth=0,text=name)
button.pack()
button.lift()
--- 152,156 ----
value=buttonValue,padx=5,pady=5,takefocus=FALSE,underline=0,
indicatoron=FALSE,highlightthickness=0,variable=self.pageNum,
! selectcolor=buttonSelColour,borderwidth=0,text=name)
button.pack()
button.lift()
***************
*** 217,223 ****
self.listFontName=Listbox(frameFontName,height=5,takefocus=FALSE,
exportselection=FALSE)
! self.listFontName.bind('<<ListboxSelect>>',self.__SetFontSample)
scrollFont=Scrollbar(frameFontName)
! self.__LoadFontList()
scrollFont.config(command=self.listFontName.yview)
self.listFontName.config(yscrollcommand=scrollFont.set)
--- 195,201 ----
self.listFontName=Listbox(frameFontName,height=5,takefocus=FALSE,
exportselection=FALSE)
! self.listFontName.bind('<<ListboxSelect>>',self.SetFontSample)
scrollFont=Scrollbar(frameFontName)
! self.LoadFontList()
scrollFont.config(command=self.listFontName.yview)
self.listFontName.config(yscrollcommand=scrollFont.set)
***************
*** 225,235 ****
sizes=('10','11','12','13','14','16','18','20','22')
args=(frameFontSize,self.fontSize)+sizes
! keyArgs={'command':self.__SetFontSample}
optFontSize=apply(OptionMenu,args,keyArgs)
! #optFontSize.bind('<<MenuSelect>>',self.__SetFontSample)
! frameFontSample=Frame(frameFont,relief=SOLID,borderwidth=1,
! bg=self.workingTestColours['Foo-Bg'])
! self.labelFontSample=Label(frameFontSample,bg=self.workingTestColours['Foo-Bg'],
! fg='#000000',text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]',
justify=LEFT,font=self.newFont)
#frameIndent
--- 203,212 ----
sizes=('10','11','12','13','14','16','18','20','22')
args=(frameFontSize,self.fontSize)+sizes
! keyArgs={'command':self.SetFontSample}
optFontSize=apply(OptionMenu,args,keyArgs)
! #optFontSize.bind('<<MenuSelect>>',self.SetFontSample)
! frameFontSample=Frame(frameFont,relief=SOLID,borderwidth=1)
! self.labelFontSample=Label(frameFontSample,
! text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]',
justify=LEFT,font=self.newFont)
#frameIndent
***************
*** 300,315 ****
frameTheme=Frame(frame,borderwidth=2,relief=GROOVE)
#frameCustom
! frameTarget=Frame(frameCustom)
! self.frameHighlightSample=Frame(frameCustom,relief=SOLID,borderwidth=1,
! bg=self.workingTestColours['Foo-Bg'],cursor='hand2')
frameSet=Frame(frameCustom)
! self.frameColourSet=Frame(frameSet,relief=SOLID,borderwidth=1,
! bg=self.workingTestColours['Foo-Bg'])
frameFontSet=Frame(frameSet)
labelCustomTitle=Label(frameCustom,text='Set Custom Highlighting')
! labelTargetTitle=Label(frameTarget,text='for : ')
! optMenuTarget=OptionMenu(frameTarget,
self.highlightTarget,'normal text background','test target interface item 2')
- self.highlightTarget.set('normal text background')
buttonSetColour=Button(self.frameColourSet,text='Set Colour',
command=self.GetColour)
--- 277,290 ----
frameTheme=Frame(frame,borderwidth=2,relief=GROOVE)
#frameCustom
! self.frameHighlightTarget=Frame(frameCustom)
! self.frameHighlightSample=Frame(frameCustom,relief=SOLID,
! borderwidth=1,cursor='hand2')
frameSet=Frame(frameCustom)
! self.frameColourSet=Frame(frameSet,relief=SOLID,borderwidth=1)
frameFontSet=Frame(frameSet)
labelCustomTitle=Label(frameCustom,text='Set Custom Highlighting')
! labelTargetTitle=Label(self.frameHighlightTarget,text='for : ')
! self.optMenuHighlightTarget=OptionMenu(self.frameHighlightTarget,
self.highlightTarget,'normal text background','test target interface item 2')
buttonSetColour=Button(self.frameColourSet,text='Set Colour',
command=self.GetColour)
***************
*** 323,328 ****
'def Ahem(foo,bar):\n '+
'"""'+'doc hazard'+'"""'+
! '\n test=foo\n text=bar\n return',
! bg=self.workingTestColours['Foo-Bg'])
buttonSaveCustomTheme=Button(frameCustom,
text='Save as a Custom Theme')
--- 298,302 ----
'def Ahem(foo,bar):\n '+
'"""'+'doc hazard'+'"""'+
! '\n test=foo\n text=bar\n return')
buttonSaveCustomTheme=Button(frameCustom,
text='Save as a Custom Theme')
***************
*** 351,355 ****
#frameCustom
labelCustomTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
! frameTarget.pack(side=TOP,padx=5,pady=5,fill=X)
self.frameHighlightSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
frameSet.pack(side=TOP,fill=X)
--- 325,329 ----
#frameCustom
labelCustomTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
! self.frameHighlightTarget.pack(side=TOP,padx=5,pady=5,fill=X)
self.frameHighlightSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
frameSet.pack(side=TOP,fill=X)
***************
*** 357,361 ****
frameFontSet.pack(side=RIGHT,padx=5,pady=5,anchor=W)
labelTargetTitle.pack(side=LEFT,anchor=E)
! optMenuTarget.pack(side=RIGHT,anchor=W,expand=TRUE,fill=X)
buttonSetColour.pack(expand=TRUE,fill=BOTH,padx=10,pady=10)
labelFontTitle.pack(side=TOP,anchor=W)
--- 331,335 ----
frameFontSet.pack(side=RIGHT,padx=5,pady=5,anchor=W)
labelTargetTitle.pack(side=LEFT,anchor=E)
! self.optMenuHighlightTarget.pack(side=RIGHT,anchor=W,expand=TRUE,fill=X)
buttonSetColour.pack(expand=TRUE,fill=BOTH,padx=10,pady=10)
labelFontTitle.pack(side=TOP,anchor=W)
***************
*** 529,532 ****
--- 503,568 ----
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__':