Coverage for openhcs/pyqt_gui/config.py: 0.0%

131 statements  

« prev     ^ index     » next       coverage.py v7.10.3, created at 2025-08-14 05:57 +0000

1""" 

2PyQt GUI configuration dataclasses for OpenHCS. 

3 

4This module defines configuration objects for the PyQt GUI components, 

5following the same patterns as the core configuration system. 

6Configuration is intended to be immutable and provided as Python objects. 

7""" 

8 

9import logging 

10from dataclasses import dataclass, field 

11from typing import Optional, Dict, Any 

12from enum import Enum 

13 

14logger = logging.getLogger(__name__) 

15 

16 

17class PlotTheme(Enum): 

18 """Available plot themes for PyQtGraph components.""" 

19 DARK = "dark" 

20 LIGHT = "light" 

21 AUTO = "auto" # Follow system theme 

22 

23 

24class UpdateStrategy(Enum): 

25 """Update strategies for real-time monitoring components.""" 

26 FIXED_RATE = "fixed_rate" # Fixed FPS regardless of data availability 

27 ADAPTIVE = "adaptive" # Adapt rate based on data changes 

28 ON_DEMAND = "on_demand" # Update only when explicitly requested 

29 

30 

31@dataclass(frozen=True) 

32class PerformanceMonitorConfig: 

33 """Configuration for the system performance monitor widget.""" 

34 

35 # Update frequency settings 

36 update_fps: float = 5.0 

37 """Update frequency in frames per second (FPS). Default: 5 FPS for good performance.""" 

38 

39 history_duration_seconds: float = 60.0 

40 """Duration of historical data to display in seconds. Default: 60 seconds.""" 

41 

42 # Display settings 

43 plot_theme: PlotTheme = PlotTheme.DARK 

44 """Theme for plots and charts.""" 

45 

46 show_grid: bool = True 

47 """Whether to show grid lines on plots.""" 

48 

49 antialiasing: bool = True 

50 """Enable antialiasing for smoother plot rendering.""" 

51 

52 # Performance settings 

53 update_strategy: UpdateStrategy = UpdateStrategy.FIXED_RATE 

54 """Strategy for updating the display.""" 

55 

56 max_data_points: Optional[int] = None 

57 """Maximum number of data points to keep. If None, calculated from update_fps and history_duration.""" 

58 

59 # GPU monitoring settings 

60 enable_gpu_monitoring: bool = True 

61 """Enable GPU usage monitoring if available.""" 

62 

63 gpu_temperature_monitoring: bool = True 

64 """Enable GPU temperature monitoring if available.""" 

65 

66 # CPU monitoring settings 

67 cpu_frequency_monitoring: bool = True 

68 """Enable CPU frequency monitoring.""" 

69 

70 per_core_cpu_monitoring: bool = False 

71 """Monitor individual CPU cores (more detailed but higher overhead).""" 

72 

73 # Memory monitoring settings 

74 detailed_memory_info: bool = True 

75 """Include detailed memory information (available, cached, etc.).""" 

76 

77 # Chart appearance 

78 line_width: float = 2.0 

79 """Width of plot lines in pixels.""" 

80 

81 chart_colors: Dict[str, str] = field(default_factory=lambda: { 

82 'cpu': 'cyan', 

83 'ram': 'lime', 

84 'gpu': 'orange', 

85 'vram': 'magenta' 

86 }) 

87 """Color scheme for different metrics.""" 

88 

89 def __post_init__(self): 

90 """Validate configuration after initialization.""" 

91 if self.update_fps <= 0: 

92 raise ValueError("update_fps must be positive") 

93 if self.history_duration_seconds <= 0: 

94 raise ValueError("history_duration_seconds must be positive") 

95 if self.line_width <= 0: 

96 raise ValueError("line_width must be positive") 

97 

98 @property 

99 def update_interval_seconds(self) -> float: 

100 """Calculate update interval in seconds from FPS.""" 

