Coverage for openhcs/ui/shared/parameter_form_constants.py: 100.0%

73 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-04 02:09 +0000

1""" 

2Parameter form constants for eliminating magic strings throughout the parameter form managers. 

3 

4This module centralizes all hardcoded strings used in both PyQt and Textual parameter form 

5implementations to improve maintainability and reduce duplication. 

6""" 

7 

8from dataclasses import dataclass 

9from typing import FrozenSet 

10 

11 

12@dataclass(frozen=True) 

13class ParameterFormConstants: 

14 """ 

15 Centralized constants for parameter form implementations. 

16 

17 This dataclass eliminates magic strings throughout the parameter form system 

18 by providing a single source of truth for all hardcoded values used in both 

19 PyQt and Textual implementations. 

20 

21 Categories: 

22 - UI text and formatting patterns 

23 - Widget identification and naming 

24 - Framework-specific constants 

25 - Debug and validation settings 

26 """ 

27 

28 # Field ID generation patterns 

29 FIELD_ID_SEPARATOR: str = "_" 

30 NESTED_STATIC_PREFIX: str = "nested_static_" 

31 MIXED_CLASS_PREFIX: str = "Mixed" 

32 ENABLE_CHECKBOX_PREFIX: str = "Enable " 

33 RESET_BUTTON_PREFIX: str = "reset_" 

34 

35 # Placeholder text patterns 

36 DEFAULT_PLACEHOLDER_PREFIX: str = "Pipeline default" 

37 PLACEHOLDER_WITH_COLON: str = "Pipeline default:" 

38 PLACEHOLDER_NONE_TEXT: str = "(none)" 

39 

40 # Widget text constants 

41 RESET_BUTTON_TEXT: str = "Reset" 

42 NONE_STRING_LITERAL: str = "None" 

43 EMPTY_STRING: str = "" 

44 

45 # Parameter name formatting 

46 UNDERSCORE_REPLACEMENT: str = " " 

47 FIELD_LABEL_SUFFIX: str = ":" 

48 PARAMETER_DESCRIPTION_PREFIX: str = "Parameter: " 

49 

50 # Debug and logging constants 

51 DEBUG_PREFIX: str = "*** " 

52 DEBUG_SUFFIX: str = " ***" 

53 DEBUG_TARGET_PARAMS: FrozenSet[str] = frozenset({ 

54 "output_dir_suffix", 

55 "path_planning" 

56 }) 

57 

58 # Nested manager patterns 

59 NESTED_MANAGERS_ATTR: str = "nested_managers" 

60 OPTIONAL_CHECKBOXES_ATTR: str = "optional_checkboxes" 

61 ENABLED_SUFFIX: str = "_enabled" 

62 

63 # Type checking strings 

64 DATACLASS_FIELDS_ATTR: str = "__dataclass_fields__" 

65 RESOLVE_FIELD_VALUE_ATTR: str = "_resolve_field_value" 

66 BASES_ATTR: str = "__bases__" 

67 VALUE_ATTR: str = "value" 

68 

69 # Boolean conversion strings 

70 TRUE_STRINGS: FrozenSet[str] = frozenset({ 

71 "true", "1", "yes", "on" 

72 }) 

73 

74 # CSS and styling constants 

75 PARAM_LABEL_CLASS: str = "param-label clickable" 

76 PLACEHOLDER_STYLE_PROPERTY: str = "is_placeholder_state" 

77 

78 # Layout and sizing constants 

79 AUTO_SIZE: str = "auto" 

80 FLEXIBLE_WIDTH: str = "1fr" 

81 LEFT_ALIGN: str = "left" 

82 

83 # Error and validation messages 

84 UNKNOWN_CONFIG_KEY_MSG: str = "Unknown config key: {}" 

85 INVALID_CONFIG_KEYS_MSG: str = "Invalid config keys: {}" 

86 CONFIG_MUST_BE_DICT_MSG: str = "Config must be a non-empty dictionary" 

87 NO_WIDGET_CREATOR_MSG: str = "No widget creator registered for type: {}" 

88 CONVERSION_ERROR_MSG: str = "Cannot convert '{}' to {}: {}" 

89 NO_VALID_CONVERSION_MSG: str = "No valid conversion found for Union type {}" 

90 

91 # File path and naming patterns 

92 GLOBAL_CONTEXT_LAZY_PREFIX: str = "GlobalContextLazy" 

93 STATIC_LAZY_PREFIX: str = "StaticLazy" 

94 

95 # Special field analysis types 

96 DIFFERENT_VALUES_TYPE: str = "different" 

97 

98 # Tooltip and help text patterns 

99 TOOLTIP_SEPARATOR: str = ": " 

100 HELP_PARAMETER_PREFIX: str = "Parameter: " 

101 

102 # Widget state constants 

103 COLLAPSED_STATE: bool = True 

104 EXPANDED_STATE: bool = False 

105 COMPACT_WIDGET: bool = True 

106 

107 # Margin and spacing constants (for Textual layouts) 

108 NO_MARGIN: tuple = (0, 0, 0, 0) 

109 LEFT_MARGIN_ONLY: tuple = (0, 0, 0, 1) 

110 

111 # Thread-local and context constants 

112 CURRENT_PIPELINE_CONFIG_ATTR: str = "value" 

113 

114 # Method and attribute name constants 

115 SET_PATH_METHOD: str = "set_path" 

116 GET_VALUE_METHOD: str = "get_value" 

117 SET_VALUE_METHOD: str = "setValue" # PyQt6 uses camelCase 

118 BLOCK_SIGNALS_METHOD: str = "blockSignals" 

119 SET_TEXT_METHOD: str = "setText" 

120 SET_CHECKED_METHOD: str = "setChecked" 

121 

122 # Logging and debug message templates 

123 NESTED_DEBUG_MSG: str = "*** NESTED DEBUG *** param_name={}, parent_nested_name={}" 

124 NESTED_UPDATE_MSG: str = "*** NESTED UPDATE *** Updating {}.{} = {}" 

125 RESET_DEBUG_MSG: str = "*** RESET DEBUG *** param_name={}, parent_nested_name={}" 

126 FALLBACK_DEBUG_MSG: str = "*** FALLBACK DEBUG *** Checking fallback for {}" 

127 TEXTUAL_UPDATE_DEBUG_MSG: str = "*** TEXTUAL UPDATE DEBUG *** {} update_parameter called with: {} (type: {})" 

128 

129 # Path and hierarchy constants 

130 DOT_SEPARATOR: str = "." 

131 PATH_PLANNING_FIELD: str = "path_planning" 

132 OUTPUT_DIR_SUFFIX_FIELD: str = "output_dir_suffix" 

133 

134 # Widget creation and registry constants 

135 INPUT_TYPE_INTEGER: str = "integer" 

136 INPUT_TYPE_NUMBER: str = "number" 

137 INPUT_TYPE_TEXT: str = "text" 

138 

139 # Configuration context constants 

140 GLOBAL_CONFIG_EDITING_CONTEXT: str = "global_config_editing" 

141 LAZY_CONTEXT: str = "lazy_context" 

142 

143 # Framework identification constants 

144 PYQT6_FRAMEWORK: str = "pyqt6" 

145 TEXTUAL_FRAMEWORK: str = "textual" 

146 

147 

148# Create a singleton instance for easy access throughout the codebase 

149CONSTANTS = ParameterFormConstants()