Exposed UEnum display name to Python through method get_display_name(). Ex: print(unreal.TextureCompressionSettings.TC_GRAYSCALE.get_display_name())

- Supported reading the enum entry display name set in C++ as well as the one injected from python with the [at]uenum annotation.
  - Added unit tests.

#jira UE-132375 - Add a way for python to get the friendly name of an enum value
#rb Jamie.Dale

#ROBOMERGE-AUTHOR: patrick.laflamme
#ROBOMERGE-SOURCE: CL 18019999 in //UE5/Main/...
#ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v885-17909292)

[CL 18020038 by patrick laflamme in ue5-release-engine-test branch]
This commit is contained in:
patrick laflamme
2021-11-02 11:34:25 -04:00
parent 8212db3c80
commit 87e164b574
3 changed files with 17 additions and 4 deletions

View File

@@ -23,7 +23,7 @@ DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FPyTestMulticastDelegate, FString, I
UENUM(BlueprintType)
enum class EPyTestEnum : uint8
{
One,
One UMETA(DisplayName = "Says One but my value is Zero"),
Two,
};

View File

@@ -8,6 +8,7 @@
#include "PyConversion.h"
#include "Containers/ArrayView.h"
#include "Internationalization/Text.h"
#if WITH_PYTHON
@@ -403,6 +404,17 @@ PyTypeObject InitializePyWrapperEnumType()
UEnum* Enum = FPyWrapperEnumMetaData::GetEnum(InType);
return PyConversion::Pythonize(Enum);
}
static PyObject* GetDisplayName(FPyWrapperEnum* InSelf)
{
if (!FPyWrapperEnum::ValidateInternalState(InSelf))
{
return nullptr;
}
int64 EnumEntryValue = FPyWrapperEnum::GetEnumEntryValue(InSelf);
UEnum* Enum = FPyWrapperEnumMetaData::GetEnum(InSelf);
return PyConversion::Pythonize(Enum->GetDisplayNameTextByValue(EnumEntryValue));
}
};
static PyMemberDef PyMembers[] = {
@@ -414,6 +426,7 @@ PyTypeObject InitializePyWrapperEnumType()
static PyMethodDef PyMethods[] = {
{ "cast", PyCFunctionCast(&FMethods::Cast), METH_VARARGS | METH_CLASS, "X.cast(object) -> enum -- cast the given object to this Unreal enum type" },
{ "static_enum", PyCFunctionCast(&FMethods::StaticEnum), METH_NOARGS | METH_CLASS, "X.static_enum() -> Enum -- get the Unreal enum of this type" },
{ "get_display_name", PyCFunctionCast(&FMethods::GetDisplayName), METH_NOARGS, "X.get_display_name() -> Text -- get the UMETA display name of this type in the current culture" },
{ nullptr, nullptr, 0, nullptr }
};