Settings Manager - griffingilreath/Punch-Card-Project GitHub Wiki
Settings Manager
This document explains the technical implementation of the Settings Manager component in the Punch Card Project.
Overview
The Settings Manager provides a centralized system for accessing, validating, and persisting application settings. It replaces the previous approach of scattered settings access throughout the codebase with a single, type-safe interface.
Key Features
- Centralized Configuration: Single point of access for all application settings
- Type Safety: Settings are accessed with proper type validation
- Automatic Persistence: Settings changes are automatically tracked and saved
- Organized Categories: Settings are grouped by functionality for better organization
- Default Values: Sensible defaults are provided for all settings
- Error Handling: Robust error handling for configuration loading and saving
Implementation
Core Components
The Settings Manager is built around these key components:
- SettingsManager Class: Central class that manages all settings access
- Settings Categories: Organization of settings into logical groups
- Settings Dialog: UI component for modifying settings
- Settings Storage: Persistence layer for saving settings
SettingsManager Class
The SettingsManager class provides a simple interface for accessing settings:
class SettingsManager:
def __init__(self):
self.settings = {}
self.load_settings()
def get(self, key, default=None, type_hint=None):
"""Get a setting with optional type validation"""
value = self.settings.get(key, default)
# Apply type conversion if needed
if type_hint and value is not None:
try:
value = type_hint(value)
except (ValueError, TypeError):
return default
return value
def set(self, key, value):
"""Set a setting and trigger persistence"""
self.settings[key] = value
self.save_settings()
def load_settings(self):
"""Load settings from storage"""
try:
# Load from file
# ...
except Exception as e:
# Error handling
# ...
def save_settings(self):
"""Save settings to storage"""
try:
# Save to file
# ...
except Exception as e:
# Error handling
# ...
Settings Categories
Settings are organized into logical categories:
- General: Application-wide settings
- Display: Visual appearance and behavior settings
- Animation: Animation timing and behavior
- API: External API configuration
- Hardware: Hardware connectivity settings
- Debug: Debugging and development settings
Using the Settings Manager
To access settings from anywhere in the code:
# Get the singleton instance
settings = SettingsManager.instance()
# Get settings with type safety
delay = settings.get('animation.delay', 100, int)
api_key = settings.get('api.key', '')
show_debug = settings.get('debug.enabled', False, bool)
# Update settings
settings.set('animation.delay', 150)
Settings Dialog
The Settings Dialog provides a user interface for modifying settings:
- Tabbed Interface: Settings are organized into tabs by category
- Type-Appropriate Controls: Different control types for different setting types
- Validation: Input validation prevents invalid settings
- Apply/Cancel: Changes can be previewed before saving
Security Considerations
The Settings Manager integrates with the keychain system for secure storage of sensitive settings:
- API keys are stored in the system keychain rather than in settings files
- Sensitive settings are never saved to disk in plaintext
- Access to secure settings requires proper authorization
Known Issues
- Some settings aren't properly preserved between sessions
- Large configuration files can cause loading delays
- Settings dialog may not immediately reflect changes made programmatically
Future Improvements
Planned enhancements to the Settings Manager:
- Schema Validation: Formal schema definition for settings structure
- Change Notifications: Event system for settings changes
- Profile Support: Multiple configuration profiles for different uses
- Import/Export: Configuration import and export functionality
- User Permissions: Different access levels for settings
Integration with Other Components
The Settings Manager works closely with other system components:
- Animation Manager: Provides animation settings
- Hardware Controller: Provides hardware configuration
- API Client: Manages API connection details
- UI Components: Controls appearance and behavior