2003-01-14 18:03:31 -04:00
|
|
|
"""Provides access to stored IDLE configuration information.
|
|
|
|
|
|
|
|
Refer to the comments at the beginning of config-main.def for a description of
|
|
|
|
the available configuration files and the design implemented to update user
|
|
|
|
configuration information. In particular, user configuration choices which
|
|
|
|
duplicate the defaults will be removed from the user's configuration files,
|
2003-01-26 22:36:18 -04:00
|
|
|
and if a file becomes empty, it will be deleted.
|
2003-01-14 18:03:31 -04:00
|
|
|
|
|
|
|
The contents of the user files may be altered using the Options/Configure IDLE
|
|
|
|
menu to access the configuration GUI (configDialog.py), or manually.
|
|
|
|
|
|
|
|
Throughout this module there is an emphasis on returning useable defaults
|
|
|
|
when a problem occurs in 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.
|
2001-10-26 03:50:54 -03:00
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
# TODOs added Oct 2014, tjr
|
|
|
|
|
2014-09-19 23:37:24 -03:00
|
|
|
from __future__ import print_function
|
2003-01-14 18:03:31 -04:00
|
|
|
import os
|
|
|
|
import sys
|
2014-10-06 02:32:21 -03:00
|
|
|
|
2014-07-01 19:52:31 -03:00
|
|
|
from ConfigParser import ConfigParser
|
2001-09-24 06:43:17 -03:00
|
|
|
|
2002-11-30 15:10:19 -04:00
|
|
|
class InvalidConfigType(Exception): pass
|
|
|
|
class InvalidConfigSet(Exception): pass
|
|
|
|
class InvalidFgBg(Exception): pass
|
|
|
|
class InvalidTheme(Exception): pass
|
|
|
|
|
2001-09-24 06:43:17 -03:00
|
|
|
class IdleConfParser(ConfigParser):
|
|
|
|
"""
|
|
|
|
A ConfigParser specialised for idle configuration file handling
|
|
|
|
"""
|
|
|
|
def __init__(self, cfgFile, cfgDefaults=None):
|
|
|
|
"""
|
|
|
|
cfgFile - string, fully specified configuration file name
|
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
self.file = cfgFile
|
2014-10-06 02:32:21 -03:00
|
|
|
ConfigParser.__init__(self, defaults=cfgDefaults)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2007-02-05 02:03:18 -04:00
|
|
|
def Get(self, section, option, type=None, default=None, raw=False):
|
2001-09-24 06:43:17 -03:00
|
|
|
"""
|
|
|
|
Get an option value for given section/option or return default.
|
|
|
|
If type is specified, return as type.
|
|
|
|
"""
|
2014-10-22 21:15:12 -03:00
|
|
|
# TODO Use default as fallback, at least if not None
|
|
|
|
# Should also print Warning(file, section, option).
|
|
|
|
# Currently may raise ValueError
|
2007-02-05 02:03:18 -04:00
|
|
|
if not self.has_option(section, option):
|
|
|
|
return default
|
2014-10-07 00:26:17 -03:00
|
|
|
if type == 'bool':
|
2007-02-05 02:03:18 -04:00
|
|
|
return self.getboolean(section, option)
|
2014-10-07 00:26:17 -03:00
|
|
|
elif type == 'int':
|
2007-02-05 02:03:18 -04:00
|
|
|
return self.getint(section, option)
|
2002-01-24 02:02:50 -04:00
|
|
|
else:
|
2007-02-05 02:03:18 -04:00
|
|
|
return self.get(section, option, raw=raw)
|
2001-09-24 06:43:17 -03:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
def GetOptionList(self, section):
|
|
|
|
"Return a list of options for given section, else []."
|
2002-02-05 00:52:32 -04:00
|
|
|
if self.has_section(section):
|
2001-09-24 06:43:17 -03:00
|
|
|
return self.options(section)
|
|
|
|
else: #return a default value
|
|
|
|
return []
|
|
|
|
|
|
|
|
def Load(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
"Load the configuration file from disk."
|
2001-09-24 06:43:17 -03:00
|
|
|
self.read(self.file)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2001-09-24 06:43:17 -03:00
|
|
|
class IdleUserConfParser(IdleConfParser):
|
|
|
|
"""
|
2002-01-29 04:35:29 -04:00
|
|
|
IdleConfigParser specialised for user configuration handling.
|
2001-09-24 06:43:17 -03:00
|
|
|
"""
|
2002-01-29 04:35:29 -04:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
def AddSection(self, section):
|
|
|
|
"If section doesn't exist, add it."
|
2002-01-29 04:35:29 -04:00
|
|
|
if not self.has_section(section):
|
|
|
|
self.add_section(section)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-01-29 04:35:29 -04:00
|
|
|
def RemoveEmptySections(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
"Remove any sections that have no options."
|
2002-01-29 04:35:29 -04:00
|
|
|
for section in self.sections():
|
|
|
|
if not self.GetOptionList(section):
|
2002-12-31 12:03:23 -04:00
|
|
|
self.remove_section(section)
|
|
|
|
|
2002-01-29 04:35:29 -04:00
|
|
|
def IsEmpty(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
"Return True if no sections after removing empty sections."
|
2002-01-29 04:35:29 -04:00
|
|
|
self.RemoveEmptySections()
|
2014-10-07 00:26:17 -03:00
|
|
|
return not self.sections()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
def RemoveOption(self, section, option):
|
|
|
|
"""Return True if option is removed from section, else False.
|
|
|
|
|
|
|
|
False if either section does not exist or did not have option.
|
2002-01-29 04:35:29 -04:00
|
|
|
"""
|
|
|
|
if self.has_section(section):
|
2014-10-07 00:26:17 -03:00
|
|
|
return self.remove_option(section, option)
|
|
|
|
return False
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
def SetOption(self, section, option, value):
|
|
|
|
"""Return True if option is added or changed to value, else False.
|
|
|
|
|
|
|
|
Add section if required. False means option already had value.
|
2002-01-29 04:35:29 -04:00
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
if self.has_option(section, option):
|
|
|
|
if self.get(section, option) == value:
|
|
|
|
return False
|
2002-01-29 04:35:29 -04:00
|
|
|
else:
|
2014-10-07 00:26:17 -03:00
|
|
|
self.set(section, option, value)
|
|
|
|
return True
|
2002-01-29 04:35:29 -04:00
|
|
|
else:
|
|
|
|
if not self.has_section(section):
|
|
|
|
self.add_section(section)
|
2014-10-07 00:26:17 -03:00
|
|
|
self.set(section, option, value)
|
|
|
|
return True
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-03-02 03:16:21 -04:00
|
|
|
def RemoveFile(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
"Remove user config file self.file from disk if it exists."
|
2002-03-02 03:16:21 -04:00
|
|
|
if os.path.exists(self.file):
|
2002-12-31 12:03:23 -04:00
|
|
|
os.remove(self.file)
|
|
|
|
|
2001-09-24 06:43:17 -03:00
|
|
|
def Save(self):
|
2003-01-14 18:03:31 -04:00
|
|
|
"""Update user configuration file.
|
|
|
|
|
|
|
|
Remove empty sections. If resulting config isn't empty, write the file
|
|
|
|
to disk. If config is empty, remove the file from disk if it exists.
|
|
|
|
|
2001-09-24 06:43:17 -03:00
|
|
|
"""
|
2002-01-29 04:35:29 -04:00
|
|
|
if not self.IsEmpty():
|
2008-01-23 18:19:23 -04:00
|
|
|
fname = self.file
|
|
|
|
try:
|
|
|
|
cfgFile = open(fname, 'w')
|
|
|
|
except IOError:
|
2008-02-12 11:45:50 -04:00
|
|
|
os.unlink(fname)
|
2008-01-23 18:19:23 -04:00
|
|
|
cfgFile = open(fname, 'w')
|
2014-10-06 02:32:21 -03:00
|
|
|
with cfgFile:
|
|
|
|
self.write(cfgFile)
|
2002-01-29 04:35:29 -04:00
|
|
|
else:
|
2002-03-02 03:16:21 -04:00
|
|
|
self.RemoveFile()
|
2001-09-24 06:43:17 -03:00
|
|
|
|
|
|
|
class IdleConf:
|
2014-10-07 00:26:17 -03:00
|
|
|
"""Hold config parsers for all idle config files in singleton instance.
|
|
|
|
|
|
|
|
Default config files, self.defaultCfg --
|
|
|
|
for config_type in self.config_types:
|
|
|
|
(idle install dir)/config-{config-type}.def
|
|
|
|
|
|
|
|
User config files, self.userCfg --
|
|
|
|
for config_type in self.config_types:
|
|
|
|
(user home dir)/.idlerc/config-{config-type}.cfg
|
2001-09-24 06:43:17 -03:00
|
|
|
"""
|
|
|
|
def __init__(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
self.config_types = ('main', 'extensions', 'highlight', 'keys')
|
|
|
|
self.defaultCfg = {}
|
|
|
|
self.userCfg = {}
|
|
|
|
self.cfg = {} # TODO use to select userCfg vs defaultCfg
|
2001-09-24 06:43:17 -03:00
|
|
|
self.CreateConfigHandlers()
|
|
|
|
self.LoadCfgFiles()
|
2014-10-07 00:26:17 -03:00
|
|
|
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2001-09-24 06:43:17 -03:00
|
|
|
def CreateConfigHandlers(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
"Populate default and user config parser dictionaries."
|
2001-09-24 06:43:17 -03:00
|
|
|
#build idle install path
|
|
|
|
if __name__ != '__main__': # we were imported
|
2002-01-31 23:02:37 -04:00
|
|
|
idleDir=os.path.dirname(__file__)
|
2001-09-24 06:43:17 -03:00
|
|
|
else: # we were exec'ed (for testing only)
|
2002-01-31 23:02:37 -04:00
|
|
|
idleDir=os.path.abspath(sys.path[0])
|
|
|
|
userDir=self.GetUserCfgDir()
|
2014-10-07 00:26:17 -03:00
|
|
|
|
|
|
|
defCfgFiles = {}
|
|
|
|
usrCfgFiles = {}
|
|
|
|
# TODO eliminate these temporaries by combining loops
|
|
|
|
for cfgType in self.config_types: #build config file names
|
|
|
|
defCfgFiles[cfgType] = os.path.join(
|
|
|
|
idleDir, 'config-' + cfgType + '.def')
|
|
|
|
usrCfgFiles[cfgType] = os.path.join(
|
|
|
|
userDir, 'config-' + cfgType + '.cfg')
|
|
|
|
for cfgType in self.config_types: #create config parsers
|
|
|
|
self.defaultCfg[cfgType] = IdleConfParser(defCfgFiles[cfgType])
|
|
|
|
self.userCfg[cfgType] = IdleUserConfParser(usrCfgFiles[cfgType])
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-01-31 23:02:37 -04:00
|
|
|
def GetUserCfgDir(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
"""Return a filesystem directory for storing user config files.
|
2005-01-13 13:37:38 -04:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
Creates it if required.
|
2002-01-31 23:02:37 -04:00
|
|
|
"""
|
2005-01-11 15:29:39 -04:00
|
|
|
cfgDir = '.idlerc'
|
|
|
|
userDir = os.path.expanduser('~')
|
|
|
|
if userDir != '~': # expanduser() found user home dir
|
2002-01-31 23:02:37 -04:00
|
|
|
if not os.path.exists(userDir):
|
2014-10-07 00:26:17 -03:00
|
|
|
warn = ('\n Warning: os.path.expanduser("~") points to\n ' +
|
|
|
|
userDir + ',\n but the path does not exist.')
|
2008-04-21 19:35:30 -03:00
|
|
|
try:
|
2014-09-19 23:37:24 -03:00
|
|
|
print(warn, file=sys.stderr)
|
2008-04-21 19:35:30 -03:00
|
|
|
except IOError:
|
|
|
|
pass
|
2005-01-11 15:29:39 -04:00
|
|
|
userDir = '~'
|
|
|
|
if userDir == "~": # still no path to home!
|
|
|
|
# traditionally IDLE has defaulted to os.getcwd(), is this adequate?
|
|
|
|
userDir = os.getcwd()
|
|
|
|
userDir = os.path.join(userDir, cfgDir)
|
2002-01-31 23:02:37 -04:00
|
|
|
if not os.path.exists(userDir):
|
2005-01-11 15:29:39 -04:00
|
|
|
try:
|
2002-01-31 23:02:37 -04:00
|
|
|
os.mkdir(userDir)
|
2005-01-11 15:29:39 -04:00
|
|
|
except (OSError, IOError):
|
2014-10-07 00:26:17 -03:00
|
|
|
warn = ('\n Warning: unable to create user config directory\n' +
|
|
|
|
userDir + '\n Check path and permissions.\n Exiting!\n')
|
2014-09-19 23:37:24 -03:00
|
|
|
print(warn, file=sys.stderr)
|
2005-01-11 15:29:39 -04:00
|
|
|
raise SystemExit
|
2014-10-07 00:26:17 -03:00
|
|
|
# TODO continue without userDIr instead of exit
|
2002-01-31 23:02:37 -04:00
|
|
|
return userDir
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2004-06-05 22:29:22 -03:00
|
|
|
def GetOption(self, configType, section, option, default=None, type=None,
|
2007-02-05 02:03:18 -04:00
|
|
|
warn_on_default=True, raw=False):
|
2014-10-07 00:26:17 -03:00
|
|
|
"""Return a value for configType section option, or default.
|
|
|
|
|
|
|
|
If type is not None, return a value of that type. Also pass raw
|
|
|
|
to the config parser. First try to return a valid value
|
|
|
|
(including type) from a user configuration. If that fails, try
|
|
|
|
the default configuration. If that fails, return default, with a
|
|
|
|
default of None.
|
2004-06-05 22:29:22 -03:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
Warn if either user or default configurations have an invalid value.
|
|
|
|
Warn if default is returned and warn_on_default is True.
|
2001-10-23 07:42:12 -03:00
|
|
|
"""
|
2012-12-24 07:17:59 -04:00
|
|
|
try:
|
2014-10-07 00:26:17 -03:00
|
|
|
if self.userCfg[configType].has_option(section, option):
|
2012-12-24 07:17:59 -04:00
|
|
|
return self.userCfg[configType].Get(section, option,
|
|
|
|
type=type, raw=raw)
|
|
|
|
except ValueError:
|
|
|
|
warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n'
|
|
|
|
' invalid %r value for configuration option %r\n'
|
2014-09-19 23:37:24 -03:00
|
|
|
' from section %r: %r' %
|
2012-12-24 07:17:59 -04:00
|
|
|
(type, option, section,
|
2014-10-07 00:26:17 -03:00
|
|
|
self.userCfg[configType].Get(section, option, raw=raw)))
|
2012-12-24 07:17:59 -04:00
|
|
|
try:
|
2014-09-19 23:37:24 -03:00
|
|
|
print(warning, file=sys.stderr)
|
2012-12-24 07:17:59 -04:00
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
if self.defaultCfg[configType].has_option(section,option):
|
2014-10-07 00:26:17 -03:00
|
|
|
return self.defaultCfg[configType].Get(
|
|
|
|
section, option, type=type, raw=raw)
|
2012-12-24 07:17:59 -04:00
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
#returning default, print warning
|
|
|
|
if warn_on_default:
|
|
|
|
warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n'
|
|
|
|
' problem retrieving configuration option %r\n'
|
|
|
|
' from section %r.\n'
|
2014-09-19 23:37:24 -03:00
|
|
|
' returning default value: %r' %
|
2012-12-24 07:17:59 -04:00
|
|
|
(option, section, default))
|
|
|
|
try:
|
2014-09-19 23:37:24 -03:00
|
|
|
print(warning, file=sys.stderr)
|
2012-12-24 07:17:59 -04:00
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
return default
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2004-06-05 22:29:22 -03:00
|
|
|
def SetOption(self, configType, section, option, value):
|
2014-10-07 00:26:17 -03:00
|
|
|
"""Set section option to value in user config file."""
|
2004-06-05 22:29:22 -03:00
|
|
|
self.userCfg[configType].SetOption(section, option, value)
|
|
|
|
|
2001-10-26 03:50:54 -03:00
|
|
|
def GetSectionList(self, configSet, configType):
|
2014-10-07 00:26:17 -03:00
|
|
|
"""Return sections for configSet configType configuration.
|
|
|
|
|
2002-12-31 12:03:23 -04:00
|
|
|
configSet must be either 'user' or 'default'
|
2014-10-07 00:26:17 -03:00
|
|
|
configType must be in self.config_types.
|
2001-10-26 03:50:54 -03:00
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
if not (configType in self.config_types):
|
2014-10-06 02:32:21 -03:00
|
|
|
raise InvalidConfigType('Invalid configType specified')
|
2001-10-26 03:50:54 -03:00
|
|
|
if configSet == 'user':
|
2014-10-07 00:26:17 -03:00
|
|
|
cfgParser = self.userCfg[configType]
|
2001-10-26 03:50:54 -03:00
|
|
|
elif configSet == 'default':
|
|
|
|
cfgParser=self.defaultCfg[configType]
|
|
|
|
else:
|
2014-10-06 02:32:21 -03:00
|
|
|
raise InvalidConfigSet('Invalid configSet specified')
|
2001-10-26 03:50:54 -03:00
|
|
|
return cfgParser.sections()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-01-03 08:05:17 -04:00
|
|
|
def GetHighlight(self, theme, element, fgBg=None):
|
2014-10-09 19:44:26 -03:00
|
|
|
"""Return individual theme element highlight color(s).
|
2014-10-07 00:26:17 -03:00
|
|
|
|
2014-10-09 19:44:26 -03:00
|
|
|
fgBg - string ('fg' or 'bg') or None.
|
|
|
|
If None, return a dictionary containing fg and bg colors with
|
|
|
|
keys 'foreground' and 'background'. Otherwise, only return
|
|
|
|
fg or bg color, as specified. Colors are intended to be
|
|
|
|
appropriate for passing to Tkinter in, e.g., a tag_config call).
|
2002-01-03 08:05:17 -04:00
|
|
|
"""
|
2002-02-10 22:51:18 -04:00
|
|
|
if self.defaultCfg['highlight'].has_section(theme):
|
2014-10-07 00:26:17 -03:00
|
|
|
themeDict = self.GetThemeDict('default', theme)
|
2002-02-10 22:51:18 -04:00
|
|
|
else:
|
2014-10-07 00:26:17 -03:00
|
|
|
themeDict = self.GetThemeDict('user', theme)
|
|
|
|
fore = themeDict[element + '-foreground']
|
2014-10-09 19:44:26 -03:00
|
|
|
if element == 'cursor': # There is no config value for cursor bg
|
2014-10-07 00:26:17 -03:00
|
|
|
back = themeDict['normal-background']
|
2002-12-31 12:03:23 -04:00
|
|
|
else:
|
2014-10-07 00:26:17 -03:00
|
|
|
back = themeDict[element + '-background']
|
|
|
|
highlight = {"foreground": fore, "background": back}
|
2014-10-09 19:44:26 -03:00
|
|
|
if not fgBg: # Return dict of both colors
|
2002-01-03 08:05:17 -04:00
|
|
|
return highlight
|
2014-10-09 19:44:26 -03:00
|
|
|
else: # Return specified color only
|
2002-01-03 08:05:17 -04:00
|
|
|
if fgBg == 'fg':
|
|
|
|
return highlight["foreground"]
|
|
|
|
if fgBg == 'bg':
|
|
|
|
return highlight["background"]
|
2002-12-31 12:03:23 -04:00
|
|
|
else:
|
2014-10-06 02:32:21 -03:00
|
|
|
raise InvalidFgBg('Invalid fgBg specified')
|
2002-02-10 22:51:18 -04:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
def GetThemeDict(self, type, themeName):
|
|
|
|
"""Return {option:value} dict for elements in themeName.
|
|
|
|
|
2002-01-24 02:02:50 -04:00
|
|
|
type - string, 'default' or 'user' theme type
|
|
|
|
themeName - string, theme name
|
2014-10-07 00:26:17 -03:00
|
|
|
Values are loaded over ultimate fallback defaults to guarantee
|
|
|
|
that all theme elements are present in a newly created theme.
|
2002-01-24 02:02:50 -04:00
|
|
|
"""
|
|
|
|
if type == 'user':
|
2014-10-07 00:26:17 -03:00
|
|
|
cfgParser = self.userCfg['highlight']
|
2002-01-24 02:02:50 -04:00
|
|
|
elif type == 'default':
|
2014-10-07 00:26:17 -03:00
|
|
|
cfgParser = self.defaultCfg['highlight']
|
2002-01-24 02:02:50 -04:00
|
|
|
else:
|
2014-10-06 02:32:21 -03:00
|
|
|
raise InvalidTheme('Invalid theme type specified')
|
2014-10-09 19:44:26 -03:00
|
|
|
# Provide foreground and background colors for each theme
|
|
|
|
# element (other than cursor) even though some values are not
|
|
|
|
# yet used by idle, to allow for their use in the future.
|
|
|
|
# Default values are generally black and white.
|
|
|
|
# TODO copy theme from a class attribute.
|
2014-10-07 00:26:17 -03:00
|
|
|
theme ={'normal-foreground':'#000000',
|
2002-12-31 12:03:23 -04:00
|
|
|
'normal-background':'#ffffff',
|
|
|
|
'keyword-foreground':'#000000',
|
|
|
|
'keyword-background':'#ffffff',
|
2004-03-08 14:15:31 -04:00
|
|
|
'builtin-foreground':'#000000',
|
|
|
|
'builtin-background':'#ffffff',
|
2002-12-31 12:03:23 -04:00
|
|
|
'comment-foreground':'#000000',
|
|
|
|
'comment-background':'#ffffff',
|
2002-01-24 02:02:50 -04:00
|
|
|
'string-foreground':'#000000',
|
|
|
|
'string-background':'#ffffff',
|
2002-12-31 12:03:23 -04:00
|
|
|
'definition-foreground':'#000000',
|
2002-01-24 02:02:50 -04:00
|
|
|
'definition-background':'#ffffff',
|
|
|
|
'hilite-foreground':'#000000',
|
|
|
|
'hilite-background':'gray',
|
|
|
|
'break-foreground':'#ffffff',
|
|
|
|
'break-background':'#000000',
|
|
|
|
'hit-foreground':'#ffffff',
|
|
|
|
'hit-background':'#000000',
|
|
|
|
'error-foreground':'#ffffff',
|
2002-12-31 12:03:23 -04:00
|
|
|
'error-background':'#000000',
|
|
|
|
#cursor (only foreground can be set)
|
|
|
|
'cursor-foreground':'#000000',
|
2002-01-24 02:02:50 -04:00
|
|
|
#shell window
|
|
|
|
'stdout-foreground':'#000000',
|
|
|
|
'stdout-background':'#ffffff',
|
|
|
|
'stderr-foreground':'#000000',
|
|
|
|
'stderr-background':'#ffffff',
|
|
|
|
'console-foreground':'#000000',
|
|
|
|
'console-background':'#ffffff' }
|
2014-10-06 02:32:21 -03:00
|
|
|
for element in theme:
|
2014-10-07 00:26:17 -03:00
|
|
|
if not cfgParser.has_option(themeName, element):
|
2014-10-09 19:44:26 -03:00
|
|
|
# Print warning that will return a default color
|
|
|
|
warning = ('\n Warning: configHandler.IdleConf.GetThemeDict'
|
2004-02-12 13:35:32 -04:00
|
|
|
' -\n problem retrieving theme element %r'
|
|
|
|
'\n from theme %r.\n'
|
2014-10-09 19:44:26 -03:00
|
|
|
' returning default color: %r' %
|
2004-02-12 13:35:32 -04:00
|
|
|
(element, themeName, theme[element]))
|
2008-04-21 19:35:30 -03:00
|
|
|
try:
|
2014-09-19 23:37:24 -03:00
|
|
|
print(warning, file=sys.stderr)
|
2008-04-21 19:35:30 -03:00
|
|
|
except IOError:
|
|
|
|
pass
|
2014-10-09 19:44:26 -03:00
|
|
|
theme[element] = cfgParser.Get(
|
|
|
|
themeName, element, default=theme[element])
|
2002-01-24 02:02:50 -04:00
|
|
|
return theme
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-01-03 08:05:17 -04:00
|
|
|
def CurrentTheme(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
"Return the name of the currently active theme."
|
|
|
|
return self.GetOption('main', 'Theme', 'name', default='')
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-01-03 08:05:17 -04:00
|
|
|
def CurrentKeys(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
"Return the name of the currently active key set."
|
|
|
|
return self.GetOption('main', 'Keys', 'name', default='')
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2004-06-05 22:29:22 -03:00
|
|
|
def GetExtensions(self, active_only=True, editor_only=False, shell_only=False):
|
2014-10-07 00:26:17 -03:00
|
|
|
"""Return extensions in default and user config-extensions files.
|
|
|
|
|
|
|
|
If active_only True, only return active (enabled) extensions
|
|
|
|
and optionally only editor or shell extensions.
|
|
|
|
If active_only False, return all extensions.
|
2002-01-03 08:05:17 -04:00
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
extns = self.RemoveKeyBindNames(
|
|
|
|
self.GetSectionList('default', 'extensions'))
|
|
|
|
userExtns = self.RemoveKeyBindNames(
|
|
|
|
self.GetSectionList('user', 'extensions'))
|
2002-01-03 08:05:17 -04:00
|
|
|
for extn in userExtns:
|
|
|
|
if extn not in extns: #user has added own extension
|
2002-12-31 12:03:23 -04:00
|
|
|
extns.append(extn)
|
2004-06-05 22:29:22 -03:00
|
|
|
if active_only:
|
2014-10-07 00:26:17 -03:00
|
|
|
activeExtns = []
|
2002-01-03 08:05:17 -04:00
|
|
|
for extn in extns:
|
2004-06-05 22:29:22 -03:00
|
|
|
if self.GetOption('extensions', extn, 'enable', default=True,
|
|
|
|
type='bool'):
|
2002-01-03 08:05:17 -04:00
|
|
|
#the extension is enabled
|
2014-10-07 00:26:17 -03:00
|
|
|
if editor_only or shell_only: # TODO if both, contradictory
|
2004-06-05 22:29:22 -03:00
|
|
|
if editor_only:
|
|
|
|
option = "enable_editor"
|
|
|
|
else:
|
|
|
|
option = "enable_shell"
|
|
|
|
if self.GetOption('extensions', extn,option,
|
|
|
|
default=True, type='bool',
|
|
|
|
warn_on_default=False):
|
|
|
|
activeExtns.append(extn)
|
|
|
|
else:
|
|
|
|
activeExtns.append(extn)
|
2002-01-03 08:05:17 -04:00
|
|
|
return activeExtns
|
|
|
|
else:
|
2002-12-31 12:03:23 -04:00
|
|
|
return extns
|
2002-01-03 08:05:17 -04:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
def RemoveKeyBindNames(self, extnNameList):
|
|
|
|
"Return extnNameList with keybinding section names removed."
|
|
|
|
# TODO Easier to return filtered copy with list comp
|
|
|
|
names = extnNameList
|
|
|
|
kbNameIndicies = []
|
2002-01-19 06:33:21 -04:00
|
|
|
for name in names:
|
2006-06-09 17:43:48 -03:00
|
|
|
if name.endswith(('_bindings', '_cfgBindings')):
|
2002-12-31 12:03:23 -04:00
|
|
|
kbNameIndicies.append(names.index(name))
|
2014-10-07 00:26:17 -03:00
|
|
|
kbNameIndicies.sort(reverse=True)
|
2002-12-31 12:03:23 -04:00
|
|
|
for index in kbNameIndicies: #delete each keybinding section name
|
2002-01-19 06:33:21 -04:00
|
|
|
del(names[index])
|
|
|
|
return names
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
def GetExtnNameForEvent(self, virtualEvent):
|
|
|
|
"""Return the name of the extension binding virtualEvent, or None.
|
|
|
|
|
|
|
|
virtualEvent - string, name of the virtual event to test for,
|
|
|
|
without the enclosing '<< >>'
|
2002-01-31 21:33:36 -04:00
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
extName = None
|
|
|
|
vEvent = '<<' + virtualEvent + '>>'
|
2004-06-05 22:29:22 -03:00
|
|
|
for extn in self.GetExtensions(active_only=0):
|
2014-10-06 02:32:21 -03:00
|
|
|
for event in self.GetExtensionKeys(extn):
|
2002-01-31 21:33:36 -04:00
|
|
|
if event == vEvent:
|
2014-10-07 00:26:17 -03:00
|
|
|
extName = extn # TODO return here?
|
2002-01-31 21:33:36 -04:00
|
|
|
return extName
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
def GetExtensionKeys(self, extensionName):
|
|
|
|
"""Return dict: {configurable extensionName event : active keybinding}.
|
|
|
|
|
|
|
|
Events come from default config extension_cfgBindings section.
|
|
|
|
Keybindings come from GetCurrentKeySet() active key dict,
|
|
|
|
where previously used bindings are disabled.
|
2002-01-19 06:33:21 -04:00
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
keysName = extensionName + '_cfgBindings'
|
|
|
|
activeKeys = self.GetCurrentKeySet()
|
|
|
|
extKeys = {}
|
2002-01-19 06:33:21 -04:00
|
|
|
if self.defaultCfg['extensions'].has_section(keysName):
|
2014-10-07 00:26:17 -03:00
|
|
|
eventNames = self.defaultCfg['extensions'].GetOptionList(keysName)
|
2002-01-19 06:33:21 -04:00
|
|
|
for eventName in eventNames:
|
2014-10-07 00:26:17 -03:00
|
|
|
event = '<<' + eventName + '>>'
|
|
|
|
binding = activeKeys[event]
|
|
|
|
extKeys[event] = binding
|
2002-12-31 12:03:23 -04:00
|
|
|
return extKeys
|
|
|
|
|
2002-01-19 06:33:21 -04:00
|
|
|
def __GetRawExtensionKeys(self,extensionName):
|
2014-10-07 00:26:17 -03:00
|
|
|
"""Return dict {configurable extensionName event : keybinding list}.
|
|
|
|
|
|
|
|
Events come from default config extension_cfgBindings section.
|
|
|
|
Keybindings list come from the splitting of GetOption, which
|
|
|
|
tries user config before default config.
|
2002-01-19 06:33:21 -04:00
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
keysName = extensionName+'_cfgBindings'
|
|
|
|
extKeys = {}
|
2002-01-19 06:33:21 -04:00
|
|
|
if self.defaultCfg['extensions'].has_section(keysName):
|
2014-10-07 00:26:17 -03:00
|
|
|
eventNames = self.defaultCfg['extensions'].GetOptionList(keysName)
|
2002-01-19 06:33:21 -04:00
|
|
|
for eventName in eventNames:
|
2014-10-07 00:26:17 -03:00
|
|
|
binding = self.GetOption(
|
|
|
|
'extensions', keysName, eventName, default='').split()
|
|
|
|
event = '<<' + eventName + '>>'
|
|
|
|
extKeys[event] = binding
|
2002-12-31 12:03:23 -04:00
|
|
|
return extKeys
|
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
def GetExtensionBindings(self, extensionName):
|
|
|
|
"""Return dict {extensionName event : active or defined keybinding}.
|
|
|
|
|
|
|
|
Augment self.GetExtensionKeys(extensionName) with mapping of non-
|
|
|
|
configurable events (from default config) to GetOption splits,
|
|
|
|
as in self.__GetRawExtensionKeys.
|
2002-01-19 06:33:21 -04:00
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
bindsName = extensionName + '_bindings'
|
|
|
|
extBinds = self.GetExtensionKeys(extensionName)
|
2002-01-19 06:33:21 -04:00
|
|
|
#add the non-configurable bindings
|
|
|
|
if self.defaultCfg['extensions'].has_section(bindsName):
|
2014-10-07 00:26:17 -03:00
|
|
|
eventNames = self.defaultCfg['extensions'].GetOptionList(bindsName)
|
2002-01-19 06:33:21 -04:00
|
|
|
for eventName in eventNames:
|
2014-10-07 00:26:17 -03:00
|
|
|
binding = self.GetOption(
|
|
|
|
'extensions', bindsName, eventName, default='').split()
|
|
|
|
event = '<<' + eventName + '>>'
|
|
|
|
extBinds[event] = binding
|
2002-12-31 12:03:23 -04:00
|
|
|
|
|
|
|
return extBinds
|
|
|
|
|
2002-01-04 03:53:06 -04:00
|
|
|
def GetKeyBinding(self, keySetName, eventStr):
|
2014-10-07 00:26:17 -03:00
|
|
|
"""Return the keybinding list for keySetName eventStr.
|
|
|
|
|
|
|
|
keySetName - name of key binding set (config-keys section).
|
|
|
|
eventStr - virtual event, including brackets, as in '<<event>>'.
|
2002-01-04 03:53:06 -04:00
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
eventName = eventStr[2:-2] #trim off the angle brackets
|
|
|
|
binding = self.GetOption('keys', keySetName, eventName, default='').split()
|
2002-01-04 03:53:06 -04:00
|
|
|
return binding
|
|
|
|
|
2002-01-19 06:33:21 -04:00
|
|
|
def GetCurrentKeySet(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
"Return CurrentKeys with 'darwin' modifications."
|
2006-06-11 11:33:36 -03:00
|
|
|
result = self.GetKeySet(self.CurrentKeys())
|
|
|
|
|
2014-03-28 00:47:04 -03:00
|
|
|
if sys.platform == "darwin":
|
|
|
|
# OS X Tk variants do not support the "Alt" keyboard modifier.
|
|
|
|
# So replace all keybingings that use "Alt" with ones that
|
|
|
|
# use the "Option" keyboard modifier.
|
2014-10-07 00:26:17 -03:00
|
|
|
# TODO (Ned?): the "Option" modifier does not work properly for
|
2014-03-28 00:47:04 -03:00
|
|
|
# Cocoa Tk and XQuartz Tk so we should not use it
|
|
|
|
# in default OS X KeySets.
|
2006-06-11 11:33:36 -03:00
|
|
|
for k, v in result.items():
|
|
|
|
v2 = [ x.replace('<Alt-', '<Option-') for x in v ]
|
|
|
|
if v != v2:
|
|
|
|
result[k] = v2
|
|
|
|
|
|
|
|
return result
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
def GetKeySet(self, keySetName):
|
|
|
|
"""Return event-key dict for keySetName core plus active extensions.
|
|
|
|
|
|
|
|
If a binding defined in an extension is already in use, the
|
|
|
|
extension binding is disabled by being set to ''
|
2002-01-19 06:33:21 -04:00
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
keySet = self.GetCoreKeys(keySetName)
|
|
|
|
activeExtns = self.GetExtensions(active_only=1)
|
2002-01-19 06:33:21 -04:00
|
|
|
for extn in activeExtns:
|
2014-10-07 00:26:17 -03:00
|
|
|
extKeys = self.__GetRawExtensionKeys(extn)
|
2002-01-19 06:33:21 -04:00
|
|
|
if extKeys: #the extension defines keybindings
|
2014-10-06 02:32:21 -03:00
|
|
|
for event in extKeys:
|
2002-01-24 02:02:50 -04:00
|
|
|
if extKeys[event] in keySet.values():
|
2002-01-19 06:33:21 -04:00
|
|
|
#the binding is already in use
|
2014-10-07 00:26:17 -03:00
|
|
|
extKeys[event] = '' #disable this binding
|
|
|
|
keySet[event] = extKeys[event] #add binding
|
2002-01-24 02:02:50 -04:00
|
|
|
return keySet
|
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
def IsCoreBinding(self, virtualEvent):
|
|
|
|
"""Return True if the virtual event is one of the core idle key events.
|
|
|
|
|
|
|
|
virtualEvent - string, name of the virtual event to test for,
|
|
|
|
without the enclosing '<< >>'
|
2002-01-31 21:33:36 -04:00
|
|
|
"""
|
2014-10-06 02:32:21 -03:00
|
|
|
return ('<<'+virtualEvent+'>>') in self.GetCoreKeys()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
# TODO make keyBindins a file or class attribute used for test above
|
|
|
|
# and copied in function below
|
|
|
|
|
2002-01-19 06:33:21 -04:00
|
|
|
def GetCoreKeys(self, keySetName=None):
|
2014-10-07 00:26:17 -03:00
|
|
|
"""Return dict of core virtual-key keybindings for keySetName.
|
|
|
|
|
|
|
|
The default keySetName None corresponds to the keyBindings base
|
|
|
|
dict. If keySetName is not None, bindings from the config
|
|
|
|
file(s) are loaded _over_ these defaults, so if there is a
|
|
|
|
problem getting any core binding there will be an 'ultimate last
|
|
|
|
resort fallback' to the CUA-ish bindings defined here.
|
2001-12-02 20:37:28 -04:00
|
|
|
"""
|
|
|
|
keyBindings={
|
2002-01-31 21:33:36 -04:00
|
|
|
'<<copy>>': ['<Control-c>', '<Control-C>'],
|
|
|
|
'<<cut>>': ['<Control-x>', '<Control-X>'],
|
|
|
|
'<<paste>>': ['<Control-v>', '<Control-V>'],
|
2001-12-02 20:37:28 -04:00
|
|
|
'<<beginning-of-line>>': ['<Control-a>', '<Home>'],
|
|
|
|
'<<center-insert>>': ['<Control-l>'],
|
|
|
|
'<<close-all-windows>>': ['<Control-q>'],
|
|
|
|
'<<close-window>>': ['<Alt-F4>'],
|
2002-09-26 19:13:22 -03:00
|
|
|
'<<do-nothing>>': ['<Control-x>'],
|
2001-12-02 20:37:28 -04:00
|
|
|
'<<end-of-file>>': ['<Control-d>'],
|
|
|
|
'<<python-docs>>': ['<F1>'],
|
2002-12-31 12:03:23 -04:00
|
|
|
'<<python-context-help>>': ['<Shift-F1>'],
|
2001-12-02 20:37:28 -04:00
|
|
|
'<<history-next>>': ['<Alt-n>'],
|
|
|
|
'<<history-previous>>': ['<Alt-p>'],
|
|
|
|
'<<interrupt-execution>>': ['<Control-c>'],
|
2003-01-03 21:43:53 -04:00
|
|
|
'<<view-restart>>': ['<F6>'],
|
2003-01-21 20:23:23 -04:00
|
|
|
'<<restart-shell>>': ['<Control-F6>'],
|
2001-12-02 20:37:28 -04:00
|
|
|
'<<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>'],
|
2002-06-11 01:45:34 -03:00
|
|
|
'<<print-window>>': ['<Control-p>'],
|
2001-12-02 20:37:28 -04:00
|
|
|
'<<redo>>': ['<Control-y>'],
|
|
|
|
'<<remove-selection>>': ['<Escape>'],
|
2003-11-24 01:26:16 -04:00
|
|
|
'<<save-copy-of-window-as-file>>': ['<Alt-Shift-S>'],
|
2001-12-02 20:37:28 -04:00
|
|
|
'<<save-window-as-file>>': ['<Alt-s>'],
|
|
|
|
'<<save-window>>': ['<Control-s>'],
|
|
|
|
'<<select-all>>': ['<Alt-a>'],
|
|
|
|
'<<toggle-auto-coloring>>': ['<Control-slash>'],
|
2002-01-04 03:53:06 -04:00
|
|
|
'<<undo>>': ['<Control-z>'],
|
|
|
|
'<<find-again>>': ['<Control-g>', '<F3>'],
|
|
|
|
'<<find-in-files>>': ['<Alt-F3>'],
|
|
|
|
'<<find-selection>>': ['<Control-F3>'],
|
|
|
|
'<<find>>': ['<Control-f>'],
|
|
|
|
'<<replace>>': ['<Control-h>'],
|
2002-12-31 12:03:23 -04:00
|
|
|
'<<goto-line>>': ['<Alt-g>'],
|
2002-09-14 00:17:01 -03:00
|
|
|
'<<smart-backspace>>': ['<Key-BackSpace>'],
|
2012-03-29 13:54:58 -03:00
|
|
|
'<<newline-and-indent>>': ['<Key-Return>', '<Key-KP_Enter>'],
|
2002-09-14 00:17:01 -03:00
|
|
|
'<<smart-indent>>': ['<Key-Tab>'],
|
|
|
|
'<<indent-region>>': ['<Control-Key-bracketright>'],
|
|
|
|
'<<dedent-region>>': ['<Control-Key-bracketleft>'],
|
|
|
|
'<<comment-region>>': ['<Alt-Key-3>'],
|
|
|
|
'<<uncomment-region>>': ['<Alt-Key-4>'],
|
|
|
|
'<<tabify-region>>': ['<Alt-Key-5>'],
|
|
|
|
'<<untabify-region>>': ['<Alt-Key-6>'],
|
|
|
|
'<<toggle-tabs>>': ['<Alt-Key-t>'],
|
2005-01-27 20:16:16 -04:00
|
|
|
'<<change-indentwidth>>': ['<Alt-Key-u>'],
|
|
|
|
'<<del-word-left>>': ['<Control-Key-BackSpace>'],
|
|
|
|
'<<del-word-right>>': ['<Control-Key-Delete>']
|
2002-09-14 00:17:01 -03:00
|
|
|
}
|
2001-12-02 20:37:28 -04:00
|
|
|
if keySetName:
|
2014-10-06 02:32:21 -03:00
|
|
|
for event in keyBindings:
|
2014-10-07 00:26:17 -03:00
|
|
|
binding = self.GetKeyBinding(keySetName, event)
|
2002-02-17 21:43:11 -04:00
|
|
|
if binding:
|
2014-10-07 00:26:17 -03:00
|
|
|
keyBindings[event] = binding
|
2002-02-17 21:43:11 -04:00
|
|
|
else: #we are going to return a default, print warning
|
2004-02-12 13:35:32 -04:00
|
|
|
warning=('\n Warning: configHandler.py - IdleConf.GetCoreKeys'
|
|
|
|
' -\n problem retrieving key binding for event %r'
|
|
|
|
'\n from key set %r.\n'
|
2014-09-19 23:37:24 -03:00
|
|
|
' returning default value: %r' %
|
2004-02-12 13:35:32 -04:00
|
|
|
(event, keySetName, keyBindings[event]))
|
2008-04-21 19:35:30 -03:00
|
|
|
try:
|
2014-09-19 23:37:24 -03:00
|
|
|
print(warning, file=sys.stderr)
|
2008-04-21 19:35:30 -03:00
|
|
|
except IOError:
|
|
|
|
pass
|
2001-12-02 20:37:28 -04:00
|
|
|
return keyBindings
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
def GetExtraHelpSourceList(self, configSet):
|
|
|
|
"""Return list of extra help sources from a given configSet.
|
2003-01-26 22:36:18 -04:00
|
|
|
|
2003-01-14 18:03:31 -04:00
|
|
|
Valid configSets are 'user' or 'default'. Return a list of tuples of
|
|
|
|
the form (menu_item , path_to_help_file , option), or return the empty
|
|
|
|
list. 'option' is the sequence number of the help resource. 'option'
|
|
|
|
values determine the position of the menu items on the Help menu,
|
|
|
|
therefore the returned list must be sorted by 'option'.
|
|
|
|
|
2002-12-31 12:03:23 -04:00
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
helpSources = []
|
|
|
|
if configSet == 'user':
|
|
|
|
cfgParser = self.userCfg['main']
|
|
|
|
elif configSet == 'default':
|
|
|
|
cfgParser = self.defaultCfg['main']
|
2002-02-05 00:52:32 -04:00
|
|
|
else:
|
2014-10-06 02:32:21 -03:00
|
|
|
raise InvalidConfigSet('Invalid configSet specified')
|
2002-02-05 00:52:32 -04:00
|
|
|
options=cfgParser.GetOptionList('HelpFiles')
|
|
|
|
for option in options:
|
2014-10-07 00:26:17 -03:00
|
|
|
value=cfgParser.Get('HelpFiles', option, default=';')
|
|
|
|
if value.find(';') == -1: #malformed config entry with no ';'
|
|
|
|
menuItem = '' #make these empty
|
|
|
|
helpPath = '' #so value won't be added to list
|
2002-02-05 00:52:32 -04:00
|
|
|
else: #config entry contains ';' as expected
|
2014-10-06 02:32:21 -03:00
|
|
|
value=value.split(';')
|
2002-02-05 00:52:32 -04:00
|
|
|
menuItem=value[0].strip()
|
|
|
|
helpPath=value[1].strip()
|
|
|
|
if menuItem and helpPath: #neither are empty strings
|
|
|
|
helpSources.append( (menuItem,helpPath,option) )
|
2010-04-02 05:15:26 -03:00
|
|
|
helpSources.sort(key=lambda x: int(x[2]))
|
2002-02-05 00:52:32 -04:00
|
|
|
return helpSources
|
|
|
|
|
|
|
|
def GetAllExtraHelpSourcesList(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
"""Return a list of the details of all additional help sources.
|
|
|
|
|
|
|
|
Tuples in the list are those of GetExtraHelpSourceList.
|
2002-02-05 00:52:32 -04:00
|
|
|
"""
|
2014-10-07 00:26:17 -03:00
|
|
|
allHelpSources = (self.GetExtraHelpSourceList('default') +
|
2002-02-05 00:52:32 -04:00
|
|
|
self.GetExtraHelpSourceList('user') )
|
2002-12-31 12:03:23 -04:00
|
|
|
return allHelpSources
|
|
|
|
|
2001-09-24 06:43:17 -03:00
|
|
|
def LoadCfgFiles(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
"Load all configuration files."
|
2014-10-06 02:32:21 -03:00
|
|
|
for key in self.defaultCfg:
|
2002-12-31 12:03:23 -04:00
|
|
|
self.defaultCfg[key].Load()
|
|
|
|
self.userCfg[key].Load() #same keys
|
2001-09-24 06:43:17 -03:00
|
|
|
|
|
|
|
def SaveUserCfgFiles(self):
|
2014-10-07 00:26:17 -03:00
|
|
|
"Write all loaded user configuration files to disk."
|
2014-10-06 02:32:21 -03:00
|
|
|
for key in self.userCfg:
|
2002-12-31 12:03:23 -04:00
|
|
|
self.userCfg[key].Save()
|
2001-09-24 06:43:17 -03:00
|
|
|
|
|
|
|
|
2014-10-07 00:26:17 -03:00
|
|
|
idleConf = IdleConf()
|
|
|
|
|
|
|
|
# TODO Revise test output, write expanded unittest
|
2001-09-24 06:43:17 -03:00
|
|
|
### module test
|
|
|
|
if __name__ == '__main__':
|
|
|
|
def dumpCfg(cfg):
|
2014-09-19 23:37:24 -03:00
|
|
|
print('\n', cfg, '\n')
|
2014-10-06 02:32:21 -03:00
|
|
|
for key in cfg:
|
2014-10-07 00:26:17 -03:00
|
|
|
sections = cfg[key].sections()
|
2014-09-19 23:37:24 -03:00
|
|
|
print(key)
|
|
|
|
print(sections)
|
2001-09-24 06:43:17 -03:00
|
|
|
for section in sections:
|
2014-10-07 00:26:17 -03:00
|
|
|
options = cfg[key].options(section)
|
2014-09-19 23:37:24 -03:00
|
|
|
print(section)
|
|
|
|
print(options)
|
2001-09-24 06:43:17 -03:00
|
|
|
for option in options:
|
2014-10-07 00:26:17 -03:00
|
|
|
print(option, '=', cfg[key].Get(section, option))
|
2001-09-24 06:43:17 -03:00
|
|
|
dumpCfg(idleConf.defaultCfg)
|
|
|
|
dumpCfg(idleConf.userCfg)
|
2014-10-07 00:26:17 -03:00
|
|
|
print(idleConf.userCfg['main'].Get('Theme', 'name'))
|
2014-09-19 23:37:24 -03:00
|
|
|
#print(idleConf.userCfg['highlight'].GetDefHighlight('Foo','normal'))
|