diff options
author | Aylur <[email protected]> | 2024-07-15 22:09:58 +0200 |
---|---|---|
committer | Aylur <[email protected]> | 2024-07-15 22:09:58 +0200 |
commit | e5251d23f158c7cc092121c3a7cc0438a73746ec (patch) | |
tree | dbd972adfb768e5600ca15f779b4cffc666a442f /python/astal/variable.py | |
parent | be163b310398ad7f454d3ece574a476abfa216e9 (diff) |
remove python and node
I have no desire to work on the python version
The node version has the issue of promises not working which makes it
unusable but gjs works just as good if not better. Might look back into
node later
Diffstat (limited to 'python/astal/variable.py')
-rw-r--r-- | python/astal/variable.py | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/python/astal/variable.py b/python/astal/variable.py deleted file mode 100644 index 9b165cd..0000000 --- a/python/astal/variable.py +++ /dev/null @@ -1,100 +0,0 @@ -from gi.repository import Astal - -from .binding import Binding - - -class Variable: - def __init__(self, init): - v = Astal.Variable.new(init) - self._variable = v - self._err_handler = print - v.connect("error", lambda _, err: self._err_handler(err) if self._err_handler else None) - - def __call__(self, transform=None): - if transform: - return Binding(self).as_(transform) - - return Binding(self) - - def __str__(self): - return f"Variable<{self.get()}>" - - def get(self): - return self._variable.get_value() - - def set(self, value): - return self._variable.set_value(value) - - def watch(self, cmd): - if isinstance(cmd, str): - self._variable.watch(cmd) - elif isinstance(cmd, list): - self._variable.watchv(cmd) - return self - - def poll(self, interval, cmd): - if isinstance(cmd, str): - self._variable.poll(interval, cmd) - elif isinstance(cmd, list): - self._variable.pollv(interval, cmd) - else: - self._variable.pollfn(interval, cmd) - return self - - def start_watch(self): - self._variable.start_watch() - - def start_poll(self): - self._variable.start_poll() - - def stop_watch(self): - self._variable.stop_watch() - - def stop_poll(self): - self._variable.stop_poll() - - def drop(self): - self._variable.emit_dropped() - self._variable.run_dispose() - - def on_dropped(self, callback): - self._variable.connect("dropped", lambda _: callback()) - return self - - def on_error(self, callback): - self._err_handler = None - self._variable.connect("error", lambda _, e: callback(e)) - return self - - def subscribe(self, callback): - s = self._variable.connect("changed", lambda _: callback(self.get())) - return lambda: self._variable.disconnect(s) - - def observe(self, objs, sigOrFn, callback=None): - if callable(sigOrFn): - f = sigOrFn - elif callable(callback): - f = callback - else: - f = lambda *_: self.get() - - def setter(*args): - self.set(f(*args)) - - if isinstance(objs, list): - for obj in objs: - obj[0].connect(obj[1], setter) - elif isinstance(sigOrFn, str): - objs.connect(sigOrFn, setter) - - return self - - @staticmethod - def derive(deps, fn): - def update(): - return fn(*[d.get() for d in deps]) - - derived = Variable(update()) - unsubs = [dep.subscribe(lambda _: derived.set(update())) for dep in deps] - derived.on_dropped(lambda: ([unsub() for unsub in unsubs])) - return derived |