Skip to content

Commit c58c342

Browse files
author
Roberto De Ioris
committed
added (still broken) SFilePathPicker
1 parent fa3810b commit c58c342

5 files changed

Lines changed: 135 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#if WITH_EDITOR
2+
#include "UnrealEnginePythonPrivatePCH.h"
3+
4+
#include "UEPySFilePathPicker.h"
5+
6+
#define sw_file_path_picker StaticCastSharedRef<SFilePathPicker>(self->s_compound_widget.s_widget.s_widget)
7+
8+
9+
static PyMethodDef ue_PySFilePathPicker_methods[] = {
10+
{ NULL } /* Sentinel */
11+
};
12+
13+
PyTypeObject ue_PySFilePathPickerType = {
14+
PyVarObject_HEAD_INIT(NULL, 0)
15+
"unreal_engine.SFilePathPicker", /* tp_name */
16+
sizeof(ue_PySFilePathPicker), /* tp_basicsize */
17+
0, /* tp_itemsize */
18+
0, /* tp_dealloc */
19+
0, /* tp_print */
20+
0, /* tp_getattr */
21+
0, /* tp_setattr */
22+
0, /* tp_reserved */
23+
0, /* tp_repr */
24+
0, /* tp_as_number */
25+
0, /* tp_as_sequence */
26+
0, /* tp_as_mapping */
27+
0, /* tp_hash */
28+
0, /* tp_call */
29+
0, /* tp_str */
30+
0, /* tp_getattro */
31+
0, /* tp_setattro */
32+
0, /* tp_as_buffer */
33+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
34+
"Unreal Engine FilePathPicker", /* tp_doc */
35+
0, /* tp_traverse */
36+
0, /* tp_clear */
37+
0, /* tp_richcompare */
38+
0, /* tp_weaklistoffset */
39+
0, /* tp_iter */
40+
0, /* tp_iternext */
41+
ue_PySFilePathPicker_methods, /* tp_methods */
42+
};
43+
44+
static int ue_py_sfile_path_picker_init(ue_PySFilePathPicker *self, PyObject *args, PyObject *kwargs) {
45+
ue_py_slate_setup_farguments(SFilePathPicker);
46+
47+
ue_py_slate_farguments_optional_struct_ptr("browse_button_image", BrowseButtonImage, FSlateBrush);
48+
ue_py_slate_farguments_optional_struct_ptr("browse_button_style", BrowseButtonStyle, FButtonStyle);
49+
ue_py_slate_farguments_text("browse_button_tool_tip", BrowseButtonToolTip);
50+
ue_py_slate_farguments_string("browse_directory", BrowseDirectory);
51+
ue_py_slate_farguments_text("browse_title", BrowseTitle);
52+
ue_py_slate_farguments_string("file_path", FilePath);
53+
ue_py_slate_farguments_string("file_type_filter", FileTypeFilter);
54+
ue_py_slate_farguments_struct("font", Font, FSlateFontInfo);
55+
ue_py_slate_farguments_bool("is_read_only", IsReadOnly);
56+
ue_py_slate_farguments_event("on_path_picked", OnPathPicked, FOnPathPicked, OnStringChanged);
57+
58+
ue_py_snew(SFilePathPicker, s_compound_widget.s_widget);
59+
return 0;
60+
}
61+
62+
void ue_python_init_sfile_path_picker(PyObject *ue_module) {
63+
64+
ue_PySFilePathPickerType.tp_init = (initproc)ue_py_sfile_path_picker_init;
65+
66+
ue_PySFilePathPickerType.tp_base = &ue_PySCompoundWidgetType;
67+
68+
if (PyType_Ready(&ue_PySFilePathPickerType) < 0)
69+
return;
70+
71+
Py_INCREF(&ue_PySFilePathPickerType);
72+
PyModule_AddObject(ue_module, "SFilePathPicker", (PyObject *)&ue_PySFilePathPickerType);
73+
}
74+
#endif
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include "UnrealEnginePython.h"
4+
5+
6+
#include "UEPySCompoundWidget.h"
7+
8+
#include "Developer/DesktopWidgets/Public/Widgets/Input/SFilePathPicker.h"
9+
10+
extern PyTypeObject ue_PySFilePathPickerType;
11+
12+
typedef struct {
13+
ue_PySCompoundWidget s_compound_widget;
14+
/* Type-specific fields go here. */
15+
} ue_PySFilePathPicker;
16+
17+
void ue_python_init_sfile_path_picker(PyObject *);

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ void UPythonSlateDelegate::OnTextChanged(const FText& text) {
7676
Py_DECREF(ret);
7777
}
7878