101 return 1.0 / self.update_fps 

102 

103 @property 

104 def calculated_max_data_points(self) -> int: 

105 """Calculate maximum data points based on FPS and history duration.""" 

106 if self.max_data_points is not None: 

107 return self.max_data_points 

108 return int(self.history_duration_seconds / self.update_interval_seconds) 

109 

110 

111@dataclass(frozen=True) 

112class WindowConfig: 

113 """Configuration for main window behavior.""" 

114 

115 # Window properties 

116 default_width: int = 1200 

117 """Default window width in pixels.""" 

118 

119 default_height: int = 800 

120 """Default window height in pixels.""" 

121 

122 remember_window_state: bool = True 

123 """Remember window size and position between sessions.""" 

124 

125 floating_by_default: bool = True 

126 """Whether main window should be floating (non-tiled) by default.""" 

127 

128 # Behavior settings 

129 confirm_close: bool = True 

130 """Show confirmation dialog when closing the application.""" 

131 

132 minimize_to_tray: bool = False 

133 """Minimize to system tray instead of taskbar.""" 

134 

135 auto_save_interval_minutes: Optional[int] = 5 

136 """Auto-save interval in minutes. None to disable auto-save.""" 

137 

138 

139@dataclass(frozen=True) 

140class StyleConfig: 

141 """Configuration for GUI styling and appearance.""" 

142 

143 # Theme settings 

144 theme: PlotTheme = PlotTheme.DARK 

145 """Overall application theme.""" 

146 

147 # Font settings 

148 default_font_family: str = "Arial" 

149 """Default font family for the application.""" 

150 

151 default_font_size: int = 10 

152 """Default font size in points.""" 

153 

154 monospace_font_family: str = "Consolas" 

155 """Font family for monospace text (logs, code, etc.).""" 

156 

157 # Color customization 

158 custom_colors: Dict[str, str] = field(default_factory=dict) 

159 """Custom color overrides for theme colors.""" 

160 

161 # Animation settings 

162 enable_animations: bool = True 

163 """Enable UI animations and transitions.""" 

164 

165 animation_duration_ms: int = 200 

166 """Duration of animations in milliseconds.""" 

167 

168 

169@dataclass(frozen=True) 

170class LoggingConfig: 

171 """Configuration for GUI logging and debugging.""" 

172 

173 # Log display settings 

174 max_log_entries: int = 1000 

175 """Maximum number of log entries to keep in memory.""" 

176 

177 auto_scroll_logs: bool = True 

178 """Automatically scroll to newest log entries.""" 

179 

180 log_level_filter: str = "INFO" 

181 """Minimum log level to display in GUI.""" 

182 

183 # Log file settings 

184 enable_file_logging: bool = True 

185 """Enable logging to file.""" 

186 

187 log_file_max_size_mb: int = 10 

188 """Maximum log file size in MB before rotation.""" 

189 

190 log_file_backup_count: int = 5 

191 """Number of backup log files to keep.""" 

192 

193 

194@dataclass(frozen=True) 

195class PyQtGUIConfig: 

196 """ 

197 Root configuration object for the PyQt GUI application. 

198  

199 This follows the same pattern as GlobalPipelineConfig, providing 

200 a centralized, immutable configuration for all GUI components. 

201 """ 

202 

203 # Component configurations 

204 performance_monitor: PerformanceMonitorConfig = field(default_factory=PerformanceMonitorConfig) 

205 """Configuration for the system performance monitor.""" 

206 

207 window: WindowConfig = field(default_factory=WindowConfig) 

208 """Configuration for main window behavior.""" 

209 

210 style: StyleConfig = field(default_factory=StyleConfig) 

211 """Configuration for GUI styling and appearance.""" 

212 

213 logging: LoggingConfig = field(default_factory=LoggingConfig) 

214 """Configuration for GUI logging.""" 

215 

216 # Global GUI settings 

