Gui: Provide ViewProviderFeaturePython selection callbacks

Adds support for Python-based selection callbacks to
`ViewProviderFeaturePython` objects.

It follows the same conventions as `SelectionObserverPython`, follows an
example:

```python
    def setPreselection(self, document, object, element):
        print("setPreselection: %s.%s.%s"%(document, object, element))

    def removePreselection(self, document, object, element):
print("removePreselection: %s.%s.%s"%(document, object,
element))

    def addSelection(self, document, object, element, position):
print("addSelection: %s.%s.%s at %s"%(document, object, element,
str(position)))

    def removeSelection(self,document, object, element):
        print("removeSelection: %s.%s.%s"%(document, object, element))

    def setSelection(self,doc):
        sel = FreeCADGui.Selection.getSelection(doc)
        print("setSelection: %s"%sel)

    def clearSelection(self,doc):
        print("clearSelection\n")
```
This commit is contained in:
tritao
2025-01-15 21:05:07 +00:00
parent 10ad4b7e15
commit ea80310642
6 changed files with 84 additions and 8 deletions

View File

@@ -36,7 +36,9 @@ class GuiExport SelectionObserverPythonHandler
public:
/// Constructor
explicit SelectionObserverPythonHandler() = default;
void init(const Py::Object& obj);
virtual ~SelectionObserverPythonHandler();
void init(PyObject* obj);
void handleSelectionChanged(const SelectionChanges& msg);
protected:
@@ -48,10 +50,10 @@ protected:
void removePreselection(const SelectionChanges&);
void pickedListChanged();
Py::Object inst;
private:
PyObject* inst{nullptr};
#define FC_PY_SEL_OBSERVER \
FC_PY_ELEMENT(onSelectionChanged) \
FC_PY_ELEMENT(addSelection) \
@@ -89,6 +91,7 @@ public:
private:
void onSelectionChanged(const SelectionChanges& msg) override;
Py::Object inst;
static std::vector<SelectionObserverPython*> _instances;
};