Drop-down button in python workbenches
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Drop-down button in python workbenches
Hi,
I have been working on the last week on a fasteners workbench that lets the user easily add screws, bolts, nuts etc to the design. https://github.com/shaise/FreeCAD_FastenersWB
The problem is, as the number of different types grow, the toolbar becomes more and more crowded: My question: is it possible to group several functions into a drop-down button like this: Can it be done in pure python workbench?
Thanks!
shai
I have been working on the last week on a fasteners workbench that lets the user easily add screws, bolts, nuts etc to the design. https://github.com/shaise/FreeCAD_FastenersWB
The problem is, as the number of different types grow, the toolbar becomes more and more crowded: My question: is it possible to group several functions into a drop-down button like this: Can it be done in pure python workbench?
Thanks!
shai
Last edited by shaise on Fri Jun 26, 2015 11:24 am, edited 1 time in total.
Re: Drop-down button in python workbenches
Not yet but I have it on my to-do list.Can it be done in pure python workbench?
Re: Drop-down button in python workbenches
Thanks for the quick reply.
For the meantime I think I will just separate to several toolbars so they can be moved around.
For the meantime I think I will just separate to several toolbars so they can be moved around.
Re: Drop-down button in python workbenches
git commit 882ecd3 implements this feature now.
How does it work? You write a Python command class with this interface:
If for any reason the group command class must manage the activation of a clicked command you can additionally implement the method Activated.
How does it work? You write a Python command class with this interface:
Code: Select all
class MyGroupCommand:
def GetCommands(self):
return ("Cmd1", "Cmd2", "Cmd3", "Cmd4") # a tuple of command names that you want to group
def GetDefaultCommand(self): # return the index of the tuple of the default command. This method is optional and when not implemented '0' is used
return 2
def GetResources(self):
return { 'MenuText': 'Group command', 'ToolTip': 'Example group command'}
def IsActive(self): # optional
return True
FreeCADGui.addCommand('MyGroupCommand',MyGroupCommand())
Code: Select all
class MyGroupCommand:
...
def Activated(self, index): # index is an int in the range [0, len(GetCommands)[
if index == 0:
...
elif index == 1:
...
elif index == 2:
...
Re: Drop-down button in python workbenches
That was fast! Thanks!
Re: Drop-down button in python workbenches
Awesome Werner, like always, much better implementation than what I was thinking
Re: Drop-down button in python workbenches
Hi wmayer,
Looks great, I plan to make use of the GroupCommand Feature for the drawing dimension workbench.
Before I do so however i would like add support for backwards compatibility with regard to FreeCAD 0.15 users.
There i would like add a check to see if the user's FreeCAD has the GroupCommand Feature.
I suppose something along the lines of
would work, but is there a nicer way of doing this check?(which is backwards compilable upto FreeCAD 0.15 )
Looks great, I plan to make use of the GroupCommand Feature for the drawing dimension workbench.
Before I do so however i would like add support for backwards compatibility with regard to FreeCAD 0.15 users.
There i would like add a check to see if the user's FreeCAD has the GroupCommand Feature.
I suppose something along the lines of
Code: Select all
if int( FreeCAD.Version()[1] > 15 ) and int( FreeCAD.Version()[2].split()[0] ) > 5165 then
GroupCommand Feature
else
...
Re: Drop-down button in python workbenches
I think that's the only way to go.would work, but is there a nicer way of doing this check?(which is backwards compilable upto FreeCAD 0.15 )
Re: Drop-down button in python workbenches
Implemented the Group Command Feature and its working as expected.
The feature saves alot of toolbar space which is great, so thanks wmayer!
Is there an option to change the drop-list from a text list (containing each command's menu text), to an icon list?
If so, i would prefer this icon based alternative.
The feature saves alot of toolbar space which is great, so thanks wmayer!
Is there an option to change the drop-list from a text list (containing each command's menu text), to an icon list?
If so, i would prefer this icon based alternative.
Re: Drop-down button in python workbenches
Looks good.hamish wrote:Implemented the Group Command Feature and its working as expected.
The feature saves alot of toolbar space which is great, so thanks wmayer!
Is there an option to change the drop-list from a text list (containing each command's menu text), to an icon list?
If so, i would prefer this icon based alternative.
P.S. Just a side note probably this new toolbar should be set to ON by default.