Show
Ignore:
Timestamp:
08/06/10 14:03:29 (3 years ago)
Author:
diogo
Message:

added function to remove all binds created

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • umit-keybinder/libkeybinder.py

    r5765 r5777  
    3838kb = Keybinder() 
    3939 
     40binds = [] 
     41 
    4042def bind(modifiers, key, handler, param=None): 
    4143    """ 
     44    Bind a key combination to an handler if keys aren't already binded 
    4245    """ 
    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 
    4451     
    4552def unbind(modifiers, key, handler): 
    4653    """ 
     54    Remove previous created bind 
    4755    """ 
    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     
     63def 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         
     72def 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