|
1 | 1 |
|
2 | 2 | #include "UnrealEnginePythonPrivatePCH.h" |
3 | 3 |
|
| 4 | +#if WITH_EDITOR |
| 5 | +#include "Editor/MainFrame/Public/Interfaces/IMainFrameModule.h" |
| 6 | +#endif |
| 7 | + |
4 | 8 | #include "UEPySWindow.h" |
5 | 9 |
|
6 | 10 | #define sw_window StaticCastSharedRef<SWindow>(self->s_compound_widget.s_widget.s_widget) |
@@ -41,7 +45,7 @@ static PyObject *py_ue_swindow_set_content(ue_PySWindow *self, PyObject * args) |
41 | 45 | if (!py_swidget) { |
42 | 46 | return PyErr_Format(PyExc_Exception, "argument is not a SWidget"); |
43 | 47 | } |
44 | | - |
| 48 | + |
45 | 49 | Py_XDECREF(self->s_compound_widget.s_widget.py_swidget_content); |
46 | 50 | Py_INCREF(py_swidget); |
47 | 51 | self->s_compound_widget.s_widget.py_swidget_content = py_swidget; |
@@ -73,13 +77,35 @@ static PyObject *py_ue_swindow_get_handle(ue_PySWindow *self, PyObject * args) { |
73 | 77 | return PyLong_FromLongLong((long long)sw_window->GetNativeWindow()->GetOSWindowHandle()); |
74 | 78 | } |
75 | 79 |
|
| 80 | +static PyObject *py_ue_swindow_request_destroy(ue_PySWindow *self, PyObject * args) { |
| 81 | + |
| 82 | + sw_window->RequestDestroyWindow(); |
| 83 | + |
| 84 | + Py_RETURN_NONE; |
| 85 | +} |
| 86 | + |
| 87 | +#if WITH_EDITOR |
| 88 | +static PyObject *py_ue_swindow_add_modal(ue_PySWindow *self, PyObject * args) { |
| 89 | + TSharedPtr<SWindow> parent_window; |
| 90 | + if (FModuleManager::Get().IsModuleLoaded("MainFrame")) { |
| 91 | + parent_window = FModuleManager::LoadModuleChecked<IMainFrameModule>("MainFrame").GetParentWindow(); |
| 92 | + } |
| 93 | + FSlateApplication::Get().AddModalWindow(StaticCastSharedRef<SWindow>(sw_window->AsShared()), parent_window, false); |
| 94 | + Py_RETURN_NONE; |
| 95 | +} |
| 96 | +#endif |
| 97 | + |
76 | 98 | static PyMethodDef ue_PySWindow_methods[] = { |
77 | 99 | { "set_title", (PyCFunction)py_ue_swindow_set_title, METH_VARARGS, "" }, |
78 | 100 | { "set_sizing_rule", (PyCFunction)py_ue_swindow_set_sizing_rule, METH_VARARGS, "" }, |
79 | 101 | { "resize", (PyCFunction)py_ue_swindow_resize, METH_VARARGS, "" }, |
80 | 102 | { "set_client_size", (PyCFunction)py_ue_swindow_resize, METH_VARARGS, "" }, |
81 | 103 | { "set_content", (PyCFunction)py_ue_swindow_set_content, METH_VARARGS, "" }, |
82 | 104 | { "get_handle", (PyCFunction)py_ue_swindow_get_handle, METH_VARARGS, "" }, |
| 105 | + { "request_destroy", (PyCFunction)py_ue_swindow_request_destroy, METH_VARARGS, "" }, |
| 106 | +#if WITH_EDITOR |
| 107 | + { "add_modal", (PyCFunction)py_ue_swindow_add_modal, METH_VARARGS, "" }, |
| 108 | +#endif |
83 | 109 | { NULL } /* Sentinel */ |
84 | 110 | }; |
85 | 111 |
|
@@ -115,7 +141,7 @@ PyTypeObject ue_PySWindowType = { |
115 | 141 | }; |
116 | 142 |
|
117 | 143 | static int ue_py_swindow_init(ue_PySWindow *self, PyObject *args, PyObject *kwargs) { |
118 | | - |
| 144 | + |
119 | 145 | ue_py_slate_setup_farguments(SWindow); |
120 | 146 |
|
121 | 147 | ue_py_slate_farguments_optional_bool("activate_when_first_shown", ActivateWhenFirstShown); |
@@ -158,6 +184,14 @@ static int ue_py_swindow_init(ue_PySWindow *self, PyObject *args, PyObject *kwar |
158 | 184 |
|
159 | 185 | ue_py_snew(SWindow, s_compound_widget.s_widget); |
160 | 186 |
|
| 187 | +#if WITH_EDITOR |
| 188 | + // is it a modal window ? |
| 189 | + PyObject *is_modal = ue_py_dict_get_item(kwargs, "modal"); |
| 190 | + if (is_modal && PyObject_IsTrue(is_modal)) { |
| 191 | + return 0; |
| 192 | + } |
| 193 | +#endif |
| 194 | + |
161 | 195 | FSlateApplication::Get().AddWindow(StaticCastSharedRef<SWindow>(sw_window->AsShared()), true); |
162 | 196 |
|
163 | 197 | return 0; |
|
0 commit comments