Skip to content

Commit 38c9399

Browse files
committed
Add support for FSlowTask
1 parent 0a95537 commit 38c9399

File tree

3 files changed

+182
-0
lines changed

3 files changed

+182
-0
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#include "UEPyUScriptStruct.h"
8383

8484
#if WITH_EDITOR
85+
#include "Wrappers/UEPyFSlowTask.h"
8586
#include "Wrappers/UEPyFAssetData.h"
8687
#include "Wrappers/UEPyFARFilter.h"
8788
#include "Wrappers/UEPyFRawMesh.h"
@@ -439,6 +440,7 @@ static PyMethodDef unreal_engine_methods[] = {
439440
{ "clipboard_copy", py_unreal_engine_clipboard_copy, METH_VARARGS, "" },
440441
{ "clipboard_paste", py_unreal_engine_clipboard_paste, METH_VARARGS, "" },
441442

443+
442444
#pragma warning(suppress: 4191)
443445
{ "copy_properties_for_unrelated_objects", (PyCFunction)py_unreal_engine_copy_properties_for_unrelated_objects, METH_VARARGS | METH_KEYWORDS, "" },
444446

@@ -1517,6 +1519,7 @@ void unreal_engine_init_py_module()
15171519

15181520

15191521
#if WITH_EDITOR
1522+
ue_python_init_fslowtask(new_unreal_engine_module);
15201523
ue_python_init_swidget(new_unreal_engine_module);
15211524
ue_python_init_farfilter(new_unreal_engine_module);
15221525
ue_python_init_fassetdata(new_unreal_engine_module);
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#include "UEPyFSlowTask.h"
2+
3+
#include "Misc/FeedbackContext.h"
4+
5+
#if WITH_EDITOR
6+
7+
static PyObject *py_ue_fslowtask_initialize(ue_PyFSlowTask *self, PyObject * args)
8+
{
9+
self->slowtask.Initialize();
10+
11+
Py_RETURN_NONE;
12+
}
13+
14+
static PyObject *py_ue_fslowtask_destroy(ue_PyFSlowTask *self, PyObject * args)
15+
{
16+
self->slowtask.Destroy();
17+
18+
Py_RETURN_NONE;
19+
}
20+
21+
static PyObject *py_ue_fslowtask_make_dialog_delayed(ue_PyFSlowTask *self, PyObject * args)
22+
{
23+
float threshold;
24+
int show_cancel_button = 0;
25+
int allow_in_pie = 0;
26+
if(!PyArg_ParseTuple(args, "f|ii:make_dialog_delayed", &threshold, &show_cancel_button, &allow_in_pie))
27+
{
28+
return nullptr;
29+
}
30+
31+
self->slowtask.MakeDialogDelayed(threshold, show_cancel_button, allow_in_pie);
32+
33+
Py_RETURN_NONE;
34+
}
35+
36+
static PyObject *py_ue_fslowtask_make_dialog(ue_PyFSlowTask *self, PyObject * args)
37+
{
38+
int show_cancel_button = 0;
39+
int allow_in_pie = 0;
40+
if(!PyArg_ParseTuple(args, "|ii:make_dialog", &show_cancel_button, &allow_in_pie))
41+
{
42+
return nullptr;
43+
}
44+
45+
self->slowtask.MakeDialog(show_cancel_button, allow_in_pie);
46+
47+
Py_RETURN_NONE;
48+
}
49+
50+
static PyObject *py_ue_fslowtask_enter_progress_frame(ue_PyFSlowTask *self, PyObject * args)
51+
{
52+
float expected_work_this_frame = 1.0;
53+
char *text = "";
54+
if(!PyArg_ParseTuple(args, "|fs:enter_progress_frame", &expected_work_this_frame, &text))
55+
{
56+
return nullptr;
57+
}
58+
59+
self->slowtask.EnterProgressFrame(expected_work_this_frame, FText::FromString(UTF8_TO_TCHAR(text)));
60+
61+
Py_RETURN_NONE;
62+
}
63+
64+
static PyObject *py_ue_fslowtask_get_current_message(ue_PyFSlowTask *self, PyObject * args)
65+
{
66+
FText current_message = self->slowtask.GetCurrentMessage();
67+
return PyUnicode_FromString(TCHAR_TO_UTF8(*current_message.ToString()));
68+
}
69+
70+
static PyObject *py_ue_fslowtask_received_user_cancel(ue_PyFSlowTask *self, PyObject * args )
71+
{
72+
if(GWarn->ReceivedUserCancel())
73+
{
74+
Py_INCREF(Py_True);
75+
return Py_True;
76+
}
77+
Py_INCREF(Py_False);
78+
return Py_False;
79+
}
80+
81+
static PyMethodDef ue_PyFSlowTask_methods[] = {
82+
{ "initialize", (PyCFunction)py_ue_fslowtask_initialize, METH_VARARGS, "" },
83+
{ "destroy", (PyCFunction)py_ue_fslowtask_destroy, METH_VARARGS, "" },
84+
{ "make_dialog_delayed", (PyCFunction)py_ue_fslowtask_make_dialog_delayed, METH_VARARGS, "" },
85+
{ "make_dialog", (PyCFunction)py_ue_fslowtask_make_dialog, METH_VARARGS, "" },
86+
{ "enter_progress_frame", (PyCFunction)py_ue_fslowtask_enter_progress_frame, METH_VARARGS, "" },
87+
{ "get_current_message", (PyCFunction)py_ue_fslowtask_get_current_message, METH_VARARGS, "" },
88+
{ "received_user_cancel", (PyCFunction)py_ue_fslowtask_received_user_cancel, METH_VARARGS, "" },
89+
{ NULL } /* Sentinel */
90+
};
91+
92+
static PyTypeObject ue_PyFSlowTaskType = {
93+
PyVarObject_HEAD_INIT(NULL, 0)
94+
"unreal_engine.FSlowTask", /* tp_name */
95+
sizeof(ue_PyFSlowTask), /* tp_basicsize */
96+
0, /* tp_itemsize */
97+
0, /* tp_dealloc */
98+
0, /* tp_print */
99+
0, /* tp_getattr */
100+
0, /* tp_setattr */
101+
0, /* tp_reserved */
102+
0, /* tp_repr */
103+
0, /* tp_as_number */
104+
0, /* tp_as_sequence */
105+
0, /* tp_as_mapping */
106+
0, /* tp_hash */
107+
0, /* tp_call */
108+
0, /* tp_str */
109+
0, /* tp_getattro */
110+
0, /* tp_setattro */
111+
0, /* tp_as_buffer */
112+
#if PY_MAJOR_VERSION < 3
113+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
114+
#else
115+
Py_TPFLAGS_DEFAULT, /* tp_flags */
116+
#endif
117+
"Unreal Engine FSlowTask", /* tp_doc */
118+
0, /* tp_traverse */
119+
0, /* tp_clear */
120+
0, /* tp_richcompare */
121+
0, /* tp_weaklistoffset */
122+
0, /* tp_iter */
123+
0, /* tp_iternext */
124+
ue_PyFSlowTask_methods, /* tp_methods */
125+
0,
126+
0,
127+
};
128+
129+
static int py_ue_fslowtask_init(ue_PyFSlowTask *self, PyObject * args)
130+
{
131+
float amount_of_work;
132+
char *default_message = "";
133+
int enabled = 1;
134+
if(!PyArg_ParseTuple(args, "f|si:__init__", &amount_of_work, &default_message, &enabled))
135+
{
136+
return -1;
137+
}
138+
139+
new(&self->slowtask) FSlowTask(amount_of_work, FText::FromString(UTF8_TO_TCHAR(default_message)), enabled);
140+
return 0;
141+
}
142+
143+
void ue_python_init_fslowtask(PyObject *ue_module)
144+
{
145+
ue_PyFSlowTaskType.tp_new = PyType_GenericNew;
146+
ue_PyFSlowTaskType.tp_init = (initproc)py_ue_fslowtask_init;
147+
148+
if (PyType_Ready(&ue_PyFSlowTaskType) < 0)
149+
return;
150+
151+
Py_INCREF(&ue_PyFSlowTaskType);
152+
PyModule_AddObject(ue_module, "FSlowTask", (PyObject *)&ue_PyFSlowTaskType);
153+
}
154+
155+
ue_PyFSlowTask *py_ue_is_fslowtask(PyObject *obj)
156+
{
157+
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyFSlowTaskType))
158+
return nullptr;
159+
return (ue_PyFSlowTask *)obj;
160+
}
161+
162+
#endif
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
#include "UnrealEnginePython.h"
3+
4+
#if WITH_EDITOR
5+
6+
struct ue_PyFSlowTask {
7+
PyObject_HEAD
8+
/* Type-specific fields go here. */
9+
10+
FSlowTask slowtask;
11+
};
12+
13+
void ue_python_init_fslowtask(PyObject *);
14+
15+
ue_PyFSlowTask *py_ue_is_fslowtask(PyObject *);
16+
17+
#endif

0 commit comments

Comments
 (0)