[UI] "Pop-up" Operator Allowed in Panel but NOT in Pop-Up Menu?

Hi,

I was planning to have a “pop-up” menu when a button (operator) is pressed.
It’s implemented under two scenario

  1. On a panel (it works): https://bit.ly/3iujw4V
  2. On a pop-up simple menu (it doesn’t). Yes, a pop-up within a pop-up. : https://bit.ly/3ivKLMm

You can see #1 in action here: (expected behavior)

You can see #2 in action here: (i.e. nothign happens. no popup)

The code are exactly the same, as you can see in the link above. With the difference that one is a panel and other pop-up menu.

Is there a way around this?

Credits to Darkfall (Youtube) for the sample code.

Usually you wouldn’t have to, but sometimes you need a

layout.operator_context = 'INVOKE_DEFAULT'

so that the operator’s invoke method is called if it exists. If it doesn’t, it will fall back to the regular execute.

So, the menu draw function needs to look like this:

class SimpleCustomMenu(bpy.types.Menu):
    bl_label = "Simple Custom Menu"
    bl_idname = "OBJECT_MT_simple_custom_menu"

    def draw(self, context):
        layout = self.layout
        layout.operator_context = 'INVOKE_DEFAULT'
        layout.operator("wm.textopbasic", text= "Text Tool", icon= 'OUTLINER_OB_FONT')
1 Like

@iceythe

Works as expected!

Thank you :slight_smile: