def __delitem__(self, k,): registry = self.poller if k not in registry: raise KeyError(k) v = registry[k] del registry[k] trellis.on_undo(registry.__setitem__, k, v,)
def _updated(self): schedule = self._schedule while self._tick >= schedule[0]: key = heapq.heappop(schedule) trellis.on_undo(heapq.heappush, schedule, key) if key in self._events: self._events[key].receive(True)
def call(self, func, *args, **kw): """Call `func(*args, **kw)` at the next opportunity""" self._call_queue.append((func, args, kw)) if not self.initialized: self._setup() self.initialized = True trellis.on_undo(self._call_queue.pop) self._callback_if_needed()
def doit(): c5.value for c in c2, c3: trellis.ctrl.has_run.setdefault(c, 1) trellis.on_undo(trellis.ctrl.has_run.pop, c) trellis.ctrl.to_retry.setdefault(c, 1) trellis.on_undo(trellis.ctrl._unrun, c2, [c3]) trellis.ctrl._retry()
def __setitem__(self, k, v,): registry = self.poller if k in registry: v = registry[k] undo = registry.__setitem__, k, v, else: undo = registry.__delitem__, k, registry[k] = v trellis.on_undo(*undo)
def _data(self): """The dictionary containing the set cells.""" if self._new_input: data = self._data added = iter(x for x in self._new_input if not x in self._data) removed = set(x for x in self._data if not x in self._new_input) else: data = self._data added = self.input.added removed = self.input.removed for item in added: cell = data.get(item, None) if cell is None: rule = self._create_cell_rule(item, data) cell = trellis.Cell(rule=rule, value=rule()) trellis.on_undo(data.pop, item, None) data[item] = cell trellis.mark_dirty() for item in removed: cell = data.get(item, None) if cell is not None: self.to_remove[item] = cell.value trellis.on_undo(setattr, cell, "rule", cell.rule) cell.rule = lambda: () trellis.on_undo(data.__setitem__, item, data[item]) del data[item] trellis.mark_dirty() return data