forked from M-Labs/artiq
1
0
Fork 0

gui/tools/DictSyncer: keep original data

This commit is contained in:
Sebastien Bourdeauducq 2015-01-29 19:58:25 +08:00
parent cba0011431
commit 26b1282b2b
1 changed files with 7 additions and 1 deletions

View File

@ -79,7 +79,9 @@ class ListSyncer:
class DictSyncer: class DictSyncer:
def __init__(self, store, init): def __init__(self, store, init, keep_data=False):
if keep_data:
self.data = init
self.store = store self.store = store
self.store.clear() self.store.clear()
self.order = [] self.order = []
@ -94,6 +96,8 @@ class DictSyncer:
raise KeyError raise KeyError
def __setitem__(self, key, value): def __setitem__(self, key, value):
if hasattr(self, "data"):
data[key] = value
try: try:
i = self._find_index(key) i = self._find_index(key)
except KeyError: except KeyError:
@ -111,6 +115,8 @@ class DictSyncer:
self.order.insert(j, (key, ord_el)) self.order.insert(j, (key, ord_el))
def __delitem__(self, key): def __delitem__(self, key):
if hasattr(self, "data"):
del self.data[key]
i = self._find_index(key) i = self._find_index(key)
del self.store[i] del self.store[i]
del self.order[i] del self.order[i]