Skip to content

Commit 58601f3

Browse files
author
Roberto De Ioris
committed
refactored docktab
1 parent 66430a4 commit 58601f3

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

Source/UnrealEnginePython/Private/Slate/UEPySDockTab.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,9 @@ PyTypeObject ue_PySDockTabType = {
6464
ue_PySDockTab_methods, /* tp_methods */
6565
};
6666

67-
static int ue_py_sdock_tab_init(ue_PySDockTab *self, PyObject *args, PyObject *kwargs) {
68-
int tab_role;
69-
if (!PyArg_ParseTuple(args, "i", &tab_role))
70-
return -1;
71-
self->s_border.s_compound_widget.s_widget.s_widget_owned = SNew(SDockTab).TabRole((ETabRole)tab_role);
72-
self->s_border.s_compound_widget.s_widget.s_widget = &self->s_border.s_compound_widget.s_widget.s_widget_owned.Get();
73-
return 0;
74-
}
75-
7667
void ue_python_init_sdock_tab(PyObject *ue_module) {
7768
ue_PySDockTabType.tp_new = PyType_GenericNew;
7869

79-
ue_PySDockTabType.tp_init = (initproc)ue_py_sdock_tab_init;
80-
8170
ue_PySDockTabType.tp_base = &ue_PySBorderType;
8271

8372
if (PyType_Ready(&ue_PySDockTabType) < 0)

Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "Runtime/Slate/Public/Framework/Commands/UICommandList.h"
77
#include "Runtime/Slate/Public/Framework/Commands/UICommandInfo.h"
88
#include "Runtime/Slate/Public/Framework/Docking/TabManager.h"
9+
#include "Runtime/Slate/Public/Widgets/Views/STableRow.h"
10+
911

1012
#include "UEPySlate.h"
1113

@@ -44,26 +46,29 @@ FReply UPythonSlateDelegate::OnClicked() {
4446
}
4547

4648
TSharedRef<SDockTab> UPythonSlateDelegate::SpawnPythonTab(const FSpawnTabArgs &args) {
47-
PyObject *ret = PyObject_CallFunction(py_callable, nullptr);
49+
TSharedRef<SDockTab> dock_tab = SNew(SDockTab).TabRole(ETabRole::NomadTab);
50+
PyObject *py_dock = (PyObject *)ue_py_get_swidget(dock_tab);
51+
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"O", py_dock);
52+
if (!ret) {
53+
unreal_engine_py_log_error();
54+
}
55+
Py_XDECREF(ret);
56+
return dock_tab;
57+
}
58+
59+
TSharedRef<ITableRow> UPythonSlateDelegate::GenerateWidgetForList(TSharedPtr<PyObject> InItem, const TSharedRef<STableViewBase>& OwnerTable) {
60+
PyObject *ret = PyObject_CallFunction(py_callable, (char*)"O", InItem.Get());
4861
if (!ret) {
4962
unreal_engine_py_log_error();
50-
return SNew(SDockTab).TabRole(ETabRole::NomadTab);
63+
return SNew(STableRow<TSharedPtr<PyObject>>, OwnerTable);
5164
}
5265
ue_PySWidget *s_widget = py_ue_is_swidget(ret);
5366
if (!s_widget) {
5467
UE_LOG(LogPython, Error, TEXT("python callable did not return a SDockTab object"));
55-
return SNew(SDockTab).TabRole(ETabRole::NomadTab);
56-
}
57-
58-
if (s_widget->s_widget_owned->GetType() != FName("SDockTab")) {
59-
UE_LOG(LogPython, Error, TEXT("python callable did not return a SDockTab object"));
60-
return SNew(SDockTab).TabRole(ETabRole::NomadTab);
68+
return SNew(STableRow<TSharedPtr<PyObject>>, OwnerTable);
6169
}
6270

63-
TSharedRef<SDockTab> dock_tab = StaticCastSharedRef<SDockTab>(s_widget->s_widget_owned);
64-
// increase dock reference counting
65-
Py_INCREF(ret);
66-
return dock_tab;
71+
return SNew(STableRow<TSharedPtr<PyObject>>, OwnerTable).Content()[s_widget->s_widget_owned];
6772
}
6873

