Skip to content

Commit 604b969

Browse files
author
Roberto De Ioris
committed
added IAssetEditorInstance wrapper
1 parent 76fd962 commit 604b969

File tree

5 files changed

+180
-10
lines changed

5 files changed

+180
-10
lines changed

Source/UnrealEnginePython/Private/UEPyEditor.cpp

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "Wrappers/UEPyFVector.h"
3434
#include "Wrappers/UEPyFAssetData.h"
3535
#include "Wrappers/UEPyFEditorViewportClient.h"
36+
#include "Wrappers/UEPyIAssetEditorInstance.h"
3637

3738
#include "UEPyIPlugin.h"
3839

@@ -997,25 +998,66 @@ PyObject *py_unreal_engine_get_selected_assets(PyObject * self, PyObject * args)
997998
return assets_list;
998999
}
9991000

1001+
PyObject *py_unreal_engine_get_all_edited_assets(PyObject * self, PyObject * args)
1002+
{
1003+
TArray<UObject *> assets = FAssetEditorManager::Get().GetAllEditedAssets();
1004+
PyObject *assets_list = PyList_New(0);
1005+
1006+
for (UObject *asset : assets)
1007+
{
1008+
ue_PyUObject *ret = ue_get_python_uobject(asset);
1009+
if (ret)
1010+
{
1011+
PyList_Append(assets_list, (PyObject *)ret);
1012+
}
1013+
}
1014+
1015+
return assets_list;
1016+
}
1017+
10001018
PyObject *py_unreal_engine_open_editor_for_asset(PyObject * self, PyObject * args)
10011019
{
10021020
PyObject *py_obj;
10031021

10041022
if (!PyArg_ParseTuple(args, "O:open_editor_for_asset", &py_obj))
10051023
{
1006-
return NULL;
1024+
return nullptr;
10071025
}
10081026

10091027
UObject *u_obj = ue_py_check_type<UObject>(py_obj);
10101028
if (!u_obj)
10111029
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
1030+
10121031
if (FAssetEditorManager::Get().OpenEditorForAsset(u_obj))
10131032
{
1014-
Py_INCREF(Py_True);
1015-
return Py_True;
1033+
Py_RETURN_TRUE;
10161034
}
1017-
Py_INCREF(Py_False);
1018-
return Py_False;
1035+
Py_RETURN_FALSE;
1036+
}
1037+
1038+
PyObject *py_unreal_engine_find_editor_for_asset(PyObject * self, PyObject * args)
1039+
{
1040+
PyObject *py_obj;
1041+
PyObject *py_bool = nullptr;
1042+
1043+
if (!PyArg_ParseTuple(args, "O|O:find_editor_for_asset", &py_obj, &py_bool))
1044+
{
1045+
return nullptr;
1046+
}
1047+
1048+
UObject *u_obj = ue_py_check_type<UObject>(py_obj);
1049+
if (!u_obj)
1050+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
1051+
1052+
bool bFocus = false;
1053+
if (py_bool && PyObject_IsTrue(py_bool))
1054+
bFocus = true;
1055+
1056+
IAssetEditorInstance *instance = FAssetEditorManager::Get().FindEditorForAsset(u_obj, bFocus);
1057+
if (!instance)
1058+
return PyErr_Format(PyExc_Exception, "no editor found for asset");
1059+
1060+
return py_ue_new_iasset_editor_instance(instance);
10191061
}
10201062

10211063
PyObject *py_unreal_engine_close_editor_for_asset(PyObject * self, PyObject * args)
@@ -1024,24 +1066,22 @@ PyObject *py_unreal_engine_close_editor_for_asset(PyObject * self, PyObject * ar
10241066

10251067
if (!PyArg_ParseTuple(args, "O:close_editor_for_asset", &py_obj))
10261068
{
1027-
return NULL;
1069+
return nullptr;
10281070
}
10291071

10301072
UObject *u_obj = ue_py_check_type<UObject>(py_obj);
10311073
if (!u_obj)
10321074
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
10331075
FAssetEditorManager::Get().CloseAllEditorsForAsset(u_obj);
10341076

1035-
Py_INCREF(Py_None);
1036-
return Py_None;
1077+
Py_RETURN_NONE;
10371078
}
10381079

