26
$\begingroup$

is it possible to trigger this kind of menu:

enter image description here

in the property panel when I press a hotkey over a button/input field? I want to specifically,when the user presses a specific hotkey when over an input field, call a function that checks if this input field allows divers and if it does to show the user this kind of popup menu (which of course includes own function, etc.).

$\endgroup$
4
  • 5
    $\begingroup$ This is easy except knowing if and what input field is under the cursor. I dont think this can be pulled off since bpy has nothing on this. You would have to somehow compute the position of elements from dpi, area dimensions and how much the panels are scrolled. And I dont think there is access to something like panel scroll amount. There are only some view_to_region and region_to_view functions on view2d of regions. $\endgroup$ Commented Dec 10, 2014 at 17:07
  • $\begingroup$ @Jerryno are you sure about that? I mean the tooltips that appear when you have your mouse cursor over a value come from somewhere and my guess is, that is python. So there should be some callback or something for each value field. If you could find that, you should be able to abuse it, right? $\endgroup$
    – TeeTrinker
    Commented Oct 8, 2017 at 18:05
  • 2
    $\begingroup$ @TeeTrinker What is in those tooltips is defined in python classes, yep. But when, how and where do these tooltips show up is driven internally by Blender. As far as my knowledge goes, it is not exposed to the python api yet. $\endgroup$ Commented Oct 8, 2017 at 18:24
  • 1
    $\begingroup$ For anyone searching for this, you can read this BA thread on workaround using ui.copy_data_path_button (Custom ui operators) $\endgroup$
    – Yudaka
    Commented Nov 5, 2020 at 1:10

1 Answer 1

1
$\begingroup$

I have created this simple menu so you can test it. This will pop up with Y

import bpy

addon_keymaps = {}

class CUSTOM_MT_PANEL(bpy.types.Menu):
    bl_idname = "CUSTOM_MT_PANEL"
    bl_label = "Custom Menu"

    def draw(self, context):
        layout = self.layout.column_flow(columns=1)
        layout.operator_context = "INVOKE_DEFAULT"
        op = layout.operator('mesh.primitive_cube_add', text='Add Cube', icon='CUBE')
        op = layout.operator('mesh.primitive_uv_sphere_add', text='Add Sphere', icon='SPHERE')
        op = layout.operator('mesh.primitive_ico_sphere_add', text='Add Ico Sphere', icon='MESH_ICOSPHERE')
        op = layout.operator('mesh.primitive_torus_add', text='Add Torus', icon='MESH_TORUS')
        op = layout.operator('mesh.primitive_monkey_add', text='Add Monkey', icon='MONKEY')
        layout.menu('SUB_MT_MENU')


class SUB_MT_MENU(bpy.types.Menu):
    bl_idname = "SUB_MT_MENU"
    bl_label = "Curves"

    def draw(self, context):
        layout = self.layout.column_flow(columns=1)
        layout.operator_context = "INVOKE_DEFAULT"
        op = layout.operator('curve.primitive_bezier_curve_add', text='Add Bezier', icon='IPO_BEZIER')
        op = layout.operator('curve.primitive_bezier_circle_add', text='Add Circle', icon='CURVE_NCIRCLE')
        op = layout.operator('curve.primitive_nurbs_path_add', text='Add Path', icon='CURVE_PATH')

def register():
    bpy.utils.register_class(CUSTOM_MT_PANEL)
    bpy.utils.register_class(SUB_MT_MENU)
    kc = bpy.context.window_manager.keyconfigs.addon
    km = kc.keymaps.new(name='3D View', space_type='VIEW_3D')
    kmi = km.keymap_items.new('wm.call_menu', 'Y', 'PRESS')
    kmi.properties.name = 'CUSTOM_MT_PANEL'
    addon_keymaps['EA098'] = (km, kmi)

def unregister():
    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    for km, kmi in addon_keymaps.values():
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()
    bpy.utils.unregister_class(CUSTOM_MT_PANEL)
    bpy.utils.unregister_class(SUB_MT_MENU)
 
if __name__ == "__main__":
    register()
```
$\endgroup$

You must log in to answer this question.

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