Skip to content

Commit

Permalink
+ make Python API of Selection consistent to C++ API
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 18, 2015
1 parent 969b43b commit 5e48d2e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/Gui/Selection.cpp
Expand Up @@ -989,7 +989,9 @@ PyMethodDef SelectionSingleton::Methods[] = {
{"getSelection", (PyCFunction) SelectionSingleton::sGetSelection, 1,
"getSelection([string]) -- Return a list of selected objets\n"
"Return a list of selected objects for a given document name. If no\n"
"document is given the complete selection is returned."},
"document name is given the selection for the active document is returned."},
{"getCompleteSelection", (PyCFunction) SelectionSingleton::sGetCompleteSelection, 1,
"getCompleteSelection() -- Return a list of selected objects of all documents."},
{"getSelectionEx", (PyCFunction) SelectionSingleton::sGetSelectionEx, 1,
"getSelectionEx([string]) -- Return a list of SelectionObjects\n"
"Return a list of SelectionObjects for a given document name. If no\n"
Expand Down Expand Up @@ -1107,10 +1109,27 @@ PyObject *SelectionSingleton::sGetSelection(PyObject * /*self*/, PyObject *args,
return NULL; // NULL triggers exception

std::vector<SelectionSingleton::SelObj> sel;
if (documentName)
sel = Selection().getSelection(documentName);
else
sel = Selection().getCompleteSelection();
sel = Selection().getSelection(documentName);

try {
Py::List list;
for (std::vector<SelectionSingleton::SelObj>::iterator it = sel.begin(); it != sel.end(); ++it) {
list.append(Py::asObject(it->pObject->getPyObject()));
}
return Py::new_reference_to(list);
}
catch (Py::Exception&) {
return 0;
}
}

PyObject *SelectionSingleton::sGetCompleteSelection(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/)
{
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
return NULL; // NULL triggers exception

std::vector<SelectionSingleton::SelObj> sel;
sel = Selection().getCompleteSelection();

try {
Py::List list;
Expand Down
1 change: 1 addition & 0 deletions src/Gui/Selection.h
Expand Up @@ -311,6 +311,7 @@ class GuiExport SelectionSingleton : public Base::Subject<const SelectionChanges
static PyObject *sIsSelected (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject *sCountObjectsOfType (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject *sGetSelection (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject *sGetCompleteSelection(PyObject *self,PyObject *args,PyObject *kwd);
static PyObject *sGetSelectionEx (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject *sGetSelectionObject (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject *sAddSelObserver (PyObject *self,PyObject *args,PyObject *kwd);
Expand Down

0 comments on commit 5e48d2e

Please sign in to comment.