forked from M-Labs/artiq
gui/tools/DictSyncer: keep original data
This commit is contained in:
parent
cba0011431
commit
26b1282b2b
|
@ -79,7 +79,9 @@ class ListSyncer:
|
|||
|
||||
|
||||
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.clear()
|
||||
self.order = []
|
||||
|
@ -94,6 +96,8 @@ class DictSyncer:
|
|||
raise KeyError
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
if hasattr(self, "data"):
|
||||
data[key] = value
|
||||
try:
|
||||
i = self._find_index(key)
|
||||
except KeyError:
|
||||
|
@ -111,6 +115,8 @@ class DictSyncer:
|
|||
self.order.insert(j, (key, ord_el))
|
||||
|
||||
def __delitem__(self, key):
|
||||
if hasattr(self, "data"):
|
||||
del self.data[key]
|
||||
i = self._find_index(key)
|
||||
del self.store[i]
|
||||
del self.order[i]
|
||||
|
|
Loading…
Reference in New Issue