Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gui: [skip ci] move Python functions for commands to its own class
- Loading branch information
Showing
6 changed files
with
327 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd"> | ||
<PythonExport | ||
Father="PyObjectBase" | ||
Name="CommandPy" | ||
Twin="Command" | ||
TwinPointer="Command" | ||
Include="Gui/Command.h" | ||
FatherInclude="Base/PyObjectBase.h" | ||
Namespace="Gui" | ||
FatherNamespace="Base"> | ||
<Documentation> | ||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer[at]users.sourceforge.net" /> | ||
<UserDocu>FreeCAD Python wrapper of Command functions</UserDocu> | ||
</Documentation> | ||
<Methode Name="get" Static='true'> | ||
<Documentation> | ||
<UserDocu>get(string) -> Command | ||
|
||
Get a given command by name or None if it doesn't exist. | ||
</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="update" Static='true'> | ||
<Documentation> | ||
<UserDocu>update() -> None | ||
|
||
Update active status of all commands. | ||
</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="listAll" Static='true'> | ||
<Documentation> | ||
<UserDocu>listAll() -> list of strings | ||
|
||
Returns the name of all commands. | ||
</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="run"> | ||
<Documentation> | ||
<UserDocu>run() -> None | ||
|
||
Runs the given command. | ||
</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="isActive" Const="true"> | ||
<Documentation> | ||
<UserDocu>isActive() -> bool | ||
|
||
Returns True if the command is active, False otherwise. | ||
</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="getShortcut"> | ||
<Documentation> | ||
<UserDocu>getShortcut() -> string | ||
|
||
Returns string representing shortcut key accelerator for command. | ||
</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="setShortcut"> | ||
<Documentation> | ||
<UserDocu>setShortcut(string) -> bool | ||
|
||
Sets shortcut for given command, returns bool True for success. | ||
</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="getInfo"> | ||
<Documentation> | ||
<UserDocu>getInfo() -> list of strings | ||
|
||
Usage: menuText, tooltipText, whatsThisText, statustipText, pixmapText, shortcutText. | ||
</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
</PythonExport> | ||
</GenerateModel> |
Oops, something went wrong.
9b529bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This moves the commands but doesn't reimplement them with the same name,
isCommandActive
,listCommands
,getCommandInfo
,getCommandShortcut
,setCommandShortcut
,updateCommands
.This breaks things in scripts because some tools check for the existence of other tools.
Something like this is needed.
9b529bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the handling with commands isn't something that belongs to the FreeCADGui module directly but rather to a sub-module or a class.
Some years ago we had exactly two functions in FreeCADGui to deal with commands: addCommand() and runCommand() that are used in several places in Python code and that was OK.
But over the years more and more functions have been added: listCommand (in 2016), isCommandActive (in 2019), updateCommands (in 2019), getCommandShortcut (in April 2020), getCommandInfo (in April 2020), setCommandShortcut (in July 2020) and listCommandByShortcut was about to be added next. Now, none of these functions added since 2016 are used anywhere in FreeCAD code.
In the first place I wonder why more and more functions are added which nobody uses.
In the second place when a header file is touched that is included from many source files I end up in re-compiling big parts of the application. And if a PR cannot be directly merged but requires to be merged locally I end up in re-compiling the stuff twice.
I was thinking for a longer time to move command specific functions to another place. Now that in the recent months more functions have been added regularly I just did it and refactored the code.
Since the functions have been moved to the FreeCADGui.Command class there is no need to keep the superfluous word "Command" in the function names and this makes it more consistent to the C++ API.
The only function that eventually might be used in some external add-ons is listCommands but all the others are too new in order to be used there. So, do you know of a concrete add-on that is affected by the change?
9b529bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BIM Workbench uses
listCommands
it to see if a particular command exists, loaded by another workbench, so it can set up its toolbars appropriately, yorikvanhavre/BIM_Workbench#59. I think Dodo may use it as well. In general I think thislistCommands
is pretty useful to handle undefined commands.About the other functions, you are right that I haven't seen them used, so maybe they are fine being moved. However, I suspect TheMarkster, who implemented the latest
CommandShortcut
functions, wanted to use them to better manage the shortcuts of each workbench, as it is currently being discussed in the forum, [Volunteers welcome] Refactoring the keyboard shortcuts.Also, what is your opinion on other Command functions, like
doCommand
,doCommandGui
? Do you also plan on moving them, or it's best to keep them in the mainGui
namespace?9b529bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks. This can be easily fixed by adding this line to FreeCADGuiInit.py:
OK, I will drop a note there.
I don't have a string option on them. If I decide to move them as well I for sure will add an alias as above.
9b529bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
76e7429
9b529bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wwmayer Some of these Python API have existed for some time. Removing it will likely break some existing Python workbench (well, it breaks my asm3 workbench). Would it be nicer to leave them there, and put some deprecation warning maybe?
9b529bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see the alias thing. So maybe add other aliases as well?
9b529bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which aliases exactly do you miss?
9b529bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using
isCommandActive()
. But looks like it can't be aliased just like that, becauseCommand.isActive()
expect the input to be aCommand
instance.9b529bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two ways to achieve it:
9b529bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See 393da0d
9b529bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's neat. Thanks!