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:
@@ -32,15 +32,28 @@ using namespace Gui;
|
||||
|
||||
std::vector<SelectionObserverPython*> SelectionObserverPython::_instances;
|
||||
|
||||
void SelectionObserverPythonHandler::init(const Py::Object& obj)
|
||||
void SelectionObserverPythonHandler::init(PyObject* obj)
|
||||
{
|
||||
this->inst = obj;
|
||||
|
||||
#undef FC_PY_ELEMENT
|
||||
#define FC_PY_ELEMENT(_name) FC_PY_GetCallable(obj.ptr(),#_name,py_##_name);
|
||||
#define FC_PY_ELEMENT(_name) FC_PY_GetCallable(obj,#_name,py_##_name);
|
||||
FC_PY_SEL_OBSERVER
|
||||
}
|
||||
|
||||
SelectionObserverPythonHandler::~SelectionObserverPythonHandler()
|
||||
{
|
||||
#undef FC_PY_ELEMENT
|
||||
#define FC_PY_ELEMENT(_name) py_##_name = Py::None();
|
||||
|
||||
try {
|
||||
FC_PY_SEL_OBSERVER
|
||||
}
|
||||
catch (Py::Exception& e) {
|
||||
e.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void SelectionObserverPythonHandler::handleSelectionChanged(const SelectionChanges& msg)
|
||||
{
|
||||
switch (msg.Type)
|
||||
@@ -198,7 +211,7 @@ void SelectionObserverPythonHandler::removePreselection(const SelectionChanges&
|
||||
SelectionObserverPython::SelectionObserverPython(const Py::Object& obj, ResolveMode resolve)
|
||||
: SelectionObserver(true, resolve)
|
||||
{
|
||||
this->init(obj);
|
||||
this->init(obj.ptr());
|
||||
}
|
||||
|
||||
SelectionObserverPython::~SelectionObserverPython() = default;
|
||||
|
||||
Reference in New Issue
Block a user