SKILL.md
Test Bindings Skill
Interactively test mouse button bindings in Slicer.
When to Use
Use this skill when:
- User wants to verify their bindings work
- User is debugging why a binding isn't triggering
- User wants to see what actions are available
Steps
- Check MouseMaster Status
Provide code to check if MouseMaster is active:
```python import slicer
try: mm = slicer.modules.mousemaster widget = slicer.modules.MouseMasterWidget print("MouseMaster module loaded")
# Check if logic is initialized if hasattr(widget, 'logic') and widget.logic: if widget.logic.is_active(): print("Event handler: ACTIVE") else: print("Event handler: INACTIVE") print("Click 'Enable' in the module panel to activate") else: print("Logic not initialized - open the module first") except: print("MouseMaster not loaded - check Extensions Manager") ```
- List Current Bindings
Show the current preset configuration:
```python # Get current preset logic = slicer.modules.MouseMasterWidget.logic preset = logic.getcurrentpreset() mouse = logic.getcurrentmouse()
if preset and mouse: print(f"Mouse: {mouse.name}") print(f"Preset: {preset.name}") print("\nDefault Mappings:") for buttonid, mapping in preset.mappings.items(): button = mouse.getbutton(buttonid) name = button.name if button else buttonid print(f" {name}: {mapping.action}")
print("\nContext Mappings:") for context, mappings in preset.contextmappings.items(): print(f" {context}:") for buttonid, mapping in mappings.items(): print(f" {button_id}: {mapping.action}") else: print("No preset or mouse selected") ```
- Test Individual Action
Manually trigger an action to verify it works:
```python from MouseMasterLib.action_registry import ActionRegistry, ActionContext
registry = ActionRegistry.get_instance()
# List available actions print("Available actions:") for action in registry.getallactions(): print(f" {action.id}: {action.description}")
# Test specific action context = ActionContext(modulename="Welcome") result = registry.execute("editundo", context) print(f"Action executed: {result}") ```
- Monitor Button Presses
Set up real-time monitoring:
```python def onbuttonpress(buttonid, context): print(f"Button: {buttonid}, Context: {context}")
handler = slicer.modules.MouseMasterWidget.logic.eventhandler handler.setonbuttonpress(onbuttonpress) print("Monitoring active. Press buttons to see output.") print("Run: handler.setonbuttonpress(None) to stop") ```
- Debug Specific Binding
If a binding isn't working:
```python # Check if button is in profile mouse = logic.getcurrentmouse() button = mouse.getbutton("back") if button: print(f"Button found: {button.name}, Qt code: {button.qtbutton}") print(f"Remappable: {button.remappable}") else: print("Button not found in profile")
# Check if mapping exists preset = logic.getcurrentpreset() mapping = preset.get_mapping("back") if mapping: print(f"Mapping: {mapping.action}") else: print("No mapping defined")
# Check if action exists registry = ActionRegistry.getinstance() action = registry.getaction(mapping.action if mapping else "unknown") if action: print(f"Action found: {action.description}") else: print("Action not registered") ```
Common Issues
Button Press Not Detected
- Check handler is installed:
``python print(logic.eventhandler.is_installed) ``
- Check handler is enabled:
``python print(logic.eventhandler.is_enabled) ``
- Check Qt button code is in profile
Action Not Executing
- Verify action is registered:
``python print(registry.getaction("actionid")) ``
- Check action availability:
``python context = ActionContext(modulename="SegmentEditor") action = registry.getaction("segmentnext") print(action.handler.isavailable(context)) ``
Context Not Detected
- Check current module:
``python print(slicer.app.moduleManager().currentModule()) ``
- Verify context name in preset matches exactly
Troubleshooting Checklist
- MouseMaster module is loaded
- Logic is initialized
- Event handler is installed
- Event handler is enabled
- Mouse profile is selected
- Preset is selected
- Button is in mouse profile
- Mapping exists for button
- Action is registered
- Action is available in current context