hand tracking, state management

This commit includes updates to global state management, and a state reset node.
It includes new tracking nodes powered by media pipe.
Includes an interactive mask node.
This commit is contained in:
RyanOnTheInside
2025-02-02 18:14:16 -05:00
parent d027473741
commit 9a9754de3c
7 changed files with 583 additions and 4 deletions
+30 -1
View File
@@ -16,13 +16,35 @@ class Pattern(ABC):
class StateManager:
"""Handles persistent state between executions"""
def __init__(self):
self._states = {}
self._states = {}
def get_state(self, node_id: str, default=None):
return self._states.get(node_id, default)
def set_state(self, node_id: str, state):
self._states[node_id] = state
def clear_state(self, node_id: str) -> bool:
"""Clear state for a specific node. Returns True if state was found and cleared."""
if node_id in self._states:
del self._states[node_id]
return True
return False
def clear_all_states(self):
"""Clear all states"""
self._states.clear()
def get_all_node_ids(self):
"""Get list of all node IDs with state"""
return list(self._states.keys())
def cleanup_orphaned_states(self, active_node_ids: set[str]):
"""Remove states for nodes that no longer exist"""
orphaned = [nid for nid in self._states.keys() if nid not in active_node_ids]
for nid in orphaned:
del self._states[nid]
return len(orphaned)
class ControlNodeBase(ABC):
"""Base class for all control nodes"""
@@ -57,6 +79,13 @@ class ControlNodeBase(ABC):
def set_state(self, state):
self.state_manager.set_state(self.node_id, state)
def cleanup(self):
"""Clean up node state when node is destroyed"""
self.state_manager.clear_state(self.node_id)
def __del__(self):
self.cleanup()
@abstractmethod
def update(self, *args, **kwargs):
"""Main update method to be implemented by control nodes"""