10391080
PyObject *py_unreal_engine_close_all_asset_editors(PyObject * self, PyObject * args)
10401081
{
10411082
FAssetEditorManager::Get().CloseAllAssetEditors();
10421083

1043-
Py_INCREF(Py_None);
1044-
return Py_None;
1084+
Py_RETURN_NONE;
10451085
}
10461086

10471087
PyObject *py_unreal_engine_set_fbx_import_option(PyObject * self, PyObject * args)

Source/UnrealEnginePython/Private/UEPyEditor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ PyObject *py_unreal_engine_get_asset_referencers(PyObject *, PyObject *);
9191
PyObject *py_unreal_engine_get_asset_dependencies(PyObject *, PyObject *);
9292

9393
PyObject *py_unreal_engine_open_editor_for_asset(PyObject *, PyObject *);
94+
PyObject *py_unreal_engine_find_editor_for_asset(PyObject *, PyObject *);
95+
PyObject *py_unreal_engine_get_all_edited_assets(PyObject *, PyObject *);
9496
PyObject *py_unreal_engine_close_editor_for_asset(PyObject *, PyObject *);
9597
PyObject *py_unreal_engine_close_all_asset_editors(PyObject *, PyObject *);
9698

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include "Wrappers/UEPyFViewportClient.h"
7474
#if WITH_EDITOR
7575
#include "Wrappers/UEPyFEditorViewportClient.h"
76+
#include "Wrappers/UEPyIAssetEditorInstance.h"
7677
#endif
7778

