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

View File

@ -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]