Changeset 5777 for umit-keybinder/libkeybinder.py
- Timestamp:
- 08/06/10 14:03:29 (3 years ago)
- Files:
-
- 1 modified
-
umit-keybinder/libkeybinder.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
umit-keybinder/libkeybinder.py
r5765 r5777 38 38 kb = Keybinder() 39 39 40 binds = [] 41 40 42 def bind(modifiers, key, handler, param=None): 41 43 """ 44 Bind a key combination to an handler if keys aren't already binded 42 45 """ 43 kb.bind(modifiers, key, handler, param) 46 if check_bind(modifiers, key) and kb.bind(modifiers, key, handler, param): 47 binds.append((modifiers, key, handler)) 48 return True 49 else: 50 return False 44 51 45 52 def unbind(modifiers, key, handler): 46 53 """ 54 Remove previous created bind 47 55 """ 48 kb.unbind(modifiers, key, handler) 56 if not check_bind(modifiers, key): 57 kb.unbind(modifiers, key, handler) 58 binds.remove((modifiers, key, handler)) 59 return True 60 else: 61 return False 62 63 def unbind_all(): 64 """ 65 Remove all binds created 66 """ 67 _binds = list(binds) 68 for b in _binds: 69 (modifiers, key, handler) = b 70 unbind(modifiers, key, handler) 71 72 def check_bind(modifiers, key): 73 """ 74 Verify if the keyshortcut doesn't exist 75 return True if key combination available, False otherwise 76 """ 77 for b in binds: 78 (b_modifiers, b_key, _) = b 79 if b_modifiers == modifiers and b_key == key: 80 return False 81 return True
