adopt new solution for enumerations and umlauts

This commit is contained in:
Vukas Pajic
2021-12-22 14:00:05 +01:00
parent 67d62e5f21
commit 203a31a2bf
+29 -4
View File
@@ -24,6 +24,7 @@ import ifcopenshell
import ifcopenshell.util.pset import ifcopenshell.util.pset
import blenderbim.bim.handler import blenderbim.bim.handler
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from collections import defaultdict
from bpy.types import PropertyGroup from bpy.types import PropertyGroup
from bpy.props import ( from bpy.props import (
PointerProperty, PointerProperty,
@@ -191,12 +192,36 @@ def update_is_visible(self, context):
pass pass
def getAttributeEnumValues(self, context): def InternStr(s):
if not hasattr(InternStr, "StringCache"): # Another way to define a function attribute
InternStr.StringCache = defaultdict(str)
InternStr.StringCache[s] = s
return InternStr.StringCache[s]
InternStr.StringCache = {}
def getAttributeEnumValues(prop, context):
# Support weird buildingSMART dictionary mappings which behave like enums # Support weird buildingSMART dictionary mappings which behave like enums
data = json.loads(self.enum_items) items = []
data = json.loads(prop.enum_items)
if isinstance(data, dict): if isinstance(data, dict):
return [(str(k), v, "") for k, v in data.items()] for k, v in data.items():
return [(e, e, "") for e in data] for e in data:
items.append((
InternStr(k),
InternStr(v),
"",
))
else:
for e in data:
items.append((
InternStr(e),
InternStr(e),
"",
))
return items
def update_schema_dir(self, context): def update_schema_dir(self, context):