217 enable_debug_mode: bool = False 

218 """Enable debug mode with additional logging and diagnostics.""" 

219 

220 check_for_updates: bool = True 

221 """Check for application updates on startup.""" 

222 

223 # Future extension points 

224 plugin_settings: Dict[str, Any] = field(default_factory=dict) 

225 """Settings for GUI plugins and extensions.""" 

226 

227 

228# --- Default Configuration Providers --- 

229 

230_DEFAULT_PERFORMANCE_MONITOR_CONFIG = PerformanceMonitorConfig( 

231 update_fps=5.0, # 5 FPS for good performance balance 

232 history_duration_seconds=60.0, 

233 plot_theme=PlotTheme.DARK, 

234 enable_gpu_monitoring=True 

235) 

236 

237_DEFAULT_WINDOW_CONFIG = WindowConfig( 

238 default_width=1200, 

239 default_height=800, 

240 floating_by_default=True, # User preference for tiling window manager 

241 remember_window_state=True 

242) 

243 

244_DEFAULT_STYLE_CONFIG = StyleConfig( 

245 theme=PlotTheme.DARK, 

246 enable_animations=True 

247) 

248 

249_DEFAULT_LOGGING_CONFIG = LoggingConfig( 

250 max_log_entries=1000, 

251 auto_scroll_logs=True, 

252 log_level_filter="INFO" 

253) 

254 

255 

256def get_default_pyqt_gui_config() -> PyQtGUIConfig: 

257 """ 

258 Provides a default instance of PyQtGUIConfig. 

259  

260 This function provides sensible defaults for the PyQt GUI application, 

261 following the same pattern as get_default_global_config(). 

262  

263 Returns: 

264 PyQtGUIConfig: Default configuration instance 

265 """ 

266 logger.debug("Initializing with default PyQtGUIConfig.") 

267 return PyQtGUIConfig( 

268 performance_monitor=_DEFAULT_PERFORMANCE_MONITOR_CONFIG, 

269 window=_DEFAULT_WINDOW_CONFIG, 

270 style=_DEFAULT_STYLE_CONFIG, 

271 logging=_DEFAULT_LOGGING_CONFIG, 

272 enable_debug_mode=False, 

273 check_for_updates=True 

274 ) 

275 

276 

277def create_high_performance_config() -> PyQtGUIConfig: 

278 """ 

279 Create a high-performance configuration preset. 

280  

281 Returns: 

282 PyQtGUIConfig: High-performance configuration 

283 """ 

284 return PyQtGUIConfig( 

285 performance_monitor=PerformanceMonitorConfig( 

286 update_fps=30.0, # High refresh rate 

287 history_duration_seconds=30.0, # Shorter history for performance 

288 antialiasing=False, # Disable for performance 

289 per_core_cpu_monitoring=True, # More detailed monitoring 

290 detailed_memory_info=True 

291 ), 

292 style=StyleConfig( 

293 enable_animations=False # Disable animations for performance 

294 ) 

295 ) 

296 

297 

298def create_low_resource_config() -> PyQtGUIConfig: 

299 """ 

300 Create a low-resource configuration preset. 

301  

302 Returns: 

303 PyQtGUIConfig: Low-resource configuration 

304 """ 

305 return PyQtGUIConfig( 

306 performance_monitor=PerformanceMonitorConfig( 

307 update_fps=1.0, # Very low refresh rate 

308 history_duration_seconds=120.0, # Longer history with fewer points 

309 antialiasing=False, 

310 enable_gpu_monitoring=False, # Disable GPU monitoring 

311 gpu_temperature_monitoring=False, 

312 cpu_frequency_monitoring=False, 

313 detailed_memory_info=False 

314 ), 

315 logging=LoggingConfig( 

316 max_log_entries=100, # Fewer log entries 

317 enable_file_logging=False 

318 ), 

319 style=StyleConfig( 

320 enable_animations=False 

321 ) 

322 )