m &UIc@s*dZdkZdkZdkZdklZlZlZdefdYZdefdYZ defdYZ d efd YZ d efd YZ d e fdYZ dfdYZeZedjo?dZeeieeieididdGHndS(sProvides 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(s ConfigParsers NoOptionErrorsNoSectionErrortInvalidConfigTypecBstZRS(N(t__name__t __module__(((t2/data/zmath/lib/python2.4/idlelib/configHandler.pyRstInvalidConfigSetcBstZRS(N(RR(((RRst InvalidFgBgcBstZRS(N(RR(((RRst InvalidThemecBstZRS(N(RR(((RRstIdleConfParsercBs;tZdZedZeedZdZdZRS(sI A ConfigParser specialised for idle configuration file handling cCs ||_ti|d|dS(sK cfgFile - string, fully specified configuration file name tdefaultsN(tcfgFiletselftfilet ConfigParsert__init__t cfgDefaults(R R R((RR "s cCsi|djo |i}n$|djo |i}n |i}|i||o|||Sn|SdS(s Get an option value for given section/option or return default. If type is specified, return as type. tbooltintN( ttypeR t getbooleantgetValtgetinttgett has_optiontsectiontoptiontdefault(R RRRRR((RtGet)s     cCs)|i|o|i|SngSdS(s6 Get an option list for given section N(R t has_sectionRtoptions(R R((Rt GetOptionList:scCs|i|idS(s7 Load the configuration file from disk N(R treadR (R ((RtLoadCs(RRt__doc__tNoneR RRR(((RRs   tIdleUserConfParsercBsMtZdZdZdZdZdZdZdZdZ RS(sG IdleConfigParser specialised for user configuration handling. cCs%|i|p|i|ndS(s2 if section doesn't exist, add it N(R RRt add_section(R R((Rt AddSectionNscCs<x5|iD]'}|i|p|i|q q WdS(s: remove any sections that have no options N(R tsectionsRRtremove_section(R R((RtRemoveEmptySectionsUs  cCs'|i|iodSndSdS(sp Remove empty sections and then return 1 if parser has no sections left, else return 0. iiN(R R'R%(R ((RtIsEmpty]s   cCs(|i|o|i||SndS(sl If section/option exists, remove it. Returns 1 if option was removed, 0 otherwise. N(R RRt remove_optionR(R RR((Rt RemoveOptionhscCs|i||o<|i|||jodSq|i|||dSn9|i|p|i|n|i|||dSdS(s Sets option to value, adding section if required. Returns 1 if option was added or changed, otherwise 0. iiN( R RRRRtvaluetsetRR#(R RRR+((Rt SetOptionpscCs.tii|ioti|indS(sF Removes the user config file from disk if it exists. N(tostpathtexistsR R tremove(R ((Rt RemoveFilescCs>|ip#t|id}|i|n |idS(sUpdate 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. twN(R R(topenR R twriteR2(R R ((RtSaves  ( RRR R$R'R(R*R-R2R6(((RR"Is      tIdleConfcBstZdZdZdZdZeeedZdZ dZ edZ dZ d Z d Zeeed Zd Zd ZdZdZdZdZdZdZdZedZdZdZdZdZdZRS(s holds config parsers for all idle config files: default config files (idle install dir)/config-main.def (idle install dir)/config-extensions.def (idle install dir)/config-highlight.def (idle install dir)/config-keys.def user config files (user home dir)/.idlerc/config-main.cfg (user home dir)/.idlerc/config-extensions.cfg (user home dir)/.idlerc/config-highlight.cfg (user home dir)/.idlerc/config-keys.cfg cCs3h|_h|_h|_|i|idS(N(R t defaultCfgtuserCfgtcfgtCreateConfigHandlerst LoadCfgFiles(R ((RR s     cCstdjotiit}ntiitid}|i }d }h}h}xP|D]H}tii|d|d||R?R@RAsInvalid configType specifiedtuserRsInvalid configSet specifiedN(smains extensionss highlightskeys( RXRt configSetR R9t cfgParserR8RR%(R R]RXR^((RtGetSectionLists     cCs|idi|o|id|}n|id|}||d}|djo|d}n||d}hd|<d |<}|p|Sn<|d jo |dSn|d jo |d Sn t d d S(s$ return individual highlighting theme elements. fgBg - string ('fg'or'bg') or None, if None return a dictionary containing fg and bg colours (appropriate for passing to Tkinter in, e.g., a tag_config call), otherwise fg or bg colour only as specified. R@RR\s -foregroundtcursorsnormal-backgrounds -backgroundt foregroundt backgroundtfgtbgsInvalid fgBg specifiedN( R R8Rtthemet GetThemeDictt themeDicttelementtforetbackR@tfgBgR(R ReRhRkRgRjRiR@((Rt GetHighlights      cCs|djo|id}n(|djo|id}n tdhdd<dd<d d<d d<d d<d d<d d<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<d d<d!d<d"d<}xx|iD]j}|i ||p+d#||||f}t i i|n|i||d||}|||tThemetnameRtN(R R[(R ((Rt CurrentThemegscCs|idddddS(sB Returns the name of the currently active key set R>tKeysRqRRrN(R R[(R ((Rt CurrentKeysmsc Cs(|i|idd}|i|idd}x,|D]$}||jo|i|q=q=W|og}x|D]}|i d|ddt ddos|p|oT|o d}nd}|i d||dt ddd to|i|qq|i|qyqyW|Sn|Sd S( s Gets a list of all idle extensions declared in the config files. active_only - boolean, if true only return active (enabled) extensions RR?R\tenableRRt enable_editort enable_shellRYN(R tRemoveKeyBindNamesR_textnst userExtnstextntappendt active_onlyt activeExtnsR[tTruet editor_onlyt shell_onlyRtFalse( R R~RRRzRR|R{R((Rt GetExtensionsss0     cCs|}g}xH|D]@}|idp|ido|i|i|qqW|i|ix|D] }||=qrW|S(Nt _bindingst _cfgBindings( t extnNameListtnamestkbNameIndiciesRqtendswithR}tindextsorttreverse(R RRRqRR((RRys    cCsld}d|d}xQ|iddD]=}x4|i|iD]}||jo |}qCqCWq'W|S(s Returns the name of the extension that virtualEvent is bound in, or None if not bound in any extension. virtualEvent - string, name of the virtual event to test for, without the enclosing '<< >>' s<>R~iN( R!textNamet virtualEventtvEventR RR|tGetExtensionKeysRAtevent(R RRRR|R((RtGetExtnNameForEvents c Cs|d}|i}h}|idi|oM|idi|}x4|D](}d|d}||}|||>N( t extensionNametkeysNameR tGetCurrentKeySett activeKeystextKeysR8RRt eventNamest eventNameRtbinding( R RRRRRRRR((RRs   cCs|d}h}|idi|od|idi|}xK|D]?}|i d||ddi }d|d}|||>N( RRRR R8RRRRR[tsplitRR(R RRRRRRR((Rt__GetRawExtensionKeyss  cCs|d}|i|}|idi|od|idi|}xK|D]?}|i d||ddi }d|d}|||>N(Rt bindsNameR RtextBindsR8RRRRR[RRR(R RRRRRRR((RtGetExtensionBindingss  cCs2|dd!}|id||ddi}|S(s returns the keybinding for a specific event. keySetName - string, name of key binding set eventStr - string, the virtual event we want the binding for, represented as a string, eg. '<>' iiRARRrN(teventStrRR R[t keySetNameRR(R RRRR((Rt GetKeyBindings !cCs|i|iS(N(R t GetKeySetRu(R ((RRscCs|i|}|idd}xr|D]j}|i|}|oNxK|i D]9}|||i jod||>' s<>N(RR RRA(R R((Rt IsCoreBindingscCshdddg<dddg<ddd g<d d d g<d dg<ddg<ddg<ddg<ddg<ddg<ddg<ddg<ddg<ddg<dd g<d!d"g<d#d$g<d%d&g<d'd(g<d)d*g<d+d,g<d-d.g<d/d0g<d1d2g<d3d4g<d5d6g<d7d8g<d9d:g<d;d<g<d=d>g<d?d@dAg<dBdCg<dDdEg<dFdGg<dHdIg<dJdKg<dLdMg<dNdOg<dPdQg<dRdSg<dTdUg<dVdWg<dXdYg<dZd[g<d\d]g<d^d_g<d`dag<}|oixb|iD]T}|i||}|o|||>s s s<>s s s <>s s s<>s ss<>s s<>s s<>ss<>s<>s s<>ss<>s s<>ss<>ss<>s<>ss<>s s<>ss<>ss<>s s<>s s<>s s<>s s<>s s<>ss<>s s<>ss<>s s<>ss<>ss<>s s<>s ss<>ss<>s s<>s s <>s s <>ss<>ss<>s s<>s s<>ss<>ss<>s s<>s s<>s s<>s s<>s s<>s s Warning: configHandler.py - IdleConf.GetCoreKeys - problem retrieving key binding for event %r from key set %r. returning default value: %r N( t keyBindingsRRARR RRRZRFRRR5(R RRRZRR((RRsK1 c Csg}|djo|id}n(|djo|id}n td|id}x|D]}|i d|dd}|i ddjod}d}n3ti|d}|d i}|d i}|o!|o|i|||fqaqaW|i|i|S( sFetch 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'. R\R>RsInvalid configSet specifiedt HelpFilest;iRriiN(t helpSourcesR]R R9R^R8RRRRRR+tfindtmenuItemthelpPathtstringRtstripR}Rt_IdleConf__helpsort( R R]R^RRR+RRR((RtGetExtraHelpSourceListVs*     cCsZt|dt|djodSn.t|dt|djodSndSdS(Niiii(Rth1th2(R RR((Rt __helpsortvs !!cCs |id|id}|S(s Returns a list of tuples containing the details of all additional help sources configured, or an empty list if there are none. Tuples are of the format returned by GetExtraHelpSourceList. RR\N(R RtallHelpSources(R R((RtGetAllExtraHelpSourcesList~scCs@x9|iiD](}|i|i|i|iqWdS(s/ load all configuration files. N(R R8RAtkeyRR9(R R((RR<s cCs/x(|iiD]}|i|iqWdS(sH write all loaded user configuration files back to disk N(R R9RARR6(R R((RtSaveUserCfgFiless( RRR R R;RGR!RR[R-R_RlRfRsRuRRRyRRRRRRRRRRRRR<R(((RR7s6        =  !        H  R=cCsdG|GdGHx|iD]|}||i}|GH|GHxY|D]Q}||i|}|GH|GHx+|D]#}|GdG||i||GHqkWqAWqWdS(Ns t=(R:RARR%RRRR(R:RRRR%R((RtdumpCfgs  R>RpRq(R R.RFRR t NoOptionErrortNoSectionErrort ExceptionRRRRRR"R7tidleConfRRR8R9R(RRRRR"RR7RFRRRRR.RR ((Rt?s&   +L