Skip to content

Commit 439f2c1

Browse files
author
Roberto De Ioris
committed
implemented add_property(), another step for 20tab#5
1 parent 81c8c47 commit 439f2c1

File tree

7 files changed

+59
-11
lines changed

7 files changed

+59
-11
lines changed

Source/PythonConsole/Private/SPythonLog.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,6 @@ void SPythonConsoleInputBox::OnTextCommitted(const FText& InText, ETextCommit::T
264264
}
265265

266266

267-
void SPythonConsoleInputBox::OnFocusLost(const FFocusEvent& InFocusEvent)
268-
{
269-
// SuggestionBox->SetIsOpen(false);
270-
}
271-
272-
273267
TSharedRef< FPythonLogTextLayoutMarshaller > FPythonLogTextLayoutMarshaller::Create(TArray< TSharedPtr<FLogMessage> > InMessages)
274268
{
275269
return MakeShareable(new FPythonLogTextLayoutMarshaller(MoveTemp(InMessages)));

Source/PythonConsole/Private/SPythonLog.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class SPythonConsoleInputBox
6262

6363
virtual bool SupportsKeyboardFocus() const override { return true; }
6464

65-
void OnFocusLost( const FFocusEvent& InFocusEvent ) override;
66-
6765
/** Handles entering in a command */
6866
void OnTextCommitted(const FText& InText, ETextCommit::Type CommitInfo);
6967

Source/UnrealEnginePython/Private/UEPyEngine.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ PyObject *py_unreal_engine_new_object(PyObject * self, PyObject * args) {
476476
outer = py_outer_obj->ue_object;
477477
}
478478

479-
UObject *new_object = NewObject<UObject>(outer, obj_class, f_name);
479+
UObject *new_object = NewObject<UObject>(outer, obj_class, f_name, RF_Public| RF_Standalone);
480480
if (!new_object)
481481
return PyErr_Format(PyExc_Exception, "unable to create object");
482482

@@ -487,8 +487,6 @@ PyObject *py_unreal_engine_new_object(PyObject * self, PyObject * args) {
487487
return (PyObject *)ret;
488488
}
489489

490-
491-
492490
PyObject *py_unreal_engine_new_blueprint_class(PyObject * self, PyObject * args) {
493491

494492
PyObject *py_parent;

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
273273
{ "set_timer", (PyCFunction)py_ue_set_timer, METH_VARARGS, "" },
274274

275275
{ "add_function", (PyCFunction)py_ue_add_function, METH_VARARGS, "" },
276+
{ "add_property", (PyCFunction)py_ue_add_property, METH_VARARGS, "" },
276277
{ "as_dict", (PyCFunction)py_ue_as_dict, METH_VARARGS, "" },
277278
{ NULL } /* Sentinel */
278279
};

Source/UnrealEnginePython/Private/UEPyObject.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,53 @@ PyObject *py_ue_add_function(ue_PyUObject * self, PyObject * args) {
334334
return Py_None;
335335
}
336336

337+
PyObject *py_ue_add_property(ue_PyUObject * self, PyObject * args) {
338+
339+
ue_py_check(self);
340+
341+
PyObject *obj;
342+
char *name;
343+
PyObject *replicate = nullptr;
344+
if (!PyArg_ParseTuple(args, "Os|O:add_property", &obj, &name, &replicate)) {
345+
return NULL;
346+
}
347+
348+
if (!self->ue_object->IsA<UStruct>())
349+
return PyErr_Format(PyExc_Exception, "uobject is not a UStruct");
350+
351+
if (!ue_is_pyuobject(obj)) {
352+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
353+
}
354+
355+
ue_PyUObject *py_obj = (ue_PyUObject *)obj;
356+
357+
if (!py_obj->ue_object->IsA<UClass>()) {
358+
return PyErr_Format(PyExc_Exception, "uobject is not a UClass");
359+
}
360+
361+
UProperty *u_property = NewObject<UProperty>(self->ue_object, (UClass *)py_obj->ue_object, UTF8_TO_TCHAR(name));
362+
if (!u_property)
363+
return PyErr_Format(PyExc_Exception, "unable to allocate new UProperty");
364+
365+
uint64 flags = CPF_Edit;
366+
if (replicate && PyObject_IsTrue(replicate)) {
367+
flags |= CPF_Net;
368+
}
369+
370+
u_property->SetPropertyFlags(flags);
371+
372+
UStruct *u_struct = (UStruct *)self->ue_object;
373+
374+
u_struct->AddCppProperty(u_property);
375+
376+
ue_PyUObject *ret = ue_get_python_wrapper(u_property);
377+
if (!ret)
378+
return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
379+
Py_INCREF(ret);
380+
return (PyObject *)ret;
381+
382+
}
383+
337384
PyObject *py_ue_as_dict(ue_PyUObject * self, PyObject * args) {
338385

339386
ue_py_check(self);
@@ -370,6 +417,8 @@ PyObject *py_ue_save_package(ue_PyUObject * self, PyObject * args) {
370417
return NULL;
371418
}
372419

420+
// NOTE maybe we should check for transient object, to avoid crashes
421+
373422
if (UPackage::SavePackage(GetTransientPackage(), self->ue_object, EObjectFlags::RF_NoFlags, UTF8_TO_TCHAR(filename))) {
374423
Py_INCREF(Py_True);
375424
return Py_True;

Source/UnrealEnginePython/Private/UEPyObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ PyObject *py_ue_remove_from_root(ue_PyUObject *, PyObject *);
2020

2121
PyObject *py_ue_bind_event(ue_PyUObject *, PyObject *);
2222
PyObject *py_ue_add_function(ue_PyUObject *, PyObject *);
23+
PyObject *py_ue_add_property(ue_PyUObject *, PyObject *);
2324

2425
PyObject *py_ue_as_dict(ue_PyUObject *, PyObject *);
2526

Source/UnrealEnginePython/Private/UnrealEnginePython.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ void FUnrealEnginePythonModule::StartupModule()
3333

3434
UE_LOG(LogPython, Log , TEXT("Python VM initialized: %s"), UTF8_TO_TCHAR(Py_GetVersion()));
3535
UE_LOG(LogPython, Log, TEXT("Python Scripts search path: %s"), UTF8_TO_TCHAR(scripts_path));
36+
37+
if (PyImport_ImportModule("ue_site")) {
38+
UE_LOG(LogPython, Log, TEXT("ue_site Python module successfully imported"));
39+
}
40+
else {
41+
unreal_engine_py_log_error();
42+
}
3643
}
3744

3845
void FUnrealEnginePythonModule::ShutdownModule()

0 commit comments

Comments
 (0)