Feature Request- Keyboard shortcut for Selection Mode

Hey @petebankhead and the QuPath Team-
I have a tiny feature request- could you make a keyboard shortcut for Selection Mode?

image

I recommend “S”.

Thanks!

1 Like

Hi @smcardle, sure we can look into that.

I’ve no idea how popular the option is, only that it is confusing for people who have it turned on my accident – so my fear is that a shortcut would make it too easy to activate. So I think Shift + S would be a bit safer.

But I’m curious: what do you use selection mode for primarily (e.g. when classifying, deleting, something else)?

Upon closer investigation, there is a shortcut for selection mode defined here… it’s just that it is unfortunately the same as the one for synchronizing viewers, which takes precedence in the end.

As a temporary workaround, this script seems to work to set an alternative shortcut:

def combo = javafx.scene.input.KeyCombination.keyCombination("shift+s")
def action = getQuPath().getDefaultActions().SELECTION_MODE
action.setAccelerator(combo)
getQuPath().registerAccelerator(action)
print "Accelerator is now ${action.getAccelerator()}"

Edit: Created an issue for this now:

3 Likes

I use it when I’m cleaning up annotations made by an inaccurate classifier. I use the Selection mode to highlight a bunch of objects to delete them, and then switch it off to edit the boundaries of a single object. Toggling back and forth would be easier with a shortcut, and Shift + S would work perfectly for me.

Thank you for the script, but it doesn’t seem to work for me? I ran it and got the message at the end, but shift + s still doesn’t do anything. Do I need to do something special to make it work? I’m on Windows, 0.2.3 + Tensorflow.

1 Like

This looks really cool, and would be great as part of a startup script, but like @smcardle do not see any response. No errors, no crash, the print statement prints, but the shortcut does not seem to change.
Is there any chance this will only work when run through Eclipse or similar?

Nevermind, it does work for other things, like I can turn detections on or off with the S key. Hmm.

I do notice that in most cases the ActionIcon has a different name than the Accelerator. Could that be the issue?

Also, if I try to switch “S” back to SELECTION_MODE after making S the action for show/hide detections, I get this message:

WARN: Multiple actions registered for S, will keep Selection mode and drop Show detections
INFO: Accelerator is now S

However, “Show detections” remains the function of the S key, so it is not being dropped.

Ah, it works on a Mac but I haven’t tried it on Windows. Accelerators are handled slightly differently. I expect that’s the problem.

I really thought this would be simple. I swear I’m not trying to be a troublemaker! :stuck_out_tongue:

1 Like

A few more tests as I had time:


I can adjust SHOW_LOG, which uses the same sort of combo as selection mode.

In all other cases the PathIcons name is different from the Action name. It is still the primary difference I can see, and haven’t had an issue changing any other shortcuts. At least where there is an @ActionAccelerator, I cannot seem to add one to an action that did not already have an Accelerator.

1 Like

Probably best just ignore my script then! It’s a quick hack that I thought might work, but seems it only does on a Mac. The fact that it does for some commands might be because they have corresponding menu entries. But whatever the reason, it’s not particularly intended to be able to change accelerators via a script after QuPath has been initialized so I don’t think it’s worth spending too long debugging it.

Changing the shortcut in the code and rebuilding is another option.

1 Like

just add this macro to your startup file and s will switch between the rectangle tool and the line too.
You can check it out to see how it works by opening it in the macro editor and running it, or you can make it a function to include in a macro.

macro “toggle rectangle [s]”{

if (IJ.getToolName() != "rectangle") {

setTool(“rectangle”);
}
else {
setTool(“line”);
}
}

I think that is for ImageJ/FIJI.

1 Like

Sorry, I thought qupath was a IJ/FIJI plugin. My bad.

@rondespain Thanks for your help anyway!!