Skip to content

Commit 599b062

Browse files
committed
Move example socket processors to examples module
Refactors `dlc_processor_socket.py` by removing the in-file example processors and `OneEuroFilter`, and adds them to a new `dlclivegui/processors/examples.py` module. This separates demonstration/experiment-specific logic from the core socket processor implementation, improving maintainability while preserving existing example processor behavior.
1 parent 29b791c commit 599b062

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

‎dlclivegui/processors/dlc_processor_socket.py‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@
2727
_handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(message)s"))
2828
logger.addHandler(_handler)
2929

30+
# Registry for GUI discovery
31+
PROCESSOR_REGISTRY = {}
32+
33+
34+
def register_processor(cls):
35+
registry_key = getattr(cls, "PROCESSOR_ID", cls.__name__)
36+
if registry_key in PROCESSOR_REGISTRY:
37+
raise ValueError(
38+
f"Duplicate processor registration key '{registry_key}': "
39+
f"{PROCESSOR_REGISTRY[registry_key].__name__} vs {cls.__name__}"
40+
)
41+
PROCESSOR_REGISTRY[registry_key] = cls
42+
return cls
43+
3044

3145
# pragma: cover
3246
class BaseProcessorSocket(Processor):
@@ -424,3 +438,38 @@ def get_data(self):
424438
if self.dlc_cfg is not None:
425439
save_dict["dlc_cfg"] = self.dlc_cfg
426440
return save_dict
441+
442+
443+
def get_available_processors():
444+
"""
445+
Get list of available processor classes.
446+
447+
Returns:
448+
dict: Dictionary mapping registry keys to processor info.
449+
"""
450+
return {
451+
name: {
452+
"class": cls,
453+
"name": getattr(cls, "PROCESSOR_NAME", name),
454+
"description": getattr(cls, "PROCESSOR_DESCRIPTION", ""),
455+
"params": getattr(cls, "PROCESSOR_PARAMS", {}),
456+
}
457+
for name, cls in PROCESSOR_REGISTRY.items()
458+
}
459+
460+
461+
def instantiate_processor(class_name, **kwargs):
462+
"""
463+
Instantiate a processor by class name with given parameters.
464+
465+
Args:
466+
class_name: Registry key (e.g., "MyProcessorSocket")
467+
**kwargs: Constructor kwargs
468+
469+
Raises:
470+
ValueError: If class_name is not in registry
471+
"""
472+
if class_name not in PROCESSOR_REGISTRY:
473+
available = ", ".join(PROCESSOR_REGISTRY.keys())
474+
raise ValueError(f"Unknown processor '{class_name}'. Available: {available}")
475+
return PROCESSOR_REGISTRY[class_name](**kwargs)

‎dlclivegui/processors/examples.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
import numpy as np
88

9-
from dlclivegui.processors import register_processor
10-
from dlclivegui.processors.dlc_processor_socket import BaseProcessorSocket
9+
from dlclivegui.processors import BaseProcessorSocket, register_processor
1110

1211
logger = logging.getLogger(__name__)
1312

0 commit comments

Comments
 (0)