Skip to content

Commit 44f90bd

Browse files
committed
added submenu support, 20tab#603
1 parent 6544d27 commit 44f90bd

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

Source/UnrealEnginePython/Private/Slate/UEPyFMenuBuilder.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,32 @@ static PyObject *py_ue_fmenu_builder_add_menu_entry(ue_PyFMenuBuilder *self, PyO
6363
Py_RETURN_NONE;
6464
}
6565

66+
static PyObject *py_ue_fmenu_builder_add_sub_menu(ue_PyFMenuBuilder *self, PyObject * args)
67+
{
68+
char *label;
69+
char *tooltip;
70+
PyObject *py_callable;
71+
PyObject *py_bool = nullptr;
72+
if (!PyArg_ParseTuple(args, "ssO|O:add_sub_menu", &label, &tooltip, &py_callable, &py_bool))
73+
return nullptr;
74+
75+
if (!PyCallable_Check(py_callable))
76+
{
77+
return PyErr_Format(PyExc_Exception, "argument is not callable");
78+
}
79+
80+
81+
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewStaticSlateDelegate(py_callable);
82+
83+
FNewMenuDelegate menu_delegate;
84+
menu_delegate.BindSP(py_delegate, &FPythonSlateDelegate::SubMenuPyBuilder);
85+
86+
87+
self->menu_builder.AddSubMenu(FText::FromString(UTF8_TO_TCHAR(label)), FText::FromString(UTF8_TO_TCHAR(tooltip)), menu_delegate, (py_bool && PyObject_IsTrue(py_bool)) ? true : false);
88+
89+
Py_RETURN_NONE;
90+
}
91+
6692
static PyObject *py_ue_fmenu_builder_add_menu_separator(ue_PyFMenuBuilder *self, PyObject * args)
6793
{
6894
char *name = nullptr;
@@ -130,6 +156,7 @@ static PyMethodDef ue_PyFMenuBuilder_methods[] = {
130156
{ "add_menu_entry", (PyCFunction)py_ue_fmenu_builder_add_menu_entry, METH_VARARGS, "" },
131157
{ "add_menu_separator", (PyCFunction)py_ue_fmenu_builder_add_menu_separator, METH_VARARGS, "" },
132158
{ "add_search_widget", (PyCFunction)py_ue_fmenu_builder_add_search_widget, METH_VARARGS, "" },
159+
{ "add_sub_menu", (PyCFunction)py_ue_fmenu_builder_add_sub_menu, METH_VARARGS, "" },
133160
#if WITH_EDITOR
134161
{ "add_asset_actions", (PyCFunction)py_ue_fmenu_builder_add_asset_actions, METH_VARARGS, "" },
135162
#endif

Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,20 @@ void FPythonSlateDelegate::MenuPyAssetBuilder(FMenuBuilder &Builder, TArray<FAss
416416
Py_DECREF(ret);
417417
}
418418

419+
420+
void FPythonSlateDelegate::SubMenuPyBuilder(FMenuBuilder &Builder)
421+
{
422+
FScopePythonGIL gil;
423+
424+
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"N", py_ue_new_fmenu_builder(Builder));
425+
if (!ret)
426+
{
427+
unreal_engine_py_log_error();
428+
return;
429+
}
430+
Py_DECREF(ret);
431+
}
432+
419433
TSharedRef<FExtender> FPythonSlateDelegate::OnExtendContentBrowserMenu(const TArray<FAssetData>& SelectedAssets)
420434
{
421435
TSharedRef<FExtender> Extender(new FExtender());
@@ -1321,6 +1335,7 @@ PyObject *py_unreal_engine_add_menu_bar_extension(PyObject * self, PyObject * ar
13211335
if (!PyCallable_Check(py_callable))
13221336
return PyErr_Format(PyExc_Exception, "argument is not callable");
13231337

1338+
13241339
TSharedRef<FPythonSlateCommands> *commands = new TSharedRef<FPythonSlateCommands>(new FPythonSlateCommands());
13251340

13261341
commands->Get().Setup(command_name, py_callable);
@@ -1332,8 +1347,7 @@ PyObject *py_unreal_engine_add_menu_bar_extension(PyObject * self, PyObject * ar
13321347

13331348
ExtensibleModule.GetMenuExtensibilityManager()->AddExtender(extender);
13341349

1335-
Py_INCREF(Py_None);
1336-
return Py_None;
1350+
Py_RETURN_NONE;
13371351
}
13381352

13391353
PyObject *py_unreal_engine_add_tool_bar_extension(PyObject * self, PyObject * args)

Source/UnrealEnginePython/Private/Slate/UEPySlateDelegate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class FPythonSlateDelegate : public FPythonSmartDelegate
4545
void OnAssetSelected(const FAssetData& AssetData);
4646
TSharedRef<FExtender> OnExtendContentBrowserMenu(const TArray<FAssetData> &SelectedAssets);
4747
void MenuPyAssetBuilder(FMenuBuilder &Builder, TArray<FAssetData> SelectedAssets);
48+
void SubMenuPyBuilder(FMenuBuilder &Builder);
4849
void OnAssetChanged(const FAssetData &AssetData);
4950
bool OnShouldFilterAsset(const FAssetData& AssetData);
5051
#endif

Source/UnrealEnginePython/Private/UnrealEnginePython.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,11 @@ void FUnrealEnginePythonModule::StartupModule()
362362

363363
const int32 MaxPathVarLen = 32768;
364364
FString OrigPathVar = FString::ChrN(MaxPathVarLen, TEXT('\0'));
365+
#if ENGINE_MINOR_VERSION >= 21
366+
OrigPathVar = FPlatformMisc::GetEnvironmentVariable(TEXT("PATH"));
367+
#else
365368
FPlatformMisc::GetEnvironmentVariable(TEXT("PATH"), OrigPathVar.GetCharArray().GetData(), MaxPathVarLen);
369+
#endif
366370

367371
// Get the current path and remove elements with python in them, we don't want any conflicts
368372
const TCHAR* PathDelimiter = FPlatformMisc::GetPathVarDelimiter();

0 commit comments

Comments
 (0)