summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Holland <william.holland@codethink.co.uk>2015-05-31 00:46:51 +0100
committerWilliam Holland <william.holland@codethink.co.uk>2015-05-31 00:46:51 +0100
commitc8e78ce217457e6790860c3b8da92aa83ac0002f (patch)
tree4a1010e22c5623427c443b051014535e6a9ae331
parentede57801be4852b30a8327a6f8094e2a1c1c70d6 (diff)
downloadkeyboard-python-c8e78ce217457e6790860c3b8da92aa83ac0002f.tar.bz2
Add comments
-rw-r--r--keyboardpython/key.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/keyboardpython/key.py b/keyboardpython/key.py
index 57fbffc..24642e0 100644
--- a/keyboardpython/key.py
+++ b/keyboardpython/key.py
@@ -32,7 +32,7 @@ class KeyCombination:
return to_print
def __eq__(self,other):
- if not isinstance(other,KeyCombination):
+ if not isinstance(other,KeyCombination):
if not isinstance(other,Key): return False
return str(self) == str(other)
@@ -43,27 +43,32 @@ class KeyCombination:
return hash(str(self))
def contains_key(self,key):
+ ''' is key in this combination? '''
if key in self.keys: return True
return False
def add_key(self,_key):
+ ''' add _key to this combination '''
assert isinstance(_key,Key)
if self.contains_key(_key): return
self.keys.append(_key)
self.keys = list(set(self.keys))
def remove_key(self,key):
+ ''' remove key from this combination '''
assert isinstance(_key,Key)
if key in self.keys:
key_index = self.keys.index(key)
self.keys.pop(key_index)
def add_keyCombination(self,key_comb):
+ ''' add each key from key_comb to this combination '''
assert isinstance(key_comb,KeyCombination)
for _key in key_comb.keys: self.keys.append(_key)
self.keys = list(set(self.keys))
def diff(self,key_comb):
+ ''' return keys in key_comb that aren't in this combination '''
assert isinstance(key_comb,KeyCombination)
to_return = KeyCombination()
for _key in key_comb.keys:
@@ -80,7 +85,7 @@ class Key:
self.name = name
def __eq__(self,other):
- if not isinstance(other,KeyCombination):
+ if not isinstance(other,KeyCombination):
if not isinstance(other,Key): return False
return str(self) == str(other)
@@ -93,6 +98,7 @@ class Key:
def __str__(self):
return self.name
+# define modifier Keys
ALT = Key('Alt')
CTRL = Key('Control')
@@ -171,6 +177,12 @@ def _get_ctrl_alpha(code):
return KeyCombination(alpha_key,CTRL)
def _match_start_in_table(_code,table):
+ ''' look for match at start of _code in table,
+ if a match if found remove it from _code
+ returns _code,key_comb where key_comb is
+ the key combination corresponding to the
+ match found, None if no match found
+ '''
import re
code_str = ''.join(_code)
for c in table.keys():