1
$\begingroup$

I am trying to make a panel and a menu . But using the same code have different result. I am trying to make a row with 3 operators, The panel Works fine , The menu Dont resize the element and act weird. Here a screenshot and a question about it :::: blenderartists.org/t/layout-error/1279457

I am also trying to set a property in the menu, I thought that that could be done in the same way i did for operators, but no. Here a screenshot and a question about it ::: blenderartists.org/t/using-button-to-set-property-in-operators-menu-panels-b-290/1284432

Thanks for your time

$\endgroup$

1 Answer 1

1
$\begingroup$

1_conscience_0_dimen Answered me a solution. Basically the layout work differently but we can call the menu in this different way to keep the right layout.

He posted me this script that show the behaviour. You can see it in the link above too

import bpy

###Panel 
class PANEL_PT_Menu(bpy.types.Panel):
    bl_label = "panel menu"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "0data"  # to hide it. bl_context = "object" to show it in props   
    bl_options = {'DEFAULT_CLOSED'}

    def draw(self, context):
        layout = self.layout
        layout.label(text="The Menu you want as a panel")

####call as an operator        
class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    
    def execute(self, context):
        bpy.ops.wm.call_panel(name='PANEL_PT_Menu', keep_open=True)
        return {'FINISHED'}         

addon_keymaps = []

def register():
    bpy.utils.register_class(PANEL_PT_Menu)
    bpy.utils.register_class(SimpleOperator)
    
    wm = bpy.context.window_manager

    if wm.keyconfigs.addon: #### call it from a key

        km = wm.keyconfigs.addon.keymaps.new(name = '3D View Generic', space_type = 'VIEW_3D')
        kmi = km.keymap_items.new(idname='wm.call_panel', type='Q', value='PRESS', alt=True)
        kmi.properties.name = "PANEL_PT_Menu"
        addon_keymaps.append((km, kmi)) 

def unregister():
    bpy.utils.unregister_class(PANEL_PT_Menu)
    bpy.utils.unregister_class(SimpleOperator)
    
    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        for km, kmi in addon_keymaps:
            km.keymap_items.remove(kmi)
    addon_keymaps.clear()    

if __name__ == "__main__":
    register()

    # test call
    bpy.ops.object.simple_operator()
$\endgroup$

You must log in to answer this question.

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