1
$\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
$\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')
| improve this answer | |
$\endgroup$
  • $\begingroup$ OK, So i cant use it directly as a class... $\endgroup$ – Leon95 Oct 22 '14 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$ – MostHost LA May 17 '19 at 19:40

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.