Skip to content

Commit ad3c049

Browse files
author
Roberto De Ioris
committed
fixed enums
1 parent a165578 commit ad3c049

7 files changed

Lines changed: 57 additions & 14 deletions

File tree

‎Source/UnrealEnginePython/Private/Slate/UEPySBorder.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static int ue_py_sborder_init(ue_PySBorder *self, PyObject *args, PyObject *kwar
153153
ue_py_slate_farguments_optional_struct_ptr("border_image", BorderImage, FSlateBrush);
154154
ue_py_slate_farguments_optional_enum("h_align", HAlign, EHorizontalAlignment);
155155
ue_py_slate_farguments_optional_enum("v_align", VAlign, EVerticalAlignment);
156-
ue_py_slate_farguments_struct("padding", Padding, FMargin);
156+
ue_py_slate_farguments_padding("padding", Padding);
157157
ue_py_slate_farguments_struct("foreground_color", ForegroundColor, FSlateColor);
158158
ue_py_slate_farguments_fvector2d("content_scale", ContentScale);
159159
ue_py_slate_farguments_fvector2d("desired_size_scale", DesiredSizeScale);

‎Source/UnrealEnginePython/Private/Slate/UEPySGridPanel.cpp‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,41 @@ static PyObject *py_ue_sgrid_panel_clear_children(ue_PySGridPanel *self, PyObjec
1111
Py_RETURN_NONE;
1212
}
1313

14-
static PyObject *py_ue_sgrid_panel_add_slot(ue_PySGridPanel *self, PyObject * args)
14+
static PyObject *py_ue_sgrid_panel_add_slot(ue_PySGridPanel *self, PyObject * args, PyObject * kwargs)
1515
{
1616
ue_py_slate_cast(SGridPanel);
17+
1718
PyObject *py_content;
18-
int col;
19+
int column;
1920
int row;
2021
int layer = 0;
21-
if (!PyArg_ParseTuple(args, "Oii|i:add_slot", &py_content, &col, &row, &layer))
22-
{
23-
return NULL;
24-
}
2522

26-
TSharedPtr<SWidget> Content = py_ue_is_swidget<SWidget>(py_content);
27-
if (!Content.IsValid())
23+
char *kwlist[] = { (char *)"widget", (char *)"column", (char *)"row", (char *)"layer", nullptr };
24+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oii|i:add_slot", kwlist, &py_content, &column, &row, &layer))
2825
{
2926
return nullptr;
3027
}
3128

29+
int32 retCode = [&]() {
30+
ue_py_slate_setup_hack_slot_args_grid(SGridPanel, py_SGridPanel, column, row, SGridPanel::Layer(layer));
31+
ue_py_slate_farguments_optional_int32("column_span", ColumnSpan);
32+
ue_py_slate_farguments_optional_fvector2d("nudge", Nudge);
33+
ue_py_slate_farguments_optional_int32("row_span", RowSpan);
34+
return 0;
35+
}();
3236

33-
SGridPanel::FSlot &fslot = py_SGridPanel->AddSlot(col, row, SGridPanel::Layer(layer));
34-
fslot.AttachWidget(Content.ToSharedRef());
37+
if (retCode != 0)
38+
{
39+
return PyErr_Format(PyExc_Exception, "could not add GridPanel slot");
40+
}
3541

3642
Py_RETURN_SLATE_SELF;
3743
}
3844

3945
static PyMethodDef ue_PySGridPanel_methods[] = {
4046
{ "clear_children", (PyCFunction)py_ue_sgrid_panel_clear_children, METH_VARARGS, "" },
41-
{ "add_slot", (PyCFunction)py_ue_sgrid_panel_add_slot, METH_VARARGS, "" },
47+
#pragma warning(suppress: 4191)
48+
{ "add_slot", (PyCFunction)py_ue_sgrid_panel_add_slot, METH_VARARGS | METH_KEYWORDS, "" },
4249
{ NULL } /* Sentinel */
4350
};
4451

‎Source/UnrealEnginePython/Private/Slate/UEPySlate.h‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ ue_PySWidget *ue_py_get_swidget(TSharedRef<SWidget> s_widget);
196196
}\
197197
ue_py_slate_down(param)
198198

