Source code for yyagl.computer_proxy

from functools import wraps


[docs]def compute_once(fun): @wraps(fun) def wrapper(*args, **kwargs): self = args[0] key = fun.__name__, args # add support for kwargs if key not in self.buffered_vals: self.buffered_vals[key] = fun(*args, **kwargs) return self.buffered_vals[key] return wrapper
[docs]def once_a_frame(fun): @wraps(fun) def wrapper(*args, **kwargs): self = args[0] key = fun.__name__, args # add support for kwargs if key not in self.buffered_vals_frm: self.buffered_vals_frm[key] = fun(*args, **kwargs) return self.buffered_vals_frm[key] return wrapper
[docs]class ComputerProxy: def __init__(self): self.eng.attach_obs(self.on_start_frame) # there are issues if the object has another on_start_frame self.buffered_vals, self.buffered_vals_frm = {}, {}
[docs] def on_start_frame(self): self.buffered_vals_frm = {}
[docs] def destroy(self): self.eng.detach_obs(self.on_start_frame) self.buffered_vals = self.buffered_vals_frm = None