|
|
|
|
@ -50,10 +50,7 @@ class EventfulDict(dict):
|
|
|
|
|
The callback should have a signature of callback(key, value). The
|
|
|
|
|
callback should return a boolean True if the additon should be
|
|
|
|
|
canceled, False or None otherwise."""
|
|
|
|
|
if callable(callback):
|
|
|
|
|
self._add_callback = callback
|
|
|
|
|
else:
|
|
|
|
|
self._add_callback = _void
|
|
|
|
|
self._add_callback = callback if callable(callback) else _void
|
|
|
|
|
|
|
|
|
|
def on_del(self, callback):
|
|
|
|
|
"""Register a callback for when an item is deleted from the dict.
|
|
|
|
|
@ -66,11 +63,8 @@ class EventfulDict(dict):
|
|
|
|
|
The callback should have a signature of callback(key). The
|
|
|
|
|
callback should return a boolean True if the deletion should be
|
|
|
|
|
canceled, False or None otherwise."""
|
|
|
|
|
if callable(callback):
|
|
|
|
|
self._del_callback = callback
|
|
|
|
|
else:
|
|
|
|
|
self._del_callback = _void
|
|
|
|
|
|
|
|
|
|
self._del_callback = callback if callable(callback) else _void
|
|
|
|
|
|
|
|
|
|
def on_set(self, callback):
|
|
|
|
|
"""Register a callback for when an item is changed in the dict.
|
|
|
|
|
|
|
|
|
|
@ -82,11 +76,8 @@ class EventfulDict(dict):
|
|
|
|
|
The callback should have a signature of callback(key, value). The
|
|
|
|
|
callback should return a boolean True if the change should be
|
|
|
|
|
canceled, False or None otherwise."""
|
|
|
|
|
if callable(callback):
|
|
|
|
|
self._set_callback = callback
|
|
|
|
|
else:
|
|
|
|
|
self._set_callback = _void
|
|
|
|
|
|
|
|
|
|
self._set_callback = callback if callable(callback) else _void
|
|
|
|
|
|
|
|
|
|
def pop(self, key):
|
|
|
|
|
"""Returns the value of an item in the dictionary and then deletes the
|
|
|
|
|
item from the dictionary."""
|
|
|
|
|
@ -182,11 +173,8 @@ class EventfulList(list):
|
|
|
|
|
The callback should have a signature of callback(index, value). The
|
|
|
|
|
callback should return a boolean True if the insertion should be
|
|
|
|
|
canceled, False or None otherwise."""
|
|
|
|
|
if callable(callback):
|
|
|
|
|
self._insert_callback = callback
|
|
|
|
|
else:
|
|
|
|
|
self._insert_callback = _void
|
|
|
|
|
|
|
|
|
|
self._insert_callback = callback if callable(callback) else _void
|
|
|
|
|
|
|
|
|
|
def on_del(self, callback):
|
|
|
|
|
"""Register a callback for item deletion.
|
|
|
|
|
|
|
|
|
|
@ -198,10 +186,7 @@ class EventfulList(list):
|
|
|
|
|
The callback should have a signature of callback(index). The
|
|
|
|
|
callback should return a boolean True if the deletion should be
|
|
|
|
|
canceled, False or None otherwise."""
|
|
|
|
|
if callable(callback):
|
|
|
|
|
self._del_callback = callback
|
|
|
|
|
else:
|
|
|
|
|
self._del_callback = _void
|
|
|
|
|
self._del_callback = callback if callable(callback) else _void
|
|
|
|
|
|
|
|
|
|
def on_set(self, callback):
|
|
|
|
|
"""Register a callback for items are set.
|
|
|
|
|
@ -215,10 +200,7 @@ class EventfulList(list):
|
|
|
|
|
The callback should have a signature of callback(index, value). The
|
|
|
|
|
callback should return a boolean True if the set should be
|
|
|
|
|
canceled, False or None otherwise."""
|
|
|
|
|
if callable(callback):
|
|
|
|
|
self._set_callback = callback
|
|
|
|
|
else:
|
|
|
|
|
self._set_callback = _void
|
|
|
|
|
self._set_callback = callback if callable(callback) else _void
|
|
|
|
|
|
|
|
|
|
def on_reverse(self, callback):
|
|
|
|
|
"""Register a callback for list reversal.
|
|
|
|
|
@ -228,10 +210,7 @@ class EventfulList(list):
|
|
|
|
|
The callback should have a signature of callback(). The
|
|
|
|
|
callback should return a boolean True if the reverse should be
|
|
|
|
|
canceled, False or None otherwise."""
|
|
|
|
|
if callable(callback):
|
|
|
|
|
self._reverse_callback = callback
|
|
|
|
|
else:
|
|
|
|
|
self._reverse_callback = _void
|
|
|
|
|
self._reverse_callback = callback if callable(callback) else _void
|
|
|
|
|
|
|
|
|
|
def on_sort(self, callback):
|
|
|
|
|
"""Register a callback for sortting of the list.
|
|
|
|
|
@ -242,10 +221,7 @@ class EventfulList(list):
|
|
|
|
|
method or `callback(*pargs, **kwargs)` as a catch all. The callback
|
|
|
|
|
should return a boolean True if the reverse should be canceled,
|
|
|
|
|
False or None otherwise."""
|
|
|
|
|
if callable(callback):
|
|
|
|
|
self._sort_callback = callback
|
|
|
|
|
else:
|
|
|
|
|
self._sort_callback = _void
|
|
|
|
|
self._sort_callback = callback if callable(callback) else _void
|
|
|
|
|
|
|
|
|
|
def append(self, x):
|
|
|
|
|
"""Add an item to the end of the list."""
|
|
|
|
|
|