7879
#include "Wrappers/UEPyFFoliageInstance.h"
@@ -262,6 +263,8 @@ static PyMethodDef unreal_engine_methods[] = {
262263
{ "create_property_view", (PyCFunction)py_unreal_engine_create_property_view, METH_VARARGS | METH_KEYWORDS, "" },
263264

264265
{ "open_editor_for_asset", py_unreal_engine_open_editor_for_asset, METH_VARARGS, "" },
266+
{ "find_editor_for_asset", py_unreal_engine_find_editor_for_asset, METH_VARARGS, "" },
267+
{ "get_all_edited_assets", py_unreal_engine_get_all_edited_assets, METH_VARARGS, "" },
265268
{ "close_editor_for_asset", py_unreal_engine_close_editor_for_asset, METH_VARARGS, "" },
266269
{ "close_all_asset_editors", py_unreal_engine_close_all_asset_editors, METH_VARARGS, "" },
267270
{ "allow_actor_script_execution_in_editor", py_unreal_engine_allow_actor_script_execution_in_editor , METH_VARARGS, "" },
@@ -1505,6 +1508,7 @@ void unreal_engine_init_py_module()
15051508
ue_python_init_fviewport_client(new_unreal_engine_module);
15061509
#if WITH_EDITOR
15071510
ue_python_init_feditor_viewport_client(new_unreal_engine_module);
1511+
ue_python_init_iasset_editor_instance(new_unreal_engine_module);
15081512
#endif
15091513

15101514
ue_python_init_fpython_output_device(new_unreal_engine_module);
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include "UEPyIAssetEditorInstance.h"
2+
3+
#if WITH_EDITOR
4+
5+
6+
7+
static PyObject *py_ue_iasset_editor_instance_close_window(ue_PyIAssetEditorInstance *self, PyObject * args)
8+
{
9+
self->editor_instance->CloseWindow();
10+
Py_RETURN_NONE;
11+
}
12+
13+
static PyObject *py_ue_iasset_editor_instance_focus_window(ue_PyIAssetEditorInstance *self, PyObject * args)
14+
{
15+
self->editor_instance->FocusWindow();
16+
Py_RETURN_NONE;
17+
}
18+
19+
static PyObject *py_ue_iasset_editor_instance_get_editor_name(ue_PyIAssetEditorInstance *self, PyObject * args)
20+
{
21+
return PyUnicode_FromString(TCHAR_TO_UTF8(*self->editor_instance->GetEditorName().ToString()));
22+
}
23+
24+
static PyObject *py_ue_iasset_editor_instance_get_last_activation_time(ue_PyIAssetEditorInstance *self, PyObject * args)
25+
{
26+
return PyFloat_FromDouble(self->editor_instance->GetLastActivationTime());
27+
}
28+
29+
static PyMethodDef ue_PyIAssetEditorInstance_methods[] = {
30+
{ "close_window", (PyCFunction)py_ue_iasset_editor_instance_close_window, METH_VARARGS, "" },
31+
{ "focus_window", (PyCFunction)py_ue_iasset_editor_instance_focus_window, METH_VARARGS, "" },
32+
{ "get_editor_name", (PyCFunction)py_ue_iasset_editor_instance_get_editor_name, METH_VARARGS, "" },
33+
{ "get_last_activation_time", (PyCFunction)py_ue_iasset_editor_instance_get_last_activation_time, METH_VARARGS, "" },
34+
{ nullptr } /* Sentinel */
35+
};
36+
37+
static PyObject *ue_PyIAssetEditorInstance_str(ue_PyIAssetEditorInstance *self)
38+
{
39+
return PyUnicode_FromFormat("<unreal_engine.IAssetEditorInstance %p>",
40+
&self->editor_instance);
41+
}
42+
43+
static PyTypeObject ue_PyIAssetEditorInstanceType = {
44+
PyVarObject_HEAD_INIT(NULL, 0)
45+
"unreal_engine.IAssetEditorInstance", /* tp_name */
46+
sizeof(ue_PyIAssetEditorInstance), /* tp_basicsize */
47+
0, /* tp_itemsize */
48+
0, /* tp_dealloc */
49+
0, /* tp_print */
50+
0, /* tp_getattr */
51+
0, /* tp_setattr */
52+
0, /* tp_reserved */
53+
0, /* tp_repr */
54+
0, /* tp_as_number */
55+
0, /* tp_as_sequence */
56+
0, /* tp_as_mapping */
57+
0, /* tp_hash */
58+
0, /* tp_call */
59+
(reprfunc)ue_PyIAssetEditorInstance_str, /* tp_str */
60+
0, /* tp_getattro */
61+
0, /* tp_setattro */
62+
0, /* tp_as_buffer */
63+
#if PY_MAJOR_VERSION < 3
64+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
65+
#else
66+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
67+
#endif
68+
"Unreal Engine IAssetEditorInstance", /* tp_doc */
69+
0, /* tp_traverse */
70+
0, /* tp_clear */
71+
0, /* tp_richcompare */
72+
0, /* tp_weaklistoffset */
73+
0, /* tp_iter */
74+
0, /* tp_iternext */
75+
ue_PyIAssetEditorInstance_methods, /* tp_methods */
76+
0,
77+
};
78+
79+
void ue_python_init_iasset_editor_instance(PyObject *ue_module)
80+
{
81+
ue_PyIAssetEditorInstanceType.tp_new = PyType_GenericNew;
82+
83+
if (PyType_Ready(&ue_PyIAssetEditorInstanceType) < 0)
84+
return;
85+
86+
Py_INCREF(&ue_PyIAssetEditorInstanceType);
87+
PyModule_AddObject(ue_module, "IAssetEditorInstance", (PyObject *)&ue_PyIAssetEditorInstanceType);
88+
}
89+
90+
ue_PyIAssetEditorInstance *py_ue_is_iasset_editor_instance(PyObject *obj)
91+
{
92+
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyIAssetEditorInstanceType))
93+
return nullptr;
94+
return (ue_PyIAssetEditorInstance *)obj;
95+
}
96+
97+
PyObject *py_ue_new_iasset_editor_instance(IAssetEditorInstance *editor_instance)
98+
{
99+
ue_PyIAssetEditorInstance *ret = (ue_PyIAssetEditorInstance *)PyObject_New(ue_PyIAssetEditorInstance, &ue_PyIAssetEditorInstanceType);
100+
ret->editor_instance = editor_instance;
101+
return (PyObject *)ret;
102+
}
103+
#endif
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
#include "UnrealEnginePython.h"
3+
4+
#if WITH_EDITOR
5+
6+
#include "Editor/UnrealEd/Public/Toolkits/AssetEditorManager.h"
7+
8+
struct ue_PyIAssetEditorInstance
9+
{
10+
PyObject_HEAD
11+
/* Type-specific fields go here. */
12+
IAssetEditorInstance *editor_instance;
13+
};
14+
15+
void ue_python_init_iasset_editor_instance(PyObject *);
16+
17+
PyObject *py_ue_new_iasset_editor_instance(IAssetEditorInstance *);
18+
19+
ue_PyIAssetEditorInstance *py_ue_is_iasset_editor_instance(PyObject *);
20+
21+
#endif

0 commit comments

Comments
 (0)