Skip to content

Commit 5d1c8b3

Browse files
author
ikrima
committed
Merge remote-tracking branch 'upstream/master' into bebylon
2 parents 497c86e + ae2eff3 commit 5d1c8b3

14 files changed

Lines changed: 332 additions & 1 deletion

Source/PythonConsole/Private/SPythonLog.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,14 @@ void SPythonConsoleInputBox::OnTextCommitted(const FText& InText, ETextCommit::T
208208
this->History.Add(ExecString);
209209
this->HistoryPosition = this->History.Num();
210210

211-
UE_LOG(LogTemp, Log, TEXT(">>> %s"), *ExecString);
211+
if (IsMultiline)
212+
{
213+
UE_LOG(LogTemp, Log, TEXT("... %s"), *ExecString);
214+
}
215+
else
216+
{
217+
UE_LOG(LogTemp, Log, TEXT(">>> %s"), *ExecString);
218+
}
212219

213220
// Clear the console input area
214221
bIgnoreUIUpdate = true;

Source/UnrealEnginePython/Private/Slate/UEPyFCharacterEvent.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,31 @@ static PyTypeObject ue_PyFCharacterEventType = {
5353
ue_PyFCharacterEvent_methods, /* tp_methods */
5454
};
5555

56+
static int ue_py_fcharacter_event_init(ue_PyFCharacterEvent *self, PyObject *args, PyObject *kwargs)
57+
{
58+
char *key;
59+
if (!PyArg_ParseTuple(args, "s", &key))
60+
{
61+
return -1;
62+
}
63+
64+
// TODO make it configurable
65+
FModifierKeysState modifier;
66+
67+
// TODO make repeat configurable
68+
FCharacterEvent Event(*UTF8_TO_TCHAR(key), modifier, 0, false);
69+
70+
new(&self->character_event) FCharacterEvent(Event);
71+
new(&self->f_input.input) FInputEvent(Event);
72+
73+
return 0;
74+
}
75+
5676
void ue_python_init_fcharacter_event(PyObject *ue_module)
5777
{
5878

5979
ue_PyFCharacterEventType.tp_base = &ue_PyFInputEventType;
80+
ue_PyFCharacterEventType.tp_init = (initproc)ue_py_fcharacter_event_init;
6081

6182
if (PyType_Ready(&ue_PyFCharacterEventType) < 0)
6283
return;
@@ -72,3 +93,10 @@ PyObject *py_ue_new_fcharacter_event(FCharacterEvent key_event)
7293
new(&ret->f_input.input) FInputEvent(key_event);
7394
return (PyObject *)ret;
7495
}
96+
97+
ue_PyFCharacterEvent *py_ue_is_fcharacter_event(PyObject *obj)
98+
{
99+
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyFCharacterEventType))
100+
return nullptr;
101+
return (ue_PyFCharacterEvent *)obj;
102+
}

Source/UnrealEnginePython/Private/Slate/UEPyFCharacterEvent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ typedef struct {
1515
void ue_python_init_fcharacter_event(PyObject *);
1616

1717
PyObject *py_ue_new_fcharacter_event(FCharacterEvent);
18+
ue_PyFCharacterEvent *py_ue_is_fcharacter_event(PyObject *);

Source/UnrealEnginePython/Private/Slate/UEPyFKeyEvent.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,33 @@ static PyTypeObject ue_PyFKeyEventType = {
5555
ue_PyFKeyEvent_methods, /* tp_methods */
5656
};
5757

58+
static int ue_py_fkey_event_init(ue_PyFKeyEvent *self, PyObject *args, PyObject *kwargs)
59+
{
60+
char *key;
61+
if (!PyArg_ParseTuple(args, "s", &key))
62+
{
63+
return -1;
64+
}
65+
66+
FKey InKey(key);
67+
68+
// TODO make it configurable
69+
FModifierKeysState modifier;
70+
71+
// TODO configure repeat
72+
FKeyEvent Event(InKey, modifier, 0, false, 0, 0);
73+
74+
new(&self->key_event) FKeyEvent(Event);
75+
new(&self->f_input.input) FInputEvent(Event);
76+
77+
return 0;
78+
}
79+
80+
5881
void ue_python_init_fkey_event(PyObject *ue_module) {
5982

6083
ue_PyFKeyEventType.tp_base = &ue_PyFInputEventType;
84+
ue_PyFKeyEventType.tp_init = (initproc)ue_py_fkey_event_init;
6185

6286
if (PyType_Ready(&ue_PyFKeyEventType) < 0)
6387
return;
@@ -72,3 +96,10 @@ PyObject *py_ue_new_fkey_event(FKeyEvent key_event) {
7296
new(&ret->f_input.input) FInputEvent(key_event);
7397
return (PyObject *)ret;
7498
}
99+
100+
ue_PyFKeyEvent *py_ue_is_fkey_event(PyObject *obj)
101+
{
102+
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyFKeyEventType))
103+
return nullptr;
104+
return (ue_PyFKeyEvent *)obj;
105+
}