79+
void UPythonSlateDelegate::OnStringChanged(const FString& text) {
80+
FScopePythonGIL gil;
81+
82+
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"s", TCHAR_TO_UTF8(*text));
83+
if (!ret) {
84+
unreal_engine_py_log_error();
85+
return;
86+
}
87+
Py_DECREF(ret);
88+
}
89+
7990
void UPythonSlateDelegate::OnTextCommitted(const FText& text, ETextCommit::Type commit_type) {
8091
FScopePythonGIL gil;
8192

@@ -229,6 +240,26 @@ FText UPythonSlateDelegate::GetterFText() const {
229240
return text;
230241
}
231242

243+
FString UPythonSlateDelegate::GetterFString() const {
244+
FScopePythonGIL gil;
245+
246+
PyObject *ret = PyObject_CallFunction(py_callable, nullptr);
247+
if (!ret) {
248+
unreal_engine_py_log_error();
249+
return FString();
250+
}
251+
PyObject *str = PyObject_Str(ret);
252+
if (!str) {
253+
unreal_engine_py_log_error();
254+
Py_DECREF(ret);
255+
return FString();
256+
}
257+
258+
FString fstr = UTF8_TO_TCHAR(PyUnicode_AsUTF8(str));
259+
Py_DECREF(str);
260+
Py_DECREF(ret);
261+
return fstr;
262+
}
232263

233264
float UPythonSlateDelegate::GetterFloat() const {
234265
FScopePythonGIL gil;
@@ -505,6 +536,7 @@ void ue_python_init_slate(PyObject *module) {
505536
ue_python_init_spython_editor_viewport(module);
506537
ue_python_init_sgraph_editor(module);
507538
ue_python_init_spython_shelf(module);
539+
ue_python_init_sfile_path_picker(module);
508540
#endif
509541

510542
ue_python_init_ftab_spawner_entry(module);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "UEPySPythonEditorViewport.h"
6161
#include "UEPySGraphEditor.h"
6262
#include "UEPySPythonShelf.h"
63+
#include "UEPySFilePathPicker.h"
6364
#endif
6465

6566
#include "Runtime/Core/Public/Misc/Attribute.h"
@@ -133,6 +134,13 @@ ue_PySWidget *ue_py_get_swidget(TSharedRef<SWidget> s_widget);
133134
ue_py_slate_down(param)
134135

135136

137+
#define ue_py_slate_farguments_string(param, attribute) ue_py_slate_up(FString, GetterFString, param, attribute)\
138+
else if (PyUnicode_Check(value)) {\
139+
arguments.attribute(UTF8_TO_TCHAR(PyUnicode_AsUTF8(value)));\
140+
}\
141+
ue_py_slate_down(param)
142+
143+
136144

137145
#define ue_py_slate_farguments_float(param, attribute) ue_py_slate_up(float, GetterFloat, param, attribute)\
138146
else if (PyNumber_Check(value)) {\
@@ -361,6 +369,8 @@ class UPythonSlateDelegate : public UPythonDelegate
361369
void OnFloatChanged(float value);
362370
void OnFloatCommitted(float value, ETextCommit::Type commit_type);
363371

372+
void OnStringChanged(const FString &text);
373+
364374
TSharedRef<SDockTab> SpawnPythonTab(const FSpawnTabArgs& args);
365375

366376
TSharedRef<ITableRow> GenerateRow(TSharedPtr<FPythonItem> InItem, const TSharedRef<STableViewBase>& OwnerTable);
@@ -378,6 +388,7 @@ class UPythonSlateDelegate : public UPythonDelegate
378388
void ExecuteAction(PyObject *py_obj);
379389

380390
FText GetterFText() const;
391+
FString GetterFString() const;
381392
float GetterFloat() const;
382393
TOptional<float> GetterTFloat() const;
383394
int GetterInt() const;

‎Source/UnrealEnginePython/UnrealEnginePython.Build.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public UnrealEnginePython(TargetInfo Target)
143143
"UMGEditor",
144144
"AIGraph",
145145
"RawMesh",
146+
"DesktopWidgets"
146147
});
147148
}
148149

0 commit comments

Comments
 (0)