[Idle-dev] CVS: idle configHandler.py,1.11,1.12

Stephen M. Gava elguavas@users.sourceforge.net
Sat, 19 Jan 2002 02:32:15 -0800


Update of /cvsroot/idlefork/idle
In directory usw-pr-cvs1:/tmp/cvs-serv16713

Modified Files:
	configHandler.py 
Log Message:
further work on keybinding configuration


Index: configHandler.py
===================================================================
RCS file: /cvsroot/idlefork/idle/configHandler.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** configHandler.py	2002/01/19 00:29:54	1.11
--- configHandler.py	2002/01/19 10:32:13	1.12
***************
*** 154,158 ****
          else:
              raise 'Invalid configSet specified'
-         
          return cfgParser.sections()
      
--- 154,157 ----
***************
*** 216,221 ****
          activeOnly - boolean, if true only return active (enabled) extensions
          """
!         extns=self.GetSectionList('default','extensions')
!         userExtns=self.GetSectionList('user','extensions')
          for extn in userExtns:
              if extn not in extns: #user has added own extension
--- 215,222 ----
          activeOnly - boolean, if true only return active (enabled) extensions
          """
!         extns=self.RemoveKeyBindNames(
!                 self.GetSectionList('default','extensions'))
!         userExtns=self.RemoveKeyBindNames(
!                 self.GetSectionList('user','extensions'))
          for extn in userExtns:
              if extn not in extns: #user has added own extension
***************
*** 231,234 ****
--- 232,304 ----
              return extns        
  
+     def RemoveKeyBindNames(self,extnNameList):
+         #get rid of keybinding section names
+         names=extnNameList
+         kbNameIndicies=[]
+         for name in names:
+             if name.endswith('_bindings') or name.endswith('_cfgBindings'): 
+                     kbNameIndicies.append(names.index(name))
+         kbNameIndicies.sort()
+         kbNameIndicies.reverse()
+         for index in kbNameIndicies: #delete each keybinding section name    
+             del(names[index])
+         return names
+         
+     def GetExtensionKeys(self,extensionName):
+         """
+         returns a dictionary of the configurable keybindings for a particular
+         extension,as they exist in the dictionary returned by GetCurrentKeySet;
+         that is, where previously re-used bindings are disabled.
+         """
+         keysName=extensionName+'_cfgBindings'
+         activeKeys=self.GetCurrentKeySet()
+         extKeys={}
+         if self.defaultCfg['extensions'].has_section(keysName):
+             eventNames=self.defaultCfg['extensions'].GetOptionList(keysName)
+             for eventName in eventNames:
+                 event='<<'+eventName+'>>'
+                 binding=activeKeys[event]
+                 extKeys[event]=binding
+         return extKeys 
+         
+     def __GetRawExtensionKeys(self,extensionName):
+         """
+         returns a dictionary of the configurable keybindings for a particular
+         extension, as defined in the configuration files, or an empty dictionary
+         if no bindings are found
+         """
+         keysName=extensionName+'_cfgBindings'
+         extKeys={}
+         if self.defaultCfg['extensions'].has_section(keysName):
+             eventNames=self.defaultCfg['extensions'].GetOptionList(keysName)
+             for eventName in eventNames:
+                 binding=self.GetOption('extensions',keysName,
+                         eventName,default='').split()
+                 event='<<'+eventName+'>>'
+                 extKeys[event]=binding
+         return extKeys 
+     
+     def GetExtensionBindings(self,extensionName):
+         """
+         Returns a dictionary of all the event bindings for a particular
+         extension. The configurable keybindings are returned as they exist in
+         the dictionary returned by GetCurrentKeySet; that is, where re-used 
+         keybindings are disabled.
+         """
+         bindsName=extensionName+'_bindings'
+         extBinds=self.GetExtensionKeys(extensionName)
+         #add the non-configurable bindings
+         if self.defaultCfg['extensions'].has_section(bindsName):
+             eventNames=self.defaultCfg['extensions'].GetOptionList(bindsName)
+             for eventName in eventNames:
+                 binding=self.GetOption('extensions',bindsName,
+                         eventName,default='').split()
+                 event='<<'+eventName+'>>'
+                 extBinds[event]=binding
+         
+         return extBinds 
+         
+     
+     
      def GetKeyBinding(self, keySetName, eventStr):
          """
***************
*** 242,251 ****
          return binding
  
!     def GetKeys(self, keySetName=None):
          """
!         returns the requested set of keybindings, with fallbacks if required.
          """
          #keybindings loaded from the config file(s) are loaded _over_ these
!         #defaults, so if there is a problem getting any binding there will
          #be an 'ultimate last resort fallback' to the CUA-ish bindings
          #defined here.
--- 312,340 ----
          return binding
  
!     def GetCurrentKeySet(self):
!         """
!         Returns a dictionary of: all current core keybindings, plus the 
!         keybindings for all currently active extensions. If a binding defined
!         in an extension is already in use, that binding is disabled.
!         """
!         currentKeySet=self.GetCoreKeys(keySetName=self.CurrentKeys())
!         activeExtns=self.GetExtensions(activeOnly=1)
!         for extn in activeExtns:
!             extKeys=self.__GetRawExtensionKeys(extn)
!             if extKeys: #the extension defines keybindings
!                 for event in extKeys.keys():
!                     if extKeys[event] in currentKeySet.values():
!                         #the binding is already in use
!                         extKeys[event]='' #disable this binding
!                     currentKeySet[event]=extKeys[event] #add binding
!         return currentKeySet
!     
!     def GetCoreKeys(self, keySetName=None):
          """
!         returns the requested set of core keybindings, with fallbacks if
!         required.
          """
          #keybindings loaded from the config file(s) are loaded _over_ these
!         #defaults, so if there is a problem getting any core binding there will
          #be an 'ultimate last resort fallback' to the CUA-ish bindings
          #defined here.