Appending to the button toolbox

When you right click over a property in the UI you get the Menu with Add Driver, Copy DataPath etc… It appears to be the BUTTONS_OT_toolbox operator. Is there a way to append to this?

Looking for the same thing, anybody have any ideas?

Thanks,
Randy

These menu items are stored in interface_handlers.c file.

Source code file path:

…\blender\source\blender\editors\interface\interface_handlers.c

But I’m not sure if appending is possible via Python.

Here is a fudge. I have overwritten the view docs operator with one that inserts a single driver and then invokes a popup from which i can select a custom driver…


import bpy
from random import random
from bpy.props import StringProperty

def main(context,channel):
    
    print('Datapath %s channel %s'%(bpy.context.window_manager.clipboard,channel))
    context.object.animation_data.drivers[-1].driver.expression = 'SoundDrive("%s")'%channel

class SimpleOperator2(bpy.types.Operator):
    '''Add Custom Sound Drivers'''
    bl_idname = "simple.operator"
    bl_label = "Add Custom Sound Driver"
    channel = StringProperty(default="Menu")
    @classmethod
    def poll(cls, context):
        return context.active_object is not None
    
    def invoke(self, context, event):
        print(self.channel)
        if self.channel == "Menu":
            print("invoke")
            wm = context.window_manager
            #return wm.invoke_props_dialog(self)           
            return wm.invoke_popup(self)
        else:
            main(context,self.channel)
            return{'RUNNING_MODAL'}

    def draw(self,context):
        self.layout.label("Select Channel")
        
        layout = self.layout
        
        #layout.menu("sounds.channelmenu")
        channels = ["CH!","CH2","CH3"]
        for channel in channels:
            layout.operator("simple.operator",text=channel).channel=channel

                
           
    def execute(self, context):
        print("execute %s"%self.channel)
        if self.channel != 'Menu':
            main(context,self.channel)
        return {'FINISHED'}

class SimpleOperator(bpy.types.Operator):
    '''Add Custom Sound Drivers'''
    bl_idname = "wm.doc_view"
    bl_label = "Add Custom Sound Driver"

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):
        bpy.ops.ui.copy_data_path_button()
        bpy.ops.anim.driver_button_remove(all=False)
        bpy.ops.anim.driver_button_add(all=False)
        return(bpy.ops.simple.operator('INVOKE_DEFAULT'))
        

class SoundDriverMenu(bpy.types.Menu):
    bl_idname = "sounds.channelmenu"
    bl_label = "Chanels"
    
    
    def draw(self,context):
        
        
        
        layout = self.layout
        
        channels = ["CH!","CH2","CH3"]
        for channel in channels:
            layout.operator("simple.operator",text=channel).channel=channel


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

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


    
#bpy.types.OBJECT_PT_context_object.draw = goofer
#bpy.types.OBJECT_PT_transform.draw = goofer
if __name__ == "__main__":
    register()

    # test call
    #bpy.ops.object.simple_operator()

def SoundDrive(channel):
    print("SoundDrive %s"%channel)
    return(random())
    
bpy.app.driver_namespace["SoundDrive"] = SoundDrive    

It would be handy if there was a menu defined here that I could append to, and if there is a way to get the button data_path and index from context that would be handy too.

PS there is still a menu class that is not used… when I tried to use menus I started to get wierd data_path results from the button operators.

you cant - if it was important we could add a way to extend ui_but_menu() with py menu items,
rewriting in py is impractical because this menu inspects the interface in ways not exposed to py yet.

Cheers for that.

The workaround enables me to quickly add custom drivers (in my case i’m using different frequencies from a sound file baked to custom props) to drive any property on the fly… and the menu is the most convenient place for this.

Would it be difficult to extend the menu and maybe add a button_datapath and button_index to the context?

Once again cheers for the reply… IRC and my internet connection don’t play well together.