From f8f8dd03512d59128963659c2ec29540e6f6a7e1 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 11 Sep 2025 22:02:50 +0200 Subject: [PATCH] Allow Client updates to diversify into zero to many TUI updates. --- ircplom/client.py | 41 ++++++++++++++++++++--------------------- ircplom/client_tui.py | 9 +++++---- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ircplom/client.py b/ircplom/client.py index 6f324a6..dc5ee3b 100644 --- a/ircplom/client.py +++ b/ircplom/client.py @@ -198,30 +198,29 @@ class _CompletableStringsOrdered(_Clearable, _CompletableStringsCollection): self._collected = tuple() -class IntoUpdateValueMixin(AutoAttrMixin): - 'Provides .into_update_value(), exportable for module-external consumers.' +class IntoEndnodeUpdatesMixin(AutoAttrMixin): + 'Provides .into_endnode_updates exportable for module-external consumers.' - def into_update_value(self) -> Any: - 'Return non-updating copy of self.' - if isinstance(self, _Dict): - return None + def into_endnode_updates(self, path: tuple[str, ...] + ) -> list[tuple[tuple[str, ...], Any]]: + 'Return path-value pairs for any update-worthy sub-elements.' if isinstance(self, _CompletableStringsCollection): - return self._completed + return ([(path, self._completed)] if self._completed is not None + else []) if isinstance(self, _CompletableTopic): - return Topic(*self._completed) - for cls in [cls for cls in self.__class__.__mro__ - if AutoAttrMixin not in cls.__mro__]: - obj = cls() - break - for key in self._deep_annotations(): - attr_val = getattr(self, key) - setattr(obj, key, - attr_val if not isinstance(attr_val, _UpdatingMixin) - else attr_val.static_copy) - return obj - - -class _UpdatingMixin(IntoUpdateValueMixin): + return [(path, Topic(*self._completed))] + updates = [] + for key, val in (self._dict.items() if isinstance(self, Dict) + else ((k, getattr(self, k)) + for k in self._deep_annotations())): + p = path + (key,) + updates += (val.into_endnode_updates(p) + if isinstance(val, IntoEndnodeUpdatesMixin) + else [(p, val)]) + return updates + + +class _UpdatingMixin(IntoEndnodeUpdatesMixin): _on_update: Callable def __init__(self, on_update: Callable, **kwargs) -> None: diff --git a/ircplom/client_tui.py b/ircplom/client_tui.py index e9e0234..1a96377 100644 --- a/ircplom/client_tui.py +++ b/ircplom/client_tui.py @@ -9,7 +9,7 @@ from ircplom.tui_base import (BaseTui, PromptWidget, TuiEvent, Window, CMD_SHORTCUTS) from ircplom.client import ( AutoAttrMixin, Client, ClientQueueMixin, Dict, DictItem, - IntoUpdateValueMixin, IrcConnSetup, LogScope, NewClientEvent, + IntoEndnodeUpdatesMixin, IrcConnSetup, LogScope, NewClientEvent, NickUserHost, ServerCapability, SharedClientDbFields, Topic) CMD_SHORTCUTS['disconnect'] = 'window.disconnect' @@ -512,6 +512,7 @@ class _ClientKnowingTui(Client): value = ((parent[last_step] if last_step in parent.keys() else None) if isinstance(parent, Dict) else getattr(parent, last_step)) - if isinstance(value, IntoUpdateValueMixin): - value = value.into_update_value() - self._client_tui_trigger('update_db', update=_Update(path, value)) + for path, value in (value.into_endnode_updates(path) + if isinstance(value, IntoEndnodeUpdatesMixin) + else [(path, value)]): + self._client_tui_trigger('update_db', update=_Update(path, value)) -- 2.30.2