Implemented new InstancesDebugger.py. Based on the HierarchicalCanvasGraph.py

This commit is contained in:
2026-02-22 17:51:39 +01:00
parent 8b8172231a
commit 0686103a8f
8 changed files with 536 additions and 141 deletions

View File

@@ -77,7 +77,8 @@ class Command:
return key
def __init__(self, name,
def __init__(self,
name,
description,
owner=None,
callback=None,
@@ -102,10 +103,10 @@ class Command:
if auto_register:
if self._key is not None:
if self._key in CommandsManager.commands_by_key:
#logger.debug(f"Command {self.name} with key={self._key} will not be registered.")
# logger.debug(f"Command {self.name} with key={self._key} will not be registered.")
self.id = CommandsManager.commands_by_key[self._key].id
else:
#logger.debug(f"Command {self.name} with key={self._key} will be registered.")
# logger.debug(f"Command {self.name} with key={self._key} will be registered.")
CommandsManager.register(self)
else:
logger.warning(f"Command {self.name} has no key, it will not be registered.")
@@ -150,13 +151,13 @@ class Command:
logger.debug(f" will execute bound command {bound_cmd.command.name} BEFORE...")
r = bound_cmd.command.execute(client_response)
ret_from_before_commands.append(r)
# Execute main callback
kwargs = self._create_kwargs(self.default_kwargs,
client_response,
{"client_response": client_response or {}})
ret = self.callback(*self.default_args, **kwargs)
# Execute "after" bound commands
ret_from_after_commands = []
if self.owner:
@@ -165,12 +166,15 @@ class Command:
logger.debug(f" will execute bound command {bound_cmd.command.name} AFTER...")
r = bound_cmd.command.execute(client_response)
ret_from_after_commands.append(r)
all_ret = flatten(ret, ret_from_before_commands, ret_from_after_commands, collector.results)
# Set the hx-swap-oob attribute on all elements returned by the callback
if self._htmx_extra[AUTO_SWAP_OOB]:
for r in all_ret[1:]:
for index, r in enumerate(all_ret[1:]):
if hasattr(r, "__ft__"):
r = r.__ft__()
all_ret[index + 1] = r
if (hasattr(r, 'attrs')
and "hx-swap-oob" not in r.attrs
and r.get("id", None) is not None):

View File

@@ -106,6 +106,9 @@ class BaseInstance:
def get_full_id(self) -> str:
return f"{InstancesManager.get_session_id(self._session)}#{self._id}"
def get_description(self) -> str:
pass
def get_parent_full_id(self) -> Optional[str]:
parent = self.get_parent()
return parent.get_full_id() if parent else None
@@ -118,8 +121,21 @@ class BaseInstance:
command: Command name or Command instance to bind to
command_to_bind: Command to execute when the main command is triggered
when: "before" or "after" - when to execute the bound command (default: "after")
Note:
Duplicate bindings are automatically prevented using two mechanisms:
1. Check if the same binding already exists
"""
command_name = command.name if hasattr(command, "name") else command
# Protection 1: Check if this binding already exists to prevent duplicates
existing_bindings = self._bound_commands.get(command_name, [])
for existing in existing_bindings:
if existing.command.name == command_to_bind.name and existing.when == when:
# Binding already exists, don't add it again
return
# Add new binding
bound = BoundCommand(command=command_to_bind, when=when)
self._bound_commands.setdefault(command_name, []).append(bound)