[Bf-python] How to use "set" callbacks on EnumProperty? GUI no longer updates

Сергей igelbox at gmail.com
Sun Apr 10 01:04:21 CEST 2016


Hello.

>From blender api documentation (
https://www.blender.org/api/blender_python_api_2_77_release/bpy.props.html):
"items (sequence of string tuples or a function) – sequence of enum items
formatted: [(identifier, name, description, "

Try to pass your unique identifiers as first tuple element, e.g.:
    devices = [("unique-device-id-1", "User-friendly device name",""),
               ("unique-device-id-2", "User-friendly device
name","duplicated name"),
    ]
then 'my_settings.device' returns your 'unique-device-id-1' or
'unique-device-id-2' identifiers (not non-unique 'User-friendly device
name')


2016-04-08 6:34 GMT+03:00 Henrique Nunes Jung <henriquenj at gmail.com>:

> Hello bf-python! This is my first time posting on this list.
>
> I working on a plugin for Blender for some time now and I'm having some
> issues when using the EnumProperty object. My objective is to provide a
> drop-down menu for the user where he/she can select a given device from a
> list. I then want to retrieve the currently selected device and perform
> some initialization.
>
> Well I managed to create the menu and populated it with my device list -
> which are strings, basically. But when the user select the device he wants,
> I can only access the string that is currently selected, and not the unique
> identifier of the string (such as an index). This can cause bugs on my
> plugin since I can have two devices with the same name.
>
> One of my attempted solutions is using the "set" callback from the
> EnumProperties, that I can capture the "value" argument and use as an
> index. But there's one problem, as soon as I set a "set" callback function,
> the menu itself stop updating with the selected device, even though I
> receive the right value on my callback.
>
> Here's a sample
>
>         cls.device = EnumProperty(
>                 name="Device",
>                 description="Device to use for rendering",
>                 items=my_devices,
>                 set=set_my_device,
>                 )
>
> def set_my_device(self, value):
>     print("Device index is {0}".format(value))
>     return None
>
>
>
> I do receive the "Device index is X" with the right index, but the user
> interface does not change. I'm following the tutorial available on Property
> documentation [1], my guess is that I'm suppose to do something within the
> callback to get the right option to appear selected on Blender, but I don't
> know what it is.
>
> Attached there's a minimal sample that you can copy and paste into blender
> to reproduce the problem. Button appears on the Render panel, below the
>  render button. I'm testing in 2.76b.
>
> I stuck into this problem for some time and would really appreciate any
> help, or maybe some other solution to get the index from EnumProperty.
>
> Henrique Jung
>
> [1]
> https://www.blender.org/api/blender_python_api_current/bpy.props.html#get-set-example
>
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> https://lists.blender.org/mailman/listinfo/bf-python
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20160410/b5b3ba3b/attachment.html>


More information about the Bf-python mailing list