A toggle button in the toolbar

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!
User avatar
shaise
Posts: 486
Joined: Thu Jun 11, 2015 8:11 am

Re: A toggle button in the toolbar

Post by shaise »

wmayer wrote: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.
Great!
Thanks for the fast response.

shai
User avatar
ebrahim raeyat
Posts: 621
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: A toggle button in the toolbar

Post by ebrahim raeyat »

Thanks. I have some commands for view the objects. How can I check other icons status when user clicks on any icon?
how can I set last state of each icon when restart FreeCAD? is there and easy way?
when I change the WB and select it (activate it) again, only first icon appears and others did not shown. there is no icon in there.
wmayer wrote: pinged by pinger macro
icons.png
icons.png (10.28 KiB) Viewed 537 times
wmayer
Founder
Posts: 20302
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: A toggle button in the toolbar

Post by wmayer »

How can I check other icons status when user clicks on any icon?
If there should be only one button checked at a time then you can use a QButtonGroup

If you need the status of other buttons for internal calculations then put the buttons into a data structure where you can easily access them.
when I change the WB and select it (activate it) again, only first icon appears and others did not shown. there is no icon in there.
I guess you have a Workbench class. Re-implement the Activated() and Deactivated() functions where you restore and save the current status of the buttons, e.g. in a suitable parameter group.
User avatar
ebrahim raeyat
Posts: 621
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: A toggle button in the toolbar

Post by ebrahim raeyat »

Thanks @wmayer
If there should be only one button checked at a time then you can use a QButtonGroup
No, each icon can act individually.
If you need the status of other buttons for internal calculations then put the buttons into a data structure where you can easily access them.
Thank you so much. I implemented it as below:

Code: Select all

class OSAFEViewGroupCommand:
    def __init__(self):
        self.icon_status = {}
        for command in self.GetCommands():
            self.icon_status[command] = True

    def GetCommands(self):
        return (
            "OSAFE_wireframe_views",
            "OSAFE_view_basefoundation",
            "OSAFE_view_columns",
            "OSAFE_view_beams",
            "OSAFE_view_slabs",
            "OSAFE_view_foundations",
            "OSAFE_view_design_layer_a",
            "OSAFE_view_design_layer_b",
            "OSAFE_view_punch",
            "OSAFE_view_arch_wall",
        )  # a tuple of command names that you want to group

    def Activated(self, index):
        command = self.GetCommands()[index]
        self.icon_status[command] = not self.icon_status[command]
        wireframe = self.icon_status["OSAFE_wireframe_views"]
        show_base_foundation = self.icon_status["OSAFE_view_basefoundation"]
        show_column = self.icon_status["OSAFE_view_columns"]
        show_beam = self.icon_status["OSAFE_view_beams"]
        show_slab = self.icon_status["OSAFE_view_slabs"]
        show_foundation = self.icon_status["OSAFE_view_foundations"]
        show_design_layer_a = self.icon_status["OSAFE_view_design_layer_a"]
        show_design_layer_b = self.icon_status["OSAFE_view_design_layer_b"]
        show_punch = self.icon_status["OSAFE_view_punch"]
        show_arch_wall = self.icon_status["OSAFE_view_arch_wall"]
I guess you have a Workbench class. Re-implement the Activated() and Deactivated() functions where you restore and save the current status of the buttons, e.g. in a suitable parameter group.
I will examine this if I understand you!
Post Reply