ADR-005: Persistence Strategy
Status
Accepted
Context
MouseMaster needs to persist several types of data:
User preferences: Active mouse, active preset, UI state
User presets: Custom button mappings created by user
Mouse profiles: Custom mouse definitions from button detection
Import history: Record of imported presets
Storage options considered:
Qt Settings (
QSettings): Slicer’s standard settings mechanismUser directory files: JSON files in user-specific directory
Slicer scene: Persist in MRML scene (resets on new scene)
Database: SQLite or similar (overkill for this use case)
Decision
Use a hybrid approach:
Qt Settings for Preferences
Small, simple settings stored in Slicer’s settings:
settings = qt.QSettings()
settings.setValue("MouseMaster/ActiveMouse", mouse_id)
settings.setValue("MouseMaster/ActivePreset", preset_id)
settings.setValue("MouseMaster/Enabled", True)
User Directory for Presets and Profiles
Larger, structured data stored as JSON files:
~/.slicer/MouseMaster/
├── presets/
│ ├── my_custom_preset.json
│ └── imported_preset.json
├── profiles/
│ └── my_detected_mouse.json
└── cache/
└── action_registry.json
Location determined by:
import slicer
user_dir = os.path.join(
slicer.app.slicerHome,
"..",
"MouseMaster"
)
# Or use: slicer.app.slicerUserSettingsFilePath parent directory
Built-in Resources
Default profiles and presets bundled with extension:
MouseMaster/
├── Resources/
│ └── MouseDefinitions/
│ ├── logitech_mx_master_3s.json
│ └── generic_3_button.json
└── presets/
└── builtin/
└── default_mx_master_3s.json
Consequences
Positive
Qt Settings integrates with Slicer’s settings management
File-based presets are easy to backup and share
Clear separation between user data and extension resources
Human-readable JSON files for debugging
Survives Slicer upgrades (user directory persists)
Negative
Two storage mechanisms to maintain
Need to handle migration if file structure changes
File permissions issues possible on some systems
Neutral
User must have write access to user directory
Built-in resources are read-only
References
Qt Settings: https://doc.qt.io/qt-5/qsettings.html
Slicer Settings: https://slicer.readthedocs.io/en/latest/developer_guide/settings.html
ADR-002: Preset file format
ADR-007: Preset sharing