diff options
author | Steven M. Gava <elguavas@python.net> | 2002-01-03 12:05:17 (GMT) |
---|---|---|
committer | Steven M. Gava <elguavas@python.net> | 2002-01-03 12:05:17 (GMT) |
commit | ad4f532f6532cc099ba5665e3553394db907796c (patch) | |
tree | ceea0cb24c3167aa1074fbed4b00e3a746f844af /Lib/idlelib | |
parent | 767a7ee9ad3a84b20375f557f3363636d116a643 (diff) | |
download | cpython-ad4f532f6532cc099ba5665e3553394db907796c.zip cpython-ad4f532f6532cc099ba5665e3553394db907796c.tar.gz cpython-ad4f532f6532cc099ba5665e3553394db907796c.tar.bz2 |
further development of highlighting and editor preference handling,
plus misc fixes cleanups for new config system
Diffstat (limited to 'Lib/idlelib')
-rw-r--r-- | Lib/idlelib/config-highlight.def | 60 | ||||
-rw-r--r-- | Lib/idlelib/config-main.def | 4 | ||||
-rw-r--r-- | Lib/idlelib/config.txt | 2 | ||||
-rw-r--r-- | Lib/idlelib/configDialog.py | 45 | ||||
-rw-r--r-- | Lib/idlelib/configHandler.py | 106 |
5 files changed, 153 insertions, 64 deletions
diff --git a/Lib/idlelib/config-highlight.def b/Lib/idlelib/config-highlight.def index 83c9807..821b2f0 100644 --- a/Lib/idlelib/config-highlight.def +++ b/Lib/idlelib/config-highlight.def @@ -1,56 +1,82 @@ # 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 +[IDLE Classic] +normal-foreground= #000000 +normal-background= #ffffff normal-fontStyle= normal keyword-foreground= #ff7700 +keyword-background= #ffffff keyword-fontStyle= normal comment-foreground= #dd0000 +comment-background= #ffffff comment-fontStyle= normal string-foreground= #00aa00 +string-background= #ffffff string-fontStyle= normal definition-foreground= #0000ff +definition-background= #ffffff definition-fontStyle= normal -hilite-foreground= #000068 -hilite-background= #006868 +hilite-foreground= #ffffff +hilite-background= gray hilite-fontStyle= normal break-foreground= #ff7777 +break-background= #ffffff break-fontStyle= normal -hit-background= #000000 hit-foreground= #ffffff +hit-background= #000000 hit-fontStyle= normal -cursor-foreround= black +error-foreground= #000000 error-background= #ff7777 +#cursor (only foreground can be set) +cursor-foreground= black #shell window stdout-foreground= blue +stdout-background= #ffffff stdout-fontStyle= normal stderr-foreground= red +stderr-background= #ffffff stderr-fontStyle= normal console-foreground= #770000 +console-background= #ffffff console-fontStyle= normal -[IDLE Classic New] -normal-foreground= black -normal-background= white -normal-fontStyle= normal +[IDLE New] +bold-foreground= #000000 +bold-background= #ffffff +bold-fontStyle= bold keyword-foreground= #ff7700 +keyword-background= #ffffff keyword-fontStyle= bold comment-foreground= #dd0000 -comment-fontStyle= italic +comment-background= #ffffff +comment-fontStyle= bold string-foreground= #00aa00 -string-fontStyle= normal +string-background= #ffffff +string-fontStyle= bold definition-foreground= #0000ff +definition-background= #ffffff definition-fontStyle= bold -hilite-foreground= #000068 -hilite-background= #006868 +hilite-foreground= #ffffff +hilite-background= gray +hilite-fontStyle= bold break-foreground= #ff7777 -hit-background= #000000 +break-background= #ffffff +break-fontStyle= bold hit-foreground= #ffffff -cursor-foreground= black +hit-background= #000000 +hit-fontStyle= bold +error-foreground= #000000 error-background= #ff7777 +#cursor (only foreground can be set) +cursor-foreground= black #shell window stdout-foreground= blue +stdout-background= #ffffff +stdout-fontStyle= bold stderr-foreground= red +stderr-background= #ffffff +stderr-fontStyle= bold console-foreground= #770000 +console-background= #ffffff +console-fontStyle= bold diff --git a/Lib/idlelib/config-main.def b/Lib/idlelib/config-main.def index dca0e54..fbb760f 100644 --- a/Lib/idlelib/config-main.def +++ b/Lib/idlelib/config-main.def @@ -48,7 +48,7 @@ python="_Python Documentation","" [EditorWindow] editor-on-startup= 0 width= 80 -height= 24 +height= 30 font= courier font-size= 12 @@ -59,7 +59,7 @@ tab-cols= 4 [Theme] default= 1 -name= IDLE Classic New +name= IDLE Classic [Keys] default= 1 diff --git a/Lib/idlelib/config.txt b/Lib/idlelib/config.txt index 223b302..11adae1 100644 --- a/Lib/idlelib/config.txt +++ b/Lib/idlelib/config.txt @@ -49,7 +49,7 @@ cursor-background= black [FormatParagraph] -[ZoomHeight] +#[ZoomHeight] #[ScriptBinding] # disabled in favor of ExecBinding diff --git a/Lib/idlelib/configDialog.py b/Lib/idlelib/configDialog.py index b131eeb..6c88d60 100644 --- a/Lib/idlelib/configDialog.py +++ b/Lib/idlelib/configDialog.py @@ -22,18 +22,18 @@ class ConfigDialog(Toplevel): #The second value is the display name list sort index. #The third value indicates whether the element can have a foreground #or background colour or both. - self.themeElements={'Normal Text':('normal','00','both'), - 'Python Keywords':('keyword','01','both'), - 'Python Definitions':('definition','02','both'), - 'Python Comments':('comment','03','both'), - 'Python Strings':('string','04','both'), - 'Selected Text':('hilite','05','both'), - 'Found Text':('hit','06','both'), - 'Cursor':('cursor','07','fg'), - 'Error Background':('error','08','bg'), - 'Shell Foreground':('console','09','fg'), - 'Shell Stdout Foreground':('stdout','10','fg'), - 'Shell Stderr Foreground':('stderr','11','fg')} + self.themeElements={'Normal Text':('normal','00'), + 'Python Keywords':('keyword','01'), + 'Python Definitions':('definition','02'), + 'Python Comments':('comment','03'), + 'Python Strings':('string','04'), + 'Selected Text':('hilite','05'), + 'Found Text':('hit','06'), + 'Cursor':('cursor','07'), + 'Error Text':('error','08'), + 'Shell Normal Text':('console','09'), + 'Shell Stdout Text':('stdout','10'), + 'Shell Stderr Text':('stderr','11')} self.CreateWidgets() self.resizable(height=FALSE,width=FALSE) self.transient(parent) @@ -115,19 +115,14 @@ class ConfigDialog(Toplevel): self.SetHighlightTarget() def SetHighlightTarget(self): - colourPlane=self.themeElements[self.highlightTarget.get()][2] - if colourPlane == 'bg': + if self.highlightTarget.get()=='Cursor': #bg not possible self.radioFg.config(state=DISABLED) self.radioBg.config(state=DISABLED) - self.fgHilite.set(0) - elif colourPlane == 'fg': + self.fgHilite.set(1) + else: #both fg and bg can be set self.radioFg.config(state=DISABLED) self.radioBg.config(state=DISABLED) self.fgHilite.set(1) - elif colourPlane == 'both': - self.radioFg.config(state=NORMAL) - self.radioBg.config(state=NORMAL) - self.fgHilite.set(1) #default to setting foreground attribute self.SetColourSample() def SetColourSampleBinding(self,*args): @@ -144,6 +139,7 @@ class ConfigDialog(Toplevel): def CreateWidgets(self): self.tabPages = TabPageSet(self, pageNames=['Fonts/Tabs','Highlighting','Keys','General']) + self.tabPages.ChangePage()#activates default (first) page frameActionButtons = Frame(self) #action buttons self.buttonHelp = Button(frameActionButtons,text='Help', @@ -498,9 +494,12 @@ class ConfigDialog(Toplevel): theme=self.customTheme.get() for element in self.themeElements.keys(): colours=idleConf.GetHighlight(theme, self.themeElements[element][0]) + if element=='Cursor': #cursor sample needs special painting + colours['background']=idleConf.GetHighlight(theme, + 'normal-text', fgBg='bg') apply(self.textHighlightSample.tag_config, (self.themeElements[element][0],),colours) - + def LoadFontCfg(self): ##base editor font selection list fonts=list(tkFont.families(self)) @@ -538,7 +537,7 @@ class ConfigDialog(Toplevel): self.themeIsBuiltin.set(idleConf.GetOption('main','Theme','default', type='int',default=1)) ##currently set theme - currentOption=idleConf.GetOption('main','Theme','name') + currentOption=idleConf.CurrentTheme() ##load available theme option menus if self.themeIsBuiltin.get(): #default theme selected itemList=idleConf.GetSectionList('default','highlight') @@ -575,7 +574,7 @@ class ConfigDialog(Toplevel): self.keysAreDefault.set(idleConf.GetOption('main','Keys','default', type='int',default=1)) ##currently set keys - currentOption=idleConf.GetOption('main','Keys','name') + currentOption=idleConf.CurrentKeys() ##load available keyset option menus if self.keysAreDefault.get(): #default theme selected itemList=idleConf.GetSectionList('default','keys') diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py index f1fbd8d..b84fc4e 100644 --- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -1,13 +1,13 @@ -##---------------------------------------------------------------------------## -## -## idle - configuration data handler, based on and replacing IdleConfig.py -## elguavas -## -##---------------------------------------------------------------------------## -""" -Provides access to stored idle configuration information """ +Provides access to stored idle configuration information. +Throughout this module there is an emphasis on returning useable defaults if +there is a problem returning a requested configuration value back to idle. +This is to allow idle to continue to function in spite of errors in the +retrieval of config information. When a default is returned instead of a +requested config value, a message is printed to stderr to aid in +configuration problem notification and resolution. +""" import os import sys from ConfigParser import ConfigParser, NoOptionError, NoSectionError @@ -23,10 +23,11 @@ class IdleConfParser(ConfigParser): self.file=cfgFile ConfigParser.__init__(self,defaults=cfgDefaults) - def Get(self, section, option, default=None, type=None): + def Get(self, section, option, type=None): #,default=None) """ Get an option value for given section/option or return default. If type is specified, return as type. + If a default is returned a warning is printed to stderr. """ if type=='bool': getVal=self.getboolean @@ -37,8 +38,14 @@ class IdleConfParser(ConfigParser): if self.has_option(section,option): #return getVal(section, option, raw, vars) return getVal(section, option) - else: - return default +# #the following handled in IdleConf.GetOption instead +# else: +# warning=('\n Warning: configHandler.py - IdleConfParser.Get -\n'+ +# ' problem retrieving configration option '+`option`+'\n'+ +# ' from section '+`section`+'.\n'+ +# ' returning default value: '+`default`+'\n') +# sys.stderr.write(warning) +# return default def GetOptionList(self,section): """ @@ -75,10 +82,10 @@ class IdleConf: (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 + (user home dir)/.idlerc/config-main.cfg + (user home dir)/.idlerc/config-extensions.cfg + (user home dir)/.idlerc/config-highlight.cfg + (user home dir)/.idlerc/config-keys.cfg """ def __init__(self): self.defaultCfg={} @@ -90,7 +97,7 @@ class IdleConf: def CreateConfigHandlers(self): """ - set up a dictionary config parsers for default and user + set up a dictionary of config parsers for default and user configurations respectively """ #build idle install path @@ -112,7 +119,7 @@ class IdleConf: 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') + usrCfgFiles[cfgType]=os.path.join(userdir,'config-'+cfgType+'.cfg') for cfgType in configTypes: #create config parsers self.defaultCfg[cfgType]=IdleConfParser(defCfgFiles[cfgType]) self.userCfg[cfgType]=IdleUserConfParser(usrCfgFiles[cfgType]) @@ -132,6 +139,11 @@ class IdleConf: elif self.defaultCfg[configType].has_option(section,option): return self.defaultCfg[configType].Get(section, option, type=type) else: + warning=('\n Warning: configHandler.py - IdleConf.GetOption -\n'+ + ' problem retrieving configration option '+`option`+'\n'+ + ' from section '+`section`+'.\n'+ + ' returning default value: '+`default`+'\n') + sys.stderr.write(warning) return default def GetSectionList(self, configSet, configType): @@ -152,7 +164,13 @@ class IdleConf: return cfgParser.sections() - def GetHighlight(self, theme, element): + def GetHighlight(self, theme, element, fgBg=None): + """ + return individual highlighting theme elements. + fgBg - string ('fg'or'bg') or None, if None return a dictionary + containing fg and bg colours (appropriate for passing to Tkinter in, + e.g., a tag_config call), otherwise fg or bg colour only as specified. + """ #get some fallback defaults defaultFg=self.GetOption('highlight', theme, 'normal' + "-foreground", default='#000000') @@ -160,12 +178,25 @@ class IdleConf: default='#ffffff') #try for requested element colours fore = self.GetOption('highlight', theme, element + "-foreground") - back = self.GetOption('highlight', theme, element + "-background") + back = None + if element == 'cursor': #there is no config value for cursor bg + back = None + else: + back = self.GetOption('highlight', theme, element + "-background") #fall back if required if not fore: fore=defaultFg if not back: back=defaultBg - return {"foreground": fore, - "background": back} + highlight={"foreground": fore,"background": back} + if not fgBg: #return dict of both colours + return highlight + else: #return specified colour only + if fgBg == 'fg': + return highlight["foreground"] + if fgBg == 'bg': + return highlight["background"] + else: + raise 'Invalid fgBg specified' + def GetTheme(self, name=None): """ @@ -174,6 +205,39 @@ class IdleConf: """ pass + def CurrentTheme(self): + """ + Returns the name of the currently active theme + """ + return self.GetOption('main','Theme','name') + + + def CurrentKeys(self): + """ + Returns the name of the currently active theme + """ + return self.GetOption('main','Keys','name') + + def GetExtensions(self, activeOnly=1): + """ + Gets a list of all idle extensions declared in the config files. + activeOnly - boolean, if true only return active (enabled) extensions + """ + extns=self.GetSectionList('default','extensions') + userExtns=self.GetSectionList('user','extensions') + for extn in userExtns: + if extn not in extns: #user has added own extension + extns.append(extn) + if activeOnly: + activeExtns=[] + for extn in extns: + if self.GetOption('extensions',extn,'enable',default=1,type='bool'): + #the extension is enabled + activeExtns.append(extn) + return activeExtns + else: + return extns + def GetKeys(self, keySetName=None): """ returns the requested keybindings, with fallbacks if required. |