Skip to content

Commit

Permalink
GuiApp: create guiapp.copySelectedNodes( optional group) python funct…
Browse files Browse the repository at this point in the history
…ion (#675)

* create guiapp.copySelectedNodes( optional group) python function

This function allows to copy nodes even when multiple node graphs are opened. App1 should be passed as argument to make sure the copy is made from  the top level of the comp and not from the last active window
  • Loading branch information
bonalex01dev authored Oct 6, 2021
1 parent 0277bee commit 7629a47
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
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

0 comments on commit 7629a47

Please sign in to comment.