def build_shelf(): """ Build the 'mmSolver' shelf. """ LOG.info('Building mmSolver Shelf...') shelf_parent = shelfutils.get_shelves_parent() shelf_name = str(const.SHELF_NAME) shelf = shelfutils.create_shelf(parent=shelf_parent, name=shelf_name) if shelf is None: return # Solver UI name = 'Solver' tooltip = 'Open the MM Solver window.' icon = 'menuIconWindow.png' cmd = ('import mmSolver.tools.solver.tool;' 'mmSolver.tools.solver.tool.open_window();') btn = shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) # Create Menu Pop-Up (for both left mouse button) menu_rmb = shelfutils.create_popup_menu(parent=btn, button=3) _create_solver_menu(menu_rmb) shelfutils.create_shelf_separator(parent=shelf) # Create Marker name = 'Create' tooltip = 'Create Marker.' icon = 'createMarker_32x32.png' cmd = ('import mmSolver.tools.createmarker.tool;' 'mmSolver.tools.createmarker.tool.main();') shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) # Convert to Marker name = 'Convrt' tooltip = 'Convert 3D Transform to Marker.' icon = 'createMarker_32x32.png' cmd = ('import mmSolver.tools.convertmarker.tool;' 'mmSolver.tools.convertmarker.tool.main();') shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) # Load Marker name = 'Load...' tooltip = 'Load Marker.' icon = 'menuIconFile.png' cmd = ('import mmSolver.tools.loadmarker.tool;' 'mmSolver.tools.loadmarker.tool.open_window();') shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) # Create Bundle name = 'Create' tooltip = 'Create Bundle.' icon = 'createBundle_32x32.png' cmd = ('import mmSolver.tools.createbundle.tool;' 'mmSolver.tools.createbundle.tool.main();') shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) shelfutils.create_shelf_separator(parent=shelf) # Marker Tools name = 'MTools' tooltip = 'Marker Tools.' icon = 'createMarker_32x32.png' cmd = 'pass' btn = shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) # Create Menu Pop-Up (for both left and right mouse buttons) menu_lmb = shelfutils.create_popup_menu(parent=btn, button=1) menu_rmb = shelfutils.create_popup_menu(parent=btn, button=3) _create_marker_tools_menu(menu_lmb) _create_marker_tools_menu(menu_rmb) # Bundle Tools name = 'BTools' tooltip = 'Bundle Tools.' icon = 'createBundle_32x32.png' cmd = 'pass' btn = shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) # Create Menu Pop-Up (for both left and right mouse buttons) menu_lmb = shelfutils.create_popup_menu(parent=btn, button=1) menu_rmb = shelfutils.create_popup_menu(parent=btn, button=3) _create_bundle_tools_menu(menu_lmb) _create_bundle_tools_menu(menu_rmb) shelfutils.create_shelf_separator(parent=shelf) # Swap Markers / Bundles name = 'M / B' tooltip = 'Toggle Markers Bundles.' icon = None cmd = ('import mmSolver.tools.selection.tools as selection_tool;' 'selection_tool.swap_between_selected_markers_and_bundles();') shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) # Select Markers and Bundles name = 'M + B' tooltip = 'Select Markers and Bundles.' icon = None cmd = ('import mmSolver.tools.selection.tools as selection_tool;' 'selection_tool.select_both_markers_and_bundles();') shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) # Marker Bundle Rename name = 'MBRena' tooltip = 'Rename Selected Marker And Connected Bundles.' icon = None cmd = ('import mmSolver.tools.markerbundlerename.tool;' 'mmSolver.tools.markerbundlerename.tool.main();') shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) # Marker bundle link and unlink Tools name = 'MBLnk' tooltip = 'Marker bundle link and unlink Tools.' icon = None cmd = 'pass' btn = shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) # Create Menu Pop-Up (for both left and right mouse buttons) menu_lmb = shelfutils.create_popup_menu(parent=btn, button=1) menu_rmb = shelfutils.create_popup_menu(parent=btn, button=3) _create_link_tools_menu(menu_lmb) _create_link_tools_menu(menu_rmb) shelfutils.create_shelf_separator(parent=shelf) # Center 2D on Selected name = 'Center' tooltip = 'Center 2D on Selected.' icon = None cmd = ('import mmSolver.tools.centertwodee.tool;' 'mmSolver.tools.centertwodee.tool.main();') shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) # Channel sensitivity UI name = 'ChSen' tooltip = 'Channel sensitivity UI.' icon = None cmd = ('import mmSolver.tools.channelsen.tool;' 'mmSolver.tools.channelsen.tool.main();') shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) # Smooth Selected Keyframes name = 'Smooth' tooltip = 'Smooth Selected Keyframes.' icon = None cmd = ('import mmSolver.tools.smoothkeyframes.tool;' 'mmSolver.tools.smoothkeyframes.tool.main();') shelfutils.create_shelf_button( parent=shelf, name=name, tooltip=tooltip, icon=icon, cmd=cmd, ) return
def create_item(parents, func_def, is_first_item, is_last_item): """ Create a shelf or menu item with a function definition. :param parents: The list of parent items this item will be created under. :type parents: [str, ..] :param func_def: Function definition. :type func_def: {str: .., ..} :param is_first_item: Will this item be the start of the hierarchy? :type is_first_item: bool :param is_last_item: Will this item be the end of the hierarchy? :type is_last_item: bool :returns: List of items created. :rtype: [{}, ..] """ key_suffix = const.KEY_SUFFIX_SHELF popup = lookup_value(func_def, const.POPUP_KEY, key_suffix) items = [] for parent in parents: if is_first_item: # The first item in a shelf must be a button. key_suffix = const.KEY_SUFFIX_SHELF name = lookup_value(func_def, const.NAME_KEY, key_suffix) icon = lookup_value(func_def, const.ICON_KEY, key_suffix) tooltip = lookup_value(func_def, const.TOOLTIP_KEY, key_suffix) divider = lookup_value(func_def, const.DIVIDER_KEY, key_suffix) cmdLang = lookup_value(func_def, const.CMD_LANG_KEY, key_suffix) command = lookup_value(func_def, const.CMD_KEY, key_suffix) if isinstance(command, (list, tuple)): command = str(os.linesep).join(command) if divider: item = shelf_utils.create_shelf_separator(parent=parent) items.append(item) else: item = shelf_utils.create_shelf_button(parent=parent, name=name, tooltip=tooltip, icon=icon, cmd=command, cmdLanguage=cmdLang) items.append(item) elif is_last_item: # Last item must be a menu item, not a menu or popup menu. key_suffix = const.KEY_SUFFIX_MENU name = lookup_value(func_def, const.NAME_KEY, key_suffix) tooltip = lookup_value(func_def, const.TOOLTIP_KEY, key_suffix) divider = lookup_value(func_def, const.DIVIDER_KEY, key_suffix) popup = lookup_value(func_def, const.POPUP_KEY, key_suffix) cmdLang = lookup_value(func_def, const.CMD_LANG_KEY, key_suffix) command = lookup_value(func_def, const.CMD_KEY, key_suffix) if isinstance(command, (list, tuple)): command = str(os.linesep).join(command) item = menu_utils.create_menu_item( parent=parent, name=name, tooltip=tooltip, cmd=command, cmdLanguage=cmdLang, divider=divider, subMenu=False, ) items.append(item) elif popup: key_suffix = const.KEY_SUFFIX_MENU popupBtn = lookup_value(func_def, const.POPUP_BUTTON_KEY, key_suffix) popupPostCmd = lookup_value(func_def, const.POPUP_POST_CMD_KEY, key_suffix) if isinstance(popupPostCmd, (list, tuple)): popupPostCmd = str(os.linesep).join(popupPostCmd) # Create list of popup buttons, for each button-click used # to open them. popupBtnMap = {'left': 1, 'middle': 2, 'right': 3} popupBtnIndexList = [] if popupBtn is None: popupBtnIndexList = [None] else: assert isinstance(popupBtn, (list, tuple)) assert len(popupBtn) > 0 for btn in popupBtn: index = popupBtnMap.get(btn, None) if index not in popupBtnIndexList: popupBtnIndexList.append(index) # A pop-up menu on top of a shelf button. One menu may be # created for each mouse button needing to be clicked to # activate the pop-up menu.. for index in popupBtnIndexList: item = menu_utils.create_popup_menu(parent=parent, postCmd=popupPostCmd, button=index) items.append(item) else: # A sub-menu entry, a menu item that will contain other menu # items. key_suffix = const.KEY_SUFFIX_MENU name = lookup_value(func_def, const.NAME_KEY, key_suffix) tooltip = lookup_value(func_def, const.TOOLTIP_KEY, key_suffix) divider = lookup_value(func_def, const.DIVIDER_KEY, key_suffix) tearoff = lookup_value(func_def, const.TEAR_OFF_KEY, key_suffix) item = menu_utils.create_menu_item( parent=parent, name=name, tooltip=tooltip, divider=divider, subMenu=True, tearOff=tearoff, ) items.append(item) return items