How to create shortcuts for the Draft workbench, and calling commandManager from Python

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Moult
Posts: 321
Joined: Sat Jan 05, 2019 11:46 am
Contact:

How to create shortcuts for the Draft workbench, and calling commandManager from Python

Post by Moult »

Hello everyone! As a disclaimer, I am not a C++ coder, but I can do Python, however I don't mind learning C++ if it is the better way to solve a problem.

If I go to Tools->Customize->Keyboard tab, I can select from a list of categories, see their commands, and then assign shortcuts to them. I noticed that the "Draft" workbench is not there. I can also see that the Draft workbench keyboard shortcuts are hardcoded.

I'd like to add the draft workbench's commands to this command manager, so that users can customise their commands.

Questions:

1. A quick look at the C++ makes me think that I need to add the command to the commandManager. Since the Draft WB is written in Python, can I write a bit of C++ that somehow adds the Python defined commands into the C++ Command Manager?
2. Alternatively, perhaps I can write some Python bindings for the commandManager class?

Any hints would be appreciated on the best approach to solve this.
I also blog about 3D rendering, architecture, software and other on thinkMoult.com. RSS / Atom feed available for your convenience.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: How to create shortcuts for the Draft workbench, and calling commandManager from Python

Post by triplus »

Moult wrote: Mon May 27, 2019 10:04 am If I go to Tools->Customize->Keyboard tab, I can select from a list of categories, see their commands, and then assign shortcuts to them. I noticed that the "Draft" workbench is not there.
They are there but likely in not all that obvious place. After Draft workbench gets activated look again under i guess the Python entry.
I'd like to add the draft workbench's commands to this command manager, so that users can customise their commands.
This therefore should already be possible.
Any hints would be appreciated on the best approach to solve this.
As for some additional hints, there is ShortCuts module.
User avatar
Moult
Posts: 321
Joined: Sat Jan 05, 2019 11:46 am
Contact:

Re: How to create shortcuts for the Draft workbench, and calling commandManager from Python

Post by Moult »

Thank you triplus. I didn't notice the Python entry.

Is there another way to add a customisable shortcut to that list without it having to be a command? For example, the "draft" workbench has what are called "in-command shortcuts". E.g. once you are already inside a command, pressing a single key will toggle a mode within that command. These keys are being listened to by keyboard events, but are not technically a command and therefore don't show up in that module.
I also blog about 3D rendering, architecture, software and other on thinkMoult.com. RSS / Atom feed available for your convenience.
User avatar
yorik
Founder
Posts: 13664
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: How to create shortcuts for the Draft workbench, and calling commandManager from Python

Post by yorik »

Okay I see you found a way that is good for now...

My original idea was this: for each of the Draft shortcuts, create a dummy FreeCAD command (a class with its getResources() dictionary)). That command would basically just do nothing at all. But it would get registered by FreeCAD, and appear in the keyboard shortcuts config screen, where users can change shortcuts. All shortcuts that are changed by the users that way, get an own entry in the preferences ( BaseApp/Preferences/Shortcut), so it's also easy to look them up from Python
Post Reply