Coverage for openhcs/ui/shared/ui_utils.py: 55.0%
20 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-04 02:09 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-04 02:09 +0000
1"""
2Consolidated UI utilities for PyQt6 parameter forms.
4This module replaces four over-engineered utility modules (979 lines) with simple
5functional implementations (~45 lines), adhering to OpenHCS coding standards.
7Replaces:
8- debug_config.py (321 lines)
9- enum_display_formatter.py (170 lines)
10- parameter_name_formatter.py (276 lines)
11- field_id_generator.py (208 lines)
12"""
14import logging
15from typing import Any
16from enum import Enum
19def format_param_name(name: str) -> str:
20 """Convert snake_case to Title Case: 'param_name' -> 'Param Name'"""
21 return name.replace('_', ' ').title()
24def format_checkbox_label(name: str) -> str:
25 """Create checkbox label: 'param_name' -> 'Enable Param Name'"""
26 return f"Enable {format_param_name(name)}"
29def format_field_label(name: str) -> str:
30 """Create field label: 'param_name' -> 'Param Name:'"""
31 return f"{format_param_name(name)}:"
34def format_field_id(parent: str, param: str) -> str:
35 """Generate field ID: 'parent', 'param' -> 'parent_param'"""
36 return f"{parent}_{param}"
39def format_reset_button_id(widget_id: str) -> str:
40 """Generate reset button ID: 'widget_id' -> 'reset_widget_id'"""
41 return f"reset_{widget_id}"
44def format_enum_display(enum_value: Enum) -> str:
45 """Get enum display text: Enum.VALUE -> 'VALUE'"""
46 return enum_value.name.upper()
49def format_enum_placeholder(enum_value: Enum, prefix: str = "Pipeline default: ") -> str:
50 """Get enum placeholder: Enum.VALUE -> 'Pipeline default: VALUE'"""
51 return f"{prefix}{format_enum_display(enum_value)}"
54def debug_param(param_name: str, value: Any, context: str = "") -> None:
55 """Simple parameter debug logging"""
56 context_str = f" [{context}]" if context else ""
57 logging.debug(f"PARAM: {param_name} = {value}{context_str}")