Hi guys, I’m trying to change locale of custom created properties by switching one’s property value. In the giving example I have two enums, and I want to change locale of one enum (simple_enum) by changing value of another enum (lang).
I tried to do this by:
if bpy.context.scene.s_props.lang == '1':
locale = locale_1
else:
locale = locale_2
But it didn’t work.
bl_info = {
"name": "Test",
"author": "",
"version": (0, 0, 0),
"blender": (2, 7, 2),
"location": "Properties > Scene",
"description": "Test",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "3D View"}
import bpy
from bpy.props import (EnumProperty,
PointerProperty,
)
from bpy.types import (PropertyGroup,
Panel,
)
locale_1 = {
'1' : 'locale 1',
'2' : 'locale 1',
'3' : 'locale 1',
}
locale_2 = {
'1' : 'locale 2',
'2' : 'locale 2',
'3' : 'locale 2',
}
if bpy.context.scene.s_props.lang == '1':
locale = locale_1
else:
locale = locale_2
class TestProperties(PropertyGroup):
lang = EnumProperty(
items=(
('1', 'locale 1', ""),
('2', 'locale 2', ""),
),
name='',
default='1')
# Template selector
simple_enum = EnumProperty(
items=(
('1', locale['1'], ""),
('2', locale['2'], ""),
('3', locale['3'], ""),
),
name=locale['1'],
default='1')
class TestPanel(Panel):
bl_label = "Test"
bl_idname = "VIEW3D_PT_test"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "scene"
def draw(self, context):
layout = self.layout
sce = context.scene
s_props = sce.s_props
lang = s_props.lang
if lang == '1':
locale = locale_1
elif lang == '2':
locale = locale_2
col = layout.column()
col.prop(s_props, "lang")
col.prop(s_props, "simple_enum")
classes = [
TestPanel,
TestProperties,
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.s_props = PointerProperty(type=TestProperties)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
del bpy.types.Scene.s_props
if __name__ == "__main__":
register()