2
$\begingroup$

I want to use the bpy.types.UIPopupMenu in my addon but it turns out that it can not register.

(Console:UIPopupMenu does not support registration).

Can i use this class for addons? and how is it possible?

class testpopup(bpy.types.UIPopupMenu):
    bl_name = "Name"
    bl_idname = "wm.testpopup"
    bl_label = "Popup Menue Test"

    info = {}
    def draw(self, context):
        layout=self.layout
        colsub=layout.column()
        split = colsub.row().split(percentage=0.15)
        split.label(text="Some")
        split.label(text="layout")
$\endgroup$

1 Answer 1

3
$\begingroup$

You don't need that class, just call bpy.context.window_manager.popup_menu():

import bpy

# only executed if run in operator context EXEC_*
def main(context):
    for ob in context.scene.objects:
        print(ob)

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    @staticmethod
    def draw_func(self, context):
        layout = self.layout

        col = layout.column()
        split = col.split(percentage=0.15)
        split.label(text="Some")
        split.label(text="layout")

    def invoke(self, context, event):
        wm = context.window_manager
        wm.popup_menu(self.draw_func, title="THE TITLE", icon="INFO")
        return {'RUNNING_MODAL'}

    def execute(self, context):
        main(context)
        return {'FINISHED'}


def register():
    bpy.utils.register_class(SimpleOperator)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
    register()

    # test call
    bpy.ops.object.simple_operator('INVOKE_DEFAULT')
$\endgroup$
3
  • $\begingroup$ OK, So i cant use it directly as a class... $\endgroup$
    – Leon95
    Oct 22, 2014 at 23:16
  • $\begingroup$ I agree, this is the most confusing comment ever. "oh you don't need a class, here's a class that does this"... straight from the documentation: Popup menus can be useful for creating menus without having to register menu classes. Note that they will not block the scripts execution, so the caller can’t wait for user input. import bpy def draw(self, context): self.layout.label("Hello World") bpy.context.window_manager.popup_menu(draw, title="Greeting", icon='INFO') $\endgroup$ May 17, 2019 at 19:40
  • $\begingroup$ @MostHostLA The question subclassed the menu itself to try to create a new type of menu. The answer shows that that's not necessary, by calling it from an operator. It's not exactly the same thing. $\endgroup$
    – Will Chen
    Jul 11, 2021 at 12:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .