We have "slotDeletedObject", I need "slotBeforeDeleteObject"
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
We have "slotDeletedObject", I need "slotBeforeDeleteObject"
I can't figure out a way to trap prior to FreeCAD deleting the object on using the delete key. Using slotDeletedObject is after the event of deleting. I tried capturing the key press but that is also after the event. SlotBeforeChangeObject fires early but I don't know how to recognize if the action is a delete. It looks like I need "slotBeforeDeletedObject" and there is no such slot.
What I want: If the user presses the delete key I want to be able to code if they should under the current situation. I wouldn't have a problem with using clearSelection to stop the processes but I just don't know how to set the trap.
Thanks
What I want: If the user presses the delete key I want to be able to code if they should under the current situation. I wouldn't have a problem with using clearSelection to stop the processes but I just don't know how to set the trap.
Thanks
Re: We have "slotDeletedObject", I need "slotBeforeDeletedObject"
What kind of object?
Any object or specific ones of a document?
Is the slot the one of DocumentObserver (Gui or App?) or of DocumentObjectObserver?
Any object or specific ones of a document?
Is the slot the one of DocumentObserver (Gui or App?) or of DocumentObjectObserver?
Re: We have "slotDeletedObject", I need "slotBeforeDeleteObject"
Edit: I would want to allow other objs and some Bodies to be deleted so I do need to filter the object i.e. look for custom properties.What kind of object?
Any object or specific ones of a document?
Is the slot the one of DocumentObserver (Gui or App?) or of DocumentObjectObserver?
The object being deleted is a Body in PartDesign. The macro selects a Body (hightlighted in the tree and 3D), I want to be able to block if the user clicks delete.
Here are the last few lines of the macro:
Code: Select all
visCB = cbToolBox()
v = Gui.ActiveDocument.ActiveView
o = visCB.ViewObserver()
s = o.SelObserver()
FreeCADGui.Selection.addObserver(s)
do = visCB.DocObserver()
App.addDocumentObserver(do)
Re: We have "slotDeletedObject", I need "slotBeforeDeleteObject"
There is not an onDelete() method somewhere?
Regards.
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
-
- Posts: 614
- Joined: Wed Sep 29, 2021 8:35 am
Re: We have "slotDeletedObject", I need "slotBeforeDeleteObject"
I tried that first and it works .immediately issue an 'undo' action
I would be depending on the undo to work perfectly, could be issues with many depenencies and the Delete tears up the model.
Re: We have "slotDeletedObject", I need "slotBeforeDeleteObject"
If there is an onDelete property you could simply intercept his action and substitute his content with your desired action.
On Qt there is some examples of intercepting onClose() actionas example to avoid to close a dialog using the "small x" that many OS used to close a Window.
Same work if an object have the onDelete() you could not pass the action or emit a dialog to confirm, like "are you sure you want to delete me?".
More object oriented and robust than intercept keypress or Gui Commands.
But it depends on what the object is and if it have such s method. @wmayer?
Regards.
Carlo D.
Last edited by onekk on Tue Jun 06, 2023 6:47 am, edited 1 time in total.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: We have "slotDeletedObject", I need "slotBeforeDeleteObject"
Here is the code from the prior post, I can't get it to work. I get a no attribute "proxy". I tried this code without the proxy and the class fires once at startup but never again. I don't understand.
Code: Select all
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",partName)
class MyViewProviderProxy:
# print("1")
def onDelete(self, feature, subelements): # subelements is a tuple of strings
# print("2")
...
return True # If False is returned the object won't be deleted
obj.ViewObject.Proxy = MyViewProviderProxy()
Re: We have "slotDeletedObject", I need "slotBeforeDeleteObject"
As usual with partial code and too minimal code fragments is hard to tell and even experiment with code.
A little standalone script that load and executed will show the problem could be of some help.
Regards.
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/