How to remove "Set colors" from Part::FeaturePython object context menu?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

How to remove "Set colors" from Part::FeaturePython object context menu?

Post by Roy_043 »

In the Draft Workbench we have a Hatch object that is derived from a Part::FeaturePython object. Since a Draft_Hatch can only contain edges, the "Set Colors" option in the Tree view context menu does not make sense. Is there a way to remove that option?

Code: Select all

obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "Hatch"
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How to remove "Set colors" from Part::FeaturePython object context menu?

Post by openBrain »

Will try to have a look but I'm not sure it's doable. ;)
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How to remove "Set colors" from Part::FeaturePython object context menu?

Post by openBrain »

Maybe found a solution using FC abilities.
See here : https://github.com/FreeCAD/FreeCAD/pull/7180

@Roy_043 The PR is draft now so you can test and see if it fits your needs.
If you want this PR to go in master, tell me and I'll release it.
If you want to integrate the modification in a bigger PR you have in preparation, tell me and I'll delete my own one. ;)
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: How to remove "Set colors" from Part::FeaturePython object context menu?

Post by Roy_043 »

Thank you very much. I would like to preserve the Transform option. In the code below I 'manually' add it again. Maybe there is a better way though?

openBrain wrote: Wed Jul 13, 2022 10:12 am If you want to integrate the modification in a bigger PR you have in preparation, tell me and I'll delete my own one
I have an existing PR (I would not call it big though) and I'll integrate your suggestion in that PR. Thanks again.

Code: Select all

    def setupContextMenu(self, vobj, menu):
        action1 = QtGui.QAction(Gui.getIcon("Std_TransformManip.svg"),
                                translate("Command", "Transform"), # Context `Command` instead of `draft`.
                                menu)
        QtCore.QObject.connect(action1,
                               QtCore.SIGNAL("triggered()"),
                               self.transform)
        menu.addAction(action1)

        return True # Removes `Transform` and `Set colors` from the default
                    # Part::FeaturePython context menu.

    def transform(self):
        Gui.runCommand("Std_TransformManip", 0)
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How to remove "Set colors" from Part::FeaturePython object context menu?

Post by openBrain »

Roy_043 wrote: Thu Jul 14, 2022 6:56 am Thank you very much. I would like to preserve the Transform option. In the code below I 'manually' add it again. Maybe there is a better way though?
I think that's the correct way. ;)
I have an existing PR (I would not call it big though) and I'll integrate your suggestion in that PR.
Great. I'll close my PR soon then.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: How to remove "Set colors" from Part::FeaturePython object context menu?

Post by Roy_043 »

Do you know why the first item in the context menu is bold? Should that item perhaps be the EditMode=0 command?
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How to remove "Set colors" from Part::FeaturePython object context menu?

Post by openBrain »

Roy_043 wrote: Fri Jul 15, 2022 10:32 am Do you know why the first item in the context menu is bold? Should that item perhaps be the EditMode=0 command?
Just a guess, but maybe it tries to denote action that is performed when object is double-clicked. ;)
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: How to remove "Set colors" from Part::FeaturePython object context menu?

Post by Roy_043 »

Well, that's not the case in the Draft Workbench then.
Post Reply