199+
200+
#define ue_py_slate_farguments_int32(param, attribute) ue_py_slate_up(int32, GetterInt, param, attribute)\
201+
else if (PyNumber_Check(value)) {\
202+
PyObject *py_int = PyNumber_Long(value);\
203+
arguments.attribute((int32)PyLong_AsLong(py_int)); \
204+
Py_DECREF(py_int);\
205+
}\
206+
ue_py_slate_down(param)
207+
208+
199209
#define ue_py_slate_farguments_tint(param, attribute) ue_py_slate_up(TOptional<int32>, GetterIntT<TOptional<int32>>, param, attribute)\
200210
else if (PyNumber_Check(value)) {\
201211
PyObject *py_int = PyNumber_Long(value);\
@@ -312,6 +322,20 @@ ue_PySWidget *ue_py_get_swidget(TSharedRef<SWidget> s_widget);
312322
}
313323

314324

325+
#define ue_py_slate_farguments_optional_int32(param, attribute) { PyObject *value = ue_py_dict_get_item(kwargs, param);\
326+
if (value) {\
327+
if (PyNumber_Check(value)) {\
328+
PyObject *py_int = PyNumber_Long(value);\
329+
arguments.attribute((int32)PyLong_AsLong(py_int)); \
330+
Py_DECREF(py_int);\
331+
}\
332+
else {\
333+
PyErr_SetString(PyExc_TypeError, "unsupported type for attribute " param); \
334+
return -1;\
335+
}\
336+
}\
337+
}
338+
315339

316340
#define ue_py_slate_farguments_optional_float(param, attribute) { PyObject *value = ue_py_dict_get_item(kwargs, param);\
317341
if (value) {\
@@ -450,6 +474,7 @@ ue_PySWidget *ue_py_get_swidget(TSharedRef<SWidget> s_widget);
450474

451475
#define ue_py_slate_farguments_required_slot(param) { PyObject *value = ue_py_dict_get_item(kwargs, param);\
452476
value = value ? value : PyTuple_GetItem(args, 0);\
477+
if (!value) {PyErr_Clear(); PyErr_SetString(PyExc_TypeError, "you need to specify a widget"); return -1;}\
453478
TSharedPtr<SWidget> Widget = py_ue_is_swidget<SWidget>(value);\
454479
if (Widget.IsValid())\
455480
arguments.AttachWidget(Widget.ToSharedRef());\
@@ -464,6 +489,10 @@ ue_PySWidget *ue_py_get_swidget(TSharedRef<SWidget> s_widget);
464489
TArray<TSharedRef<FPythonSlateDelegate>> DeferredSlateDelegates;\
465490
ue_py_slate_farguments_required_slot("widget");
466491

492+
#define ue_py_slate_setup_hack_slot_args_grid(_type, _swidget_ref, column, row, layer) _type::FSlot &arguments = _swidget_ref->AddSlot(column, row, layer);\
493+
TArray<TSharedRef<FPythonSlateDelegate>> DeferredSlateDelegates;\
494+
ue_py_slate_farguments_required_slot("widget");
495+
467496
void ue_python_init_slate(PyObject *);
468497

469498

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,16 +1254,23 @@ static PyObject *ue_PyUObject_getattro(ue_PyUObject *self, PyObject *attr_name)
12541254
#endif
12551255
}
12561256
}
1257+
return PyErr_Format(PyExc_Exception, "unknown enum name \"%s\"", attr);
12571258
}
12581259
#endif
12591260
if (self->ue_object->IsA<UEnum>())
12601261
{
12611262
UEnum *u_enum = (UEnum *)self->ue_object;
12621263
PyErr_Clear();
12631264
#if ENGINE_MINOR_VERSION > 15
1264-
return PyLong_FromLong(u_enum->GetIndexByName(FName(UTF8_TO_TCHAR(attr))));
1265+
int32 value = u_enum->GetIndexByName(FName(UTF8_TO_TCHAR(attr)));
1266+
if (value == INDEX_NONE)
1267+
return PyErr_Format(PyExc_Exception, "unknown enum name \"%s\"", attr);
1268+
return PyLong_FromLong(value);
12651269
#else
1266-
return PyLong_FromLong(u_enum->FindEnumIndex(FName(UTF8_TO_TCHAR(attr))));
1270+
int32 value = u_enum->FindEnumIndex(FName(UTF8_TO_TCHAR(attr)));
1271+
if (value == INDEX_NONE)
1272+
return PyErr_Format(PyExc_Exception, "unknown enum name \"%s\"", attr);
1273+
return PyLong_FromLong(value);
12671274
#endif
12681275
}
12691276
}
54.4 KB
Loading
55 KB
Loading
34.5 KB
Loading

0 commit comments

Comments
 (0)