2
$\begingroup$

There doesn't seem to be a context-sensitive "Specials" menu for the Sequencer(like shortcut key 'w' in 3d View). How do I add one to the Sequencer with python scripting?

(I know about the "Add" menu in the sequencer, and options can be added to this one, but I need a new menu only containing context-sensitive editing options. Ex. if there is a gap between two strips at the mouse cursor position, then a "Remove gap" option would become selectable in the menu.)

This is where I am at the moment(menu containing the add menu options):

import bpy
from bpy.types import Menu

class SEQUENCER_MT_edit(Menu):
    bl_label = "Edit"
    bl_idname = "sequencer.edit_menu"                        # ID name of the class that code will call, lowercase
    def draw(self, context):
        layout = self.layout

        layout.operator_context = 'INVOKE_REGION_WIN'

        layout.operator("sequencer.movie_strip_add", text="Movie") # Example options
        layout.operator("sequencer.image_strip_add", text="Image")
        layout.operator("sequencer.sound_strip_add", text="Sound")

        layout.menu("SEQUENCER_MT_add_effect")

addon_keymaps = []
def register():
    bpy.utils.register_class(SEQUENCER_MT_edit)

    # handle the keymap
    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        km = wm.keyconfigs.addon.keymaps.new(name='Sequencer', space_type='SEQUENCE_EDITOR')
        km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
        kmi = km.keymap_items.new(SEQUENCER_MT_edit.bl_idname, type='RIGHTMOUSE', value='PRESS', shift=True)
        addon_keymaps.append((km, kmi))

def unregister():

    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()

    bpy.utils.unregister_class(SEQUENCER_MT_edit)


if __name__ == "__main__":
    register()
$\endgroup$
-1
$\begingroup$

This seems to be working, however, the cut functions aren't called properly for some reason?

import bpy

class SequencerEditMenu(bpy.types.Menu):
    bl_label = "Specials"
    bl_idname = "SEQUENCER_OT_sequencer_edit_menu"

    def draw(self, context):

        if context.space_data.type == 'SEQUENCE_EDITOR':

            layout = self.layout
            layout.operator("sequencer.gap_remove").all = False
            layout.operator("sequencer.gap_insert")
            layout.separator()
            props = layout.operator("sequencer.strip_jump", text="Jump to Previous Strip")
            props.next = False
            props.center = False
            props = layout.operator("sequencer.strip_jump", text="Jump to Next Strip")
            props.next = True
            props.center = False            
            layout.separator()            
            layout.operator("transform.transform", text="Grab/Move").mode = 'TRANSLATION'
            layout.operator("transform.transform", text="Grab/Extend from Frame").mode = 'TIME_EXTEND'
            layout.operator("sequencer.slip", text="Slip Strip Contents")            
            layout.separator()
            layout.operator("sequencer.cut", text="Cut (Hard) at frame").type = 'HARD'
            layout.operator("sequencer.cut", text="Cut (Soft) at frame").type = 'SOFT'           

addon_keymaps = []
def register():
    bpy.utils.register_class(SequencerEditMenu)

    # handle the keymap
    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:    
        km = wm.keyconfigs.addon.keymaps.new(name='Sequencer', space_type='SEQUENCE_EDITOR')
        kmi = km.keymap_items.new('wm.call_menu', 'W', 'PRESS')
        kmi.properties.name = "SEQUENCER_OT_sequencer_edit_menu"    
        addon_keymaps.append((km, kmi))

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

    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()

if __name__ == "__main__":
    register()
$\endgroup$
1
  • $\begingroup$ Why the down-vote? $\endgroup$
    – tintwotin
    Jan 4 '18 at 11:25

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.