@@ -215,7 +215,8 @@ def GetUserCfgDir(self):
215215 sys .stderr .write (warn )
216216 return userDir
217217
218- def GetOption (self , configType , section , option , default = None , type = None ):
218+ def GetOption (self , configType , section , option , default = None , type = None ,
219+ warn_on_default = True ):
219220 """
220221 Get an option value for given config type and given general
221222 configuration section/option or return a default. If type is specified,
@@ -224,21 +225,30 @@ def GetOption(self, configType, section, option, default=None, type=None):
224225 fallback to a useable passed-in default if the option isn't present in
225226 either the user or the default configuration.
226227 configType must be one of ('main','extensions','highlight','keys')
227- If a default is returned a warning is printed to stderr.
228+ If a default is returned, and warn_on_default is True, a warning is
229+ printed to stderr.
230+
228231 """
229232 if self .userCfg [configType ].has_option (section ,option ):
230233 return self .userCfg [configType ].Get (section , option , type = type )
231234 elif self .defaultCfg [configType ].has_option (section ,option ):
232235 return self .defaultCfg [configType ].Get (section , option , type = type )
233236 else : #returning default, print warning
234- warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n '
235- ' problem retrieving configration option %r\n '
236- ' from section %r.\n '
237- ' returning default value: %r\n ' %
238- (option , section , default ))
239- sys .stderr .write (warning )
237+ if warn_on_default :
238+ warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n '
239+ ' problem retrieving configration option %r\n '
240+ ' from section %r.\n '
241+ ' returning default value: %r\n ' %
242+ (option , section , default ))
243+ sys .stderr .write (warning )
240244 return default
241245
246+ def SetOption (self , configType , section , option , value ):
247+ """In user's config file, set section's option to value.
248+
249+ """
250+ self .userCfg [configType ].SetOption (section , option , value )
251+
242252 def GetSectionList (self , configSet , configType ):
243253 """
244254 Get a list of sections from either the user or default config for
@@ -356,10 +366,10 @@ def CurrentKeys(self):
356366 """
357367 return self .GetOption ('main' ,'Keys' ,'name' ,default = '' )
358368
359- def GetExtensions (self , activeOnly = 1 ):
369+ def GetExtensions (self , active_only = True , editor_only = False , shell_only = False ):
360370 """
361371 Gets a list of all idle extensions declared in the config files.
362- activeOnly - boolean, if true only return active (enabled) extensions
372+ active_only - boolean, if true only return active (enabled) extensions
363373 """
364374 extns = self .RemoveKeyBindNames (
365375 self .GetSectionList ('default' ,'extensions' ))
@@ -368,13 +378,23 @@ def GetExtensions(self, activeOnly=1):
368378 for extn in userExtns :
369379 if extn not in extns : #user has added own extension
370380 extns .append (extn )
371- if activeOnly :
381+ if active_only :
372382 activeExtns = []
373383 for extn in extns :
374- if self .GetOption ('extensions' ,extn ,'enable' ,default = 1 ,
375- type = 'bool' ):
384+ if self .GetOption ('extensions' , extn , 'enable' , default = True ,
385+ type = 'bool' ):
376386 #the extension is enabled
377- activeExtns .append (extn )
387+ if editor_only or shell_only :
388+ if editor_only :
389+ option = "enable_editor"
390+ else :
391+ option = "enable_shell"
392+ if self .GetOption ('extensions' , extn ,option ,
393+ default = True , type = 'bool' ,
394+ warn_on_default = False ):
395+ activeExtns .append (extn )
396+ else :
397+ activeExtns .append (extn )
378398 return activeExtns
379399 else :
380400 return extns
@@ -401,7 +421,7 @@ def GetExtnNameForEvent(self,virtualEvent):
401421 """
402422 extName = None
403423 vEvent = '<<' + virtualEvent + '>>'
404- for extn in self .GetExtensions (activeOnly = 0 ):
424+ for extn in self .GetExtensions (active_only = 0 ):
405425 for event in self .GetExtensionKeys (extn ).keys ():
406426 if event == vEvent :
407427 extName = extn
@@ -482,7 +502,7 @@ def GetKeySet(self,keySetName):
482502 in an extension is already in use, that binding is disabled.
483503 """
484504 keySet = self .GetCoreKeys (keySetName )
485- activeExtns = self .GetExtensions (activeOnly = 1 )
505+ activeExtns = self .GetExtensions (active_only = 1 )
486506 for extn in activeExtns :
487507 extKeys = self .__GetRawExtensionKeys (extn )
488508 if extKeys : #the extension defines keybindings
0 commit comments