Source/UnrealEnginePython/Private/Slate/UEPyFKeyEvent.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ typedef struct {
1515
void ue_python_init_fkey_event(PyObject *);
1616

1717
PyObject *py_ue_new_fkey_event(FKeyEvent);
18+
19+
ue_PyFKeyEvent *py_ue_is_fkey_event(PyObject *);
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
2+
#include "UnrealEnginePythonPrivatePCH.h"
3+
4+
#include "UEPyFSlateApplication.h"
5+
6+
7+
static PyObject *py_ue_get_average_delta_time(PyObject *cls, PyObject * args)
8+
{
9+
return PyFloat_FromDouble(FSlateApplication::Get().GetAverageDeltaTime());
10+
}
11+
12+
static PyObject *py_ue_get_delta_time(PyObject *cls, PyObject * args)
13+
{
14+
return PyFloat_FromDouble(FSlateApplication::Get().GetDeltaTime());
15+
}
16+
17+
static PyObject *py_ue_goto_line_in_source(PyObject *cls, PyObject * args)
18+
{
19+
char *filename;
20+
int line_number;
21+
if (!PyArg_ParseTuple(args, "si:goto_line_in_source", &filename, &line_number))
22+
{
23+
return nullptr;
24+
}
25+
26+
FSlateApplication::Get().GotoLineInSource(FString(UTF8_TO_TCHAR(filename)), line_number);
27+
28+
Py_RETURN_NONE;
29+
}
30+
31+
static PyObject *py_ue_is_gamepad_attached(PyObject *cls, PyObject * args)
32+
{
33+
bool bAttached = FSlateApplication::Get().IsGamepadAttached();
34+
if (bAttached)
35+
Py_RETURN_TRUE;
36+
Py_RETURN_FALSE;
37+
}
38+
39+
static PyObject *py_ue_is_mouse_attached(PyObject *cls, PyObject * args)
40+
{
41+
bool bAttached = FSlateApplication::Get().IsMouseAttached();
42+
if (bAttached)
43+
Py_RETURN_TRUE;
44+
Py_RETURN_FALSE;
45+
}
46+
47+
static PyObject *py_ue_process_key_down_event(PyObject *cls, PyObject * args)
48+
{
49+
PyObject *py_event;
50+
if (!PyArg_ParseTuple(args, "O:process_key_down_event", &py_event))
51+
{
52+
return nullptr;
53+
}
54+
55+
FKeyEvent *InKeyEvent = ue_py_check_struct<FKeyEvent>(py_event);
56+
if (!InKeyEvent)
57+
{
58+
ue_PyFKeyEvent *py_fkey_event = py_ue_is_fkey_event(py_event);
59+
if (!py_fkey_event)
60+
{
61+
return PyErr_Format(PyExc_Exception, "argument is not a FKeyEvent");
62+
}
63+
InKeyEvent = &py_fkey_event->key_event;
64+
}
65+
66+
if (FSlateApplication::Get().ProcessKeyDownEvent(*InKeyEvent))
67+
Py_RETURN_TRUE;
68+
69+
Py_RETURN_FALSE;
70+
}
71+
72+
static PyObject *py_ue_process_key_char_event(PyObject *cls, PyObject * args)
73+
{
74+
PyObject *py_event;
75+
if (!PyArg_ParseTuple(args, "O:process_key_char_event", &py_event))
76+
{
77+
return nullptr;
78+
}
79+
80+
FCharacterEvent *InCharEvent = ue_py_check_struct<FCharacterEvent>(py_event);
81+
if (!InCharEvent)
82+
{
83+
ue_PyFCharacterEvent *py_fchar_event = py_ue_is_fcharacter_event(py_event);
84+
if (!py_fchar_event)
85+
{
86+
return PyErr_Format(PyExc_Exception, "argument is not a FCharacterEvent");
87+
}
88+
InCharEvent = &py_fchar_event->character_event;
89+
}
90+
91+
if (FSlateApplication::Get().ProcessKeyCharEvent(*InCharEvent))
92+
Py_RETURN_TRUE;
93+
94+
Py_RETURN_FALSE;
95+
}
96+
97+
static PyMethodDef ue_PyFSlateApplication_methods[] = {
98+
{ "get_average_delta_time", (PyCFunction)py_ue_get_average_delta_time, METH_VARARGS | METH_CLASS, "" },
99+
{ "get_delta_time", (PyCFunction)py_ue_get_delta_time, METH_VARARGS | METH_CLASS, "" },
100+
{ "goto_line_in_source", (PyCFunction)py_ue_goto_line_in_source, METH_VARARGS | METH_CLASS, "" },
101+
{ "is_gamepad_attached", (PyCFunction)py_ue_is_gamepad_attached, METH_VARARGS | METH_CLASS, "" },
102+
{ "is_mouse_attached", (PyCFunction)py_ue_is_mouse_attached, METH_VARARGS | METH_CLASS, "" },
103+
{ "process_key_down_event", (PyCFunction)py_ue_process_key_down_event, METH_VARARGS | METH_CLASS, "" },
104+
{ "process_key_char_event", (PyCFunction)py_ue_process_key_char_event, METH_VARARGS | METH_CLASS, "" },
105+
{ NULL } /* Sentinel */
106+
};
107+
108+
109+
static PyTypeObject ue_PyFSlateApplicationType = {
110+
PyVarObject_HEAD_INIT(NULL, 0)
111+
"unreal_engine.FSlateApplication", /* tp_name */
112+
sizeof(ue_PyFSlateApplication), /* tp_basicsize */
113+
0, /* tp_itemsize */
114+
0, /* tp_dealloc */
115+
0, /* tp_print */
116+
0, /* tp_getattr */
117+
0, /* tp_setattr */
118+
0, /* tp_reserved */
119+
0, /* tp_repr */
120+
0, /* tp_as_number */
121+
0, /* tp_as_sequence */
122+
0, /* tp_as_mapping */
123+
0, /* tp_hash */
124+
0, /* tp_call */
125+
0, /* tp_str */
126+
0, /* tp_getattro */
127+
0, /* tp_setattro */
128+
0, /* tp_as_buffer */
129+
Py_TPFLAGS_DEFAULT, /* tp_flags */
130+
"Unreal Engine SlateApplication", /* tp_doc */
131+
0, /* tp_traverse */
132+
0, /* tp_clear */
133+
0, /* tp_richcompare */
134+
0, /* tp_weaklistoffset */
135+
0, /* tp_iter */
136+
0, /* tp_iternext */
137+
ue_PyFSlateApplication_methods, /* tp_methods */
138+
0,
139+
0,
140+
};
141+
142+
static int py_ue_fslate_application_init(ue_PyFSlateApplication *self, PyObject * args)
143+
{
144+
PyErr_SetString(PyExc_Exception, "FSlateApplication is a singleton");
145+
return -1;
146+
}
147+
148+
void ue_python_init_fslate_application(PyObject *ue_module)
149+
{
150+
ue_PyFSlateApplicationType.tp_new = PyType_GenericNew;
151+
ue_PyFSlateApplicationType.tp_init = (initproc)py_ue_fslate_application_init;
152+
153+
if (PyType_Ready(&ue_PyFSlateApplicationType) < 0)
154+
return;
155+
156+
Py_INCREF(&ue_PyFSlateApplicationType);
157+
PyModule_AddObject(ue_module, "FSlateApplication", (PyObject *)&ue_PyFSlateApplicationType);
158+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include "UnrealEnginePython.h"
4+
5+
typedef struct
6+
{
7+
PyObject_HEAD
8+
/* Type-specific fields go here. */
9+
} ue_PyFSlateApplication;
10+
11+
void ue_python_init_fslate_application(PyObject *);

Source/UnrealEnginePython/Private/UEPyEngine.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,4 +1293,23 @@ PyObject *py_unreal_engine_set_random_seed(PyObject * self, PyObject * args)
12931293
FGenericPlatformMath::RandInit(seed);
12941294

12951295
Py_RETURN_NONE;
1296+
}
1297+
1298+
PyObject *py_unreal_engine_clipboard_copy(PyObject * self, PyObject * args)
1299+
{
1300+
char *text;
1301+
if (!PyArg_ParseTuple(args, "s:clipboard_copy", &text))
1302+
{
1303+
return nullptr;
1304+
}
1305+
1306+
FGenericPlatformMisc::ClipboardCopy(UTF8_TO_TCHAR(text));
1307+
Py_RETURN_NONE;
1308+
}
1309+
1310+
PyObject *py_unreal_engine_clipboard_paste(PyObject * self, PyObject * args)
1311+
{
1312+
FString clipboard;
1313+
FGenericPlatformMisc::ClipboardPaste(clipboard);
1314+
return PyUnicode_FromString(TCHAR_TO_UTF8(*clipboard));
12961315
}

Source/UnrealEnginePython/Private/UEPyEngine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ PyObject *py_unreal_engine_get_forward_vector(PyObject *, PyObject *);
1313
PyObject *py_unreal_engine_get_right_vector(PyObject *, PyObject *);
1414
PyObject *py_unreal_engine_get_up_vector(PyObject *, PyObject *);
1515

16+
PyObject *py_unreal_engine_clipboard_copy(PyObject *, PyObject *);
17+
PyObject *py_unreal_engine_clipboard_paste(PyObject *, PyObject *);
18+
1619
PyObject *py_unreal_engine_set_random_seed(PyObject *, PyObject *);
1720

1821
PyObject *py_unreal_engine_get_game_viewport_size(PyObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ static PyMethodDef unreal_engine_methods[] = {
400400
{ "unregister_settings", py_unreal_engine_unregister_settings, METH_VARARGS, "" },
401401
#endif
402402

403+
{ "clipboard_copy", py_unreal_engine_clipboard_copy, METH_VARARGS, "" },
404+
{ "clipboard_paste", py_unreal_engine_clipboard_paste, METH_VARARGS, "" },
405+
403406
#pragma warning(suppress: 4191)
404407
{ "copy_properties_for_unrelated_objects", (PyCFunction)py_unreal_engine_copy_properties_for_unrelated_objects, METH_VARARGS | METH_KEYWORDS, "" },
405408

@@ -488,6 +491,10 @@ static PyMethodDef ue_PyUObject_methods[] = {
488491
{ "get_path_name", (PyCFunction)py_ue_get_path_name, METH_VARARGS, "" },
489492
{ "get_full_name", (PyCFunction)py_ue_get_full_name, METH_VARARGS, "" },
490493

494+
#if WITH_EDITOR
495+
{ "import_custom_properties", (PyCFunction)py_ue_import_custom_properties, METH_VARARGS, "" },
496+
#endif
497+
491498
#if ENGINE_MINOR_VERSION >= 15
492499
{ "can_modify", (PyCFunction)py_ue_can_modify, METH_VARARGS, "" },
493500
#endif
@@ -1958,6 +1965,8 @@ void unreal_engine_init_py_module()
19581965

19591966
ue_python_init_iconsole_manager(new_unreal_engine_module);
19601967

1968+
ue_python_init_fslate_application(new_unreal_engine_module);
1969+
19611970
#if WITH_EDITOR
19621971
ue_python_init_icollection_manager(new_unreal_engine_module);
19631972
#endif

0 commit comments

Comments
 (0)