Steven M. Gava | 2a63a07 | 2001-10-26 06:50:54 +0000 | [diff] [blame] | 1 | """ |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 2 | Provides access to stored idle configuration information. |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 3 | """ |
Steven M. Gava | c597640 | 2002-01-04 03:06:08 +0000 | [diff] [blame] | 4 | # Throughout this module there is an emphasis on returning useable defaults |
| 5 | # when a problem occurs in returning a requested configuration value back to |
| 6 | # idle. This is to allow idle to continue to function in spite of errors in |
| 7 | # the retrieval of config information. When a default is returned instead of |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 8 | # a requested config value, a message is printed to stderr to aid in |
| 9 | # configuration problem notification and resolution. |
Steven M. Gava | c597640 | 2002-01-04 03:06:08 +0000 | [diff] [blame] | 10 | |
Steven M. Gava | 085eb1b | 2002-02-05 04:52:32 +0000 | [diff] [blame] | 11 | import os, sys, string |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 12 | from ConfigParser import ConfigParser, NoOptionError, NoSectionError |
| 13 | |
Neal Norwitz | 5b0b00f | 2002-11-30 19:10:19 +0000 | [diff] [blame] | 14 | class InvalidConfigType(Exception): pass |
| 15 | class InvalidConfigSet(Exception): pass |
| 16 | class InvalidFgBg(Exception): pass |
| 17 | class InvalidTheme(Exception): pass |
| 18 | |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 19 | class IdleConfParser(ConfigParser): |
| 20 | """ |
| 21 | A ConfigParser specialised for idle configuration file handling |
| 22 | """ |
| 23 | def __init__(self, cfgFile, cfgDefaults=None): |
| 24 | """ |
| 25 | cfgFile - string, fully specified configuration file name |
| 26 | """ |
| 27 | self.file=cfgFile |
| 28 | ConfigParser.__init__(self,defaults=cfgDefaults) |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 29 | |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 30 | def Get(self, section, option, type=None, default=None): |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 31 | """ |
| 32 | Get an option value for given section/option or return default. |
| 33 | If type is specified, return as type. |
| 34 | """ |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 35 | if type=='bool': |
Steven M. Gava | 41a8532 | 2001-10-29 08:05:34 +0000 | [diff] [blame] | 36 | getVal=self.getboolean |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 37 | elif type=='int': |
Steven M. Gava | 41a8532 | 2001-10-29 08:05:34 +0000 | [diff] [blame] | 38 | getVal=self.getint |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 39 | else: |
Steven M. Gava | 41a8532 | 2001-10-29 08:05:34 +0000 | [diff] [blame] | 40 | getVal=self.get |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 41 | if self.has_option(section,option): |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 42 | #return getVal(section, option, raw, vars, default) |
Steven M. Gava | 429a86a | 2001-10-23 10:42:12 +0000 | [diff] [blame] | 43 | return getVal(section, option) |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 44 | else: |
| 45 | return default |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 46 | |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 47 | def GetOptionList(self,section): |
| 48 | """ |
| 49 | Get an option list for given section |
| 50 | """ |
Steven M. Gava | 085eb1b | 2002-02-05 04:52:32 +0000 | [diff] [blame] | 51 | if self.has_section(section): |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 52 | return self.options(section) |
| 53 | else: #return a default value |
| 54 | return [] |
| 55 | |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 56 | def Load(self): |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 57 | """ |
| 58 | Load the configuration file from disk |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 59 | """ |
| 60 | self.read(self.file) |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 61 | |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 62 | class IdleUserConfParser(IdleConfParser): |
| 63 | """ |
Steven M. Gava | 2d7bb3f | 2002-01-29 08:35:29 +0000 | [diff] [blame] | 64 | IdleConfigParser specialised for user configuration handling. |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 65 | """ |
Steven M. Gava | 2d7bb3f | 2002-01-29 08:35:29 +0000 | [diff] [blame] | 66 | |
| 67 | def AddSection(self,section): |
| 68 | """ |
| 69 | if section doesn't exist, add it |
| 70 | """ |
| 71 | if not self.has_section(section): |
| 72 | self.add_section(section) |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 73 | |
Steven M. Gava | 2d7bb3f | 2002-01-29 08:35:29 +0000 | [diff] [blame] | 74 | def RemoveEmptySections(self): |
| 75 | """ |
| 76 | remove any sections that have no options |
| 77 | """ |
| 78 | for section in self.sections(): |
| 79 | if not self.GetOptionList(section): |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 80 | self.remove_section(section) |
| 81 | |
Steven M. Gava | 2d7bb3f | 2002-01-29 08:35:29 +0000 | [diff] [blame] | 82 | def IsEmpty(self): |
| 83 | """ |
| 84 | Remove empty sections and then return 1 if parser has no sections |
| 85 | left, else return 0. |
| 86 | """ |
| 87 | self.RemoveEmptySections() |
| 88 | if self.sections(): |
| 89 | return 0 |
| 90 | else: |
| 91 | return 1 |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 92 | |
Steven M. Gava | 2d7bb3f | 2002-01-29 08:35:29 +0000 | [diff] [blame] | 93 | def RemoveOption(self,section,option): |
| 94 | """ |
| 95 | If section/option exists, remove it. |
| 96 | Returns 1 if option was removed, 0 otherwise. |
| 97 | """ |
| 98 | if self.has_section(section): |
| 99 | return self.remove_option(section,option) |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 100 | |
Steven M. Gava | 2d7bb3f | 2002-01-29 08:35:29 +0000 | [diff] [blame] | 101 | def SetOption(self,section,option,value): |
| 102 | """ |
| 103 | Sets option to value, adding section if required. |
| 104 | Returns 1 if option was added or changed, otherwise 0. |
| 105 | """ |
| 106 | if self.has_option(section,option): |
| 107 | if self.get(section,option)==value: |
| 108 | return 0 |
| 109 | else: |
| 110 | self.set(section,option,value) |
| 111 | return 1 |
| 112 | else: |
| 113 | if not self.has_section(section): |
| 114 | self.add_section(section) |
| 115 | self.set(section,option,value) |
| 116 | return 1 |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 117 | |
Steven M. Gava | b77d343 | 2002-03-02 07:16:21 +0000 | [diff] [blame] | 118 | def RemoveFile(self): |
| 119 | """ |
| 120 | Removes the user config file from disk if it exists. |
| 121 | """ |
| 122 | if os.path.exists(self.file): |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 123 | os.remove(self.file) |
| 124 | |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 125 | def Save(self): |
| 126 | """ |
Steven M. Gava | 2d7bb3f | 2002-01-29 08:35:29 +0000 | [diff] [blame] | 127 | If config isn't empty, write file to disk. If config is empty, |
| 128 | remove the file from disk if it exists. |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 129 | """ |
Steven M. Gava | 2d7bb3f | 2002-01-29 08:35:29 +0000 | [diff] [blame] | 130 | if not self.IsEmpty(): |
| 131 | cfgFile=open(self.file,'w') |
| 132 | self.write(cfgFile) |
| 133 | else: |
Steven M. Gava | b77d343 | 2002-03-02 07:16:21 +0000 | [diff] [blame] | 134 | self.RemoveFile() |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 135 | |
| 136 | class IdleConf: |
| 137 | """ |
| 138 | holds config parsers for all idle config files: |
| 139 | default config files |
| 140 | (idle install dir)/config-main.def |
| 141 | (idle install dir)/config-extensions.def |
| 142 | (idle install dir)/config-highlight.def |
| 143 | (idle install dir)/config-keys.def |
| 144 | user config files |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 145 | (user home dir)/.idlerc/config-main.cfg |
| 146 | (user home dir)/.idlerc/config-extensions.cfg |
| 147 | (user home dir)/.idlerc/config-highlight.cfg |
| 148 | (user home dir)/.idlerc/config-keys.cfg |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 149 | """ |
| 150 | def __init__(self): |
| 151 | self.defaultCfg={} |
| 152 | self.userCfg={} |
| 153 | self.cfg={} |
| 154 | self.CreateConfigHandlers() |
| 155 | self.LoadCfgFiles() |
| 156 | #self.LoadCfg() |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 157 | |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 158 | def CreateConfigHandlers(self): |
| 159 | """ |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 160 | set up a dictionary of config parsers for default and user |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 161 | configurations respectively |
| 162 | """ |
| 163 | #build idle install path |
| 164 | if __name__ != '__main__': # we were imported |
Steven M. Gava | 7cff66d | 2002-02-01 03:02:37 +0000 | [diff] [blame] | 165 | idleDir=os.path.dirname(__file__) |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 166 | else: # we were exec'ed (for testing only) |
Steven M. Gava | 7cff66d | 2002-02-01 03:02:37 +0000 | [diff] [blame] | 167 | idleDir=os.path.abspath(sys.path[0]) |
| 168 | userDir=self.GetUserCfgDir() |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 169 | configTypes=('main','extensions','highlight','keys') |
| 170 | defCfgFiles={} |
| 171 | usrCfgFiles={} |
| 172 | for cfgType in configTypes: #build config file names |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 173 | defCfgFiles[cfgType]=os.path.join(idleDir,'config-'+cfgType+'.def') |
| 174 | usrCfgFiles[cfgType]=os.path.join(userDir,'config-'+cfgType+'.cfg') |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 175 | for cfgType in configTypes: #create config parsers |
| 176 | self.defaultCfg[cfgType]=IdleConfParser(defCfgFiles[cfgType]) |
| 177 | self.userCfg[cfgType]=IdleUserConfParser(usrCfgFiles[cfgType]) |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 178 | |
Steven M. Gava | 7cff66d | 2002-02-01 03:02:37 +0000 | [diff] [blame] | 179 | def GetUserCfgDir(self): |
| 180 | """ |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 181 | Creates (if required) and returns a filesystem directory for storing |
Steven M. Gava | 7cff66d | 2002-02-01 03:02:37 +0000 | [diff] [blame] | 182 | user config files. |
| 183 | """ |
| 184 | cfgDir='.idlerc' |
| 185 | userDir=os.path.expanduser('~') |
| 186 | if userDir != '~': #'HOME' exists as a key in os.environ |
| 187 | if not os.path.exists(userDir): |
| 188 | warn=('\n Warning: HOME environment variable points to\n '+ |
| 189 | userDir+'\n but the path does not exist.\n') |
| 190 | sys.stderr.write(warn) |
| 191 | userDir='~' |
| 192 | if userDir=='~': #we still don't have a home directory |
| 193 | #traditionally idle has defaulted to os.getcwd(), is this adeqate? |
| 194 | userDir = os.getcwd() #hack for no real homedir |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 195 | userDir=os.path.join(userDir,cfgDir) |
Steven M. Gava | 7cff66d | 2002-02-01 03:02:37 +0000 | [diff] [blame] | 196 | if not os.path.exists(userDir): |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 197 | try: #make the config dir if it doesn't exist yet |
Steven M. Gava | 7cff66d | 2002-02-01 03:02:37 +0000 | [diff] [blame] | 198 | os.mkdir(userDir) |
| 199 | except IOError: |
| 200 | warn=('\n Warning: unable to create user config directory\n '+ |
| 201 | userDir+'\n') |
| 202 | sys.stderr.write(warn) |
| 203 | return userDir |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 204 | |
Steven M. Gava | 2a63a07 | 2001-10-26 06:50:54 +0000 | [diff] [blame] | 205 | def GetOption(self, configType, section, option, default=None, type=None): |
Steven M. Gava | 429a86a | 2001-10-23 10:42:12 +0000 | [diff] [blame] | 206 | """ |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 207 | Get an option value for given config type and given general |
Steven M. Gava | 429a86a | 2001-10-23 10:42:12 +0000 | [diff] [blame] | 208 | configuration section/option or return a default. If type is specified, |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 209 | return as type. Firstly the user configuration is checked, with a |
| 210 | fallback to the default configuration, and a final 'catch all' |
| 211 | fallback to a useable passed-in default if the option isn't present in |
Steven M. Gava | 429a86a | 2001-10-23 10:42:12 +0000 | [diff] [blame] | 212 | either the user or the default configuration. |
| 213 | configType must be one of ('main','extensions','highlight','keys') |
Steven M. Gava | 0cae01c | 2002-01-04 07:53:06 +0000 | [diff] [blame] | 214 | If a default is returned a warning is printed to stderr. |
Steven M. Gava | 429a86a | 2001-10-23 10:42:12 +0000 | [diff] [blame] | 215 | """ |
| 216 | if self.userCfg[configType].has_option(section,option): |
| 217 | return self.userCfg[configType].Get(section, option, type=type) |
| 218 | elif self.defaultCfg[configType].has_option(section,option): |
| 219 | return self.defaultCfg[configType].Get(section, option, type=type) |
Steven M. Gava | 052937f | 2002-02-11 02:20:53 +0000 | [diff] [blame] | 220 | else: #returning default, print warning |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 221 | warning=('\n Warning: configHandler.py - IdleConf.GetOption -\n'+ |
| 222 | ' problem retrieving configration option '+`option`+'\n'+ |
| 223 | ' from section '+`section`+'.\n'+ |
| 224 | ' returning default value: '+`default`+'\n') |
| 225 | sys.stderr.write(warning) |
Steven M. Gava | 429a86a | 2001-10-23 10:42:12 +0000 | [diff] [blame] | 226 | return default |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 227 | |
Steven M. Gava | 2a63a07 | 2001-10-26 06:50:54 +0000 | [diff] [blame] | 228 | def GetSectionList(self, configSet, configType): |
| 229 | """ |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 230 | Get a list of sections from either the user or default config for |
Steven M. Gava | 2a63a07 | 2001-10-26 06:50:54 +0000 | [diff] [blame] | 231 | the given config type. |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 232 | configSet must be either 'user' or 'default' |
Steven M. Gava | 5f28e8f | 2002-01-21 06:38:21 +0000 | [diff] [blame] | 233 | configType must be one of ('main','extensions','highlight','keys') |
Steven M. Gava | 2a63a07 | 2001-10-26 06:50:54 +0000 | [diff] [blame] | 234 | """ |
Steven M. Gava | 5f28e8f | 2002-01-21 06:38:21 +0000 | [diff] [blame] | 235 | if not (configType in ('main','extensions','highlight','keys')): |
Neal Norwitz | 5b0b00f | 2002-11-30 19:10:19 +0000 | [diff] [blame] | 236 | raise InvalidConfigType, 'Invalid configType specified' |
Steven M. Gava | 2a63a07 | 2001-10-26 06:50:54 +0000 | [diff] [blame] | 237 | if configSet == 'user': |
| 238 | cfgParser=self.userCfg[configType] |
| 239 | elif configSet == 'default': |
| 240 | cfgParser=self.defaultCfg[configType] |
| 241 | else: |
Neal Norwitz | 5b0b00f | 2002-11-30 19:10:19 +0000 | [diff] [blame] | 242 | raise InvalidConfigSet, 'Invalid configSet specified' |
Steven M. Gava | 2a63a07 | 2001-10-26 06:50:54 +0000 | [diff] [blame] | 243 | return cfgParser.sections() |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 244 | |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 245 | def GetHighlight(self, theme, element, fgBg=None): |
| 246 | """ |
| 247 | return individual highlighting theme elements. |
| 248 | fgBg - string ('fg'or'bg') or None, if None return a dictionary |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 249 | containing fg and bg colours (appropriate for passing to Tkinter in, |
| 250 | e.g., a tag_config call), otherwise fg or bg colour only as specified. |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 251 | """ |
Steven M. Gava | 9f25e67 | 2002-02-11 02:51:18 +0000 | [diff] [blame] | 252 | if self.defaultCfg['highlight'].has_section(theme): |
| 253 | themeDict=self.GetThemeDict('default',theme) |
| 254 | else: |
| 255 | themeDict=self.GetThemeDict('user',theme) |
| 256 | fore=themeDict[element+'-foreground'] |
| 257 | if element=='cursor': #there is no config value for cursor bg |
| 258 | back=themeDict['normal-background'] |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 259 | else: |
Steven M. Gava | 9f25e67 | 2002-02-11 02:51:18 +0000 | [diff] [blame] | 260 | back=themeDict[element+'-background'] |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 261 | highlight={"foreground": fore,"background": back} |
| 262 | if not fgBg: #return dict of both colours |
| 263 | return highlight |
| 264 | else: #return specified colour only |
| 265 | if fgBg == 'fg': |
| 266 | return highlight["foreground"] |
| 267 | if fgBg == 'bg': |
| 268 | return highlight["background"] |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 269 | else: |
Neal Norwitz | 5b0b00f | 2002-11-30 19:10:19 +0000 | [diff] [blame] | 270 | raise InvalidFgBg, 'Invalid fgBg specified' |
Steven M. Gava | 9f25e67 | 2002-02-11 02:51:18 +0000 | [diff] [blame] | 271 | |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 272 | def GetThemeDict(self,type,themeName): |
Steven M. Gava | 2a63a07 | 2001-10-26 06:50:54 +0000 | [diff] [blame] | 273 | """ |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 274 | type - string, 'default' or 'user' theme type |
| 275 | themeName - string, theme name |
| 276 | Returns a dictionary which holds {option:value} for each element |
| 277 | in the specified theme. Values are loaded over a set of ultimate last |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 278 | fallback defaults to guarantee that all theme elements are present in |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 279 | a newly created theme. |
Steven M. Gava | 2a63a07 | 2001-10-26 06:50:54 +0000 | [diff] [blame] | 280 | """ |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 281 | if type == 'user': |
| 282 | cfgParser=self.userCfg['highlight'] |
| 283 | elif type == 'default': |
| 284 | cfgParser=self.defaultCfg['highlight'] |
| 285 | else: |
Neal Norwitz | 5b0b00f | 2002-11-30 19:10:19 +0000 | [diff] [blame] | 286 | raise InvalidTheme, 'Invalid theme type specified' |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 287 | #foreground and background values are provded for each theme element |
| 288 | #(apart from cursor) even though all these values are not yet used |
| 289 | #by idle, to allow for their use in the future. Default values are |
| 290 | #generally black and white. |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 291 | theme={ 'normal-foreground':'#000000', |
| 292 | 'normal-background':'#ffffff', |
| 293 | 'keyword-foreground':'#000000', |
| 294 | 'keyword-background':'#ffffff', |
| 295 | 'comment-foreground':'#000000', |
| 296 | 'comment-background':'#ffffff', |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 297 | 'string-foreground':'#000000', |
| 298 | 'string-background':'#ffffff', |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 299 | 'definition-foreground':'#000000', |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 300 | 'definition-background':'#ffffff', |
| 301 | 'hilite-foreground':'#000000', |
| 302 | 'hilite-background':'gray', |
| 303 | 'break-foreground':'#ffffff', |
| 304 | 'break-background':'#000000', |
| 305 | 'hit-foreground':'#ffffff', |
| 306 | 'hit-background':'#000000', |
| 307 | 'error-foreground':'#ffffff', |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 308 | 'error-background':'#000000', |
| 309 | #cursor (only foreground can be set) |
| 310 | 'cursor-foreground':'#000000', |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 311 | #shell window |
| 312 | 'stdout-foreground':'#000000', |
| 313 | 'stdout-background':'#ffffff', |
| 314 | 'stderr-foreground':'#000000', |
| 315 | 'stderr-background':'#ffffff', |
| 316 | 'console-foreground':'#000000', |
| 317 | 'console-background':'#ffffff' } |
| 318 | for element in theme.keys(): |
Steven M. Gava | 052937f | 2002-02-11 02:20:53 +0000 | [diff] [blame] | 319 | if not cfgParser.has_option(themeName,element): |
| 320 | #we are going to return a default, print warning |
| 321 | warning=('\n Warning: configHandler.py - IdleConf.GetThemeDict'+ |
| 322 | ' -\n problem retrieving theme element '+`element`+ |
| 323 | '\n from theme '+`themeName`+'.\n'+ |
| 324 | ' returning default value: '+`theme[element]`+'\n') |
| 325 | sys.stderr.write(warning) |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 326 | colour=cfgParser.Get(themeName,element,default=theme[element]) |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 327 | theme[element]=colour |
| 328 | return theme |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 329 | |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 330 | def CurrentTheme(self): |
| 331 | """ |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 332 | Returns the name of the currently active theme |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 333 | """ |
Steven M. Gava | 0cae01c | 2002-01-04 07:53:06 +0000 | [diff] [blame] | 334 | return self.GetOption('main','Theme','name',default='') |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 335 | |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 336 | def CurrentKeys(self): |
| 337 | """ |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 338 | Returns the name of the currently active key set |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 339 | """ |
Steven M. Gava | 0cae01c | 2002-01-04 07:53:06 +0000 | [diff] [blame] | 340 | return self.GetOption('main','Keys','name',default='') |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 341 | |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 342 | def GetExtensions(self, activeOnly=1): |
| 343 | """ |
| 344 | Gets a list of all idle extensions declared in the config files. |
| 345 | activeOnly - boolean, if true only return active (enabled) extensions |
| 346 | """ |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 347 | extns=self.RemoveKeyBindNames( |
| 348 | self.GetSectionList('default','extensions')) |
| 349 | userExtns=self.RemoveKeyBindNames( |
| 350 | self.GetSectionList('user','extensions')) |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 351 | for extn in userExtns: |
| 352 | if extn not in extns: #user has added own extension |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 353 | extns.append(extn) |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 354 | if activeOnly: |
| 355 | activeExtns=[] |
| 356 | for extn in extns: |
Steven M. Gava | 5f28e8f | 2002-01-21 06:38:21 +0000 | [diff] [blame] | 357 | if self.GetOption('extensions',extn,'enable',default=1, |
| 358 | type='bool'): |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 359 | #the extension is enabled |
| 360 | activeExtns.append(extn) |
| 361 | return activeExtns |
| 362 | else: |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 363 | return extns |
Steven M. Gava | ad4f532 | 2002-01-03 12:05:17 +0000 | [diff] [blame] | 364 | |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 365 | def RemoveKeyBindNames(self,extnNameList): |
| 366 | #get rid of keybinding section names |
| 367 | names=extnNameList |
| 368 | kbNameIndicies=[] |
| 369 | for name in names: |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 370 | if name.endswith('_bindings') or name.endswith('_cfgBindings'): |
| 371 | kbNameIndicies.append(names.index(name)) |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 372 | kbNameIndicies.sort() |
| 373 | kbNameIndicies.reverse() |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 374 | for index in kbNameIndicies: #delete each keybinding section name |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 375 | del(names[index]) |
| 376 | return names |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 377 | |
Steven M. Gava | a498af2 | 2002-02-01 01:33:36 +0000 | [diff] [blame] | 378 | def GetExtnNameForEvent(self,virtualEvent): |
| 379 | """ |
| 380 | Returns the name of the extension that virtualEvent is bound in, or |
| 381 | None if not bound in any extension. |
| 382 | virtualEvent - string, name of the virtual event to test for, without |
| 383 | the enclosing '<< >>' |
| 384 | """ |
| 385 | extName=None |
| 386 | vEvent='<<'+virtualEvent+'>>' |
| 387 | for extn in self.GetExtensions(activeOnly=0): |
| 388 | for event in self.GetExtensionKeys(extn).keys(): |
| 389 | if event == vEvent: |
| 390 | extName=extn |
Steven M. Gava | a498af2 | 2002-02-01 01:33:36 +0000 | [diff] [blame] | 391 | return extName |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 392 | |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 393 | def GetExtensionKeys(self,extensionName): |
| 394 | """ |
| 395 | returns a dictionary of the configurable keybindings for a particular |
| 396 | extension,as they exist in the dictionary returned by GetCurrentKeySet; |
Steven M. Gava | a498af2 | 2002-02-01 01:33:36 +0000 | [diff] [blame] | 397 | that is, where previously used bindings are disabled. |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 398 | """ |
| 399 | keysName=extensionName+'_cfgBindings' |
| 400 | activeKeys=self.GetCurrentKeySet() |
| 401 | extKeys={} |
| 402 | if self.defaultCfg['extensions'].has_section(keysName): |
| 403 | eventNames=self.defaultCfg['extensions'].GetOptionList(keysName) |
| 404 | for eventName in eventNames: |
| 405 | event='<<'+eventName+'>>' |
| 406 | binding=activeKeys[event] |
| 407 | extKeys[event]=binding |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 408 | return extKeys |
| 409 | |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 410 | def __GetRawExtensionKeys(self,extensionName): |
| 411 | """ |
| 412 | returns a dictionary of the configurable keybindings for a particular |
| 413 | extension, as defined in the configuration files, or an empty dictionary |
| 414 | if no bindings are found |
| 415 | """ |
| 416 | keysName=extensionName+'_cfgBindings' |
| 417 | extKeys={} |
| 418 | if self.defaultCfg['extensions'].has_section(keysName): |
| 419 | eventNames=self.defaultCfg['extensions'].GetOptionList(keysName) |
| 420 | for eventName in eventNames: |
| 421 | binding=self.GetOption('extensions',keysName, |
| 422 | eventName,default='').split() |
| 423 | event='<<'+eventName+'>>' |
| 424 | extKeys[event]=binding |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 425 | return extKeys |
| 426 | |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 427 | def GetExtensionBindings(self,extensionName): |
| 428 | """ |
| 429 | Returns a dictionary of all the event bindings for a particular |
| 430 | extension. The configurable keybindings are returned as they exist in |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 431 | the dictionary returned by GetCurrentKeySet; that is, where re-used |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 432 | keybindings are disabled. |
| 433 | """ |
| 434 | bindsName=extensionName+'_bindings' |
| 435 | extBinds=self.GetExtensionKeys(extensionName) |
| 436 | #add the non-configurable bindings |
| 437 | if self.defaultCfg['extensions'].has_section(bindsName): |
| 438 | eventNames=self.defaultCfg['extensions'].GetOptionList(bindsName) |
| 439 | for eventName in eventNames: |
| 440 | binding=self.GetOption('extensions',bindsName, |
| 441 | eventName,default='').split() |
| 442 | event='<<'+eventName+'>>' |
| 443 | extBinds[event]=binding |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 444 | |
| 445 | return extBinds |
| 446 | |
Steven M. Gava | 0cae01c | 2002-01-04 07:53:06 +0000 | [diff] [blame] | 447 | def GetKeyBinding(self, keySetName, eventStr): |
| 448 | """ |
| 449 | returns the keybinding for a specific event. |
| 450 | keySetName - string, name of key binding set |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 451 | eventStr - string, the virtual event we want the binding for, |
Steven M. Gava | 0cae01c | 2002-01-04 07:53:06 +0000 | [diff] [blame] | 452 | represented as a string, eg. '<<event>>' |
| 453 | """ |
| 454 | eventName=eventStr[2:-2] #trim off the angle brackets |
| 455 | binding=self.GetOption('keys',keySetName,eventName,default='').split() |
| 456 | return binding |
| 457 | |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 458 | def GetCurrentKeySet(self): |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 459 | return self.GetKeySet(self.CurrentKeys()) |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 460 | |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 461 | def GetKeySet(self,keySetName): |
Steven M. Gava | 2a63a07 | 2001-10-26 06:50:54 +0000 | [diff] [blame] | 462 | """ |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 463 | Returns a dictionary of: all requested core keybindings, plus the |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 464 | keybindings for all currently active extensions. If a binding defined |
| 465 | in an extension is already in use, that binding is disabled. |
| 466 | """ |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 467 | keySet=self.GetCoreKeys(keySetName) |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 468 | activeExtns=self.GetExtensions(activeOnly=1) |
| 469 | for extn in activeExtns: |
| 470 | extKeys=self.__GetRawExtensionKeys(extn) |
| 471 | if extKeys: #the extension defines keybindings |
| 472 | for event in extKeys.keys(): |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 473 | if extKeys[event] in keySet.values(): |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 474 | #the binding is already in use |
| 475 | extKeys[event]='' #disable this binding |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 476 | keySet[event]=extKeys[event] #add binding |
| 477 | return keySet |
| 478 | |
Steven M. Gava | a498af2 | 2002-02-01 01:33:36 +0000 | [diff] [blame] | 479 | def IsCoreBinding(self,virtualEvent): |
| 480 | """ |
| 481 | returns true if the virtual event is bound in the core idle keybindings. |
| 482 | virtualEvent - string, name of the virtual event to test for, without |
| 483 | the enclosing '<< >>' |
| 484 | """ |
| 485 | return ('<<'+virtualEvent+'>>') in self.GetCoreKeys().keys() |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 486 | |
Steven M. Gava | c628a06 | 2002-01-19 10:33:21 +0000 | [diff] [blame] | 487 | def GetCoreKeys(self, keySetName=None): |
| 488 | """ |
| 489 | returns the requested set of core keybindings, with fallbacks if |
| 490 | required. |
Steven M. Gava | f9bb90e | 2002-01-24 06:02:50 +0000 | [diff] [blame] | 491 | Keybindings loaded from the config file(s) are loaded _over_ these |
| 492 | defaults, so if there is a problem getting any core binding there will |
| 493 | be an 'ultimate last resort fallback' to the CUA-ish bindings |
| 494 | defined here. |
Steven M. Gava | 2a63a07 | 2001-10-26 06:50:54 +0000 | [diff] [blame] | 495 | """ |
Steven M. Gava | 17d0154 | 2001-12-03 00:37:28 +0000 | [diff] [blame] | 496 | keyBindings={ |
Steven M. Gava | a498af2 | 2002-02-01 01:33:36 +0000 | [diff] [blame] | 497 | '<<copy>>': ['<Control-c>', '<Control-C>'], |
| 498 | '<<cut>>': ['<Control-x>', '<Control-X>'], |
| 499 | '<<paste>>': ['<Control-v>', '<Control-V>'], |
Steven M. Gava | 17d0154 | 2001-12-03 00:37:28 +0000 | [diff] [blame] | 500 | '<<beginning-of-line>>': ['<Control-a>', '<Home>'], |
| 501 | '<<center-insert>>': ['<Control-l>'], |
| 502 | '<<close-all-windows>>': ['<Control-q>'], |
| 503 | '<<close-window>>': ['<Alt-F4>'], |
Kurt B. Kaiser | 84f4803 | 2002-09-26 22:13:22 +0000 | [diff] [blame] | 504 | '<<do-nothing>>': ['<Control-x>'], |
Steven M. Gava | 17d0154 | 2001-12-03 00:37:28 +0000 | [diff] [blame] | 505 | '<<end-of-file>>': ['<Control-d>'], |
| 506 | '<<python-docs>>': ['<F1>'], |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 507 | '<<python-context-help>>': ['<Shift-F1>'], |
Steven M. Gava | 17d0154 | 2001-12-03 00:37:28 +0000 | [diff] [blame] | 508 | '<<history-next>>': ['<Alt-n>'], |
| 509 | '<<history-previous>>': ['<Alt-p>'], |
| 510 | '<<interrupt-execution>>': ['<Control-c>'], |
Kurt B. Kaiser | 1061e72 | 2003-01-04 01:43:53 +0000 | [diff] [blame] | 511 | '<<view-restart>>': ['<F6>'], |
Steven M. Gava | 17d0154 | 2001-12-03 00:37:28 +0000 | [diff] [blame] | 512 | '<<open-class-browser>>': ['<Alt-c>'], |
| 513 | '<<open-module>>': ['<Alt-m>'], |
| 514 | '<<open-new-window>>': ['<Control-n>'], |
| 515 | '<<open-window-from-file>>': ['<Control-o>'], |
| 516 | '<<plain-newline-and-indent>>': ['<Control-j>'], |
Steven M. Gava | 7981ce5 | 2002-06-11 04:45:34 +0000 | [diff] [blame] | 517 | '<<print-window>>': ['<Control-p>'], |
Steven M. Gava | 17d0154 | 2001-12-03 00:37:28 +0000 | [diff] [blame] | 518 | '<<redo>>': ['<Control-y>'], |
| 519 | '<<remove-selection>>': ['<Escape>'], |
| 520 | '<<save-copy-of-window-as-file>>': ['<Alt-Shift-s>'], |
| 521 | '<<save-window-as-file>>': ['<Alt-s>'], |
| 522 | '<<save-window>>': ['<Control-s>'], |
| 523 | '<<select-all>>': ['<Alt-a>'], |
| 524 | '<<toggle-auto-coloring>>': ['<Control-slash>'], |
Steven M. Gava | 0cae01c | 2002-01-04 07:53:06 +0000 | [diff] [blame] | 525 | '<<undo>>': ['<Control-z>'], |
| 526 | '<<find-again>>': ['<Control-g>', '<F3>'], |
| 527 | '<<find-in-files>>': ['<Alt-F3>'], |
| 528 | '<<find-selection>>': ['<Control-F3>'], |
| 529 | '<<find>>': ['<Control-f>'], |
| 530 | '<<replace>>': ['<Control-h>'], |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 531 | '<<goto-line>>': ['<Alt-g>'], |
Kurt B. Kaiser | a9f8cbc | 2002-09-14 03:17:01 +0000 | [diff] [blame] | 532 | '<<smart-backspace>>': ['<Key-BackSpace>'], |
| 533 | '<<newline-and-indent>>': ['<Key-Return> <Key-KP_Enter>'], |
| 534 | '<<smart-indent>>': ['<Key-Tab>'], |
| 535 | '<<indent-region>>': ['<Control-Key-bracketright>'], |
| 536 | '<<dedent-region>>': ['<Control-Key-bracketleft>'], |
| 537 | '<<comment-region>>': ['<Alt-Key-3>'], |
| 538 | '<<uncomment-region>>': ['<Alt-Key-4>'], |
| 539 | '<<tabify-region>>': ['<Alt-Key-5>'], |
| 540 | '<<untabify-region>>': ['<Alt-Key-6>'], |
| 541 | '<<toggle-tabs>>': ['<Alt-Key-t>'], |
| 542 | '<<change-indentwidth>>': ['<Alt-Key-u>'] |
| 543 | } |
Steven M. Gava | 17d0154 | 2001-12-03 00:37:28 +0000 | [diff] [blame] | 544 | if keySetName: |
Steven M. Gava | 0cae01c | 2002-01-04 07:53:06 +0000 | [diff] [blame] | 545 | for event in keyBindings.keys(): |
| 546 | binding=self.GetKeyBinding(keySetName,event) |
Steven M. Gava | 4974575 | 2002-02-18 01:43:11 +0000 | [diff] [blame] | 547 | if binding: |
Steven M. Gava | 0cae01c | 2002-01-04 07:53:06 +0000 | [diff] [blame] | 548 | keyBindings[event]=binding |
Steven M. Gava | 4974575 | 2002-02-18 01:43:11 +0000 | [diff] [blame] | 549 | else: #we are going to return a default, print warning |
| 550 | warning=('\n Warning: configHandler.py - IdleConf.GetCoreKeys'+ |
| 551 | ' -\n problem retrieving key binding for event '+ |
| 552 | `event`+'\n from key set '+`keySetName`+'.\n'+ |
| 553 | ' returning default value: '+`keyBindings[event]`+'\n') |
| 554 | sys.stderr.write(warning) |
Steven M. Gava | 17d0154 | 2001-12-03 00:37:28 +0000 | [diff] [blame] | 555 | return keyBindings |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 556 | |
Steven M. Gava | 085eb1b | 2002-02-05 04:52:32 +0000 | [diff] [blame] | 557 | def GetExtraHelpSourceList(self,configSet): |
| 558 | """ |
| 559 | Returns a list of tuples containing the details of any additional |
| 560 | help sources configured in the requested configSet ('user' or 'default') |
| 561 | , or an empty list if there are none. Returned tuples are of the form |
| 562 | form (menu_item , path_to_help_file , option). |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 563 | """ |
Steven M. Gava | 085eb1b | 2002-02-05 04:52:32 +0000 | [diff] [blame] | 564 | helpSources=[] |
| 565 | if configSet=='user': |
| 566 | cfgParser=self.userCfg['main'] |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 567 | elif configSet=='default': |
Steven M. Gava | 085eb1b | 2002-02-05 04:52:32 +0000 | [diff] [blame] | 568 | cfgParser=self.defaultCfg['main'] |
| 569 | else: |
Neal Norwitz | 5b0b00f | 2002-11-30 19:10:19 +0000 | [diff] [blame] | 570 | raise InvalidConfigSet, 'Invalid configSet specified' |
Steven M. Gava | 085eb1b | 2002-02-05 04:52:32 +0000 | [diff] [blame] | 571 | options=cfgParser.GetOptionList('HelpFiles') |
| 572 | for option in options: |
| 573 | value=cfgParser.Get('HelpFiles',option,default=';') |
| 574 | if value.find(';')==-1: #malformed config entry with no ';' |
| 575 | menuItem='' #make these empty |
| 576 | helpPath='' #so value won't be added to list |
| 577 | else: #config entry contains ';' as expected |
| 578 | value=string.split(value,';') |
| 579 | menuItem=value[0].strip() |
| 580 | helpPath=value[1].strip() |
| 581 | if menuItem and helpPath: #neither are empty strings |
| 582 | helpSources.append( (menuItem,helpPath,option) ) |
| 583 | return helpSources |
| 584 | |
| 585 | def GetAllExtraHelpSourcesList(self): |
| 586 | """ |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 587 | Returns a list of tuples containing the details of all additional help |
Steven M. Gava | 085eb1b | 2002-02-05 04:52:32 +0000 | [diff] [blame] | 588 | sources configured, or an empty list if there are none. Tuples are of |
| 589 | the format returned by GetExtraHelpSourceList. |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 590 | """ |
| 591 | allHelpSources=( self.GetExtraHelpSourceList('default')+ |
Steven M. Gava | 085eb1b | 2002-02-05 04:52:32 +0000 | [diff] [blame] | 592 | self.GetExtraHelpSourceList('user') ) |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 593 | return allHelpSources |
| 594 | |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 595 | def LoadCfgFiles(self): |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 596 | """ |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 597 | load all configuration files. |
| 598 | """ |
| 599 | for key in self.defaultCfg.keys(): |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 600 | self.defaultCfg[key].Load() |
| 601 | self.userCfg[key].Load() #same keys |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 602 | |
| 603 | def SaveUserCfgFiles(self): |
| 604 | """ |
| 605 | write all loaded user configuration files back to disk |
| 606 | """ |
| 607 | for key in self.userCfg.keys(): |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 608 | self.userCfg[key].Save() |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 609 | |
| 610 | idleConf=IdleConf() |
| 611 | |
| 612 | ### module test |
| 613 | if __name__ == '__main__': |
| 614 | def dumpCfg(cfg): |
| 615 | print '\n',cfg,'\n' |
| 616 | for key in cfg.keys(): |
| 617 | sections=cfg[key].sections() |
| 618 | print key |
| 619 | print sections |
| 620 | for section in sections: |
| 621 | options=cfg[key].options(section) |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 622 | print section |
Steven M. Gava | c11ccf3 | 2001-09-24 09:43:17 +0000 | [diff] [blame] | 623 | print options |
| 624 | for option in options: |
| 625 | print option, '=', cfg[key].Get(section,option) |
| 626 | dumpCfg(idleConf.defaultCfg) |
| 627 | dumpCfg(idleConf.userCfg) |
| 628 | print idleConf.userCfg['main'].Get('Theme','name') |
| 629 | #print idleConf.userCfg['highlight'].GetDefHighlight('Foo','normal') |