How to set/override the Description of a FloatProperty instance

I’d like my tooltip to be customized, within the following code.


class Float(bpy.types.PropertyGroup):
    value = bpy.props.FloatProperty()
    mandatory = bpy.props.BoolProperty()
    ...
bpy.utils.register_class(Float)
float = bpy.props.PointerProperty(type=Float)
...
layout.prop(float, "value")

But float.value “description” and “doc” attributes are read only, and while layout.prop(float, “value”) can override “text”, it cannot override “description”. Having no setter or override for “description” seems intentional, but unnecessarily constraining.

My intent is to globally enhance the FloatProperty with several properties, but the straightforward approach of…


bpy.types.FloatProperty.mandatory = bpy.props.BoolProperty()

…is not permitted. If it were, I’d customize “description” for each instance of FloatProperty and have my “mandatory” flag.

So, am I overlooking how best to globally associate other properties with FloatProperty, while having a custom tooltip for each instance? Is it appropriate to request that “description” be added as a keyword argument within layout.prop()? Is there some work-around using rna properties (I’ve looked, but haven’t found any because of the no setter policy)?

Thank you,
-Doug

1 Like

This is better asked on IRC directly to the developers. I dunno what reasons they might have against a setter for descriptions.

Thank you. Yes, I found through IRC that it is intentional. Rather than override, the advice was to define the property within the operator specification, or register a new property before defining the operator.

Doug,

You can however change ID properties by changing the _RNA_UI dic.

Here is a silly example, click on the clicker to change the description of scene[“x”]. You can define & change the props akin to a FloatProperty like min , max, etc

The values in the _RNA_UI dic have to be float, int, bool or string.


import bpy

from bpy.props import BoolProperty
class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        
        row = layout.row()
        row.prop(scene, '["x"]')
        row = layout.row()
        row.prop(scene, "clicker", toggle=True)

def register():
    bpy.utils.register_class(HelloWorldPanel)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)

def desc(self, context):
    self["x"] += 1.0
    
    if self["x"] >= 10:
        
        self["_RNA_UI"]["x"]["description"] = "MAXIMUM of 10.0"
    else:
        self["_RNA_UI"]["x"]["description"] = "Value %.2f" % self["x"]


if __name__ == "__main__":
    scene = bpy.context.scene
    scene["x"] = 1.0
    bpy.types.Scene.clicker = BoolProperty(update=desc)
    if "_RNA_UI" not in scene.keys():
        scene["_RNA_UI"] = {}
    scene["_RNA_UI"]["x"] = {"description": "Value: 1.0",
                          "name": "X",
                          "max": 10.0}
    register()