99
1010#define sw_window StaticCastSharedRef<SWindow>(self->s_compound_widget.s_widget.s_widget)
1111
12- static PyObject *py_ue_swindow_set_title (ue_PySWindow *self, PyObject * args) {
12+ static PyObject *py_ue_swindow_set_title (ue_PySWindow *self, PyObject * args)
13+ {
1314 char *title;
14- if (!PyArg_ParseTuple (args, " s:set_title" , &title)) {
15+ if (!PyArg_ParseTuple (args, " s:set_title" , &title))
16+ {
1517 return NULL ;
1618 }
1719
@@ -21,10 +23,12 @@ static PyObject *py_ue_swindow_set_title(ue_PySWindow *self, PyObject * args) {
2123 return (PyObject *)self;
2224}
2325
24- static PyObject *py_ue_swindow_resize (ue_PySWindow *self, PyObject * args) {
26+ static PyObject *py_ue_swindow_resize (ue_PySWindow *self, PyObject * args)
27+ {
2528 int width;
2629 int height;
27- if (!PyArg_ParseTuple (args, " ii:resize" , &width, &height)) {
30+ if (!PyArg_ParseTuple (args, " ii:resize" , &width, &height))
31+ {
2832 return NULL ;
2933 }
3034
@@ -35,14 +39,17 @@ static PyObject *py_ue_swindow_resize(ue_PySWindow *self, PyObject * args) {
3539 return (PyObject *)self;
3640}
3741
38- static PyObject *py_ue_swindow_set_content (ue_PySWindow *self, PyObject * args) {
42+ static PyObject *py_ue_swindow_set_content (ue_PySWindow *self, PyObject * args)
43+ {
3944 PyObject *py_content;
40- if (!PyArg_ParseTuple (args, " O:set_content" , &py_content)) {
45+ if (!PyArg_ParseTuple (args, " O:set_content" , &py_content))
46+ {
4147 return NULL ;
4248 }
4349
4450 ue_PySWidget *py_swidget = py_ue_is_swidget (py_content);
45- if (!py_swidget) {
51+ if (!py_swidget)
52+ {
4653 return PyErr_Format (PyExc_Exception, " argument is not a SWidget" );
4754 }
4855
@@ -56,9 +63,11 @@ static PyObject *py_ue_swindow_set_content(ue_PySWindow *self, PyObject * args)
5663 return (PyObject *)self;
5764}
5865
59- static PyObject *py_ue_swindow_set_sizing_rule (ue_PySWindow *self, PyObject * args) {
66+ static PyObject *py_ue_swindow_set_sizing_rule (ue_PySWindow *self, PyObject * args)
67+ {
6068 int rule;
61- if (!PyArg_ParseTuple (args, " i:set_sizing_rule" , &rule)) {
69+ if (!PyArg_ParseTuple (args, " i:set_sizing_rule" , &rule))
70+ {
6271 return NULL ;
6372 }
6473
@@ -73,21 +82,25 @@ static PyObject *py_ue_swindow_set_sizing_rule(ue_PySWindow *self, PyObject * ar
7382 return (PyObject *)self;
7483}
7584
76- static PyObject *py_ue_swindow_get_handle (ue_PySWindow *self, PyObject * args) {
85+ static PyObject *py_ue_swindow_get_handle (ue_PySWindow *self, PyObject * args)
86+ {
7787 return PyLong_FromLongLong ((long long )sw_window->GetNativeWindow ()->GetOSWindowHandle ());
7888}
7989
80- static PyObject *py_ue_swindow_request_destroy (ue_PySWindow *self, PyObject * args) {
90+ static PyObject *py_ue_swindow_request_destroy (ue_PySWindow *self, PyObject * args)
91+ {
8192
8293 sw_window->RequestDestroyWindow ();
8394
8495 Py_RETURN_NONE;
8596}
8697
8798#if WITH_EDITOR
88- static PyObject *py_ue_swindow_add_modal (ue_PySWindow *self, PyObject * args) {
99+ static PyObject *py_ue_swindow_add_modal (ue_PySWindow *self, PyObject * args)
100+ {
89101 TSharedPtr<SWindow> parent_window;
90- if (FModuleManager::Get ().IsModuleLoaded (" MainFrame" )) {
102+ if (FModuleManager::Get ().IsModuleLoaded (" MainFrame" ))
103+ {
91104 parent_window = FModuleManager::LoadModuleChecked<IMainFrameModule>(" MainFrame" ).GetParentWindow ();
92105 }
93106 FSlateApplication::Get ().AddModalWindow (StaticCastSharedRef<SWindow>(sw_window->AsShared ()), parent_window, false );
@@ -140,7 +153,8 @@ PyTypeObject ue_PySWindowType = {
140153 ue_PySWindow_methods, /* tp_methods */
141154};
142155
143- static int ue_py_swindow_init (ue_PySWindow *self, PyObject *args, PyObject *kwargs) {
156+ static int ue_py_swindow_init (ue_PySWindow *self, PyObject *args, PyObject *kwargs)
157+ {
144158
145159 ue_py_slate_setup_farguments (SWindow);
146160#if ENGINE_MINOR_VERSION > 15
@@ -190,17 +204,31 @@ static int ue_py_swindow_init(ue_PySWindow *self, PyObject *args, PyObject *kwar
190204#if WITH_EDITOR
191205 // is it a modal window ?
192206 PyObject *is_modal = ue_py_dict_get_item (kwargs, " modal" );
193- if (is_modal && PyObject_IsTrue (is_modal)) {
207+ if (is_modal && PyObject_IsTrue (is_modal))
208+ {
194209 return 0 ;
195210 }
196211#endif
197212
213+ PyObject *on_closed = ue_py_dict_get_item (kwargs, " on_closed" );
214+ if (on_closed && PyCallable_Check (on_closed))
215+ {
216+ FOnWindowClosed handler;
217+ UPythonSlateDelegate *py_delegate = NewObject<UPythonSlateDelegate>();
218+ py_delegate->SetPyCallable (on_closed);
219+ py_delegate->AddToRoot ();
220+ handler.BindUObject (py_delegate, &UPythonSlateDelegate::OnWindowClosed);
221+
222+ sw_window->SetOnWindowClosed (handler);
223+ }
224+
198225 FSlateApplication::Get ().AddWindow (StaticCastSharedRef<SWindow>(sw_window->AsShared ()), true );
199226
200227 return 0 ;
201228}
202229
203- void ue_python_init_swindow (PyObject *ue_module) {
230+ void ue_python_init_swindow (PyObject *ue_module)
231+ {
204232
205233 ue_PySWindowType.tp_init = (initproc)ue_py_swindow_init;
206234 ue_PySWindowType.tp_call = (ternaryfunc)py_ue_swindow_set_content;
0 commit comments