A toggle button in the toolbar
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: A toggle button in the toolbar
Thanks!
I will check it out.
I will check it out.
Re: A toggle button in the toolbar
Hi,
The 'checkable' button works very good and very simple to use. I think it will be perfect for PrzemoF. For me it is less perfect, I was looking for something exactly like the perspective/ortho buttons: Two buttons are shown, when I press on perspective it becomes checked, and ortho becomes unchecked, and when I press on ortho, ortho becomes checked and perspective becomes unchecked.
It is not that critical, If it is even slightly complicated task, it does not worth the work. I can do great with what I have now.
Thanks!
shai
The 'checkable' button works very good and very simple to use. I think it will be perfect for PrzemoF. For me it is less perfect, I was looking for something exactly like the perspective/ortho buttons: Two buttons are shown, when I press on perspective it becomes checked, and ortho becomes unchecked, and when I press on ortho, ortho becomes checked and perspective becomes unchecked.
It is not that critical, If it is even slightly complicated task, it does not worth the work. I can do great with what I have now.
Thanks!
shai
Re: A toggle button in the toolbar
That Sounds more like what they called radio buttons to me.shaise wrote:Two buttons are shown, when I press on perspective it becomes checked, and ortho becomes unchecked, and when I press on ortho, ortho becomes checked and perspective becomes unchecked.
Re: A toggle button in the toolbar
Indeed. A radio button is a better term for it.Jee-Bee wrote:shaise wrote: That Sounds more like what they called radio buttons to me.
Do you know if it is supported in the python interface? (for toolbar buttons, I mean)
shai
Re: A toggle button in the toolbar
i don know i have only experience with LabVIEW ... just start with learning python
I saw this http://pyqt.sourceforge.net/Docs/PyQt4/ ... utton.html but that are the normal round ones...
I saw this http://pyqt.sourceforge.net/Docs/PyQt4/ ... utton.html but that are the normal round ones...
Re: A toggle button in the toolbar
Yes, this is for general gui use, not specific for FreeCAD toolbars.Jee-Bee wrote:i don know i have only experience with LabVIEW ... just start with learning python
I saw this http://pyqt.sourceforge.net/Docs/PyQt4/ ... utton.html but that are the normal round ones...
Re: A toggle button in the toolbar
With git commit 26b424e and this example you should have want you want:
The individual command must set the Checkable key to True. The command must set the Exclusive key to True and it's recommended to set DropDownMenu to False.
Code: Select all
class Cmd1:
def Activated(self, index):
pass
def GetResources(self):
return { 'MenuText': 'Command 1', 'Checkable': True}
class Cmd2:
def Activated(self, index):
pass
def GetResources(self):
return { 'MenuText': 'Command 2', 'Checkable': True}
class Cmd3:
def Activated(self, index):
pass
def GetResources(self):
return { 'MenuText': 'Command 3', 'Checkable': True}
class Cmd4:
def Activated(self, index):
pass
def GetResources(self):
return { 'MenuText': 'Command 4'}
class MyGroupCommand:
def GetCommands(self):
return ("Cmd1", "Cmd2", "Cmd3", "Cmd4") # a tuple of command names that you want to group
def Activated(self, index):
pass
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', 'DropDownMenu': False, 'Exclusive' : True, }
def IsActive(self): # optional
return True
FreeCADGui.addCommand('Cmd1',Cmd1())
FreeCADGui.addCommand('Cmd2',Cmd2())
FreeCADGui.addCommand('Cmd3',Cmd3())
FreeCADGui.addCommand('Cmd4',Cmd4())
FreeCADGui.addCommand('MyGroupCommand',MyGroupCommand())
Re: A toggle button in the toolbar
wmayer,
Thanks again!
I will give it a try!
shai
Thanks again!
I will give it a try!
shai
Re: A toggle button in the toolbar
wmayer,
Sorry for the time it took, but I checked it and it works exactly as I wanted it to. Thanks!
There is however a slight issue, perhaps I'm doing something wrong, but initially all buttons are unchecked, and I was expecting the default button to be checked.
I marked this button as: 'Checkable': True, and in the group command I returned GetDefaultCommand() with 0.
Thanks again!
shai
Sorry for the time it took, but I checked it and it works exactly as I wanted it to. Thanks!
There is however a slight issue, perhaps I'm doing something wrong, but initially all buttons are unchecked, and I was expecting the default button to be checked.
I marked this button as: 'Checkable': True, and in the group command I returned GetDefaultCommand() with 0.
Code: Select all
class FSMatchTypeInnerCommand:
def Activated(self, index):
pass
def GetResources(self):
return { 'Pixmap' : os.path.join( iconPath , 'IconMatchTypeInner.svg'),
'MenuText': 'Match screws by inner thread diameter (Tap hole)',
'Checkable': True}
class FSMatchTypeOuterCommand:
def Activated(self, index):
pass
def GetResources(self):
return { 'Pixmap' : os.path.join( iconPath , 'IconMatchTypeOuter.svg'),
'MenuText': 'Match screws by outer thread diameter (Pass hole)',
'Checkable': False}
class FSMatchTypeGroupCommand:
def GetCommands(self):
return ("FSMatchTypeInner", "FSMatchTypeOuter") # a tuple of command names that you want to group
def Activated(self, index):
if index == 0:
FSMatchOuter = False
FreeCAD.Console.PrintLog("Set auto diameter to match inner thread\n")
else:
FSMatchOuter = True
FreeCAD.Console.PrintLog("Set auto diameter to match outer thread\n")
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 0
def GetResources(self):
return { 'MenuText': 'Screw diamter matching mode', 'ToolTip': 'Screw diamter matching mode (by inner or outer thread diameter)', 'DropDownMenu': False, 'Exclusive' : True }
def IsActive(self): # optional
return True
FreeCADGui.addCommand('FSMatchTypeInner',FSMatchTypeInnerCommand())
FreeCADGui.addCommand('FSMatchTypeOuter',FSMatchTypeOuterCommand())
FreeCADGui.addCommand('FSMatchTypeGroup',FSMatchTypeGroupCommand())
shai
Re: A toggle button in the toolbar
git commit cda9bf9
If GetDefaultCommand is not there the first command is toggled, otherwise you can control which other command to toggle. And if you want to have an exclusive group but no toggled command then GetDefaultCommand must be implemented to return a number out of range, e.g. -1.
If GetDefaultCommand is not there the first command is toggled, otherwise you can control which other command to toggle. And if you want to have an exclusive group but no toggled command then GetDefaultCommand must be implemented to return a number out of range, e.g. -1.