Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken Japanese text in search operator popups #601

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions tools/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2449,12 +2449,16 @@ def is_enum_non_empty(string):
return _empty_enum_identifier != string


def wrap_dynamic_enum_items(items_func, property_name, sort=True, in_place=True):
def wrap_dynamic_enum_items(items_func, property_name, sort=True, in_place=True, is_holder=True):
"""Wrap an EnumProperty items function to automatically fix the property when it goes out of bounds of the items list.
Automatically adds at least one choice if the items function returns an empty list.
By default, sorts the items by the lowercase of the identifiers, this can be disabled by setting sort=False.
Interns and caches all strings in the items to avoid a known Blender UI bug.
Only works for properties whose owner is a scene."""
Only works for properties whose owner is a scene.

By setting is_holder=False, fixing out of bounds values will be disabled and the property_name will be treated as
the unique path to cache items under, this is mainly used for search operators since they are not the owner of the
property."""
def wrapped_items_func(self, context):
nonlocal in_place
items = items_func(self, context)
Expand All @@ -2464,11 +2468,14 @@ def wrapped_items_func(self, context):
# Sorting has already created a new list in this case, so the rest can be done in place
in_place = True
items = _ensure_enum_choices_not_empty(items, in_place=in_place)
property_path = self.path_from_id(property_name)
property_path = self.path_from_id(property_name) if is_holder else property_name
# If ensuring the list wasn't empty wasn't done in place, then a new list has been created and the rest can
# be done in place
items = _ensure_python_references(items, property_path)
return _fix_out_of_bounds_enum_choices(self, context.scene, items, property_name, property_path)
if is_holder:
return _fix_out_of_bounds_enum_choices(self, context.scene, items, property_name, property_path)
else:
return items

return wrapped_items_func

Expand Down
10 changes: 9 additions & 1 deletion ui/bone_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ..tools import rootbone as Rootbone
from ..tools.register import register_wrap
from ..tools.translations import t
from ..tools.common import wrap_dynamic_enum_items


@register_wrap
Expand All @@ -15,7 +16,14 @@ class SearchMenuOperator_root_bone(bpy.types.Operator):
bl_label = ""#t('Scene.root_bone.label')
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name=t('Scene.root_bone.label'),description= t('Scene.root_bone.desc'), items=Rootbone.get_parent_root_bones)
my_enum: bpy.props.EnumProperty(
name=t('Scene.root_bone.label'),
description=t('Scene.root_bone.desc'),
# get_parent_root_bones caches results so the wrapper cannot run in-place
items=wrap_dynamic_enum_items(
Rootbone.get_parent_root_bones, bl_idname, sort=False, in_place=False, is_holder=False
),
)

def execute(self, context):
context.scene.root_bone = self.my_enum
Expand Down
26 changes: 22 additions & 4 deletions ui/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class SearchMenuOperator_merge_armature_into(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name=t('Scene.merge_armature_into.label'), description=t('Scene.merge_armature_into.desc'), items=Common.get_armature_list)
my_enum: bpy.props.EnumProperty(
name=t('Scene.merge_armature_into.label'),
description=t('Scene.merge_armature_into.desc'),
items=Common.wrap_dynamic_enum_items(Common.get_armature_list, bl_idname, is_holder=False),
)

def execute(self, context):
context.scene.merge_armature_into = self.my_enum
Expand All @@ -38,7 +42,11 @@ class SearchMenuOperator_merge_armature(bpy.types.Operator):
bl_label = t('Scene.root_bone.label')
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name=t('Scene.merge_armature.label'), description= t('Scene.merge_armature.desc'), items=Common.get_armature_merge_list)
my_enum: bpy.props.EnumProperty(
name=t('Scene.merge_armature.label'),
description=t('Scene.merge_armature.desc'),
items=Common.wrap_dynamic_enum_items(Common.get_armature_merge_list, bl_idname, is_holder=False),
)

def execute(self, context):
context.scene.merge_armature = self.my_enum
Expand All @@ -57,7 +65,12 @@ class SearchMenuOperator_attach_to_bone(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name=t('Scene.attach_to_bone.label'), description= t('Scene.attach_to_bone.desc'), items=Common.get_bones_merge)
my_enum: bpy.props.EnumProperty(
name=t('Scene.attach_to_bone.label'),
description=
t('Scene.attach_to_bone.desc'),
items=Common.wrap_dynamic_enum_items(Common.get_bones_merge, bl_idname, sort=False, is_holder=False),
)

def execute(self, context):
context.scene.attach_to_bone = self.my_enum
Expand All @@ -76,7 +89,12 @@ class SearchMenuOperator_attach_mesh(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name=t('Scene.attach_mesh.label'), description= t('Scene.attach_mesh.desc'), items=Common.get_top_meshes)
my_enum: bpy.props.EnumProperty(
name=t('Scene.attach_mesh.label'),
description=
t('Scene.attach_mesh.desc'),
items=Common.wrap_dynamic_enum_items(Common.get_top_meshes, bl_idname, is_holder=False),
)

def execute(self, context):
context.scene.attach_mesh = self.my_enum
Expand Down
35 changes: 28 additions & 7 deletions ui/eye_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class SearchMenuOperatorBoneHead(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name="shapekeys", items=Common.get_bones_head)
my_enum: bpy.props.EnumProperty(
name="shapekeys",
items=Common.wrap_dynamic_enum_items(Common.get_bones_head, bl_idname, is_holder=False),
)

def execute(self, context):
context.scene.head = self.my_enum
Expand All @@ -36,7 +39,10 @@ class SearchMenuOperatorBoneEyeLeft(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name="shapekeys", items=Common.get_bones_eye_l)
my_enum: bpy.props.EnumProperty(
name="shapekeys",
items=Common.wrap_dynamic_enum_items(Common.get_bones_eye_l, bl_idname, is_holder=False),
)

def execute(self, context):
context.scene.eye_left = self.my_enum
Expand All @@ -55,7 +61,10 @@ class SearchMenuOperatorBoneEyeRight(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name="shapekeys", items=Common.get_bones_eye_r)
my_enum: bpy.props.EnumProperty(
name="shapekeys",
items=Common.wrap_dynamic_enum_items(Common.get_bones_eye_r, bl_idname, is_holder=False),
)

def execute(self, context):
context.scene.eye_right = self.my_enum
Expand All @@ -74,7 +83,10 @@ class SearchMenuOperatorShapekeyWinkLeft(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name="shapekeys", items=Common.get_shapekeys_eye_blink_l)
my_enum: bpy.props.EnumProperty(
name="shapekeys",
items=Common.wrap_dynamic_enum_items(Common.get_shapekeys_eye_blink_l, bl_idname, sort=False, is_holder=False),
)

def execute(self, context):
context.scene.wink_left = self.my_enum
Expand All @@ -93,7 +105,10 @@ class SearchMenuOperatorShapekeyWinkRight(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name="shapekeys", items=Common.get_shapekeys_eye_blink_r)
my_enum: bpy.props.EnumProperty(
name="shapekeys",
items=Common.wrap_dynamic_enum_items(Common.get_shapekeys_eye_blink_r, bl_idname, sort=False, is_holder=False),
)

def execute(self, context):
context.scene.wink_right = self.my_enum
Expand All @@ -112,7 +127,10 @@ class SearchMenuOperatorShapekeyLowerLidLeft(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name="shapekeys", items=Common.get_shapekeys_eye_low_l)
my_enum: bpy.props.EnumProperty(
name="shapekeys",
items=Common.wrap_dynamic_enum_items(Common.get_shapekeys_eye_low_l, bl_idname, sort=False, is_holder=False),
)

def execute(self, context):
context.scene.lowerlid_left = self.my_enum
Expand All @@ -131,7 +149,10 @@ class SearchMenuOperatorShapekeyLowerLidRight(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name="shapekeys", items=Common.get_shapekeys_eye_low_r)
my_enum: bpy.props.EnumProperty(
name="shapekeys",
items=Common.wrap_dynamic_enum_items(Common.get_shapekeys_eye_low_r, bl_idname, sort=False, is_holder=False),
)

def execute(self, context):
context.scene.lowerlid_right = self.my_enum
Expand Down
18 changes: 15 additions & 3 deletions ui/visemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ class SearchMenuOperatorMouthA(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name="shapekeys", description=t('Scene.mouth_a.desc'), items=Common.get_shapekeys_mouth_ah) #default, change after making operator in UI like shown below.7
my_enum: bpy.props.EnumProperty(
name="shapekeys",
description=t('Scene.mouth_a.desc'),
items=Common.wrap_dynamic_enum_items(Common.get_shapekeys_mouth_ah, bl_idname, sort=False, is_holder=False),
)

def execute(self, context):
context.scene.mouth_a = self.my_enum
Expand All @@ -36,7 +40,11 @@ class SearchMenuOperatorMouthO(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name="shapekeys", description=t('Scene.mouth_o.desc'), items=Common.get_shapekeys_mouth_oh) #default, change after making operator in UI like shown below.7
my_enum: bpy.props.EnumProperty(
name="shapekeys",
description=t('Scene.mouth_o.desc'),
items=Common.wrap_dynamic_enum_items(Common.get_shapekeys_mouth_oh, bl_idname, sort=False, is_holder=False),
)

def execute(self, context):
context.scene.mouth_o = self.my_enum
Expand All @@ -55,7 +63,11 @@ class SearchMenuOperatorMouthCH(bpy.types.Operator):
bl_label = ""
bl_property = "my_enum"

my_enum: bpy.props.EnumProperty(name="shapekeys", description=t('Scene.mouth_ch.desc'), items=Common.get_shapekeys_mouth_ch) #default, change after making operator in UI like shown below.7
my_enum: bpy.props.EnumProperty(
name="shapekeys",
description=t('Scene.mouth_ch.desc'),
items=Common.wrap_dynamic_enum_items(Common.get_shapekeys_mouth_ch, bl_idname, sort=False, is_holder=False),
)

def execute(self, context):
context.scene.mouth_ch = self.my_enum
Expand Down
Loading