Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: configHandler.py
"""Provides access to stored IDLE configuration information.
[0] Fix | Delete
[1] Fix | Delete
Refer to the comments at the beginning of config-main.def for a description of
[2] Fix | Delete
the available configuration files and the design implemented to update user
[3] Fix | Delete
configuration information. In particular, user configuration choices which
[4] Fix | Delete
duplicate the defaults will be removed from the user's configuration files,
[5] Fix | Delete
and if a file becomes empty, it will be deleted.
[6] Fix | Delete
[7] Fix | Delete
The contents of the user files may be altered using the Options/Configure IDLE
[8] Fix | Delete
menu to access the configuration GUI (configDialog.py), or manually.
[9] Fix | Delete
[10] Fix | Delete
Throughout this module there is an emphasis on returning useable defaults
[11] Fix | Delete
when a problem occurs in returning a requested configuration value back to
[12] Fix | Delete
idle. This is to allow IDLE to continue to function in spite of errors in
[13] Fix | Delete
the retrieval of config information. When a default is returned instead of
[14] Fix | Delete
a requested config value, a message is printed to stderr to aid in
[15] Fix | Delete
configuration problem notification and resolution.
[16] Fix | Delete
"""
[17] Fix | Delete
# TODOs added Oct 2014, tjr
[18] Fix | Delete
[19] Fix | Delete
from __future__ import print_function
[20] Fix | Delete
import os
[21] Fix | Delete
import sys
[22] Fix | Delete
[23] Fix | Delete
from ConfigParser import ConfigParser
[24] Fix | Delete
from Tkinter import TkVersion
[25] Fix | Delete
from tkFont import Font, nametofont
[26] Fix | Delete
[27] Fix | Delete
class InvalidConfigType(Exception): pass
[28] Fix | Delete
class InvalidConfigSet(Exception): pass
[29] Fix | Delete
class InvalidFgBg(Exception): pass
[30] Fix | Delete
class InvalidTheme(Exception): pass
[31] Fix | Delete
[32] Fix | Delete
class IdleConfParser(ConfigParser):
[33] Fix | Delete
"""
[34] Fix | Delete
A ConfigParser specialised for idle configuration file handling
[35] Fix | Delete
"""
[36] Fix | Delete
def __init__(self, cfgFile, cfgDefaults=None):
[37] Fix | Delete
"""
[38] Fix | Delete
cfgFile - string, fully specified configuration file name
[39] Fix | Delete
"""
[40] Fix | Delete
self.file = cfgFile
[41] Fix | Delete
ConfigParser.__init__(self, defaults=cfgDefaults)
[42] Fix | Delete
[43] Fix | Delete
def Get(self, section, option, type=None, default=None, raw=False):
[44] Fix | Delete
"""
[45] Fix | Delete
Get an option value for given section/option or return default.
[46] Fix | Delete
If type is specified, return as type.
[47] Fix | Delete
"""
[48] Fix | Delete
# TODO Use default as fallback, at least if not None
[49] Fix | Delete
# Should also print Warning(file, section, option).
[50] Fix | Delete
# Currently may raise ValueError
[51] Fix | Delete
if not self.has_option(section, option):
[52] Fix | Delete
return default
[53] Fix | Delete
if type == 'bool':
[54] Fix | Delete
return self.getboolean(section, option)
[55] Fix | Delete
elif type == 'int':
[56] Fix | Delete
return self.getint(section, option)
[57] Fix | Delete
else:
[58] Fix | Delete
return self.get(section, option, raw=raw)
[59] Fix | Delete
[60] Fix | Delete
def GetOptionList(self, section):
[61] Fix | Delete
"Return a list of options for given section, else []."
[62] Fix | Delete
if self.has_section(section):
[63] Fix | Delete
return self.options(section)
[64] Fix | Delete
else: #return a default value
[65] Fix | Delete
return []
[66] Fix | Delete
[67] Fix | Delete
def Load(self):
[68] Fix | Delete
"Load the configuration file from disk."
[69] Fix | Delete
self.read(self.file)
[70] Fix | Delete
[71] Fix | Delete
class IdleUserConfParser(IdleConfParser):
[72] Fix | Delete
"""
[73] Fix | Delete
IdleConfigParser specialised for user configuration handling.
[74] Fix | Delete
"""
[75] Fix | Delete
[76] Fix | Delete
def AddSection(self, section):
[77] Fix | Delete
"If section doesn't exist, add it."
[78] Fix | Delete
if not self.has_section(section):
[79] Fix | Delete
self.add_section(section)
[80] Fix | Delete
[81] Fix | Delete
def RemoveEmptySections(self):
[82] Fix | Delete
"Remove any sections that have no options."
[83] Fix | Delete
for section in self.sections():
[84] Fix | Delete
if not self.GetOptionList(section):
[85] Fix | Delete
self.remove_section(section)
[86] Fix | Delete
[87] Fix | Delete
def IsEmpty(self):
[88] Fix | Delete
"Return True if no sections after removing empty sections."
[89] Fix | Delete
self.RemoveEmptySections()
[90] Fix | Delete
return not self.sections()
[91] Fix | Delete
[92] Fix | Delete
def RemoveOption(self, section, option):
[93] Fix | Delete
"""Return True if option is removed from section, else False.
[94] Fix | Delete
[95] Fix | Delete
False if either section does not exist or did not have option.
[96] Fix | Delete
"""
[97] Fix | Delete
if self.has_section(section):
[98] Fix | Delete
return self.remove_option(section, option)
[99] Fix | Delete
return False
[100] Fix | Delete
[101] Fix | Delete
def SetOption(self, section, option, value):
[102] Fix | Delete
"""Return True if option is added or changed to value, else False.
[103] Fix | Delete
[104] Fix | Delete
Add section if required. False means option already had value.
[105] Fix | Delete
"""
[106] Fix | Delete
if self.has_option(section, option):
[107] Fix | Delete
if self.get(section, option) == value:
[108] Fix | Delete
return False
[109] Fix | Delete
else:
[110] Fix | Delete
self.set(section, option, value)
[111] Fix | Delete
return True
[112] Fix | Delete
else:
[113] Fix | Delete
if not self.has_section(section):
[114] Fix | Delete
self.add_section(section)
[115] Fix | Delete
self.set(section, option, value)
[116] Fix | Delete
return True
[117] Fix | Delete
[118] Fix | Delete
def RemoveFile(self):
[119] Fix | Delete
"Remove user config file self.file from disk if it exists."
[120] Fix | Delete
if os.path.exists(self.file):
[121] Fix | Delete
os.remove(self.file)
[122] Fix | Delete
[123] Fix | Delete
def Save(self):
[124] Fix | Delete
"""Update user configuration file.
[125] Fix | Delete
[126] Fix | Delete
Remove empty sections. If resulting config isn't empty, write the file
[127] Fix | Delete
to disk. If config is empty, remove the file from disk if it exists.
[128] Fix | Delete
[129] Fix | Delete
"""
[130] Fix | Delete
if not self.IsEmpty():
[131] Fix | Delete
fname = self.file
[132] Fix | Delete
try:
[133] Fix | Delete
cfgFile = open(fname, 'w')
[134] Fix | Delete
except IOError:
[135] Fix | Delete
os.unlink(fname)
[136] Fix | Delete
cfgFile = open(fname, 'w')
[137] Fix | Delete
with cfgFile:
[138] Fix | Delete
self.write(cfgFile)
[139] Fix | Delete
else:
[140] Fix | Delete
self.RemoveFile()
[141] Fix | Delete
[142] Fix | Delete
class IdleConf:
[143] Fix | Delete
"""Hold config parsers for all idle config files in singleton instance.
[144] Fix | Delete
[145] Fix | Delete
Default config files, self.defaultCfg --
[146] Fix | Delete
for config_type in self.config_types:
[147] Fix | Delete
(idle install dir)/config-{config-type}.def
[148] Fix | Delete
[149] Fix | Delete
User config files, self.userCfg --
[150] Fix | Delete
for config_type in self.config_types:
[151] Fix | Delete
(user home dir)/.idlerc/config-{config-type}.cfg
[152] Fix | Delete
"""
[153] Fix | Delete
def __init__(self):
[154] Fix | Delete
self.config_types = ('main', 'extensions', 'highlight', 'keys')
[155] Fix | Delete
self.defaultCfg = {}
[156] Fix | Delete
self.userCfg = {}
[157] Fix | Delete
self.cfg = {} # TODO use to select userCfg vs defaultCfg
[158] Fix | Delete
self.CreateConfigHandlers()
[159] Fix | Delete
self.LoadCfgFiles()
[160] Fix | Delete
[161] Fix | Delete
[162] Fix | Delete
def CreateConfigHandlers(self):
[163] Fix | Delete
"Populate default and user config parser dictionaries."
[164] Fix | Delete
#build idle install path
[165] Fix | Delete
if __name__ != '__main__': # we were imported
[166] Fix | Delete
idleDir=os.path.dirname(__file__)
[167] Fix | Delete
else: # we were exec'ed (for testing only)
[168] Fix | Delete
idleDir=os.path.abspath(sys.path[0])
[169] Fix | Delete
userDir=self.GetUserCfgDir()
[170] Fix | Delete
[171] Fix | Delete
defCfgFiles = {}
[172] Fix | Delete
usrCfgFiles = {}
[173] Fix | Delete
# TODO eliminate these temporaries by combining loops
[174] Fix | Delete
for cfgType in self.config_types: #build config file names
[175] Fix | Delete
defCfgFiles[cfgType] = os.path.join(
[176] Fix | Delete
idleDir, 'config-' + cfgType + '.def')
[177] Fix | Delete
usrCfgFiles[cfgType] = os.path.join(
[178] Fix | Delete
userDir, 'config-' + cfgType + '.cfg')
[179] Fix | Delete
for cfgType in self.config_types: #create config parsers
[180] Fix | Delete
self.defaultCfg[cfgType] = IdleConfParser(defCfgFiles[cfgType])
[181] Fix | Delete
self.userCfg[cfgType] = IdleUserConfParser(usrCfgFiles[cfgType])
[182] Fix | Delete
[183] Fix | Delete
def GetUserCfgDir(self):
[184] Fix | Delete
"""Return a filesystem directory for storing user config files.
[185] Fix | Delete
[186] Fix | Delete
Creates it if required.
[187] Fix | Delete
"""
[188] Fix | Delete
cfgDir = '.idlerc'
[189] Fix | Delete
userDir = os.path.expanduser('~')
[190] Fix | Delete
if userDir != '~': # expanduser() found user home dir
[191] Fix | Delete
if not os.path.exists(userDir):
[192] Fix | Delete
warn = ('\n Warning: os.path.expanduser("~") points to\n ' +
[193] Fix | Delete
userDir + ',\n but the path does not exist.')
[194] Fix | Delete
try:
[195] Fix | Delete
print(warn, file=sys.stderr)
[196] Fix | Delete
except IOError:
[197] Fix | Delete
pass
[198] Fix | Delete
userDir = '~'
[199] Fix | Delete
if userDir == "~": # still no path to home!
[200] Fix | Delete
# traditionally IDLE has defaulted to os.getcwd(), is this adequate?
[201] Fix | Delete
userDir = os.getcwd()
[202] Fix | Delete
userDir = os.path.join(userDir, cfgDir)
[203] Fix | Delete
if not os.path.exists(userDir):
[204] Fix | Delete
try:
[205] Fix | Delete
os.mkdir(userDir)
[206] Fix | Delete
except (OSError, IOError):
[207] Fix | Delete
warn = ('\n Warning: unable to create user config directory\n' +
[208] Fix | Delete
userDir + '\n Check path and permissions.\n Exiting!\n')
[209] Fix | Delete
print(warn, file=sys.stderr)
[210] Fix | Delete
raise SystemExit
[211] Fix | Delete
# TODO continue without userDIr instead of exit
[212] Fix | Delete
return userDir
[213] Fix | Delete
[214] Fix | Delete
def GetOption(self, configType, section, option, default=None, type=None,
[215] Fix | Delete
warn_on_default=True, raw=False):
[216] Fix | Delete
"""Return a value for configType section option, or default.
[217] Fix | Delete
[218] Fix | Delete
If type is not None, return a value of that type. Also pass raw
[219] Fix | Delete
to the config parser. First try to return a valid value
[220] Fix | Delete
(including type) from a user configuration. If that fails, try
[221] Fix | Delete
the default configuration. If that fails, return default, with a
[222] Fix | Delete
default of None.
[223] Fix | Delete
[224] Fix | Delete
Warn if either user or default configurations have an invalid value.
[225] Fix | Delete
Warn if default is returned and warn_on_default is True.
[226] Fix | Delete
"""
[227] Fix | Delete
try:
[228] Fix | Delete
if self.userCfg[configType].has_option(section, option):
[229] Fix | Delete
return self.userCfg[configType].Get(section, option,
[230] Fix | Delete
type=type, raw=raw)
[231] Fix | Delete
except ValueError:
[232] Fix | Delete
warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n'
[233] Fix | Delete
' invalid %r value for configuration option %r\n'
[234] Fix | Delete
' from section %r: %r' %
[235] Fix | Delete
(type, option, section,
[236] Fix | Delete
self.userCfg[configType].Get(section, option, raw=raw)))
[237] Fix | Delete
try:
[238] Fix | Delete
print(warning, file=sys.stderr)
[239] Fix | Delete
except IOError:
[240] Fix | Delete
pass
[241] Fix | Delete
try:
[242] Fix | Delete
if self.defaultCfg[configType].has_option(section,option):
[243] Fix | Delete
return self.defaultCfg[configType].Get(
[244] Fix | Delete
section, option, type=type, raw=raw)
[245] Fix | Delete
except ValueError:
[246] Fix | Delete
pass
[247] Fix | Delete
#returning default, print warning
[248] Fix | Delete
if warn_on_default:
[249] Fix | Delete
warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n'
[250] Fix | Delete
' problem retrieving configuration option %r\n'
[251] Fix | Delete
' from section %r.\n'
[252] Fix | Delete
' returning default value: %r' %
[253] Fix | Delete
(option, section, default))
[254] Fix | Delete
try:
[255] Fix | Delete
print(warning, file=sys.stderr)
[256] Fix | Delete
except IOError:
[257] Fix | Delete
pass
[258] Fix | Delete
return default
[259] Fix | Delete
[260] Fix | Delete
def SetOption(self, configType, section, option, value):
[261] Fix | Delete
"""Set section option to value in user config file."""
[262] Fix | Delete
self.userCfg[configType].SetOption(section, option, value)
[263] Fix | Delete
[264] Fix | Delete
def GetSectionList(self, configSet, configType):
[265] Fix | Delete
"""Return sections for configSet configType configuration.
[266] Fix | Delete
[267] Fix | Delete
configSet must be either 'user' or 'default'
[268] Fix | Delete
configType must be in self.config_types.
[269] Fix | Delete
"""
[270] Fix | Delete
if not (configType in self.config_types):
[271] Fix | Delete
raise InvalidConfigType('Invalid configType specified')
[272] Fix | Delete
if configSet == 'user':
[273] Fix | Delete
cfgParser = self.userCfg[configType]
[274] Fix | Delete
elif configSet == 'default':
[275] Fix | Delete
cfgParser=self.defaultCfg[configType]
[276] Fix | Delete
else:
[277] Fix | Delete
raise InvalidConfigSet('Invalid configSet specified')
[278] Fix | Delete
return cfgParser.sections()
[279] Fix | Delete
[280] Fix | Delete
def GetHighlight(self, theme, element, fgBg=None):
[281] Fix | Delete
"""Return individual theme element highlight color(s).
[282] Fix | Delete
[283] Fix | Delete
fgBg - string ('fg' or 'bg') or None.
[284] Fix | Delete
If None, return a dictionary containing fg and bg colors with
[285] Fix | Delete
keys 'foreground' and 'background'. Otherwise, only return
[286] Fix | Delete
fg or bg color, as specified. Colors are intended to be
[287] Fix | Delete
appropriate for passing to Tkinter in, e.g., a tag_config call).
[288] Fix | Delete
"""
[289] Fix | Delete
if self.defaultCfg['highlight'].has_section(theme):
[290] Fix | Delete
themeDict = self.GetThemeDict('default', theme)
[291] Fix | Delete
else:
[292] Fix | Delete
themeDict = self.GetThemeDict('user', theme)
[293] Fix | Delete
fore = themeDict[element + '-foreground']
[294] Fix | Delete
if element == 'cursor': # There is no config value for cursor bg
[295] Fix | Delete
back = themeDict['normal-background']
[296] Fix | Delete
else:
[297] Fix | Delete
back = themeDict[element + '-background']
[298] Fix | Delete
highlight = {"foreground": fore, "background": back}
[299] Fix | Delete
if not fgBg: # Return dict of both colors
[300] Fix | Delete
return highlight
[301] Fix | Delete
else: # Return specified color only
[302] Fix | Delete
if fgBg == 'fg':
[303] Fix | Delete
return highlight["foreground"]
[304] Fix | Delete
if fgBg == 'bg':
[305] Fix | Delete
return highlight["background"]
[306] Fix | Delete
else:
[307] Fix | Delete
raise InvalidFgBg('Invalid fgBg specified')
[308] Fix | Delete
[309] Fix | Delete
def GetThemeDict(self, type, themeName):
[310] Fix | Delete
"""Return {option:value} dict for elements in themeName.
[311] Fix | Delete
[312] Fix | Delete
type - string, 'default' or 'user' theme type
[313] Fix | Delete
themeName - string, theme name
[314] Fix | Delete
Values are loaded over ultimate fallback defaults to guarantee
[315] Fix | Delete
that all theme elements are present in a newly created theme.
[316] Fix | Delete
"""
[317] Fix | Delete
if type == 'user':
[318] Fix | Delete
cfgParser = self.userCfg['highlight']
[319] Fix | Delete
elif type == 'default':
[320] Fix | Delete
cfgParser = self.defaultCfg['highlight']
[321] Fix | Delete
else:
[322] Fix | Delete
raise InvalidTheme('Invalid theme type specified')
[323] Fix | Delete
# Provide foreground and background colors for each theme
[324] Fix | Delete
# element (other than cursor) even though some values are not
[325] Fix | Delete
# yet used by idle, to allow for their use in the future.
[326] Fix | Delete
# Default values are generally black and white.
[327] Fix | Delete
# TODO copy theme from a class attribute.
[328] Fix | Delete
theme ={'normal-foreground':'#000000',
[329] Fix | Delete
'normal-background':'#ffffff',
[330] Fix | Delete
'keyword-foreground':'#000000',
[331] Fix | Delete
'keyword-background':'#ffffff',
[332] Fix | Delete
'builtin-foreground':'#000000',
[333] Fix | Delete
'builtin-background':'#ffffff',
[334] Fix | Delete
'comment-foreground':'#000000',
[335] Fix | Delete
'comment-background':'#ffffff',
[336] Fix | Delete
'string-foreground':'#000000',
[337] Fix | Delete
'string-background':'#ffffff',
[338] Fix | Delete
'definition-foreground':'#000000',
[339] Fix | Delete
'definition-background':'#ffffff',
[340] Fix | Delete
'hilite-foreground':'#000000',
[341] Fix | Delete
'hilite-background':'gray',
[342] Fix | Delete
'break-foreground':'#ffffff',
[343] Fix | Delete
'break-background':'#000000',
[344] Fix | Delete
'hit-foreground':'#ffffff',
[345] Fix | Delete
'hit-background':'#000000',
[346] Fix | Delete
'error-foreground':'#ffffff',
[347] Fix | Delete
'error-background':'#000000',
[348] Fix | Delete
#cursor (only foreground can be set)
[349] Fix | Delete
'cursor-foreground':'#000000',
[350] Fix | Delete
#shell window
[351] Fix | Delete
'stdout-foreground':'#000000',
[352] Fix | Delete
'stdout-background':'#ffffff',
[353] Fix | Delete
'stderr-foreground':'#000000',
[354] Fix | Delete
'stderr-background':'#ffffff',
[355] Fix | Delete
'console-foreground':'#000000',
[356] Fix | Delete
'console-background':'#ffffff' }
[357] Fix | Delete
for element in theme:
[358] Fix | Delete
if not cfgParser.has_option(themeName, element):
[359] Fix | Delete
# Print warning that will return a default color
[360] Fix | Delete
warning = ('\n Warning: configHandler.IdleConf.GetThemeDict'
[361] Fix | Delete
' -\n problem retrieving theme element %r'
[362] Fix | Delete
'\n from theme %r.\n'
[363] Fix | Delete
' returning default color: %r' %
[364] Fix | Delete
(element, themeName, theme[element]))
[365] Fix | Delete
try:
[366] Fix | Delete
print(warning, file=sys.stderr)
[367] Fix | Delete
except IOError:
[368] Fix | Delete
pass
[369] Fix | Delete
theme[element] = cfgParser.Get(
[370] Fix | Delete
themeName, element, default=theme[element])
[371] Fix | Delete
return theme
[372] Fix | Delete
[373] Fix | Delete
def CurrentTheme(self):
[374] Fix | Delete
"""Return the name of the currently active text color theme.
[375] Fix | Delete
[376] Fix | Delete
idlelib.config-main.def includes this section
[377] Fix | Delete
[Theme]
[378] Fix | Delete
default= 1
[379] Fix | Delete
name= IDLE Classic
[380] Fix | Delete
name2=
[381] Fix | Delete
# name2 set in user config-main.cfg for themes added after 2015 Oct 1
[382] Fix | Delete
[383] Fix | Delete
Item name2 is needed because setting name to a new builtin
[384] Fix | Delete
causes older IDLEs to display multiple error messages or quit.
[385] Fix | Delete
See https://bugs.python.org/issue25313.
[386] Fix | Delete
When default = True, name2 takes precedence over name,
[387] Fix | Delete
while older IDLEs will just use name.
[388] Fix | Delete
"""
[389] Fix | Delete
default = self.GetOption('main', 'Theme', 'default',
[390] Fix | Delete
type='bool', default=True)
[391] Fix | Delete
if default:
[392] Fix | Delete
theme = self.GetOption('main', 'Theme', 'name2', default='')
[393] Fix | Delete
if default and not theme or not default:
[394] Fix | Delete
theme = self.GetOption('main', 'Theme', 'name', default='')
[395] Fix | Delete
source = self.defaultCfg if default else self.userCfg
[396] Fix | Delete
if source['highlight'].has_section(theme):
[397] Fix | Delete
return theme
[398] Fix | Delete
else:
[399] Fix | Delete
return "IDLE Classic"
[400] Fix | Delete
[401] Fix | Delete
def CurrentKeys(self):
[402] Fix | Delete
"Return the name of the currently active key set."
[403] Fix | Delete
return self.GetOption('main', 'Keys', 'name', default='')
[404] Fix | Delete
[405] Fix | Delete
def GetExtensions(self, active_only=True, editor_only=False, shell_only=False):
[406] Fix | Delete
"""Return extensions in default and user config-extensions files.
[407] Fix | Delete
[408] Fix | Delete
If active_only True, only return active (enabled) extensions
[409] Fix | Delete
and optionally only editor or shell extensions.
[410] Fix | Delete
If active_only False, return all extensions.
[411] Fix | Delete
"""
[412] Fix | Delete
extns = self.RemoveKeyBindNames(
[413] Fix | Delete
self.GetSectionList('default', 'extensions'))
[414] Fix | Delete
userExtns = self.RemoveKeyBindNames(
[415] Fix | Delete
self.GetSectionList('user', 'extensions'))
[416] Fix | Delete
for extn in userExtns:
[417] Fix | Delete
if extn not in extns: #user has added own extension
[418] Fix | Delete
extns.append(extn)
[419] Fix | Delete
if active_only:
[420] Fix | Delete
activeExtns = []
[421] Fix | Delete
for extn in extns:
[422] Fix | Delete
if self.GetOption('extensions', extn, 'enable', default=True,
[423] Fix | Delete
type='bool'):
[424] Fix | Delete
#the extension is enabled
[425] Fix | Delete
if editor_only or shell_only: # TODO if both, contradictory
[426] Fix | Delete
if editor_only:
[427] Fix | Delete
option = "enable_editor"
[428] Fix | Delete
else:
[429] Fix | Delete
option = "enable_shell"
[430] Fix | Delete
if self.GetOption('extensions', extn,option,
[431] Fix | Delete
default=True, type='bool',
[432] Fix | Delete
warn_on_default=False):
[433] Fix | Delete
activeExtns.append(extn)
[434] Fix | Delete
else:
[435] Fix | Delete
activeExtns.append(extn)
[436] Fix | Delete
return activeExtns
[437] Fix | Delete
else:
[438] Fix | Delete
return extns
[439] Fix | Delete
[440] Fix | Delete
def RemoveKeyBindNames(self, extnNameList):
[441] Fix | Delete
"Return extnNameList with keybinding section names removed."
[442] Fix | Delete
# TODO Easier to return filtered copy with list comp
[443] Fix | Delete
names = extnNameList
[444] Fix | Delete
kbNameIndicies = []
[445] Fix | Delete
for name in names:
[446] Fix | Delete
if name.endswith(('_bindings', '_cfgBindings')):
[447] Fix | Delete
kbNameIndicies.append(names.index(name))
[448] Fix | Delete
kbNameIndicies.sort(reverse=True)
[449] Fix | Delete
for index in kbNameIndicies: #delete each keybinding section name
[450] Fix | Delete
del(names[index])
[451] Fix | Delete
return names
[452] Fix | Delete
[453] Fix | Delete
def GetExtnNameForEvent(self, virtualEvent):
[454] Fix | Delete
"""Return the name of the extension binding virtualEvent, or None.
[455] Fix | Delete
[456] Fix | Delete
virtualEvent - string, name of the virtual event to test for,
[457] Fix | Delete
without the enclosing '<< >>'
[458] Fix | Delete
"""
[459] Fix | Delete
extName = None
[460] Fix | Delete
vEvent = '<<' + virtualEvent + '>>'
[461] Fix | Delete
for extn in self.GetExtensions(active_only=0):
[462] Fix | Delete
for event in self.GetExtensionKeys(extn):
[463] Fix | Delete
if event == vEvent:
[464] Fix | Delete
extName = extn # TODO return here?
[465] Fix | Delete
return extName
[466] Fix | Delete
[467] Fix | Delete
def GetExtensionKeys(self, extensionName):
[468] Fix | Delete
"""Return dict: {configurable extensionName event : active keybinding}.
[469] Fix | Delete
[470] Fix | Delete
Events come from default config extension_cfgBindings section.
[471] Fix | Delete
Keybindings come from GetCurrentKeySet() active key dict,
[472] Fix | Delete
where previously used bindings are disabled.
[473] Fix | Delete
"""
[474] Fix | Delete
keysName = extensionName + '_cfgBindings'
[475] Fix | Delete
activeKeys = self.GetCurrentKeySet()
[476] Fix | Delete
extKeys = {}
[477] Fix | Delete
if self.defaultCfg['extensions'].has_section(keysName):
[478] Fix | Delete
eventNames = self.defaultCfg['extensions'].GetOptionList(keysName)
[479] Fix | Delete
for eventName in eventNames:
[480] Fix | Delete
event = '<<' + eventName + '>>'
[481] Fix | Delete
binding = activeKeys[event]
[482] Fix | Delete
extKeys[event] = binding
[483] Fix | Delete
return extKeys
[484] Fix | Delete
[485] Fix | Delete
def __GetRawExtensionKeys(self,extensionName):
[486] Fix | Delete
"""Return dict {configurable extensionName event : keybinding list}.
[487] Fix | Delete
[488] Fix | Delete
Events come from default config extension_cfgBindings section.
[489] Fix | Delete
Keybindings list come from the splitting of GetOption, which
[490] Fix | Delete
tries user config before default config.
[491] Fix | Delete
"""
[492] Fix | Delete
keysName = extensionName+'_cfgBindings'
[493] Fix | Delete
extKeys = {}
[494] Fix | Delete
if self.defaultCfg['extensions'].has_section(keysName):
[495] Fix | Delete
eventNames = self.defaultCfg['extensions'].GetOptionList(keysName)
[496] Fix | Delete
for eventName in eventNames:
[497] Fix | Delete
binding = self.GetOption(
[498] Fix | Delete
'extensions', keysName, eventName, default='').split()
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function