e f}@sJdZddlZddlZddlmZddlmZddlmZm Z Gddde Z Gdd d e Z Gd d d e Z Gd d d e ZGdddeZGdddeZGdddZeZedkrFddZeejeejeejdjddndS)aProvides 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, and if a file becomes empty, it will be deleted. 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. N) ConfigParser) TkVersion)Font nametofontc@seZdZdS)InvalidConfigTypeN)__name__ __module__ __qualname__r r :/opt/alt/python34/lib64/python3.4/idlelib/configHandler.pyrs rc@seZdZdS)InvalidConfigSetN)rrr r r r r r s r c@seZdZdS) InvalidFgBgN)rrr r r r r r s r c@seZdZdS) InvalidThemeN)rrr r r r r rs rc@sReZdZdZdddZdddddZdd Zd d ZdS) IdleConfParserzI A ConfigParser specialised for idle configuration file handling NcCs&||_tj|d|dddS)zK cfgFile - string, fully specified configuration file name ZdefaultsstrictFN)filer__init__)selfcfgFileZ cfgDefaultsr r r r%s zIdleConfParser.__init__FcCsh|j||s|S|dkr2|j||S|dkrN|j||S|j||d|SdS)z Get an option value for given section/option or return default. If type is specified, return as type. boolintrawN) has_optionZ getbooleanZgetintget)rsectionoptiontypedefaultrr r r Get,s  zIdleConfParser.GetcCs$|j|r|j|SgSdS)z4Return a list of options for given section, else [].N) has_sectionoptions)rrr r r GetOptionList=s zIdleConfParser.GetOptionListcCs|j|jdS)z&Load the configuration file from disk.N)readr)rr r r LoadDszIdleConfParser.Load)rrr __doc__rrr!r#r r r r r!s  rc@sjeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)IdleUserConfParserzG IdleConfigParser specialised for user configuration handling. cCs#|j|s|j|ndS)z!If section doesn't exist, add it.N)r add_section)rrr r r AddSectionMszIdleUserConfParser.AddSectioncCs:x3|jD]%}|j|s |j|q q WdS)z)Remove any sections that have no options.N)sectionsr!Zremove_section)rrr r r RemoveEmptySectionsRsz&IdleUserConfParser.RemoveEmptySectionscCs|j|j S)z9Return True if no sections after removing empty sections.)r)r()rr r r IsEmptyXs zIdleUserConfParser.IsEmptycCs#|j|r|j||SdS)zReturn True if option is removed from section, else False. False if either section does not exist or did not have option. F)rZ remove_option)rrrr r r RemoveOption]szIdleUserConfParser.RemoveOptioncCs|j||rH|j|||kr.dS|j|||dSn6|j|sg|j|n|j|||dSdS)zReturn True if option is added or changed to value, else False. Add section if required. False means option already had value. FTN)rrsetrr&)rrrvaluer r r SetOptionfszIdleUserConfParser.SetOptioncCs,tjj|jr(tj|jndS)z9Remove user config file self.file from disk if it exists.N)ospathexistsrremove)rr r r RemoveFilewszIdleUserConfParser.RemoveFilecCs|jsv|j}yt|d}Wn.tk rXtj|t|d}YnX||j|WdQXn |jdS)zUpdate 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. wN)r*ropenOSErrorr/unlinkwriter3)rZfnamerr r r Save|s    zIdleUserConfParser.SaveN) rrr r$r'r)r*r+r.r3r9r r r r r%Hs      r%c@sieZdZdZddZddZddZddd d d d Zd dZddZ dddZ ddZ ddZ ddZ d d d ddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zdd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8ZdS)9IdleConfalHold 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 cCs<d|_i|_i|_i|_|j|jdS)Nmain extensions highlightkeys)zmainz extensionsz highlightzkeys) config_types defaultCfguserCfgcfgCreateConfigHandlers LoadCfgFiles)rr r r rs      zIdleConf.__init__cCstdkr!tjjt}ntjjtjd}|j}i}i}xS|jD]H}tjj |d|d||>' Nz<>rkr)rnGetExtensionKeys)r virtualEventZextNameZvEventrleventr r r GetExtnNameForEvents zIdleConf.GetExtnNameForEventc Cs|d}|j}i}|jdj|r~|jdj|}x3|D](}d|d}||}|||>)GetCurrentKeySetr@rr!) r extensionNamekeysNameZ activeKeysextKeys eventNames eventNamerxbindingr r r rvs    zIdleConf.GetExtensionKeyscCs|d}i}|jdj|r|jdj|}xJ|D]?}|jd||ddj}d|d}|||>)r@rr!rYsplit)rr{r|r}r~rrrxr r r Z__GetRawExtensionKeyss  zIdleConf.__GetRawExtensionKeyscCs|d}|j|}|jdj|r|jdj|}xJ|D]?}|jd||ddj}d|d}|||>)rvr@rr!rYr)rr{Z bindsNameZextBindsr~rrrxr r r GetExtensionBindingss  zIdleConf.GetExtensionBindingscCs5|dd}|jd||ddj}|S)zReturn the keybinding list for keySetName eventStr. keySetName - name of key binding set (config-keys section). eventStr - virtual event, including brackets, as in '<>'. r>rrc)rYr)r keySetNameZeventStrrrr r r GetKeyBinding s!zIdleConf.GetKeyBindingcCst|j|j}tjdkrpxI|jD]8\}}dd|D}||kr1|||"s z-IdleConf.GetCurrentKeySet..) GetKeySetrgrIplatformitems)rresultkvZv2r r r rzs zIdleConf.GetCurrentKeySetcCs|j|}|jdd}xh|D]`}|j|}|r(xB|D]7}|||jkrsd||>' z<>)r)rrwr r r IsCoreBinding:szIdleConf.IsCoreBindingc Csi1ddgd6ddgd6ddgd 6d d gd 6d gd6dgd6dgd6dgd6dgd6dgd6dgd6dgd6dgd6dgd6dgd 6d!gd"6d#gd$6d%gd&6d'gd(6d)gd*6d+gd,6d-gd.6d/gd06d1gd26d3gd46d5gd66d7gd86d9gd:6d;gd<6d=gd>6d?d@gdA6dBgdC6dDgdE6dFgdG6dHgdI6dJgdK6dLgdM6dNdOgdP6dQgdR6dSgdT6dUgdV6dWgdX6dYgdZ6d[gd\6d]gd^6d_gd`6dagdb6dcgdd6degdf6}|rxy|D]n}|j||}|r:|||z z<>z z z<>z z z <>z zz<>z z<>z z<>zz<>z<>z z<>zz<>z z<>zz<>zz<>z<>zz<>z z<>zz<>zz<>z z<>z z<>z z<>z z<>z z<>zz<>z z<>zz<>z z<>zz<>zz<>z z<>z zz<>zz<>z z<>z z<>z z <>zz <>zz<>z zz<>z z<>zz<>zz<>z z<>z z<>z z<>z z<>z z<>z z<>zz<>zz<>z Warning: configHandler.py - IdleConf.GetCoreKeys - problem retrieving key binding for event %r from key set %r. returning default value: %rr)rrOrIrPr6)rrZ keyBindingsrxrrXr r r rEs|                                                      zIdleConf.GetCoreKeysc Csg}|dkr"|jd}n(|dkr>|jd}n td|jd}x|D]}|jd|dd}|jdd krd}d}n/|jd}|d j}|dj}|r`|r`|j|||fq`q`W|j d d d |S)aReturn list of extra help sources from a given configSet. 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'. rZr;rzInvalid configSet specifiedZ HelpFiles;rrcrkeycSs|dS)Nrr )rr r r sz1IdleConf.GetExtraHelpSourceList..) rAr@r r!rfindrstriprjrt) rr[Z helpSourcesr\r rr-ZmenuItemZhelpPathr r r GetExtraHelpSourceLists&       zIdleConf.GetExtraHelpSourceListcCs |jd|jd}|S)zReturn a list of the details of all additional help sources. Tuples in the list are those of GetExtraHelpSourceList. rrZ)r)rZallHelpSourcesr r r GetAllExtraHelpSourcesLists z#IdleConf.GetAllExtraHelpSourcesListc Cs|j||ddd}|j||ddddd}|j||ddd dd }|d krtd kr~d }qtdd ddd|}tj|}|d}|d}|d krd}n|ddk}n|||rdndfS)aRetrieve a font from configuration (font, font-size, font-bold) Intercept the special value 'TkFixedFont' and substitute the actual font, factoring in some tweaks if needed for appearance sakes. The 'root' parameter can normally be any valid Tkinter widget. Return a tuple (family, size, weight) suitable for passing to tkinter.Font ZfontrZcourierz font-sizerrZ10z font-boldrrZ TkFixedFontg!@ZCourierrdr1Trootfamilysize ZweightboldZnormal)rYrrZactual) rrrVrrrrfZ actualFontr r r GetFonts          zIdleConf.GetFontcCs:x3|jD](}|j|j|j|jq WdS)zLoad all configuration files.N)r@r#rA)rrr r r rDszIdleConf.LoadCfgFilescCs)x"|jD]}|j|jq WdS)z2Write all loaded user configuration files to disk.N)rAr9)rrr r r SaveUserCfgFilesszIdleConf.SaveUserCfgFiles)rrr r$rrCrJrYr.r]rar^rfrgrnriryrvrrrrzrrrrrrrDrr r r r r:s8   -   @  #       M  r:rEc Cstd|dx|D]}||j}t|t|xf|D]^}||j|}t|t|x.|D]&}t|d||j||q|WqHWqWdS)N =)rOr(r r)rBrr(rr rr r r dumpCfgs       rr;rbrd)r$r/rIZ configparserrZtkinterrZ tkinter.fontrr Exceptionrr r rrr%r:ZidleConfrrr@rArOrr r r r s(  'GW