I am confused about the required return values of setEdit and unsetEdit.
See my comment here:
https://github.com/FreeCAD/FreeCAD/comm ... t-77851915
Return for setEdit:
True or None?
Return for unsetEdit:
Always False?
What are the required return values of setEdit and unsetEdit?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
- adrianinsaval
- Veteran
- Posts: 5548
- Joined: Thu Apr 05, 2018 5:15 pm
Re: What are the required return values of setEdit and unsetEdit?
The comment here:
https://github.com/FreeCAD/FreeCAD/blob ... se.py#L436
makes me believe returning false makes the base class manage the process of unsetting edit mode and returning true should then mean that it has been managed and no further actions are needed. Would be best to have this confirmed by some dev.
https://github.com/FreeCAD/FreeCAD/blob ... se.py#L436
makes me believe returning false makes the base class manage the process of unsetting edit mode and returning true should then mean that it has been managed and no further actions are needed. Would be best to have this confirmed by some dev.
Re: What are the required return values of setEdit and unsetEdit?
Thanks. But AFAICT this is handled inconsistently in the Draft code, but also in the code of other Python workbenches. And if setEdit returns True for mode=0, wouldn't it then make sense that unsetEdit returns True in that case as well?
- adrianinsaval
- Veteran
- Posts: 5548
- Joined: Thu Apr 05, 2018 5:15 pm
Re: What are the required return values of setEdit and unsetEdit?
I think it depends, if you close the dialog and whatever else needed when calling unsetedit with mode == 0 then you pass true, but if the command is generic enough that it can be handled by a generic unsetedit isn't it best to avoid code duplication and just pass false and let the generic one do it? It's not clear to me what unsetedit would be called if you return false in shapestring so I don't know what return value is better. The hierarchies hurt my brain
Re: What are the required return values of setEdit and unsetEdit?
@openBrain Can you help with this question?
Re: What are the required return values of setEdit and unsetEdit?
With a mobile now so not much detail, but according code in 'ViewProviderFeaturePython.cpp', I'd say return :
* 'None' if there is no specific implementation for your object
* 'True' if you were called with a mode that you can deal with
* 'False' if you were called with a mode that you don't deal with
* 'None' if there is no specific implementation for your object
* 'True' if you were called with a mode that you can deal with
* 'False' if you were called with a mode that you don't deal with
Re: What are the required return values of setEdit and unsetEdit?
To answer this question it's best to have a look at the C++ interface: https://github.com/FreeCAD/FreeCAD/blob ... der.h#L431
As you can see for setEdit() the returned type is a boolean for unsetEdit() it's void (i.e. None in Python).
For Python view providers a further option is possible:
https://github.com/FreeCAD/FreeCAD/blob ... ture.h#L43
https://github.com/FreeCAD/FreeCAD/blob ... ure.h#L522
This means a Python view provider can throw a NotImplemented exception to indicate the system to call the implementation of the C++ base class.
As you can see for setEdit() the returned type is a boolean for unsetEdit() it's void (i.e. None in Python).
For Python view providers a further option is possible:
https://github.com/FreeCAD/FreeCAD/blob ... ture.h#L43
https://github.com/FreeCAD/FreeCAD/blob ... ure.h#L522
This means a Python view provider can throw a NotImplemented exception to indicate the system to call the implementation of the C++ base class.
So, it's True, False or throwing a NotImplemented exception. Returning None is considered as False.Return for setEdit:
True or None?
It's None or throwing a NotImplemented exception. Other values are possible too but they are not considered by the system.Return for unsetEdit:
Always False?
Re: What are the required return values of setEdit and unsetEdit?
This is not my experience (which matches the info in openBrain's post). Only returning None is interpreted as 'not handled'. Returning 0 is not. And returning None is not the same as returning False. But maybe we are talking about different objects and there are some inconsistencies in how they are handled?
Related PR:
https://github.com/FreeCAD/FreeCAD/pull/7174
OpenBrain is probably referring to:
https://github.com/FreeCAD/FreeCAD/blob ... #L350-L388
Re: What are the required return values of setEdit and unsetEdit?
Exactly. That was what I looked at for my above reply.Roy_043 wrote: ↑Fri Jul 29, 2022 5:54 pm OpenBrain is probably referring to:
https://github.com/FreeCAD/FreeCAD/blob ... #L350-L388