From 3aec8b15ef148967804da0d73fc993cf0ac5add3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 11 Mar 2024 14:32:29 +0100 Subject: [PATCH] Add-on: avoid console spam about the scene's job type property Avoid these warnings on the console: ``` WARN (bpy.rna): source/blender/python/intern/bpy_rna.cc:1339 pyrna_enum_to_py: current value '0' matches no enum in 'Scene', 'Scene', 'flamenco_job_type' ``` The solution was two-fold: - Use a non-empty string as the identifier for the 'Select a Job Type' choice. - Give the property a default value. --- addon/flamenco/job_types.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/addon/flamenco/job_types.py b/addon/flamenco/job_types.py index 233c149c..0b89c70d 100644 --- a/addon/flamenco/job_types.py +++ b/addon/flamenco/job_types.py @@ -25,10 +25,22 @@ else: _available_job_types: Optional[list[_AvailableJobType]] = None +# Enum property value that indicates 'no job type selected'. This is used +# because an empty string seems to be handled by Blender as 'nothing', which +# never seems to match an enum item even when there is one with "" as its 'key'. +_JOB_TYPE_NOT_SELECTED = "-" +_JOB_TYPE_NOT_SELECTED_ENUM_ITEM = ( + _JOB_TYPE_NOT_SELECTED, + "Select a Job Type", + "", + 0, + 0, +) + # Items for a bpy.props.EnumProperty() _job_type_enum_items: list[ Union[tuple[str, str, str], tuple[str, str, str, int, int]] -] = [] +] = [_JOB_TYPE_NOT_SELECTED_ENUM_ITEM] _selected_job_type_propgroup: Optional[ type[job_types_propgroup.JobTypePropertyGroup] @@ -106,7 +118,7 @@ def _store_available_job_types(available_job_types: _AvailableJobTypes) -> None: _job_type_enum_items = [ (job_type.name, job_type.label, "") for job_type in job_types ] - _job_type_enum_items.insert(0, ("", "Select a Job Type", "", 0, 0)) + _job_type_enum_items.insert(0, _JOB_TYPE_NOT_SELECTED_ENUM_ITEM) def are_job_types_available() -> bool: @@ -215,6 +227,7 @@ def discard_flamenco_data(): def register() -> None: bpy.types.Scene.flamenco_job_type = bpy.props.EnumProperty( name="Job Type", + default=0, items=_get_job_types_enum_items, update=_update_job_type, )