home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / python2.5 / idlelib / configHandler.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-05-11  |  25.8 KB  |  816 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. """Provides access to stored IDLE configuration information.
  5.  
  6. Refer to the comments at the beginning of config-main.def for a description of
  7. the available configuration files and the design implemented to update user
  8. configuration information.  In particular, user configuration choices which
  9. duplicate the defaults will be removed from the user's configuration files,
  10. and if a file becomes empty, it will be deleted.
  11.  
  12. The contents of the user files may be altered using the Options/Configure IDLE
  13. menu to access the configuration GUI (configDialog.py), or manually.
  14.  
  15. Throughout this module there is an emphasis on returning useable defaults
  16. when a problem occurs in returning a requested configuration value back to
  17. idle. This is to allow IDLE to continue to function in spite of errors in
  18. the retrieval of config information. When a default is returned instead of
  19. a requested config value, a message is printed to stderr to aid in
  20. configuration problem notification and resolution.
  21.  
  22. """
  23. import os
  24. import sys
  25. import string
  26. import macosxSupport
  27. from ConfigParser import ConfigParser, NoOptionError, NoSectionError
  28.  
  29. class InvalidConfigType(Exception):
  30.     pass
  31.  
  32.  
  33. class InvalidConfigSet(Exception):
  34.     pass
  35.  
  36.  
  37. class InvalidFgBg(Exception):
  38.     pass
  39.  
  40.  
  41. class InvalidTheme(Exception):
  42.     pass
  43.  
  44.  
  45. class IdleConfParser(ConfigParser):
  46.     '''
  47.     A ConfigParser specialised for idle configuration file handling
  48.     '''
  49.     
  50.     def __init__(self, cfgFile, cfgDefaults = None):
  51.         '''
  52.         cfgFile - string, fully specified configuration file name
  53.         '''
  54.         self.file = cfgFile
  55.         ConfigParser.__init__(self, defaults = cfgDefaults)
  56.  
  57.     
  58.     def Get(self, section, option, type = None, default = None):
  59.         '''
  60.         Get an option value for given section/option or return default.
  61.         If type is specified, return as type.
  62.         '''
  63.         if type == 'bool':
  64.             getVal = self.getboolean
  65.         elif type == 'int':
  66.             getVal = self.getint
  67.         else:
  68.             getVal = self.get
  69.         if self.has_option(section, option):
  70.             return getVal(section, option)
  71.         else:
  72.             return default
  73.  
  74.     
  75.     def GetOptionList(self, section):
  76.         '''
  77.         Get an option list for given section
  78.         '''
  79.         if self.has_section(section):
  80.             return self.options(section)
  81.         else:
  82.             return []
  83.  
  84.     
  85.     def Load(self):
  86.         '''
  87.         Load the configuration file from disk
  88.         '''
  89.         self.read(self.file)
  90.  
  91.  
  92.  
  93. class IdleUserConfParser(IdleConfParser):
  94.     '''
  95.     IdleConfigParser specialised for user configuration handling.
  96.     '''
  97.     
  98.     def AddSection(self, section):
  99.         """
  100.         if section doesn't exist, add it
  101.         """
  102.         if not self.has_section(section):
  103.             self.add_section(section)
  104.         
  105.  
  106.     
  107.     def RemoveEmptySections(self):
  108.         '''
  109.         remove any sections that have no options
  110.         '''
  111.         for section in self.sections():
  112.             if not self.GetOptionList(section):
  113.                 self.remove_section(section)
  114.                 continue
  115.         
  116.  
  117.     
  118.     def IsEmpty(self):
  119.         '''
  120.         Remove empty sections and then return 1 if parser has no sections
  121.         left, else return 0.
  122.         '''
  123.         self.RemoveEmptySections()
  124.         if self.sections():
  125.             return 0
  126.         else:
  127.             return 1
  128.  
  129.     
  130.     def RemoveOption(self, section, option):
  131.         '''
  132.         If section/option exists, remove it.
  133.         Returns 1 if option was removed, 0 otherwise.
  134.         '''
  135.         if self.has_section(section):
  136.             return self.remove_option(section, option)
  137.         
  138.  
  139.     
  140.     def SetOption(self, section, option, value):
  141.         '''
  142.         Sets option to value, adding section if required.
  143.         Returns 1 if option was added or changed, otherwise 0.
  144.         '''
  145.         if self.has_option(section, option):
  146.             if self.get(section, option) == value:
  147.                 return 0
  148.             else:
  149.                 self.set(section, option, value)
  150.                 return 1
  151.         elif not self.has_section(section):
  152.             self.add_section(section)
  153.         
  154.         self.set(section, option, value)
  155.         return 1
  156.  
  157.     
  158.     def RemoveFile(self):
  159.         '''
  160.         Removes the user config file from disk if it exists.
  161.         '''
  162.         if os.path.exists(self.file):
  163.             os.remove(self.file)
  164.         
  165.  
  166.     
  167.     def Save(self):
  168.         """Update user configuration file.
  169.  
  170.         Remove empty sections. If resulting config isn't empty, write the file
  171.         to disk. If config is empty, remove the file from disk if it exists.
  172.  
  173.         """
  174.         if not self.IsEmpty():
  175.             cfgFile = open(self.file, 'w')
  176.             self.write(cfgFile)
  177.         else:
  178.             self.RemoveFile()
  179.  
  180.  
  181.  
  182. class IdleConf:
  183.     '''
  184.     holds config parsers for all idle config files:
  185.     default config files
  186.         (idle install dir)/config-main.def
  187.         (idle install dir)/config-extensions.def
  188.         (idle install dir)/config-highlight.def
  189.         (idle install dir)/config-keys.def
  190.     user config  files
  191.         (user home dir)/.idlerc/config-main.cfg
  192.         (user home dir)/.idlerc/config-extensions.cfg
  193.         (user home dir)/.idlerc/config-highlight.cfg
  194.         (user home dir)/.idlerc/config-keys.cfg
  195.     '''
  196.     
  197.     def __init__(self):
  198.         self.defaultCfg = { }
  199.         self.userCfg = { }
  200.         self.cfg = { }
  201.         self.CreateConfigHandlers()
  202.         self.LoadCfgFiles()
  203.  
  204.     
  205.     def CreateConfigHandlers(self):
  206.         '''
  207.         set up a dictionary of config parsers for default and user
  208.         configurations respectively
  209.         '''
  210.         if __name__ != '__main__':
  211.             idleDir = os.path.dirname(__file__)
  212.         else:
  213.             idleDir = os.path.abspath(sys.path[0])
  214.         userDir = self.GetUserCfgDir()
  215.         configTypes = ('main', 'extensions', 'highlight', 'keys')
  216.         defCfgFiles = { }
  217.         usrCfgFiles = { }
  218.         for cfgType in configTypes:
  219.             defCfgFiles[cfgType] = os.path.join(idleDir, 'config-' + cfgType + '.def')
  220.             usrCfgFiles[cfgType] = os.path.join(userDir, 'config-' + cfgType + '.cfg')
  221.         
  222.         for cfgType in configTypes:
  223.             self.defaultCfg[cfgType] = IdleConfParser(defCfgFiles[cfgType])
  224.             self.userCfg[cfgType] = IdleUserConfParser(usrCfgFiles[cfgType])
  225.         
  226.  
  227.     
  228.     def GetUserCfgDir(self):
  229.         '''
  230.         Creates (if required) and returns a filesystem directory for storing
  231.         user config files.
  232.  
  233.         '''
  234.         cfgDir = '.idlerc'
  235.         userDir = os.path.expanduser('~')
  236.         if userDir != '~':
  237.             if not os.path.exists(userDir):
  238.                 warn = '\n Warning: os.path.expanduser("~") points to\n ' + userDir + ',\n but the path does not exist.\n'
  239.                 sys.stderr.write(warn)
  240.                 userDir = '~'
  241.             
  242.         
  243.         if userDir == '~':
  244.             userDir = os.getcwd()
  245.         
  246.         userDir = os.path.join(userDir, cfgDir)
  247.         if not os.path.exists(userDir):
  248.             
  249.             try:
  250.                 os.mkdir(userDir)
  251.             except (OSError, IOError):
  252.                 warn = '\n Warning: unable to create user config directory\n' + userDir + '\n Check path and permissions.\n Exiting!\n\n'
  253.                 sys.stderr.write(warn)
  254.                 raise SystemExit
  255.             except:
  256.                 None<EXCEPTION MATCH>(OSError, IOError)
  257.             
  258.  
  259.         None<EXCEPTION MATCH>(OSError, IOError)
  260.         return userDir
  261.  
  262.     
  263.     def GetOption(self, configType, section, option, default = None, type = None, warn_on_default = True):
  264.         """
  265.         Get an option value for given config type and given general
  266.         configuration section/option or return a default. If type is specified,
  267.         return as type. Firstly the user configuration is checked, with a
  268.         fallback to the default configuration, and a final 'catch all'
  269.         fallback to a useable passed-in default if the option isn't present in
  270.         either the user or the default configuration.
  271.         configType must be one of ('main','extensions','highlight','keys')
  272.         If a default is returned, and warn_on_default is True, a warning is
  273.         printed to stderr.
  274.  
  275.         """
  276.         if self.userCfg[configType].has_option(section, option):
  277.             return self.userCfg[configType].Get(section, option, type = type)
  278.         elif self.defaultCfg[configType].has_option(section, option):
  279.             return self.defaultCfg[configType].Get(section, option, type = type)
  280.         elif warn_on_default:
  281.             warning = '\n Warning: configHandler.py - IdleConf.GetOption -\n problem retrieving configration option %r\n from section %r.\n returning default value: %r\n' % (option, section, default)
  282.             sys.stderr.write(warning)
  283.         
  284.         return default
  285.  
  286.     
  287.     def SetOption(self, configType, section, option, value):
  288.         """In user's config file, set section's option to value.
  289.  
  290.         """
  291.         self.userCfg[configType].SetOption(section, option, value)
  292.  
  293.     
  294.     def GetSectionList(self, configSet, configType):
  295.         """
  296.         Get a list of sections from either the user or default config for
  297.         the given config type.
  298.         configSet must be either 'user' or 'default'
  299.         configType must be one of ('main','extensions','highlight','keys')
  300.         """
  301.         if configType not in ('main', 'extensions', 'highlight', 'keys'):
  302.             raise InvalidConfigType, 'Invalid configType specified'
  303.         
  304.         if configSet == 'user':
  305.             cfgParser = self.userCfg[configType]
  306.         elif configSet == 'default':
  307.             cfgParser = self.defaultCfg[configType]
  308.         else:
  309.             raise InvalidConfigSet, 'Invalid configSet specified'
  310.         return cfgParser.sections()
  311.  
  312.     
  313.     def GetHighlight(self, theme, element, fgBg = None):
  314.         """
  315.         return individual highlighting theme elements.
  316.         fgBg - string ('fg'or'bg') or None, if None return a dictionary
  317.         containing fg and bg colours (appropriate for passing to Tkinter in,
  318.         e.g., a tag_config call), otherwise fg or bg colour only as specified.
  319.         """
  320.         if self.defaultCfg['highlight'].has_section(theme):
  321.             themeDict = self.GetThemeDict('default', theme)
  322.         else:
  323.             themeDict = self.GetThemeDict('user', theme)
  324.         fore = themeDict[element + '-foreground']
  325.         if element == 'cursor':
  326.             back = themeDict['normal-background']
  327.         else:
  328.             back = themeDict[element + '-background']
  329.         highlight = {
  330.             'foreground': fore,
  331.             'background': back }
  332.         if not fgBg:
  333.             return highlight
  334.         elif fgBg == 'fg':
  335.             return highlight['foreground']
  336.         
  337.         if fgBg == 'bg':
  338.             return highlight['background']
  339.         else:
  340.             raise InvalidFgBg, 'Invalid fgBg specified'
  341.  
  342.     
  343.     def GetThemeDict(self, type, themeName):
  344.         """
  345.         type - string, 'default' or 'user' theme type
  346.         themeName - string, theme name
  347.         Returns a dictionary which holds {option:value} for each element
  348.         in the specified theme. Values are loaded over a set of ultimate last
  349.         fallback defaults to guarantee that all theme elements are present in
  350.         a newly created theme.
  351.         """
  352.         if type == 'user':
  353.             cfgParser = self.userCfg['highlight']
  354.         elif type == 'default':
  355.             cfgParser = self.defaultCfg['highlight']
  356.         else:
  357.             raise InvalidTheme, 'Invalid theme type specified'
  358.         theme = {
  359.             'normal-foreground': '#000000',
  360.             'normal-background': '#ffffff',
  361.             'keyword-foreground': '#000000',
  362.             'keyword-background': '#ffffff',
  363.             'builtin-foreground': '#000000',
  364.             'builtin-background': '#ffffff',
  365.             'comment-foreground': '#000000',
  366.             'comment-background': '#ffffff',
  367.             'string-foreground': '#000000',
  368.             'string-background': '#ffffff',
  369.             'definition-foreground': '#000000',
  370.             'definition-background': '#ffffff',
  371.             'hilite-foreground': '#000000',
  372.             'hilite-background': 'gray',
  373.             'break-foreground': '#ffffff',
  374.             'break-background': '#000000',
  375.             'hit-foreground': '#ffffff',
  376.             'hit-background': '#000000',
  377.             'error-foreground': '#ffffff',
  378.             'error-background': '#000000',
  379.             'cursor-foreground': '#000000',
  380.             'stdout-foreground': '#000000',
  381.             'stdout-background': '#ffffff',
  382.             'stderr-foreground': '#000000',
  383.             'stderr-background': '#ffffff',
  384.             'console-foreground': '#000000',
  385.             'console-background': '#ffffff' }
  386.         for element in theme.keys():
  387.             if not cfgParser.has_option(themeName, element):
  388.                 warning = '\n Warning: configHandler.py - IdleConf.GetThemeDict -\n problem retrieving theme element %r\n from theme %r.\n returning default value: %r\n' % (element, themeName, theme[element])
  389.                 sys.stderr.write(warning)
  390.             
  391.             colour = cfgParser.Get(themeName, element, default = theme[element])
  392.             theme[element] = colour
  393.         
  394.         return theme
  395.  
  396.     
  397.     def CurrentTheme(self):
  398.         '''
  399.         Returns the name of the currently active theme
  400.         '''
  401.         return self.GetOption('main', 'Theme', 'name', default = '')
  402.  
  403.     
  404.     def CurrentKeys(self):
  405.         '''
  406.         Returns the name of the currently active key set
  407.         '''
  408.         return self.GetOption('main', 'Keys', 'name', default = '')
  409.  
  410.     
  411.     def GetExtensions(self, active_only = True, editor_only = False, shell_only = False):
  412.         '''
  413.         Gets a list of all idle extensions declared in the config files.
  414.         active_only - boolean, if true only return active (enabled) extensions
  415.         '''
  416.         extns = self.RemoveKeyBindNames(self.GetSectionList('default', 'extensions'))
  417.         userExtns = self.RemoveKeyBindNames(self.GetSectionList('user', 'extensions'))
  418.         for extn in userExtns:
  419.             if extn not in extns:
  420.                 extns.append(extn)
  421.                 continue
  422.         
  423.         if active_only:
  424.             activeExtns = []
  425.             for extn in extns:
  426.                 if self.GetOption('extensions', extn, 'enable', default = True, type = 'bool'):
  427.                     if editor_only or shell_only:
  428.                         if editor_only:
  429.                             option = 'enable_editor'
  430.                         else:
  431.                             option = 'enable_shell'
  432.                         if self.GetOption('extensions', extn, option, default = True, type = 'bool', warn_on_default = False):
  433.                             activeExtns.append(extn)
  434.                         
  435.                     else:
  436.                         activeExtns.append(extn)
  437.                 shell_only
  438.             
  439.             return activeExtns
  440.         else:
  441.             return extns
  442.  
  443.     
  444.     def RemoveKeyBindNames(self, extnNameList):
  445.         names = extnNameList
  446.         kbNameIndicies = []
  447.         for name in names:
  448.             if name.endswith(('_bindings', '_cfgBindings')):
  449.                 kbNameIndicies.append(names.index(name))
  450.                 continue
  451.         
  452.         kbNameIndicies.sort()
  453.         kbNameIndicies.reverse()
  454.         for index in kbNameIndicies:
  455.             del names[index]
  456.         
  457.         return names
  458.  
  459.     
  460.     def GetExtnNameForEvent(self, virtualEvent):
  461.         """
  462.         Returns the name of the extension that virtualEvent is bound in, or
  463.         None if not bound in any extension.
  464.         virtualEvent - string, name of the virtual event to test for, without
  465.                        the enclosing '<< >>'
  466.         """
  467.         extName = None
  468.         vEvent = '<<' + virtualEvent + '>>'
  469.         for extn in self.GetExtensions(active_only = 0):
  470.             for event in self.GetExtensionKeys(extn).keys():
  471.                 if event == vEvent:
  472.                     extName = extn
  473.                     continue
  474.             
  475.         
  476.         return extName
  477.  
  478.     
  479.     def GetExtensionKeys(self, extensionName):
  480.         '''
  481.         returns a dictionary of the configurable keybindings for a particular
  482.         extension,as they exist in the dictionary returned by GetCurrentKeySet;
  483.         that is, where previously used bindings are disabled.
  484.         '''
  485.         keysName = extensionName + '_cfgBindings'
  486.         activeKeys = self.GetCurrentKeySet()
  487.         extKeys = { }
  488.         if self.defaultCfg['extensions'].has_section(keysName):
  489.             eventNames = self.defaultCfg['extensions'].GetOptionList(keysName)
  490.             for eventName in eventNames:
  491.                 event = '<<' + eventName + '>>'
  492.                 binding = activeKeys[event]
  493.                 extKeys[event] = binding
  494.             
  495.         
  496.         return extKeys
  497.  
  498.     
  499.     def __GetRawExtensionKeys(self, extensionName):
  500.         '''
  501.         returns a dictionary of the configurable keybindings for a particular
  502.         extension, as defined in the configuration files, or an empty dictionary
  503.         if no bindings are found
  504.         '''
  505.         keysName = extensionName + '_cfgBindings'
  506.         extKeys = { }
  507.         if self.defaultCfg['extensions'].has_section(keysName):
  508.             eventNames = self.defaultCfg['extensions'].GetOptionList(keysName)
  509.             for eventName in eventNames:
  510.                 binding = self.GetOption('extensions', keysName, eventName, default = '').split()
  511.                 event = '<<' + eventName + '>>'
  512.                 extKeys[event] = binding
  513.             
  514.         
  515.         return extKeys
  516.  
  517.     
  518.     def GetExtensionBindings(self, extensionName):
  519.         '''
  520.         Returns a dictionary of all the event bindings for a particular
  521.         extension. The configurable keybindings are returned as they exist in
  522.         the dictionary returned by GetCurrentKeySet; that is, where re-used
  523.         keybindings are disabled.
  524.         '''
  525.         bindsName = extensionName + '_bindings'
  526.         extBinds = self.GetExtensionKeys(extensionName)
  527.         if self.defaultCfg['extensions'].has_section(bindsName):
  528.             eventNames = self.defaultCfg['extensions'].GetOptionList(bindsName)
  529.             for eventName in eventNames:
  530.                 binding = self.GetOption('extensions', bindsName, eventName, default = '').split()
  531.                 event = '<<' + eventName + '>>'
  532.                 extBinds[event] = binding
  533.             
  534.         
  535.         return extBinds
  536.  
  537.     
  538.     def GetKeyBinding(self, keySetName, eventStr):
  539.         """
  540.         returns the keybinding for a specific event.
  541.         keySetName - string, name of key binding set
  542.         eventStr - string, the virtual event we want the binding for,
  543.                    represented as a string, eg. '<<event>>'
  544.         """
  545.         eventName = eventStr[2:-2]
  546.         binding = self.GetOption('keys', keySetName, eventName, default = '').split()
  547.         return binding
  548.  
  549.     
  550.     def GetCurrentKeySet(self):
  551.         result = self.GetKeySet(self.CurrentKeys())
  552.         if macosxSupport.runningAsOSXApp():
  553.             for k, v in result.items():
  554.                 v2 = [ x.replace('<Alt-', '<Option-') for x in v ]
  555.                 if v != v2:
  556.                     result[k] = v2
  557.                     continue
  558.                 []
  559.             
  560.         
  561.         return result
  562.  
  563.     
  564.     def GetKeySet(self, keySetName):
  565.         '''
  566.         Returns a dictionary of: all requested core keybindings, plus the
  567.         keybindings for all currently active extensions. If a binding defined
  568.         in an extension is already in use, that binding is disabled.
  569.         '''
  570.         keySet = self.GetCoreKeys(keySetName)
  571.         activeExtns = self.GetExtensions(active_only = 1)
  572.         for extn in activeExtns:
  573.             extKeys = self._IdleConf__GetRawExtensionKeys(extn)
  574.             if extKeys:
  575.                 for event in extKeys.keys():
  576.                     if extKeys[event] in keySet.values():
  577.                         extKeys[event] = ''
  578.                     
  579.                     keySet[event] = extKeys[event]
  580.                 
  581.         
  582.         return keySet
  583.  
  584.     
  585.     def IsCoreBinding(self, virtualEvent):
  586.         """
  587.         returns true if the virtual event is bound in the core idle keybindings.
  588.         virtualEvent - string, name of the virtual event to test for, without
  589.                        the enclosing '<< >>'
  590.         """
  591.         return '<<' + virtualEvent + '>>' in self.GetCoreKeys().keys()
  592.  
  593.     
  594.     def GetCoreKeys(self, keySetName = None):
  595.         """
  596.         returns the requested set of core keybindings, with fallbacks if
  597.         required.
  598.         Keybindings loaded from the config file(s) are loaded _over_ these
  599.         defaults, so if there is a problem getting any core binding there will
  600.         be an 'ultimate last resort fallback' to the CUA-ish bindings
  601.         defined here.
  602.         """
  603.         keyBindings = {
  604.             '<<copy>>': [
  605.                 '<Control-c>',
  606.                 '<Control-C>'],
  607.             '<<cut>>': [
  608.                 '<Control-x>',
  609.                 '<Control-X>'],
  610.             '<<paste>>': [
  611.                 '<Control-v>',
  612.                 '<Control-V>'],
  613.             '<<beginning-of-line>>': [
  614.                 '<Control-a>',
  615.                 '<Home>'],
  616.             '<<center-insert>>': [
  617.                 '<Control-l>'],
  618.             '<<close-all-windows>>': [
  619.                 '<Control-q>'],
  620.             '<<close-window>>': [
  621.                 '<Alt-F4>'],
  622.             '<<do-nothing>>': [
  623.                 '<Control-x>'],
  624.             '<<end-of-file>>': [
  625.                 '<Control-d>'],
  626.             '<<python-docs>>': [
  627.                 '<F1>'],
  628.             '<<python-context-help>>': [
  629.                 '<Shift-F1>'],
  630.             '<<history-next>>': [
  631.                 '<Alt-n>'],
  632.             '<<history-previous>>': [
  633.                 '<Alt-p>'],
  634.             '<<interrupt-execution>>': [
  635.                 '<Control-c>'],
  636.             '<<view-restart>>': [
  637.                 '<F6>'],
  638.             '<<restart-shell>>': [
  639.                 '<Control-F6>'],
  640.             '<<open-class-browser>>': [
  641.                 '<Alt-c>'],
  642.             '<<open-module>>': [
  643.                 '<Alt-m>'],
  644.             '<<open-new-window>>': [
  645.                 '<Control-n>'],
  646.             '<<open-window-from-file>>': [
  647.                 '<Control-o>'],
  648.             '<<plain-newline-and-indent>>': [
  649.                 '<Control-j>'],
  650.             '<<print-window>>': [
  651.                 '<Control-p>'],
  652.             '<<redo>>': [
  653.                 '<Control-y>'],
  654.             '<<remove-selection>>': [
  655.                 '<Escape>'],
  656.             '<<save-copy-of-window-as-file>>': [
  657.                 '<Alt-Shift-S>'],
  658.             '<<save-window-as-file>>': [
  659.                 '<Alt-s>'],
  660.             '<<save-window>>': [
  661.                 '<Control-s>'],
  662.             '<<select-all>>': [
  663.                 '<Alt-a>'],
  664.             '<<toggle-auto-coloring>>': [
  665.                 '<Control-slash>'],
  666.             '<<undo>>': [
  667.                 '<Control-z>'],
  668.             '<<find-again>>': [
  669.                 '<Control-g>',
  670.                 '<F3>'],
  671.             '<<find-in-files>>': [
  672.                 '<Alt-F3>'],
  673.             '<<find-selection>>': [
  674.                 '<Control-F3>'],
  675.             '<<find>>': [
  676.                 '<Control-f>'],
  677.             '<<replace>>': [
  678.                 '<Control-h>'],
  679.             '<<goto-line>>': [
  680.                 '<Alt-g>'],
  681.             '<<smart-backspace>>': [
  682.                 '<Key-BackSpace>'],
  683.             '<<newline-and-indent>>': [
  684.                 '<Key-Return> <Key-KP_Enter>'],
  685.             '<<smart-indent>>': [
  686.                 '<Key-Tab>'],
  687.             '<<indent-region>>': [
  688.                 '<Control-Key-bracketright>'],
  689.             '<<dedent-region>>': [
  690.                 '<Control-Key-bracketleft>'],
  691.             '<<comment-region>>': [
  692.                 '<Alt-Key-3>'],
  693.             '<<uncomment-region>>': [
  694.                 '<Alt-Key-4>'],
  695.             '<<tabify-region>>': [
  696.                 '<Alt-Key-5>'],
  697.             '<<untabify-region>>': [
  698.                 '<Alt-Key-6>'],
  699.             '<<toggle-tabs>>': [
  700.                 '<Alt-Key-t>'],
  701.             '<<change-indentwidth>>': [
  702.                 '<Alt-Key-u>'],
  703.             '<<del-word-left>>': [
  704.                 '<Control-Key-BackSpace>'],
  705.             '<<del-word-right>>': [
  706.                 '<Control-Key-Delete>'] }
  707.         if keySetName:
  708.             for event in keyBindings.keys():
  709.                 binding = self.GetKeyBinding(keySetName, event)
  710.                 if binding:
  711.                     keyBindings[event] = binding
  712.                     continue
  713.                 warning = '\n Warning: configHandler.py - IdleConf.GetCoreKeys -\n problem retrieving key binding for event %r\n from key set %r.\n returning default value: %r\n' % (event, keySetName, keyBindings[event])
  714.                 sys.stderr.write(warning)
  715.             
  716.         
  717.         return keyBindings
  718.  
  719.     
  720.     def GetExtraHelpSourceList(self, configSet):
  721.         """Fetch list of extra help sources from a given configSet.
  722.  
  723.         Valid configSets are 'user' or 'default'.  Return a list of tuples of
  724.         the form (menu_item , path_to_help_file , option), or return the empty
  725.         list.  'option' is the sequence number of the help resource.  'option'
  726.         values determine the position of the menu items on the Help menu,
  727.         therefore the returned list must be sorted by 'option'.
  728.  
  729.         """
  730.         helpSources = []
  731.         if configSet == 'user':
  732.             cfgParser = self.userCfg['main']
  733.         elif configSet == 'default':
  734.             cfgParser = self.defaultCfg['main']
  735.         else:
  736.             raise InvalidConfigSet, 'Invalid configSet specified'
  737.         options = cfgParser.GetOptionList('HelpFiles')
  738.         for option in options:
  739.             value = cfgParser.Get('HelpFiles', option, default = ';')
  740.             if value.find(';') == -1:
  741.                 menuItem = ''
  742.                 helpPath = ''
  743.             else:
  744.                 value = string.split(value, ';')
  745.                 menuItem = value[0].strip()
  746.                 helpPath = value[1].strip()
  747.             if menuItem and helpPath:
  748.                 helpSources.append((menuItem, helpPath, option))
  749.                 continue
  750.         
  751.         helpSources.sort(self._IdleConf__helpsort)
  752.         return helpSources
  753.  
  754.     
  755.     def __helpsort(self, h1, h2):
  756.         if int(h1[2]) < int(h2[2]):
  757.             return -1
  758.         elif int(h1[2]) > int(h2[2]):
  759.             return 1
  760.         else:
  761.             return 0
  762.  
  763.     
  764.     def GetAllExtraHelpSourcesList(self):
  765.         '''
  766.         Returns a list of tuples containing the details of all additional help
  767.         sources configured, or an empty list if there are none. Tuples are of
  768.         the format returned by GetExtraHelpSourceList.
  769.         '''
  770.         allHelpSources = self.GetExtraHelpSourceList('default') + self.GetExtraHelpSourceList('user')
  771.         return allHelpSources
  772.  
  773.     
  774.     def LoadCfgFiles(self):
  775.         '''
  776.         load all configuration files.
  777.         '''
  778.         for key in self.defaultCfg.keys():
  779.             self.defaultCfg[key].Load()
  780.             self.userCfg[key].Load()
  781.         
  782.  
  783.     
  784.     def SaveUserCfgFiles(self):
  785.         '''
  786.         write all loaded user configuration files back to disk
  787.         '''
  788.         for key in self.userCfg.keys():
  789.             self.userCfg[key].Save()
  790.         
  791.  
  792.  
  793. idleConf = IdleConf()
  794. if __name__ == '__main__':
  795.     
  796.     def dumpCfg(cfg):
  797.         print '\n', cfg, '\n'
  798.         for key in cfg.keys():
  799.             sections = cfg[key].sections()
  800.             print key
  801.             print sections
  802.             for section in sections:
  803.                 options = cfg[key].options(section)
  804.                 print section
  805.                 print options
  806.                 for option in options:
  807.                     print option, '=', cfg[key].Get(section, option)
  808.                 
  809.             
  810.         
  811.  
  812.     dumpCfg(idleConf.defaultCfg)
  813.     dumpCfg(idleConf.userCfg)
  814.     print idleConf.userCfg['main'].Get('Theme', 'name')
  815.  
  816.