Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create guiapp.copySelectedNodes( optional group) python function #675

Merged
merged 5 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Gui/NatronGui/guiapp_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,77 @@ static PyObject* Sbk_GuiAppFunc_selectAllNodes(PyObject* self, PyObject* args, P
return 0;
}

static PyObject* Sbk_GuiAppFunc_copySelectedNodes(PyObject* self, PyObject* args, PyObject* kwds)
{
::GuiApp* cppSelf = 0;
SBK_UNUSED(cppSelf)
if (!Shiboken::Object::isValid(self))
return 0;
cppSelf = ((::GuiApp*)Shiboken::Conversions::cppPointer(SbkNatronGuiTypes[SBK_GUIAPP_IDX], (SbkObject*)self));
int overloadId = -1;
PythonToCppFunc pythonToCpp[] = { 0 };
SBK_UNUSED(pythonToCpp)
int numNamedArgs = (kwds ? PyDict_Size(kwds) : 0);
int numArgs = PyTuple_GET_SIZE(args);
PyObject* pyArgs[] = {0};

// invalid argument lengths
if (numArgs + numNamedArgs > 1) {
PyErr_SetString(PyExc_TypeError, "NatronGui.GuiApp.copySelectedNodes(): too many arguments");
return 0;
}

if (!PyArg_ParseTuple(args, "|O:copySelectedNodes", &(pyArgs[0])))
return 0;


// Overloaded function decisor
// 0: copySelectedNodes(Group*)
if (numArgs == 0) {
overloadId = 0; // copySelectedNodes(Group*)
} else if ((pythonToCpp[0] = Shiboken::Conversions::isPythonToCppPointerConvertible((SbkObjectType*)SbkNatronEngineTypes[SBK_GROUP_IDX], (pyArgs[0])))) {
overloadId = 0; // copySelectedNodes(Group*)
}

// Function signature not found.
if (overloadId == -1) goto Sbk_GuiAppFunc_copySelectedNodes_TypeError;

// Call function/method
{
if (kwds) {
PyObject* value = PyDict_GetItemString(kwds, "group");
if (value && pyArgs[0]) {
PyErr_SetString(PyExc_TypeError, "NatronGui.GuiApp.copySelectedNodes(): got multiple values for keyword argument 'group'.");
return 0;
} else if (value) {
pyArgs[0] = value;
if (!(pythonToCpp[0] = Shiboken::Conversions::isPythonToCppPointerConvertible((SbkObjectType*)SbkNatronEngineTypes[SBK_GROUP_IDX], (pyArgs[0]))))
goto Sbk_GuiAppFunc_copySelectedNodes_TypeError;
}
}
if (!Shiboken::Object::isValid(pyArgs[0]))
return 0;
::Group* cppArg0 = 0;
if (pythonToCpp[0]) pythonToCpp[0](pyArgs[0], &cppArg0);

if (!PyErr_Occurred()) {
// copySelectedNodes(Group*)
cppSelf->copySelectedNodes(cppArg0);
}
}

if (PyErr_Occurred()) {
return 0;
}
Py_RETURN_NONE;

Sbk_GuiAppFunc_copySelectedNodes_TypeError:
const char* overloads[] = {"NatronEngine.Group = None", 0};
Shiboken::setErrorAboutWrongArguments(args, "NatronGui.GuiApp.copySelectedNodes", overloads);
return 0;
}


static PyObject* Sbk_GuiAppFunc_selectNode(PyObject* self, PyObject* args)
{
::GuiApp* cppSelf = 0;
Expand Down Expand Up @@ -1380,6 +1451,7 @@ static PyMethodDef Sbk_GuiApp_methods[] = {
{"saveFilenameDialog", (PyCFunction)Sbk_GuiAppFunc_saveFilenameDialog, METH_VARARGS|METH_KEYWORDS},
{"saveSequenceDialog", (PyCFunction)Sbk_GuiAppFunc_saveSequenceDialog, METH_VARARGS|METH_KEYWORDS},
{"selectAllNodes", (PyCFunction)Sbk_GuiAppFunc_selectAllNodes, METH_VARARGS|METH_KEYWORDS},
{"copySelectedNodes", (PyCFunction)Sbk_GuiAppFunc_copySelectedNodes, METH_VARARGS|METH_KEYWORDS},
{"selectNode", (PyCFunction)Sbk_GuiAppFunc_selectNode, METH_VARARGS},
{"setSelection", (PyCFunction)Sbk_GuiAppFunc_setSelection, METH_O},
{"unregisterPythonPanel", (PyCFunction)Sbk_GuiAppFunc_unregisterPythonPanel, METH_O},
Expand Down
31 changes: 30 additions & 1 deletion Gui/PyGuiApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,35 @@ GuiApp::selectAllNodes(Group* group)
graph->selectAllNodes(false);
}


void
GuiApp::copySelectedNodes(Group* group)
{
if ( appPTR->isBackground() ) {
return;
}
NodeGraph* graph = 0;
NodeCollectionPtr collection;
NodeGroup* isGroup = 0;
if (group) {
collection = group->getInternalCollection();
if (collection) {
isGroup = dynamic_cast<NodeGroup*>( collection.get() );
if (isGroup) {
graph = dynamic_cast<NodeGraph*>( isGroup->getNodeGraph() );
}
}
}
if (!graph) {
graph = getInternalGuiApp()->getGui()->getNodeGraph();
}
assert(graph);
if (!graph) {
throw std::logic_error("invalid ggraph");
}
graph->copySelectedNodes();
}

void
GuiApp::deselectNode(Effect* effect)
{
Expand All @@ -449,7 +478,7 @@ GuiApp::deselectNode(Effect* effect)
}
assert(graph);
if (!graph) {
throw std::logic_error("");
throw std::logic_error("invalid graph");
}
graph->deselectNode(nodeUi);
}
Expand Down
1 change: 1 addition & 0 deletions Gui/PyGuiApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class GuiApp
void selectNode(Effect* effect, bool clearPreviousSelection);
void setSelection(const std::list<Effect*>& nodes);
void selectAllNodes(Group* group = 0);
void copySelectedNodes(Group* group = 0);
void deselectNode(Effect* effect);
void clearSelection(Group* group = 0);

Expand Down