Thank you for the great documentation on creating new toolbars.
Here is another useful example:
The command class (which is added via addCommand()) has an optional function named GetCommands(self) -> list[str]. You can return a list of command names to be grouped together. This new Group-Command can be used similar to a normal command item, but:
- In a toolbar it will display a drop-down list (like the Constraints or Circle combo menu).
- As a menu-item it will create a menu entry with all selected commands as submenu items.
There is also GetDefaultCommand(self) -> int which will trigger the command at chosen index (e.g. if user clicks on toolbar combo box without opening the drop-down).
The group can implement Activated(self, cmd: int = 0) -> None which provides the index of the performed action. If the group does NOT implement Activated(), the Activated() function of the child command is executed. If the group does implement Activated(), then the child is not called and the group is responsible for handling the action.
CmdType rules apply to the group first. E.g. if child command can be shown in edit mode, but group cannot, then you wont be able to call any child because the group will be deactivated.
...
As a related question: how to find valid menu names? E.g. I tried "Geometries" and it inserts a new menu item at the end of the "Sketch" menu. While this is where I want it to be, it is not where I would have expected the item to appear. I know the documentation says "names an entry, not a menu", but I dont know how to get either except by trial and error. Using an entry of a menu to append to that menu feels wrong, but I guess it is how it is.
Thank you for the great documentation on creating new toolbars.
Here is another useful example:
The command class (which is added via
addCommand()) has an optional function namedGetCommands(self) -> list[str]. You can return a list of command names to be grouped together. This new Group-Command can be used similar to a normal command item, but:There is also
GetDefaultCommand(self) -> intwhich will trigger the command at chosen index (e.g. if user clicks on toolbar combo box without opening the drop-down).The group can implement
Activated(self, cmd: int = 0) -> Nonewhich provides the index of the performed action. If the group does NOT implementActivated(), theActivated()function of the child command is executed. If the group does implementActivated(), then the child is not called and the group is responsible for handling the action.CmdTyperules apply to the group first. E.g. if child command can be shown in edit mode, but group cannot, then you wont be able to call any child because the group will be deactivated....
As a related question: how to find valid menu names? E.g. I tried "Geometries" and it inserts a new menu item at the end of the "Sketch" menu. While this is where I want it to be, it is not where I would have expected the item to appear. I know the documentation says "names an entry, not a menu", but I dont know how to get either except by trial and error. Using an entry of a menu to append to that menu feels wrong, but I guess it is how it is.