[Solved] Disable setting in a popup?

How can I initially disable a setting in a popup? Looks like this should work ,but it doesn’t. You have to toggle the setting first before it becomes disabled.

  col = uiLayoutColumn(split, true);
  uiLayoutSetEnabled(col, false);

  const bool toggle = RNA_enum_get(&ptr, "toggle") == 1;

  if (!toggle) {
    uiLayoutSetEnabled(col, true);
  }
  else {
    uiLayoutSetEnabled(col, false);
  }
  // setting to disable
  uiItemR(col, &ptr, "enum", 0, NULL, ICON_NONE);

Doing something similar in python works in a panel.

col = split.column(align=True)
                                
if not win.toggle:
    col.enabled = True
else:
    col.enabled = False
                                                       
col.prop(win, "enum", text="")

This should work.

    col = uiLayoutColumn(split, true);
    uiLayoutSetEnabled(col, RNA_enum_get(&ptr, "toggle") != 1);

Check what value of “toggle” you have initially.

This still seems to give the same results.

But are you sure that you have the value “toggle” = 1 initially?

I’m sure that when you explicitly set uiLayoutSetEnabled(col, false); it works.

OK, setting as false does work.

col = uiLayoutColumn(split, true);
uiLayoutSetEnabled(col, false);
uiItemR(col, &ptr, "enum", 0, NULL, ICON_NONE);

but this doesn’t

col = uiLayoutColumn(split, true);
uiLayoutSetEnabled(col, RNA_enum_get(&ptr, "toggle") != 1);
uiItemR(col, &ptr, "enum", 0, NULL, ICON_NONE);


/* properties */

RNA_def_boolean(
    ot->srna, "toggle", 1, "Toggle", "Toggle");

Maybe you just need “RNA_boolean_get()”, if it’s a “toggle”.

1 Like

That was the issue. All this time I was using RNA_enum_get and didn’t even realize it.

Aren’t there any warnings in the console that say don’t use enum for boolean ?