Skip to content

Commit 61cb345

Browse files
arturkamienieckimichalpelka
authored andcommitted
Suppport for method tooltips
Signed-off-by: Artur Kamieniecki <[email protected]>
1 parent 3162fc4 commit 61cb345

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

Gems/EditorPythonBindings/Code/Include/EditorPythonBindings/PythonUtility.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,18 @@ namespace EditorPythonBindings
155155

156156
//! Creates a string with class or global method definition and documentation.
157157
AZStd::string MethodDefinition(
158-
const AZStd::string methodName, const AZ::BehaviorMethod& behaviorMethod, const AZ::BehaviorClass* behaviorClass = nullptr);
158+
const AZStd::string methodName,
159+
const AZ::BehaviorMethod& behaviorMethod,
160+
const AZ::BehaviorClass* behaviorClass = nullptr,
161+
bool defineTooltip = false);
159162

160163
//! Creates a string with class definition and documentation.
161164
AZStd::string ClassDefinition(
162165
const AZ::BehaviorClass* behaviorClass,
163166
const AZStd::string className,
164167
bool defineProperties = true,
165-
bool defineMethods = true);
168+
bool defineMethods = true,
169+
bool defineTooltip = false);
166170

167171
//! Creates a property definition
168172
AZStd::string PropertyDefinition(

Gems/EditorPythonBindings/Code/Source/PythonUtility.cpp

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*
77
*/
88

9+
#include "AzCore/Script/ScriptContextAttributes.h"
910
#include <EditorPythonBindings/PythonUtility.h>
1011
#include <Source/PythonMarshalComponent.h>
1112
#include <Source/PythonProxyObject.h>
@@ -779,6 +780,23 @@ namespace EditorPythonBindings
779780
{
780781
namespace Internal
781782
{
783+
AZStd::string ReadStringAttribute(const AZ::AttributeArray& attributes, const AZ::Crc32& attribute)
784+
{
785+
AZStd::string attributeValue = "";
786+
if (auto attributeItem = azrtti_cast<AZ::AttributeData<AZStd::string>*>(AZ::FindAttribute(attribute, attributes)))
787+
{
788+
attributeValue = attributeItem->Get(nullptr);
789+
return attributeValue;
790+
}
791+
792+
if (auto attributeItem = azrtti_cast<AZ::AttributeData<const char*>*>(AZ::FindAttribute(attribute, attributes)))
793+
{
794+
attributeValue = attributeItem->Get(nullptr);
795+
return attributeValue;
796+
}
797+
return {};
798+
}
799+
782800
AZStd::string TypeNameFallback(const AZ::TypeId& typeId)
783801
{
784802
// fall back to class data m_name
@@ -1083,7 +1101,10 @@ namespace EditorPythonBindings
10831101

10841102
//! Creates a string with class or global method definition and documentation.
10851103
AZStd::string PythonBehaviorDescription::MethodDefinition(
1086-
const AZStd::string methodName, const AZ::BehaviorMethod& behaviorMethod, const AZ::BehaviorClass* behaviorClass)
1104+
const AZStd::string methodName,
1105+
const AZ::BehaviorMethod& behaviorMethod,
1106+
const AZ::BehaviorClass* behaviorClass,
1107+
bool defineTooltip)
10871108
{
10881109
AZStd::string buffer;
10891110
AZStd::vector<AZStd::string> pythonArgs;
@@ -1138,13 +1159,27 @@ namespace EditorPythonBindings
11381159
AZStd::string argsList;
11391160
AzFramework::StringFunc::Join(buffer, pythonArgs.begin(), pythonArgs.end(), ",");
11401161
AzFramework::StringFunc::Append(buffer, ") -> None:\n");
1162+
1163+
if (defineTooltip)
1164+
{
1165+
AZStd::string methodTooltip = Internal::ReadStringAttribute(behaviorMethod.m_attributes, AZ::Script::Attributes::ToolTip);
1166+
if (!methodTooltip.empty())
1167+
{
1168+
Internal::AddCommentBlock(indentLevel + 1, methodTooltip, buffer);
1169+
}
1170+
}
1171+
11411172
Internal::Indent(indentLevel + 1, buffer);
11421173
AzFramework::StringFunc::Append(buffer, "pass\n\n");
11431174
return buffer;
11441175
}
11451176

11461177
AZStd::string PythonBehaviorDescription::ClassDefinition(
1147-
const AZ::BehaviorClass* behaviorClass, const AZStd::string className, bool defineProperties, bool defineMethods)
1178+
const AZ::BehaviorClass* behaviorClass,
1179+
const AZStd::string className,
1180+
bool defineProperties,
1181+
bool defineMethods,
1182+
bool defineTooltip)
11481183
{
11491184
AZStd::string buffer;
11501185
AzFramework::StringFunc::Append(buffer, "class ");
@@ -1197,7 +1232,7 @@ namespace EditorPythonBindings
11971232
{
11981233
AZStd::string baseMethodName{ methodEntry.first };
11991234
Scope::FetchScriptName(method->m_attributes, baseMethodName);
1200-
AZStd::string methodDef = MethodDefinition(baseMethodName, *method, behaviorClass);
1235+
AZStd::string methodDef = MethodDefinition(baseMethodName, *method, behaviorClass, defineTooltip);
12011236
AzFramework::StringFunc::Append(buffer, methodDef.c_str());
12021237
}
12031238
}

0 commit comments

Comments
 (0)