Skip to content

Commit 05c8549

Browse files
author
Roberto De Ioris
committed
added slate assign() hack
1 parent cedc582 commit 05c8549

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Source/UnrealEnginePython/Private/Slate/UEPySWidget.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,34 @@ static PyObject *py_ue_swidget_new_ref(ue_PySWidget *self, PyObject * args)
323323
return (PyObject *)py_ue_new_swidget<ue_PySWidget>(Widget.ToSharedRef(), &ue_PySWidgetType);
324324
}
325325

326+
static PyObject *py_ue_swidget_assign(ue_PySWidget *self, PyObject * args)
327+
{
328+
char *global_name;
329+
if (!PyArg_ParseTuple(args, "s:assign", &global_name))
330+
{
331+
return nullptr;
332+
}
333+
334+
PyObject *py_globals = PyEval_GetGlobals();
335+
if (!py_globals)
336+
{
337+
return PyErr_Format(PyExc_Exception, "unable to retrieve globals");
338+
}
339+
340+
if (!PyDict_GetItemString(py_globals, global_name))
341+
{
342+
PyErr_Clear();
343+
return PyErr_Format(PyExc_Exception, "global \"%s\" not found", global_name);
344+
}
345+
346+
if (PyDict_SetItemString(py_globals, global_name, (PyObject *)self) < 0)
347+
{
348+
return PyErr_Format(PyExc_Exception, "unable to assign global \"%s\" to SWidget", global_name);
349+
}
350+
351+
Py_RETURN_SLATE_SELF;
352+
}
353+
326354
static PyMethodDef ue_PySWidget_methods[] = {
327355
{ "new_ref", (PyCFunction)py_ue_swidget_new_ref, METH_VARARGS, "" },
328356
{ "get_shared_reference_count", (PyCFunction)py_ue_swidget_get_shared_reference_count, METH_VARARGS, "" },
@@ -344,6 +372,8 @@ static PyMethodDef ue_PySWidget_methods[] = {
344372
#endif
345373
{ "on_mouse_button_down", (PyCFunction)py_ue_swidget_on_mouse_button_down, METH_VARARGS, "" },
346374
{ "on_mouse_button_up", (PyCFunction)py_ue_swidget_on_mouse_button_up, METH_VARARGS, "" },
375+
376+
{ "assign", (PyCFunction)py_ue_swidget_assign, METH_VARARGS, "" },
347377
{ NULL } /* Sentinel */
348378
};
349379

9.98 KB
Loading

0 commit comments

Comments
 (0)