[Volunteers welcome] Refactoring the keyboard shortcuts

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
TheMarkster
Posts: 2049
Joined: Thu Apr 05, 2018 1:53 am

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby TheMarkster » Fri Jul 17, 2020 9:54 pm

I found a bug in Gui.getCommandShortcut() and Gui.getCommandInfo(). They return the default shortcuts even if the user changed the shortcuts in the customize dialog. I have a PR to fix the issue:

https://github.com/FreeCAD/FreeCAD/pull/3710

In this PR I also added a new command:

Gui.setCommandShortcut() which will enable easily changing the shortcut via python. Usage example:

Gui.setCommandShortcut('Std_AxisCross','A,E')

This example would change the shortcut for toggling the Axis Cross from A,C to A,E. With this new command we can do things like create a macro for setting shortcuts via a predefined text file, sort of a style sheet for keyboard shortcuts, containing the desired shortcut definitions, similar to what user cadcam has produced.
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson
openBrain
Posts: 4874
Joined: Fri Nov 09, 2018 5:38 pm

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby openBrain » Sat Jul 18, 2020 7:21 am

TheMarkster wrote:
Fri Jul 17, 2020 9:54 pm
I found a bug in Gui.getCommandShortcut() and Gui.getCommandInfo().
I remarked something else. Eg. if you look at View->Workbenches, the first ones have a shortcut as 'W, x' where x is a digit. These commands and shortcuts aren't listed by your function. I guess it's because this kind of commands is handled differently. May you have a look at this?

In this PR I also added a new command:

Gui.setCommandShortcut() which will enable easily changing the shortcut via python. Usage example:

Gui.setCommandShortcut('Std_AxisCross','A,E')
Indeed this would made it easy to store user configuration in a JSON or XML file, and restore it. Though I think there was already something doable as @triplus succeed in https://github.com/triplus/ShortCuts ;)
cadcam
Posts: 73
Joined: Thu Apr 02, 2020 10:39 am

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby cadcam » Sat Jul 18, 2020 11:30 am

Markster,

Would be very interested to follow how this proceeds. Currently I have all my shortcuts in a spreadsheet which

1) Modifies user.cfg to give general shortcut (Manual equivalent is Triplus shortcuts)

2) Modifies user.cfg and maps shortcut to associated macro + icon

3) Updates Latex based shortcuts doc

4) Hooks for more enhanced manual production using notes in spreadsheet field + webpage currently planned to add to start wb.

Best Regards
TheMarkster
Posts: 2049
Joined: Thu Apr 05, 2018 1:53 am

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby TheMarkster » Sat Jul 18, 2020 5:29 pm

openBrain wrote:
Sat Jul 18, 2020 7:21 am
TheMarkster wrote:
Fri Jul 17, 2020 9:54 pm
I found a bug in Gui.getCommandShortcut() and Gui.getCommandInfo().
I remarked something else. Eg. if you look at View->Workbenches, the first ones have a shortcut as 'W, x' where x is a digit. These commands and shortcuts aren't listed by your function. I guess it's because this kind of commands is handled differently. May you have a look at this?

In this PR I also added a new command:

Gui.setCommandShortcut() which will enable easily changing the shortcut via python. Usage example:

Gui.setCommandShortcut('Std_AxisCross','A,E')
Indeed this would made it easy to store user configuration in a JSON or XML file, and restore it. Though I think there was already something doable as @triplus succeed in https://github.com/triplus/ShortCuts ;)
I saw somewhere in the source code a mention that some commands can have multiple actions. As an example of this you can load a workbench as:

Gui.activateWorkbench('ArchWorkbench')

or alternatively:

Gui.runCommand('Std_Workbench',0)

(presumes Arch workbench is first workbench listed in the workbenches list)

Another example: Gui.runCommand('Std_Workbench',2) would activate the 3rd workbench in the list.

I believe the commands that accept an additional integer parameter are the ones with multiple actions, or perhaps these are handled in a case switch loop or something similar.

If you look in the customize dialog, keyboards tab, view menu, you see only the one workbench command. I think the case will be if you can't see a command in the customize dialog the python command won't see it either. Similarly, I'm finding if you can't set a shortcut in the customize dialog you can't set it in the Gui.setCommandShortcut() function either. Based on initial testing I'm getting about 84.5% success rate when loading all installed workbenches and testing all commands found with Gui.listCommands(). The function will return False if it's unable to set the shortcut.
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson
catman
Posts: 277
Joined: Fri Jan 11, 2019 10:42 pm

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby catman » Sun Jul 26, 2020 10:26 pm

Just go a hint about this great thread. I find the wiki page most impressive and already useful as it is now.

The short cuts ones I know are from Tooltips and the menues that list them (not all do). I have searched many times but not yet found a list of short cuts. The offline help and the help menu at least do not give any hints.

I would like to suggest to move the wiki page from the sandbox to the section that gets pulled into the offline user manual.
Reason: This is very helpful for normal users if it reflects the current state. Its even more helpful if it contains information that there might be changes to some short cuts coming up.
catman
Posts: 277
Joined: Fri Jan 11, 2019 10:42 pm

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby catman » Sun Jul 26, 2020 11:39 pm

Would it be acceptable to introduce the version SPACE,<key> for "local" commands?

Since the SPACE key is easy and quickly to reach for both hands it would be very suitable for commands that one would rather put on a single key, but that is used aleady.

Example: In Sketcher we use constriants and dimensions a lot. Typically contraint a bit more, so they get the single letter commands: "S" for symmetrical and "C" for coincidence, "H" for Horizontal. For dimensions single letters would be greate, but the obvious choices conflict (e.g. "H" and "V"). So we use "Shift-H" and "Shift-V". At least for me that is a very uncomforable key combination to hit very quickly. Reading the wiki page on short cuts I thought about how C,V or C,H or C,R would work - but I did not really like it. But I think with Space,H Space,V or Space,R that would be a lot better. It also would free the SHIFT key as meta, e.g. to reverse things.

Any comments?
chrisb
Posts: 29061
Joined: Tue Mar 17, 2015 9:14 am

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby chrisb » Mon Jul 27, 2020 3:43 am

Space is probably one of the most used shortcuts: it toggles the visibility. I would not like to see the meaning changed, albeit in a sophisticated way of tree view visible or not.
A Sketcher Lecture with in-depth information is available in English, auf deutsch, en français, en español.
catman
Posts: 277
Joined: Fri Jan 11, 2019 10:42 pm

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby catman » Mon Jul 27, 2020 11:01 am

chrisb wrote:
Mon Jul 27, 2020 3:43 am
Space is probably one of the most used shortcuts: it toggles the visibility. I would not like to see the meaning changed, albeit in a sophisticated way of tree view visible or not.
Right. Well, was worth a try.. :roll:
catman
Posts: 277
Joined: Fri Jan 11, 2019 10:42 pm

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby catman » Mon Jul 27, 2020 11:07 am

openBrain wrote:
Mon Apr 06, 2020 1:17 pm
Once wiki page is here, this shouldn't be a big effort as it basically is only presenting shortcuts in a JSON format. ;)
Did you create that wiki page (actually the tables) manually or with some tool?
openBrain
Posts: 4874
Joined: Fri Nov 09, 2018 5:38 pm

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby openBrain » Mon Jul 27, 2020 12:05 pm

catman wrote:
Mon Jul 27, 2020 11:07 am
Did you create that wiki page (actually the tables) manually or with some tool?
It's created automatically with a macro. ;)