Skip to content

Commit 2393013

Browse files
author
Roberto De Ioris
committed
added on_main_frame_creation_finished() hook
1 parent 0fbead0 commit 2393013

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

Source/UnrealEnginePython/Private/PythonSmartDelegate.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
#include "UEPyModule.h"
55

6+
#if WITH_EDITOR
7+
#include "Slate/UEPySWindow.h"
8+
#endif
9+
610
FPythonSmartDelegate::FPythonSmartDelegate()
711
{
812
py_callable = nullptr;
@@ -59,6 +63,19 @@ void FPythonSmartDelegate::PyFOnAssetPostImport(UFactory *factory, UObject *u_ob
5963
}
6064
Py_DECREF(ret);
6165

66+
}
67+
68+
void FPythonSmartDelegate::PyFOnMainFrameCreationFinished(TSharedPtr<SWindow> InRootWindow, bool bIsNewProjectWindow)
69+
{
70+
FScopePythonGIL gil;
71+
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"OO", py_ue_new_swidget<ue_PySWindow>(InRootWindow.ToSharedRef(), &ue_PySWindowType), bIsNewProjectWindow ? Py_True : Py_False);
72+
if (!ret)
73+
{
74+
unreal_engine_py_log_error();
75+
return;
76+
}
77+
Py_DECREF(ret);
78+
6279
}
6380
#endif
6481

Source/UnrealEnginePython/Private/UEPyEditor.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "Wrappers/UEPyFAssetData.h"
3535
#include "Wrappers/UEPyFEditorViewportClient.h"
3636
#include "Wrappers/UEPyIAssetEditorInstance.h"
37+
#include "Editor/MainFrame/Public/Interfaces/IMainFrameModule.h"
3738

3839
#include "UEPyIPlugin.h"
3940

@@ -1753,9 +1754,29 @@ PyObject *py_unreal_engine_editor_on_asset_post_import(PyObject * self, PyObject
17531754
if (!PyCallable_Check(py_callable))
17541755
return PyErr_Format(PyExc_Exception, "object is not a callable");
17551756

1756-
TSharedRef<FPythonSmartDelegate> py_delegate = MakeShareable(new FPythonSmartDelegate);
1757+
// will brutally leak
1758+
FPythonSmartDelegate *py_delegate = new FPythonSmartDelegate();
17571759
py_delegate->SetPyCallable(py_callable);
1758-
FEditorDelegates::OnAssetPostImport.AddSP(py_delegate, &FPythonSmartDelegate::PyFOnAssetPostImport);
1760+
FEditorDelegates::OnAssetPostImport.AddRaw(py_delegate, &FPythonSmartDelegate::PyFOnAssetPostImport);
1761+
Py_RETURN_NONE;
1762+
}
1763+
1764+
PyObject *py_unreal_engine_on_main_frame_creation_finished(PyObject * self, PyObject * args)
1765+
{
1766+
PyObject *py_callable;
1767+
if (!PyArg_ParseTuple(args, "O:on_main_frame_creation_finished", &py_callable))
1768+
{
1769+
return NULL;
1770+
}
1771+
1772+
if (!PyCallable_Check(py_callable))
1773+
return PyErr_Format(PyExc_Exception, "object is not a callable");
1774+
1775+
// will brutally leak
1776+
FPythonSmartDelegate *py_delegate = new FPythonSmartDelegate();
1777+
py_delegate->SetPyCallable(py_callable);
1778+
IMainFrameModule& MainFrameModule = FModuleManager::LoadModuleChecked<IMainFrameModule>(TEXT("MainFrame"));
1779+
MainFrameModule.OnMainFrameCreationFinished().AddRaw(py_delegate, &FPythonSmartDelegate::PyFOnMainFrameCreationFinished);
17591780
Py_RETURN_NONE;
17601781
}
17611782

@@ -1929,7 +1950,7 @@ PyObject *py_unreal_engine_add_level_to_world(PyObject *self, PyObject * args)
19291950
if (py_bool && PyObject_IsTrue(py_bool))
19301951
{
19311952
streaming_mode_class = ULevelStreamingAlwaysLoaded::StaticClass();
1932-
}
1953+
}
19331954

19341955
#if ENGINE_MINOR_VERSION >= 17
19351956
ULevelStreaming *level_streaming = EditorLevelUtils::AddLevelToWorld(u_world, UTF8_TO_TCHAR(name), streaming_mode_class);

Source/UnrealEnginePython/Private/UEPyEditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ PyObject *py_unreal_engine_get_blueprint_components(PyObject *, PyObject *);
5454

5555
PyObject *py_unreal_engine_editor_play(PyObject *, PyObject *);
5656
PyObject *py_unreal_engine_editor_on_asset_post_import(PyObject *, PyObject *);
57+
PyObject *py_unreal_engine_on_main_frame_creation_finished(PyObject *, PyObject *);
5758

5859
PyObject *py_unreal_engine_editor_command_build(PyObject *, PyObject *);
5960
PyObject *py_unreal_engine_editor_command_build_lighting(PyObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ static PyMethodDef unreal_engine_methods[] = {
363363
{ "move_actor_to_level", py_unreal_engine_move_actor_to_level, METH_VARARGS, "" },
364364

365365
{ "editor_on_asset_post_import", py_unreal_engine_editor_on_asset_post_import, METH_VARARGS, "" },
366+
{ "on_main_frame_creation_finished", py_unreal_engine_on_main_frame_creation_finished, METH_VARARGS, "" },
366367

367368

368369
// transactions

Source/UnrealEnginePython/Public/PythonSmartDelegate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class FPythonSmartDelegate : public TSharedFromThis<FPythonSmartDelegate>
2121

2222
#if WITH_EDITOR
2323
void PyFOnAssetPostImport(UFactory *factory, UObject *u_object);
24+
void PyFOnMainFrameCreationFinished(TSharedPtr<SWindow> InRootWindow, bool bIsNewProjectWindow);
2425
#endif
2526

2627
protected:

0 commit comments

Comments
 (0)