6974
static std::map<SWidget *, ue_PySWidget *> *py_slate_mapping;
@@ -76,6 +81,9 @@ ue_PySWidget *ue_py_get_swidget(TSharedPtr<SWidget> s_widget) {
7681
if (s_widget->GetType() == FName("SWindow")) {
7782
ret = py_ue_new_swidget<ue_PySWindow>(s_widget.Get(), &ue_PySWindowType);
7883
}
84+
if (s_widget->GetType() == FName("SDockTab")) {
85+
ret = py_ue_new_swidget<ue_PySDockTab>(s_widget.Get(), &ue_PySDockTabType);
86+
}
7987
else {
8088
ret = py_ue_new_swidget<ue_PySWidget>(s_widget.Get(), &ue_PySWidgetType);
8189
}
@@ -114,6 +122,8 @@ void ue_python_init_slate(PyObject *module) {
114122
ue_python_init_spython_editor_viewport(module);
115123
ue_python_init_simage(module);
116124
ue_python_init_sdock_tab(module);
125+
ue_python_init_stable_view_base(module);
126+
ue_python_init_slist_view(module);
117127

118128
ue_python_init_ftab_spawner_entry(module);
119129
}
@@ -234,8 +244,8 @@ PyObject *py_unreal_engine_register_nomad_tab_spawner(PyObject * self, PyObject
234244
py_delegate->AddToRoot();
235245
spawn_tab.BindUObject(py_delegate, &UPythonSlateDelegate::SpawnPythonTab);
236246

237-
UE_LOG(LogPython, Warning, TEXT("SPAWNING !!"));
238-
FTabSpawnerEntry *spawner_entry = &FGlobalTabmanager::Get()->RegisterNomadTabSpawner(UTF8_TO_TCHAR(name), spawn_tab);
247+
FTabSpawnerEntry *spawner_entry = &FGlobalTabmanager::Get()->RegisterNomadTabSpawner(UTF8_TO_TCHAR(name), spawn_tab)
248+
.SetGroup(WorkspaceMenu::GetMenuStructure().GetDeveloperToolsMiscCategory());
239249

240250
PyObject *ret = py_ue_new_ftab_spawner_entry(spawner_entry);
241251
Py_INCREF(ret);

Source/UnrealEnginePython/Private/Slate/UEPySlate.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include "SlateBasics.h"
88
#include "SlateExtras.h"
99

10+
#include "Editor/WorkspaceMenuStructure/Public/WorkspaceMenuStructureModule.h"
11+
#include "Editor/WorkspaceMenuStructure/Public/WorkspaceMenuStructure.h"
12+
#include "Editor/EditorStyle/Public/EditorStyleSet.h"
13+
1014
#include <map>
1115

1216

@@ -28,6 +32,8 @@
2832
#include "UEPySPythonEditorViewport.h"
2933
#include "UEPySImage.h"
3034
#include "UEPySDockTab.h"
35+
#include "UEPySTableViewBase.h"
36+
#include "UEPySListView.h"
3137

3238
#include "UEPyFTabSpawnerEntry.h"
3339

@@ -72,6 +78,8 @@ class UPythonSlateDelegate : public UPythonDelegate
7278
FReply OnClicked();
7379

7480
TSharedRef<SDockTab> SpawnPythonTab(const FSpawnTabArgs& args);
81+
82+
TSharedRef<ITableRow> GenerateWidgetForList(TSharedPtr<PyObject> InItem, const TSharedRef<STableViewBase>& OwnerTable);
7583
};
7684

7785
#endif

0 commit comments

Comments
 (0)