Skip to content

Commit 0f2979d

Browse files
author
ikrima
committed
Add add_child window functionality
1 parent 23467ec commit 0f2979d

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

Source/UnrealEnginePython/Private/Slate/UEPySPythonMultiColumnTableRow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#define sw_python_multicolumn_table_row StaticCastSharedRef<SPythonMultiColumnTableRow>(self->s_compound_widget.s_widget.s_widget)
88

9-
static PyMethodDef ue_PySPythonListView_methods[] = {
9+
static PyMethodDef ue_PySPythonMultiColumnTableRow_methods[] = {
1010
{ NULL } /* Sentinel */
1111
};
1212

@@ -38,7 +38,7 @@ PyTypeObject ue_PySPythonMultiColumnTableRowType = {
3838
0, /* tp_weaklistoffset */
3939
0, /* tp_iter */
4040
0, /* tp_iternext */
41-
ue_PySPythonListView_methods, /* tp_methods */
41+
ue_PySPythonMultiColumnTableRow_methods, /* tp_methods */
4242
};
4343

4444
static int ue_py_spython_multicolumn_table_row_init(ue_PySPythonMultiColumnTableRow *self, PyObject *args, PyObject *kwargs) {

Source/UnrealEnginePython/Private/Slate/UEPySWindow.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,27 @@ static PyObject *py_ue_swindow_add_modal(ue_PySWindow *self, PyObject * args)
108108
}
109109
#endif
110110

111+
static PyObject *py_ue_swindow_add_child(ue_PySWindow *self, PyObject * args)
112+
{
113+
PyObject *py_obj;
114+
if (!PyArg_ParseTuple(args, "O:add_child", &py_obj))
115+
{
116+
return NULL;
117+
}
118+
119+
ue_PySWindow *py_swindow_child = py_ue_is_swindow(py_obj);
120+
if (!py_swindow_child)
121+
{
122+
return PyErr_Format(PyExc_Exception, "argument is not a SWindow");
123+
}
124+
125+
FSlateApplication::Get().AddWindowAsNativeChild(
126+
StaticCastSharedRef<SWindow>(py_swindow_child->s_compound_widget.s_widget.s_widget),
127+
sw_window);
128+
129+
Py_RETURN_NONE;
130+
}
131+
111132
static PyMethodDef ue_PySWindow_methods[] = {
112133
{ "set_title", (PyCFunction)py_ue_swindow_set_title, METH_VARARGS, "" },
113134
{ "set_sizing_rule", (PyCFunction)py_ue_swindow_set_sizing_rule, METH_VARARGS, "" },
@@ -119,6 +140,7 @@ static PyMethodDef ue_PySWindow_methods[] = {
119140
#if WITH_EDITOR
120141
{ "add_modal", (PyCFunction)py_ue_swindow_add_modal, METH_VARARGS, "" },
121142
#endif
143+
{ "add_child", (PyCFunction)py_ue_swindow_add_child, METH_VARARGS, "" },
122144
{ NULL } /* Sentinel */
123145
};
124146

@@ -222,7 +244,12 @@ static int ue_py_swindow_init(ue_PySWindow *self, PyObject *args, PyObject *kwar
222244
sw_window->SetOnWindowClosed(handler);
223245
}
224246

225-
FSlateApplication::Get().AddWindow(StaticCastSharedRef<SWindow>(sw_window->AsShared()), true);
247+
// is it a child ?
248+
PyObject *is_child = ue_py_dict_get_item(kwargs, "child");
249+
if (!(is_child && PyObject_IsTrue(is_child)))
250+
{
251+
FSlateApplication::Get().AddWindow(StaticCastSharedRef<SWindow>(sw_window->AsShared()), true);
252+
}
226253

227254
return 0;
228255
}
@@ -241,3 +268,10 @@ void ue_python_init_swindow(PyObject *ue_module)
241268
Py_INCREF(&ue_PySWindowType);
242269
PyModule_AddObject(ue_module, "SWindow", (PyObject *)&ue_PySWindowType);
243270
}
271+
272+
ue_PySWindow *py_ue_is_swindow(PyObject *obj)
273+
{
274+
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PySWindowType))
275+
return nullptr;
276+
return (ue_PySWindow *)obj;
277+
}

Source/UnrealEnginePython/Private/Slate/UEPySWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ typedef struct {
1414
} ue_PySWindow;
1515

1616
void ue_python_init_swindow(PyObject *);
17+
18+
ue_PySWindow *py_ue_is_swindow(PyObject *obj);

UnrealEnginePython.uplugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"Modules": [
1818
{
1919
"Name": "UnrealEnginePython",
20-
"Type": "Runtime",
20+
"Type": "Developer",
2121
"LoadingPhase": "Default"
2222
},
2323
{

0 commit comments

Comments
 (0)