1
$\begingroup$

Ex. how do I get the name displayed in the UI of this enum? bpy.context.preferences.system.audio_channels

It is returning ex. 'SURROUND51', but I need 5.1 Surround. How do I do that?

$\endgroup$
2
$\begingroup$

From the bl_rna

Will hunt down some links re this and possible dupe, ... tis getting harder and harder to find posts that I'm sure I've seen, even written

Can look up any property definition from its bl_rna .. in this case from the instance

>>> prefs = C.preferences
>>> enum_def = prefs.system.bl_rna.properties["audio_channels"]
>>> for i in enum_def.enum_items:
...     i.name, i.identifier, i.description
...     
('Mono', 'MONO', 'Set audio channels to mono')
('Stereo', 'STEREO', 'Set audio channels to stereo')
('4 Channels', 'SURROUND4', 'Set audio channels to 4 channels')
('5.1 Surround', 'SURROUND51', 'Set audio channels to 5.1 surround sound')
('7.1 Surround', 'SURROUND71', 'Set audio channels to 7.1 surround sound')

for example to make a look up table

>>> lut = {i.identifier : i.name for i in enum_def.enum_items}
>>> prefs.system.audio_channels
'STEREO'

>>> lut[prefs.system.audio_channels]
'Stereo'
$\endgroup$
1
  • $\begingroup$ Oh, wow. Complicated stuff. I'm glad I asked, I would never have found this solution. I wonder if bf devs will accept look-up this in a UI script. Time will show. Thank you. $\endgroup$
    – tintwotin
    Jul 13 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.