summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Holland <william.holland@codethink.co.uk>2015-06-07 14:25:09 +0100
committerWilliam Holland <william.holland@codethink.co.uk>2015-06-07 14:25:09 +0100
commit5b1b7ee0e8ff40c666cb1fe46472276ceecceacd (patch)
treec255f6f4cade6e87e4efa40311821208deefca44
parent499d575b42ce94a4d8f39fa6b5895b3b7c3daa30 (diff)
downloadkeyboard-python-5b1b7ee0e8ff40c666cb1fe46472276ceecceacd.tar.bz2
Make sure all methods of KeyCombination copy args
I'm not sure how nessesary this is but better safe than sorry and better explicit of intention
-rw-r--r--keyboardpython/key.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/keyboardpython/key.py b/keyboardpython/key.py
index eb315b5..ec5f32b 100644
--- a/keyboardpython/key.py
+++ b/keyboardpython/key.py
@@ -50,8 +50,10 @@ class KeyCombination:
def add_key(self,_key):
''' add _key to this combination '''
assert isinstance(_key,Key)
+ import copy
if self.contains_key(_key): return
- self.keys.append(_key)
+ to_add = copy.deepcopy(_key)
+ self.keys.append(to_add)
self.keys = list(set(self.keys))
self.string = self.__string()
@@ -66,17 +68,22 @@ class KeyCombination:
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)
+ import copy
+ for _key in key_comb.keys:
+ to_add = copy.deepcopy(_key)
+ self.keys.append(to_add)
self.keys = list(set(self.keys))
self.string = self.__string()
def diff(self,key_comb):
''' return keys in key_comb that aren't in this combination '''
assert isinstance(key_comb,KeyCombination)
+ import copy
to_return = KeyCombination()
for _key in key_comb.keys:
if not self.contains_key(_key):
- to_return.keys.append(_key)
+ to_add = copy.deepcopy(_key)
+ to_return.keys.append(to_add)
to_return.keys.sort(key=lambda x: x.name)
return to_return