I18n: Add translation contexts to properties declared from Python

Some property labels need a context to disambiguate them from others
which have the same name.

The only way to show the proper text currently for such properties is
to override it in the UI code with a translation context, like:

```python
    layout.prop(obj, "area", text="Area",
                context=i18n_contexts.amount)
```

Python properties already store a translation context though, but this
context cannot be chosen from a Python script.

For instance, typing:

```python
bpy.types.Scene.test_area = bpy.props.BoolProperty(name="Area")
print(bpy.context.scene.bl_rna.properties['test_area'].translation_context)
```

will print `*`, the default context for Python props.

This commit allows specifying a context in this manner:

```python
from bpy.app.translations import contexts as i18n_contexts
bpy.types.Scene.test_number_area = bpy.props.BoolProperty(
    name="Area", translation_context=i18n_contexts.amount
)
print(bpy.context.scene.bl_rna.properties['test_number_area'].translation_context)
```

will now print `Amount` and can be translated differently from other
labels. In this instance, the word for a surface area measurement,
instead of a UI area.

-----

This is what translated properties look like using the existing ("Area", "") and ("Area", "Amount") messages:
![python_prop_contexts_test.png](/attachments/b0d9737e-4b31-4c91-a08e-b347db31225f)

The panel can be generated with this script:
[python_prop_contexts_test.py](/attachments/ab613cdc-8eba-46bc-8f3c-ad0a97e7a6e5)

Pull Request: blender/blender#107150
This commit is contained in:
2023-05-22 11:38:51 +02:00
committed by Bastien Montagne
parent a440386654
commit 2decfe4f00

View File

