Skip to content

Commit eeb9caa

Browse files
author
Roberto De Ioris
committed
added preliminary support for python scripts as assets
1 parent 36b140b commit eeb9caa

7 files changed

Lines changed: 116 additions & 6 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "UnrealEnginePythonPrivatePCH.h"
2+
3+
#include "PythonScript.h"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "UnrealEnginePythonPrivatePCH.h"
2+
3+
#include "PythonScriptFactory.h"
4+
5+
UPythonScriptFactory::UPythonScriptFactory(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) {
6+
bCreateNew = true;
7+
bEditAfterNew = true;
8+
SupportedClass = UPythonScript::StaticClass();
9+
}
10+
11+
UObject* UPythonScriptFactory::FactoryCreateNew(UClass * Class, UObject *InParent, FName Name, EObjectFlags Flags, UObject *Context, FFeedbackContext *Warn) {
12+
UPythonScript *NewAsset = NewObject<UPythonScript>(InParent, Class, Name, Flags);
13+
14+
return NewAsset;
15+
}

Source/UnrealEnginePython/Private/Slate/UEPySHeaderRow.cpp

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,70 @@
66

77
#define GET_s_header_row SHeaderRow *s_header_row =(SHeaderRow *)self->s_border.s_compound_widget.s_widget.s_widget
88

9-
static PyObject *ue_PySHeaderRow_str(ue_PySButton *self)
9+
static PyObject *ue_PySHeaderRow_str(ue_PySHeaderRow *self)
1010
{
11-
return PyUnicode_FromFormat("<unreal_engine.SButton '%p'>",
11+
return PyUnicode_FromFormat("<unreal_engine.SHeaderRow '%p'>",
1212
self->s_border.s_compound_widget.s_widget.s_widget);
1313
}
1414

15+
static PyObject *py_ue_sheader_row_add_column(ue_PySHeaderRow *self, PyObject * args, PyObject *kwargs) {
16+
17+
int cell_h_align = 0;
18+
int cell_v_align = 0;
19+
char *column_id;
20+
char *default_label = nullptr;
21+
char *default_tooltip = nullptr;
22+
float fill_width = 0;
23+
24+
25+
char *kwlist[] = {
26+
(char *)"column_id",
27+
(char *)"cell_h_align",
28+
(char *)"cell_v_align",
29+
(char *)"default_label",
30+
(char *)"default_tooltip",
31+
(char *)"fill_width",
32+
nullptr
33+
};
34+
35+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iissf:add_column", kwlist,
36+
&column_id,
37+
&cell_h_align,
38+
&cell_v_align,
39+
&default_label,
40+
&default_tooltip,
41+
&fill_width)) {
42+
return NULL;
43+
}
44+
45+
if (!default_label)
46+
default_label = column_id;
47+
48+
if (!default_tooltip)
49+
default_tooltip = default_label;
50+
51+
auto &column = SHeaderRow::Column(FName(UTF8_TO_TCHAR(column_id)))
52+
.DefaultLabel(FText::FromString(UTF8_TO_TCHAR(default_label)))
53+
.DefaultTooltip(FText::FromString(UTF8_TO_TCHAR(default_tooltip)))
54+
.HAlignCell((EHorizontalAlignment)cell_h_align)
55+
.VAlignCell((EVerticalAlignment)cell_v_align);
56+
57+
if (fill_width)
58+
column.FillWidth(fill_width);
59+
60+
61+
GET_s_header_row;
62+
63+
s_header_row->AddColumn(column);
64+
65+
66+
Py_INCREF(self);
67+
return (PyObject *)self;
68+
}
1569

1670
static PyMethodDef ue_PySHeaderRow_methods[] = {
71+
#pragma warning(suppress: 4191)
72+
{ "add_column", (PyCFunction)py_ue_sheader_row_add_column, METH_VARARGS | METH_KEYWORDS, "" },
1773
{ NULL } /* Sentinel */
1874
};
1975

@@ -54,11 +110,11 @@ static int ue_py_sheader_row_init(ue_PySHeaderRow *self, PyObject *args, PyObjec
54110
}
55111

56112
void ue_python_init_sheader_row(PyObject *ue_module) {
57-
ue_PySButtonType.tp_new = PyType_GenericNew;
113+
ue_PySHeaderRowType.tp_new = PyType_GenericNew;
58114

59-
ue_PySButtonType.tp_init = (initproc)ue_py_sheader_row_init;
115+
ue_PySHeaderRowType.tp_init = (initproc)ue_py_sheader_row_init;
60116

61-
ue_PySButtonType.tp_base = &ue_PySBorderType;
117+
ue_PySHeaderRowType.tp_base = &ue_PySBorderType;
62118

63119
if (PyType_Ready(&ue_PySHeaderRowType) < 0)
64120
return;

Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ TSharedRef<SDockTab> UPythonSlateDelegate::SpawnPythonTab(const FSpawnTabArgs &a
5252
if (!ret) {
5353
unreal_engine_py_log_error();
5454
}
55-
Py_XDECREF(ret);
55+
else {
56+
Py_DECREF(ret);
57+
}
5658
return dock_tab;
5759
}
5860

@@ -124,6 +126,7 @@ void ue_python_init_slate(PyObject *module) {
124126
ue_python_init_sdock_tab(module);
125127
ue_python_init_stable_view_base(module);
126128
ue_python_init_slist_view(module);
129+
ue_python_init_spython_list_view(module);
127130
ue_python_init_ssplitter(module);
128131
ue_python_init_sheader_row(module);
129132

Source/UnrealEnginePython/Private/Slate/UEPySlate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "UEPySDockTab.h"
3535
#include "UEPySTableViewBase.h"
3636
#include "UEPySListView.h"
37+
#include "UEPySPythonListView.h"
3738
#include "UEPySSplitter.h"
3839
#include "UEPySHeaderRow.h"
3940

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
4+
#include "PythonScript.generated.h"
5+
6+
UCLASS()
7+
class UPythonScript : public UObject
8+
{
9+
GENERATED_BODY()
10+
11+
public:
12+
13+
UPROPERTY(EditAnywhere, Category = "Python")
14+
FString PyScript;
15+
16+
UPROPERTY(EditAnywhere, meta=(MultiLine), Category = "Python")
17+
FString PyCode;
18+
};
19+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include "UnrealEd.h"
4+
#include "PythonScriptFactory.generated.h"
5+
6+
UCLASS()
7+
class UPythonScriptFactory : public UFactory
8+
{
9+
GENERATED_UCLASS_BODY()
10+
11+
virtual UObject* FactoryCreateNew(UClass * Class, UObject *InParent, FName Name, EObjectFlags Flags, UObject *Context, FFeedbackContext *Warn) override;
12+
};
13+

0 commit comments

Comments
 (0)