@@ -2628,6 +2628,10 @@ static int bpy_prop_arg_parse_tag_defines(PyObject *o, void *p)
" :arg description: Text used for the tooltip and api documentation.\n" \ " :arg description: Text used for the tooltip and api documentation.\n" \
" :type description: string\n" " :type description: string\n"
#define BPY_PROPDEF_CTXT_DOC \
" :arg translation_context: Text used as context to disambiguate translations.\n" \
" :type translation_context: string\n"
#define BPY_PROPDEF_UNIT_DOC \ #define BPY_PROPDEF_UNIT_DOC \
" :arg unit: Enumerator in :ref:`rna_enum_property_unit_items`.\n" \ " :arg unit: Enumerator in :ref:`rna_enum_property_unit_items`.\n" \
" :type unit: string\n" " :type unit: string\n"
@@ -2746,6 +2750,7 @@ static int bpy_struct_id_used(StructRNA *srna, char *identifier)
PyDoc_STRVAR(BPy_BoolProperty_doc, PyDoc_STRVAR(BPy_BoolProperty_doc,
".. function:: BoolProperty(name=\"\", " ".. function:: BoolProperty(name=\"\", "
"description=\"\", " "description=\"\", "
"translation_context=\"*\", "
"default=False, " "default=False, "
"options={'ANIMATABLE'}, " "options={'ANIMATABLE'}, "
"override=set(), " "override=set(), "
@@ -2756,8 +2761,8 @@ PyDoc_STRVAR(BPy_BoolProperty_doc,
"set=None)\n" "set=None)\n"
"\n" "\n"
" Returns a new boolean property definition.\n" " Returns a new boolean property definition.\n"
"\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_OPTIONS_DOC "\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_CTXT_DOC
BPY_PROPDEF_OPTIONS_OVERRIDE_DOC BPY_PROPDEF_TAGS_DOC BPY_PROPDEF_OPTIONS_DOC BPY_PROPDEF_OPTIONS_OVERRIDE_DOC BPY_PROPDEF_TAGS_DOC
BPY_PROPDEF_SUBTYPE_NUMBER_DOC BPY_PROPDEF_UPDATE_DOC BPY_PROPDEF_GET_DOC BPY_PROPDEF_SUBTYPE_NUMBER_DOC BPY_PROPDEF_UPDATE_DOC BPY_PROPDEF_GET_DOC
BPY_PROPDEF_SET_DOC); BPY_PROPDEF_SET_DOC);
static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw) static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
@@ -2775,6 +2780,7 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
.srna = srna, .srna = srna,
}; };
const char *name = NULL, *description = ""; const char *name = NULL, *description = "";
const char *translation_context = NULL;
bool default_value = false; bool default_value = false;
PropertyRNA *prop; PropertyRNA *prop;
struct BPy_EnumProperty_Parse options_enum = { struct BPy_EnumProperty_Parse options_enum = {
@@ -2801,6 +2807,7 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
"attr", "attr",
"name", "name",
"description", "description",
"translation_context",
"default", "default",
"options", "options",
"override", "override",
@@ -2816,6 +2823,7 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
"|$" /* Optional, keyword only arguments. */ "|$" /* Optional, keyword only arguments. */
"s" /* `name` */ "s" /* `name` */
"s" /* `description` */ "s" /* `description` */
"s" /* `translation_context` */
"O&" /* `default` */ "O&" /* `default` */
"O&" /* `options` */ "O&" /* `options` */
"O&" /* `override` */ "O&" /* `override` */
@@ -2835,6 +2843,7 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
&id_data, &id_data,
&name, &name,
&description, &description,
&translation_context,
PyC_ParseBool, PyC_ParseBool,
&default_value, &default_value,
pyrna_enum_bitfield_parse_set, pyrna_enum_bitfield_parse_set,
@@ -2869,6 +2878,9 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
RNA_def_property_boolean_default(prop, default_value); RNA_def_property_boolean_default(prop, default_value);
RNA_def_property_ui_text(prop, name ? name : id_data.value, description); RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
if (translation_context) {
RNA_def_property_translation_context(prop, translation_context);
}
if (tags_enum.base.is_set) { if (tags_enum.base.is_set) {
RNA_def_property_tags(prop, tags_enum.base.value); RNA_def_property_tags(prop, tags_enum.base.value);
@@ -2890,6 +2902,7 @@ PyDoc_STRVAR(
BPy_BoolVectorProperty_doc, BPy_BoolVectorProperty_doc,
".. function:: BoolVectorProperty(name=\"\", " ".. function:: BoolVectorProperty(name=\"\", "
"description=\"\", " "description=\"\", "
"translation_context=\"*\", "
"default=(False, False, False), " "default=(False, False, False), "
"options={'ANIMATABLE'}, " "options={'ANIMATABLE'}, "
"override=set(), " "override=set(), "
@@ -2901,7 +2914,7 @@ PyDoc_STRVAR(
"set=None)\n" "set=None)\n"
"\n" "\n"
" Returns a new vector boolean property definition.\n" " Returns a new vector boolean property definition.\n"
"\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC "\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_CTXT_DOC
" :arg default: sequence of booleans the length of *size*.\n" " :arg default: sequence of booleans the length of *size*.\n"
" :type default: sequence\n" BPY_PROPDEF_OPTIONS_DOC BPY_PROPDEF_OPTIONS_OVERRIDE_DOC " :type default: sequence\n" BPY_PROPDEF_OPTIONS_DOC BPY_PROPDEF_OPTIONS_OVERRIDE_DOC
BPY_PROPDEF_TAGS_DOC BPY_PROPDEF_SUBTYPE_NUMBER_ARRAY_DOC BPY_PROPDEF_VECSIZE_DOC BPY_PROPDEF_TAGS_DOC BPY_PROPDEF_SUBTYPE_NUMBER_ARRAY_DOC BPY_PROPDEF_VECSIZE_DOC
@@ -2922,6 +2935,7 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
.srna = srna, .srna = srna,
}; };
const char *name = NULL, *description = ""; const char *name = NULL, *description = "";
const char *translation_context = NULL;
bool default_value[RNA_MAX_ARRAY_DIMENSION][PYRNA_STACK_ARRAY] = {{false}}; bool default_value[RNA_MAX_ARRAY_DIMENSION][PYRNA_STACK_ARRAY] = {{false}};
struct BPyPropArrayLength array_len_info = {.len_total = 3}; struct BPyPropArrayLength array_len_info = {.len_total = 3};
PropertyRNA *prop; PropertyRNA *prop;
@@ -2949,6 +2963,7 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
"attr", "attr",
"name", "name",
"description", "description",
"translation_context",
"default", "default",
"options", "options",
"override", "override",
@@ -2965,6 +2980,7 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
"|$" /* Optional, keyword only arguments. */ "|$" /* Optional, keyword only arguments. */
"s" /* `name` */ "s" /* `name` */
"s" /* `description` */ "s" /* `description` */
"s" /* `translation_context` */
"O" /* `default` */ "O" /* `default` */
"O&" /* `options` */ "O&" /* `options` */
"O&" /* `override` */ "O&" /* `override` */
@@ -2985,6 +3001,7 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
&id_data, &id_data,
&name, &name,
&description, &description,
&translation_context,
&default_py, &default_py,
pyrna_enum_bitfield_parse_set, pyrna_enum_bitfield_parse_set,
&options_enum, &options_enum,
@@ -3044,6 +3061,9 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
} }
RNA_def_property_ui_text(prop, name ? name : id_data.value, description); RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
if (translation_context) {
RNA_def_property_translation_context(prop, translation_context);
}
if (tags_enum.base.is_set) { if (tags_enum.base.is_set) {
RNA_def_property_tags(prop, tags_enum.base.value); RNA_def_property_tags(prop, tags_enum.base.value);
@@ -3065,6 +3085,7 @@ PyDoc_STRVAR(
BPy_IntProperty_doc, BPy_IntProperty_doc,
".. function:: IntProperty(name=\"\", " ".. function:: IntProperty(name=\"\", "
"description=\"\", " "description=\"\", "
"translation_context=\"*\", "
"default=0, " "default=0, "
"min=-2**31, max=2**31-1, " "min=-2**31, max=2**31-1, "
"soft_min=-2**31, soft_max=2**31-1, " "soft_min=-2**31, soft_max=2**31-1, "
@@ -3078,7 +3099,7 @@ PyDoc_STRVAR(
"set=None)\n" "set=None)\n"
"\n" "\n"
" Returns a new int property definition.\n" " Returns a new int property definition.\n"
"\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_NUM_MIN_DOC "\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_CTXT_DOC BPY_PROPDEF_NUM_MIN_DOC
" :type min: int\n" BPY_PROPDEF_NUM_MAX_DOC " :type max: int\n" BPY_PROPDEF_NUM_SOFTMAX_DOC " :type min: int\n" BPY_PROPDEF_NUM_MAX_DOC " :type max: int\n" BPY_PROPDEF_NUM_SOFTMAX_DOC
" :type soft_min: int\n" BPY_PROPDEF_NUM_SOFTMIN_DOC " :type soft_min: int\n" BPY_PROPDEF_NUM_SOFTMIN_DOC
" :type soft_max: int\n" BPY_PROPDEF_INT_STEP_DOC BPY_PROPDEF_OPTIONS_DOC " :type soft_max: int\n" BPY_PROPDEF_INT_STEP_DOC BPY_PROPDEF_OPTIONS_DOC
@@ -3099,6 +3120,7 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
.srna = srna, .srna = srna,
}; };
const char *name = NULL, *description = ""; const char *name = NULL, *description = "";
const char *translation_context = NULL;
int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX; int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX;
int step = 1; int step = 1;
int default_value = 0; int default_value = 0;
@@ -3127,6 +3149,7 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
"attr", "attr",
"name", "name",
"description", "description",
"translation_context",
"default", "default",
"min", "min",
"max", "max",
@@ -3147,6 +3170,7 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
"|$" /* Optional, keyword only arguments. */ "|$" /* Optional, keyword only arguments. */
"s" /* `name` */ "s" /* `name` */
"s" /* `description` */ "s" /* `description` */
"s" /* `translation_context` */
"i" /* `default` */ "i" /* `default` */
"i" /* `min` */ "i" /* `min` */
"i" /* `max` */ "i" /* `max` */
@@ -3171,6 +3195,7 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
&id_data, &id_data,
&name, &name,
&description, &description,
&translation_context,
&default_value, &default_value,
&min, &min,
&max, &max,
@@ -3209,6 +3234,9 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
RNA_def_property_int_default(prop, default_value); RNA_def_property_int_default(prop, default_value);
RNA_def_property_ui_text(prop, name ? name : id_data.value, description); RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
if (translation_context) {
RNA_def_property_translation_context(prop, translation_context);
}
RNA_def_property_range(prop, min, max); RNA_def_property_range(prop, min, max);
RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3); RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3);
@@ -3231,6 +3259,7 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
PyDoc_STRVAR(BPy_IntVectorProperty_doc, PyDoc_STRVAR(BPy_IntVectorProperty_doc,
".. function:: IntVectorProperty(name=\"\", " ".. function:: IntVectorProperty(name=\"\", "
"description=\"\", " "description=\"\", "
"translation_context=\"*\", "
"default=(0, 0, 0), min=-2**31, max=2**31-1, " "default=(0, 0, 0), min=-2**31, max=2**31-1, "
"soft_min=-2**31, " "soft_min=-2**31, "
"soft_max=2**31-1, " "soft_max=2**31-1, "
@@ -3245,7 +3274,7 @@ PyDoc_STRVAR(BPy_IntVectorProperty_doc,
"set=None)\n" "set=None)\n"
"\n" "\n"
" Returns a new vector int property definition.\n" " Returns a new vector int property definition.\n"
"\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC "\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_CTXT_DOC
" :arg default: sequence of ints the length of *size*.\n" " :arg default: sequence of ints the length of *size*.\n"
" :type default: sequence\n" BPY_PROPDEF_NUM_MIN_DOC " :type default: sequence\n" BPY_PROPDEF_NUM_MIN_DOC
" :type min: int\n" BPY_PROPDEF_NUM_MAX_DOC " :type min: int\n" BPY_PROPDEF_NUM_MAX_DOC
@@ -3271,6 +3300,7 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
.srna = srna, .srna = srna,
}; };
const char *name = NULL, *description = ""; const char *name = NULL, *description = "";
const char *translation_context = NULL;
int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX; int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX;
int step = 1; int step = 1;
int default_value[RNA_MAX_ARRAY_DIMENSION][PYRNA_STACK_ARRAY] = {0}; int default_value[RNA_MAX_ARRAY_DIMENSION][PYRNA_STACK_ARRAY] = {0};
@@ -3298,30 +3328,18 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
PyObject *set_fn = NULL; PyObject *set_fn = NULL;
static const char *_keywords[] = { static const char *_keywords[] = {
"attr", "attr", "name", "description", "translation_context",
"name", "default", "min", "max", "soft_min",
"description", "soft_max", "step", "options", "override",
"default", "tags", "subtype", "size", "update",
"min", "get", "set", NULL,
"max",
"soft_min",
"soft_max",
"step",
"options",
"override",
"tags",
"subtype",
"size",
"update",
"get",
"set",
NULL,
}; };
static _PyArg_Parser _parser = { static _PyArg_Parser _parser = {
"O&" /* `attr` */ "O&" /* `attr` */
"|$" /* Optional, keyword only arguments. */ "|$" /* Optional, keyword only arguments. */
"s" /* `name` */ "s" /* `name` */
"s" /* `description` */ "s" /* `description` */
"s" /* `translation_context` */
"O" /* `default` */ "O" /* `default` */
"i" /* `min` */ "i" /* `min` */
"i" /* `max` */ "i" /* `max` */
@@ -3347,6 +3365,7 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
&id_data, &id_data,
&name, &name,
&description, &description,
&translation_context,
&default_py, &default_py,
&min, &min,
&max, &max,
@@ -3412,6 +3431,9 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
RNA_def_property_range(prop, min, max); RNA_def_property_range(prop, min, max);
RNA_def_property_ui_text(prop, name ? name : id_data.value, description); RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
if (translation_context) {
RNA_def_property_translation_context(prop, translation_context);
}
RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3); RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3);
if (tags_enum.base.is_set) { if (tags_enum.base.is_set) {
@@ -3433,6 +3455,7 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
PyDoc_STRVAR(BPy_FloatProperty_doc, PyDoc_STRVAR(BPy_FloatProperty_doc,
".. function:: FloatProperty(name=\"\", " ".. function:: FloatProperty(name=\"\", "
"description=\"\", " "description=\"\", "
"translation_context=\"*\", "
"default=0.0, " "default=0.0, "
"min=-3.402823e+38, max=3.402823e+38, " "min=-3.402823e+38, max=3.402823e+38, "
"soft_min=-3.402823e+38, soft_max=3.402823e+38, " "soft_min=-3.402823e+38, soft_max=3.402823e+38, "
@@ -3448,8 +3471,8 @@ PyDoc_STRVAR(BPy_FloatProperty_doc,
"set=None)\n" "set=None)\n"
"\n" "\n"
" Returns a new float (single precision) property definition.\n" " Returns a new float (single precision) property definition.\n"
"\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_NUM_MIN_DOC "\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_CTXT_DOC
" :type min: float\n" BPY_PROPDEF_NUM_MAX_DOC BPY_PROPDEF_NUM_MIN_DOC " :type min: float\n" BPY_PROPDEF_NUM_MAX_DOC
" :type max: float\n" BPY_PROPDEF_NUM_SOFTMIN_DOC " :type max: float\n" BPY_PROPDEF_NUM_SOFTMIN_DOC
" :type soft_min: float\n" BPY_PROPDEF_NUM_SOFTMAX_DOC " :type soft_min: float\n" BPY_PROPDEF_NUM_SOFTMAX_DOC
" :type soft_max: float\n" BPY_PROPDEF_FLOAT_STEP_DOC BPY_PROPDEF_FLOAT_PREC_DOC " :type soft_max: float\n" BPY_PROPDEF_FLOAT_STEP_DOC BPY_PROPDEF_FLOAT_PREC_DOC
@@ -3471,6 +3494,7 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
.srna = srna, .srna = srna,
}; };
const char *name = NULL, *description = ""; const char *name = NULL, *description = "";
const char *translation_context = NULL;
float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX; float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX;
float step = 3; float step = 3;
float default_value = 0.0f; float default_value = 0.0f;
@@ -3502,15 +3526,18 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
PyObject *set_fn = NULL; PyObject *set_fn = NULL;
static const char *_keywords[] = { static const char *_keywords[] = {
"attr", "name", "description", "default", "min", "max", "soft_min", "attr", "name", "description", "translation_context",
"soft_max", "step", "precision", "options", "override", "tags", "subtype", "default", "min", "max", "soft_min",
"unit", "update", "get", "set", NULL, "soft_max", "step", "precision", "options",
"override", "tags", "subtype", "unit",
"update", "get", "set", NULL,
}; };
static _PyArg_Parser _parser = { static _PyArg_Parser _parser = {
"O&" /* `attr` */ "O&" /* `attr` */
"|$" /* Optional, keyword only arguments. */ "|$" /* Optional, keyword only arguments. */
"s" /* `name` */ "s" /* `name` */
"s" /* `description` */ "s" /* `description` */
"s" /* `translation_context` */
"f" /* `default` */ "f" /* `default` */
"f" /* `min` */ "f" /* `min` */
"f" /* `max` */ "f" /* `max` */
@@ -3537,6 +3564,7 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
&id_data, &id_data,
&name, &name,
&description, &description,
&translation_context,
&default_value, &default_value,
&min, &min,
&max, &max,
@@ -3579,6 +3607,9 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
RNA_def_property_float_default(prop, default_value); RNA_def_property_float_default(prop, default_value);
RNA_def_property_range(prop, min, max); RNA_def_property_range(prop, min, max);
RNA_def_property_ui_text(prop, name ? name : id_data.value, description); RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
if (translation_context) {
RNA_def_property_translation_context(prop, translation_context);
}
RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision); RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
if (tags_enum.base.is_set) { if (tags_enum.base.is_set) {
@@ -3600,6 +3631,7 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
PyDoc_STRVAR(BPy_FloatVectorProperty_doc, PyDoc_STRVAR(BPy_FloatVectorProperty_doc,
".. function:: FloatVectorProperty(name=\"\", " ".. function:: FloatVectorProperty(name=\"\", "
"description=\"\", " "description=\"\", "
"translation_context=\"*\", "
"default=(0.0, 0.0, 0.0), " "default=(0.0, 0.0, 0.0), "
"min=sys.float_info.min, max=sys.float_info.max, " "min=sys.float_info.min, max=sys.float_info.max, "
"soft_min=sys.float_info.min, soft_max=sys.float_info.max, " "soft_min=sys.float_info.min, soft_max=sys.float_info.max, "
@@ -3616,7 +3648,7 @@ PyDoc_STRVAR(BPy_FloatVectorProperty_doc,
"set=None)\n" "set=None)\n"
"\n" "\n"
" Returns a new vector float property definition.\n" " Returns a new vector float property definition.\n"
"\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC "\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_CTXT_DOC
" :arg default: sequence of floats the length of *size*.\n" " :arg default: sequence of floats the length of *size*.\n"
" :type default: sequence\n" BPY_PROPDEF_NUM_MIN_DOC " :type default: sequence\n" BPY_PROPDEF_NUM_MIN_DOC
" :type min: float\n" BPY_PROPDEF_NUM_MAX_DOC " :type min: float\n" BPY_PROPDEF_NUM_MAX_DOC
@@ -3643,6 +3675,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
.srna = srna, .srna = srna,
}; };
const char *name = NULL, *description = ""; const char *name = NULL, *description = "";
const char *translation_context = NULL;
float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX; float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX;
float step = 3; float step = 3;
float default_value[RNA_MAX_ARRAY_DIMENSION][PYRNA_STACK_ARRAY] = {{0.0f}}; float default_value[RNA_MAX_ARRAY_DIMENSION][PYRNA_STACK_ARRAY] = {{0.0f}};
@@ -3676,15 +3709,19 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
PyObject *set_fn = NULL; PyObject *set_fn = NULL;
static const char *_keywords[] = { static const char *_keywords[] = {
"attr", "name", "description", "default", "min", "max", "soft_min", "attr", "name", "description", "translation_context",
"soft_max", "step", "precision", "options", "override", "tags", "subtype", "default", "min", "max", "soft_min",
"unit", "size", "update", "get", "set", NULL, "soft_max", "step", "precision", "options",
"override", "tags", "subtype", "unit",
"size", "update", "get", "set",
NULL,
}; };
static _PyArg_Parser _parser = { static _PyArg_Parser _parser = {
"O&" /* `attr` */ "O&" /* `attr` */
"|$" /* Optional, keyword only arguments. */ "|$" /* Optional, keyword only arguments. */
"s" /* `name` */ "s" /* `name` */
"s" /* `description` */ "s" /* `description` */
"s" /* `translation_context` */
"O" /* `default` */ "O" /* `default` */
"f" /* `min` */ "f" /* `min` */
"f" /* `max` */ "f" /* `max` */
@@ -3712,6 +3749,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
&id_data, &id_data,
&name, &name,
&description, &description,
&translation_context,
&default_py, &default_py,
&min, &min,
&max, &max,
@@ -3783,6 +3821,9 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
RNA_def_property_range(prop, min, max); RNA_def_property_range(prop, min, max);
RNA_def_property_ui_text(prop, name ? name : id_data.value, description); RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
if (translation_context) {
RNA_def_property_translation_context(prop, translation_context);
}
RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision); RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
if (tags_enum.base.is_set) { if (tags_enum.base.is_set) {
@@ -3804,6 +3845,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
PyDoc_STRVAR(BPy_StringProperty_doc, PyDoc_STRVAR(BPy_StringProperty_doc,
".. function:: StringProperty(name=\"\", " ".. function:: StringProperty(name=\"\", "
"description=\"\", " "description=\"\", "
"translation_context=\"*\", "
"default=\"\", " "default=\"\", "
"maxlen=0, " "maxlen=0, "
"options={'ANIMATABLE'}, " "options={'ANIMATABLE'}, "
@@ -3817,7 +3859,7 @@ PyDoc_STRVAR(BPy_StringProperty_doc,
"search_options={'SUGGESTION'})\n" "search_options={'SUGGESTION'})\n"
"\n" "\n"
" Returns a new string property definition.\n" " Returns a new string property definition.\n"
"\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC "\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_CTXT_DOC
" :arg default: initializer string.\n" " :arg default: initializer string.\n"
" :type default: string\n" " :type default: string\n"
" :arg maxlen: maximum length of the string.\n" " :arg maxlen: maximum length of the string.\n"
@@ -3838,7 +3880,8 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
struct BPy_PropIDParse id_data = { struct BPy_PropIDParse id_data = {
.srna = srna, .srna = srna,
}; };
const char *name = NULL, *description = "", *default_value = ""; const char *name = NULL, *description = "";
const char *translation_context = NULL, *default_value = "";
int maxlen = 0; int maxlen = 0;
PropertyRNA *prop; PropertyRNA *prop;
@@ -3870,6 +3913,7 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
"attr", "attr",
"name", "name",
"description", "description",
"translation_context",
"default", "default",
"maxlen", "maxlen",
"options", "options",
@@ -3888,6 +3932,7 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
"|$" /* Optional, keyword only arguments. */ "|$" /* Optional, keyword only arguments. */
"s" /* `name` */ "s" /* `name` */
"s" /* `description` */ "s" /* `description` */
"s" /* `translation_context` */
"s" /* `default` */ "s" /* `default` */
"i" /* `maxlen` */ "i" /* `maxlen` */
"O&" /* `options` */ "O&" /* `options` */
@@ -3910,6 +3955,7 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
&id_data, &id_data,
&name, &name,
&description, &description,
&translation_context,
&default_value, &default_value,
&maxlen, &maxlen,
pyrna_enum_bitfield_parse_set, pyrna_enum_bitfield_parse_set,
@@ -3956,6 +4002,9 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
RNA_def_property_string_default(prop, default_value); RNA_def_property_string_default(prop, default_value);
} }
RNA_def_property_ui_text(prop, name ? name : id_data.value, description); RNA_def_property_ui_text(prop, name ? name : id_data.value, description);
if (translation_context) {
RNA_def_property_translation_context(prop, translation_context);
}
if (tags_enum.base.is_set) { if (tags_enum.base.is_set) {
RNA_def_property_tags(prop, tags_enum.base.value); RNA_def_property_tags(prop, tags_enum.base.value);
@@ -3978,6 +4027,7 @@ PyDoc_STRVAR(
".. function:: EnumProperty(items, " ".. function:: EnumProperty(items, "
"name=\"\", " "name=\"\", "
"description=\"\", " "description=\"\", "
"translation_context=\"*\", "
"default=None, " "default=None, "
"options={'ANIMATABLE'}, " "options={'ANIMATABLE'}, "
"override=set(), " "override=set(), "
@@ -4018,7 +4068,7 @@ PyDoc_STRVAR(
" will misbehave or even crash." " will misbehave or even crash."
"\n" "\n"
" :type items: sequence of string tuples or a function\n" BPY_PROPDEF_NAME_DOC " :type items: sequence of string tuples or a function\n" BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_CTXT_DOC
" :arg default: The default value for this enum, a string from the identifiers used in " " :arg default: The default value for this enum, a string from the identifiers used in "
"*items*, or integer matching an item number.\n" "*items*, or integer matching an item number.\n"
" If the *ENUM_FLAG* option is used this must be a set of such string identifiers " " If the *ENUM_FLAG* option is used this must be a set of such string identifiers "
@@ -4043,6 +4093,7 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
.srna = srna, .srna = srna,
}; };
const char *name = NULL, *description = ""; const char *name = NULL, *description = "";
const char *translation_context = NULL;
PyObject *default_py = NULL; PyObject *default_py = NULL;
int default_value = 0; int default_value = 0;
PyObject *items, *items_fast; PyObject *items, *items_fast;
@@ -4070,6 +4121,7 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
"items", "items",
"name", "name",
"description", "description",
"translation_context",
"default", "default",
"options", "options",
"override", "override",
@@ -4085,6 +4137,7 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
"|$" /* Optional, keyword only arguments. */ "|$" /* Optional, keyword only arguments. */
"s" /* `name` */ "s" /* `name` */
"s" /* `description` */ "s" /* `description` */
"s" /* `translation_context` */
"O" /* `default` */ "O" /* `default` */
"O&" /* `options` */ "O&" /* `options` */
"O&" /* `override` */ "O&" /* `override` */
@@ -4104,6 +4157,7 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
&items, &items,
&name, &name,
&description, &description,
&translation_context,
&default_py, &default_py,
pyrna_enum_bitfield_parse_set, pyrna_enum_bitfield_parse_set,
&options_enum, &options_enum,
@@ -4188,6 +4242,9 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
prop = RNA_def_enum( prop = RNA_def_enum(
srna, id_data.value, eitems, default_value, name ? name : id_data.value, description); srna, id_data.value, eitems, default_value, name ? name : id_data.value, description);
} }
if (translation_context) {
RNA_def_property_translation_context(prop, translation_context);
}
if (tags_enum.base.is_set) { if (tags_enum.base.is_set) {
RNA_def_property_tags(prop, tags_enum.base.value); RNA_def_property_tags(prop, tags_enum.base.value);
@@ -4244,6 +4301,7 @@ PyDoc_STRVAR(BPy_PointerProperty_doc,
".. function:: PointerProperty(type=None, " ".. function:: PointerProperty(type=None, "
"name=\"\", " "name=\"\", "
"description=\"\", " "description=\"\", "
"translation_context=\"*\", "
"options={'ANIMATABLE'}, " "options={'ANIMATABLE'}, "
"override=set(), " "override=set(), "
"tags=set(), " "tags=set(), "
@@ -4252,8 +4310,8 @@ PyDoc_STRVAR(BPy_PointerProperty_doc,
"\n" "\n"
" Returns a new pointer property definition.\n" " Returns a new pointer property definition.\n"
"\n" BPY_PROPDEF_POINTER_TYPE_DOC BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC "\n" BPY_PROPDEF_POINTER_TYPE_DOC BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC
BPY_PROPDEF_OPTIONS_DOC BPY_PROPDEF_OPTIONS_OVERRIDE_DOC BPY_PROPDEF_TAGS_DOC BPY_PROPDEF_CTXT_DOC BPY_PROPDEF_OPTIONS_DOC BPY_PROPDEF_OPTIONS_OVERRIDE_DOC
BPY_PROPDEF_POLL_DOC BPY_PROPDEF_UPDATE_DOC); BPY_PROPDEF_TAGS_DOC BPY_PROPDEF_POLL_DOC BPY_PROPDEF_UPDATE_DOC);
PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw) PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
{ {
StructRNA *srna; StructRNA *srna;
@@ -4270,6 +4328,7 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
.srna = srna, .srna = srna,
}; };
const char *name = NULL, *description = ""; const char *name = NULL, *description = "";
const char *translation_context = NULL;
PropertyRNA *prop; PropertyRNA *prop;
StructRNA *ptype; StructRNA *ptype;
PyObject *type = Py_None; PyObject *type = Py_None;
@@ -4292,6 +4351,7 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
"type", "type",
"name", "name",
"description", "description",
"translation_context",
"options", "options",
"override", "override",
"tags", "tags",
@@ -4305,6 +4365,7 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
"|$" /* Optional, keyword only arguments. */ "|$" /* Optional, keyword only arguments. */
"s" /* `name` */ "s" /* `name` */
"s" /* `description` */ "s" /* `description` */
"s" /* `translation_context` */
"O&" /* `options` */ "O&" /* `options` */
"O&" /* `override` */ "O&" /* `override` */
"O&" /* `tags` */ "O&" /* `tags` */
@@ -4322,6 +4383,7 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
&type, &type,
&name, &name,
&description, &description,
&translation_context,
pyrna_enum_bitfield_parse_set, pyrna_enum_bitfield_parse_set,
&options_enum, &options_enum,
pyrna_enum_bitfield_parse_set, pyrna_enum_bitfield_parse_set,
@@ -4357,6 +4419,9 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
} }
prop = RNA_def_pointer_runtime( prop = RNA_def_pointer_runtime(
srna, id_data.value, ptype, name ? name : id_data.value, description); srna, id_data.value, ptype, name ? name : id_data.value, description);
if (translation_context) {
RNA_def_property_translation_context(prop, translation_context);
}
if (tags_enum.base.is_set) { if (tags_enum.base.is_set) {
RNA_def_property_tags(prop, tags_enum.base.value); RNA_def_property_tags(prop, tags_enum.base.value);
@@ -4384,14 +4449,15 @@ PyDoc_STRVAR(BPy_CollectionProperty_doc,
".. function:: CollectionProperty(type=None, " ".. function:: CollectionProperty(type=None, "
"name=\"\", " "name=\"\", "
"description=\"\", " "description=\"\", "
"translation_context=\"*\", "
"options={'ANIMATABLE'}, " "options={'ANIMATABLE'}, "
"override=set(), " "override=set(), "
"tags=set())\n" "tags=set())\n"
"\n" "\n"
" Returns a new collection property definition.\n" " Returns a new collection property definition.\n"
"\n" BPY_PROPDEF_COLLECTION_TYPE_DOC BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC "\n" BPY_PROPDEF_COLLECTION_TYPE_DOC BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC
BPY_PROPDEF_OPTIONS_DOC BPY_PROPDEF_OPTIONS_OVERRIDE_COLLECTION_DOC BPY_PROPDEF_CTXT_DOC BPY_PROPDEF_OPTIONS_DOC
BPY_PROPDEF_TAGS_DOC); BPY_PROPDEF_OPTIONS_OVERRIDE_COLLECTION_DOC BPY_PROPDEF_TAGS_DOC);
PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw) PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
{ {
StructRNA *srna; StructRNA *srna;
@@ -4408,6 +4474,7 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
.srna = srna, .srna = srna,
}; };
const char *name = NULL, *description = ""; const char *name = NULL, *description = "";
const char *translation_context = NULL;
PropertyRNA *prop; PropertyRNA *prop;
StructRNA *ptype; StructRNA *ptype;
PyObject *type = Py_None; PyObject *type = Py_None;
@@ -4429,6 +4496,7 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
"type", "type",
"name", "name",
"description", "description",
"translation_context",
"options", "options",
"override", "override",
"tags", "tags",
@@ -4440,6 +4508,7 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
"|$" /* Optional, keyword only arguments. */ "|$" /* Optional, keyword only arguments. */
"s" /* `name` */ "s" /* `name` */
"s" /* `description` */ "s" /* `description` */
"s" /* `translation_context` */
"O&" /* `options` */ "O&" /* `options` */
"O&" /* `override` */ "O&" /* `override` */
"O&" /* `tags` */ "O&" /* `tags` */
@@ -4455,6 +4524,7 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
&type, &type,
&name, &name,
&description, &description,
&translation_context,
pyrna_enum_bitfield_parse_set, pyrna_enum_bitfield_parse_set,
&options_enum, &options_enum,
pyrna_enum_bitfield_parse_set, pyrna_enum_bitfield_parse_set,
@@ -4482,6 +4552,9 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
} }
prop = RNA_def_collection_runtime( prop = RNA_def_collection_runtime(
srna, id_data.value, ptype, name ? name : id_data.value, description); srna, id_data.value, ptype, name ? name : id_data.value, description);
if (translation_context) {
RNA_def_property_translation_context(prop, translation_context);
}
if (tags_enum.base.is_set) { if (tags_enum.base.is_set) {
RNA_def_property_tags(prop, tags_enum.base.value); RNA_def_property_tags(prop, tags_enum.base.value);