def main(): print("Creating Menus!") menus = unreal.ToolMenus.get() # Find the 'Main' menu, this should not fail, # but if we're looking for a menu we're unsure about 'if not' # works as nullptr check, main_menu = menus.find_menu("LevelEditor.MainMenu") if not main_menu: print( "Failed to find the 'Main' menu. Something is wrong in the force!") entry = unreal.ToolMenuEntry( name="Python.Tools", # If you pass a type that is not supported Unreal will let you know, type=unreal.MultiBlockType.MENU_ENTRY, # this will tell unreal to insert this entry into the First spot of the menu insert_position=unreal.ToolMenuInsert("", unreal.ToolMenuInsertType.FIRST)) entry.set_label("YourMenuItemName") # this is what gets executed on click entry.set_string_command(unreal.ToolMenuStringCommandType.PYTHON, custom_type='Test', string=("from bitbake import build;build()")) # add a new menu called PyTools to the MainMenu bar. You should probably rename the last 3 properties here to useful things for you script_menu = main_menu.add_sub_menu(main_menu.get_name(), "BitCakeTools", "BitCake", "BitCake") # add our new entry to the new menu script_menu.add_menu_entry("Scripts", entry) # refresh the UI menus.refresh_all_widgets()
def add_action(parent, macro): """Add a macro as an action to the menu :param <menu:parent> The parent menu :param <Macro:macro> The macro to add """ action = None if (program_context in ["designer", "max"]): action = parent.addAction(macro.name) action.triggered.connect(macro.run) elif (program_context == "ue4"): import unreal action = unreal.ToolMenuEntry( name=macro.name, type=unreal.MultiBlockType.MENU_ENTRY, insert_position=unreal.ToolMenuInsert( "", unreal.ToolMenuInsertType.FIRST)) action.set_label(string_utils.snake_to_name(macro.name)) command_string = textwrap.dedent(""" import tools_library.framework.tooling.macro as macro macro.MacroManager.run_macro( "{}", "{}" ) """).format(macro.plugin if macro.plugin else "ToolsLibrary", macro.name) action.set_string_command(unreal.ToolMenuStringCommandType.PYTHON, "None", string=command_string) parent.add_menu_entry("ToolsLibrary", action) return action
def make_uninstall_entry(): entry = unreal.ToolMenuEntry(name='Uninstall Package', type=unreal.MultiBlockType.MENU_ENTRY) entry.set_label('Uninstall nxt package from active python') entry.set_string_command(unreal.ToolMenuStringCommandType.PYTHON, 'Python', string='uninstall_nxt_from_interpreter()') return entry
def make_update_entry(): entry = unreal.ToolMenuEntry(name='Update nxt package', type=unreal.MultiBlockType.MENU_ENTRY) entry.set_label('Update nxt python package') entry.set_string_command(unreal.ToolMenuStringCommandType.PYTHON, 'Python', string='update_installed_nxt()') return entry
def make_open_editor_entry(): entry = unreal.ToolMenuEntry(name='Open Editor', type=unreal.MultiBlockType.MENU_ENTRY) entry.set_label('Open Editor') launch_command = "from nxt_editor.integration.unreal import launch_nxt_in_ue; launch_nxt_in_ue()" entry.set_string_command(unreal.ToolMenuStringCommandType.PYTHON, 'Python', string=launch_command) return entry
def create_python_tool_menu_entry(name, label, command_string="", entry_type=unreal.MultiBlockType.MENU_ENTRY): menu_entry = unreal.ToolMenuEntry(name, type=entry_type) menu_entry.set_label(label) if command_string: menu_entry.set_string_command(unreal.ToolMenuStringCommandType.PYTHON, "python", command_string) return menu_entry
def create_toolbar_combo_button(name, section_name, tool_tip="", register_button=True): # menu_name = ".".join([str(get_toolbar().menu_name),menu]) # section_name = ".".join([str(get_toolbar().menu_name), menu, section]) # get_toolbar().add_section(section_name) # menu_entry_script = EditorToolbarMenuEntry(get_toolbar().menu_name, section_name, name, "", tool_tip, ["EditorStyle", "DetailsView.PulldownArrow.Down", "DetailsView.PulldownArrow.Down"], get_toolbar().menu_name, ["None", unreal.ToolMenuInsertType.DEFAULT], ["None", unreal.MultiBlockType.TOOL_BAR_COMBO_BUTTON, unreal.UserInterfaceActionType.BUTTON, True, True, True, False]) # menu_entry_script.register_menu_entry() menu_entry = unreal.ToolMenuEntry( name, type=unreal.MultiBlockType.TOOL_BAR_COMBO_BUTTON) if register_button: get_toolbar().add_menu_entry(section_name, menu_entry) return menu_entry
def create_separator(name="Separator"): return unreal.ToolMenuEntry(name, type=unreal.MultiBlockType.SEPARATOR)
def create_heading(name): return unreal.ToolMenuEntry(name, type=unreal.MultiBlockType.HEADING)
def create_widget(name): return unreal.ToolMenuEntry(name, type=unreal.MultiBlockType.WIDGET)
def create_editable_text(name, label): menu_entry = unreal.ToolMenuEntry(name, type=unreal.MultiBlockType.EDITABLE_TEXT) menu_entry.set_label(label) return menu_entry
def handle_menu(data): """ handle_menu recursive menu generation """ menu = data.get("menu") if not menu: return for section, config in data.get("section", {}).items(): config = config if isinstance(config, dict) else {"label": config} config.setdefault("label", "untitle") insert = INSERT_TYPE.get(config.get("insert_type", "").upper()) if insert: config["insert_type"] = insert insert_name = config.get("insert_name") config["insert_name"] = insert_name if insert_name else "None" menu.add_section(section, **config) for prop, value in data.get("property", {}).items(): if prop == "menu_owner" or value == "": continue elif prop == "menu_type": value = MENU_TYPE.get(value.upper()) menu.set_editor_property(prop, value) for entry_name, config in data.get("entry", {}).items(): prop = config.get("property", {}) for k, v in prop.items(): prop.pop("owner") if not prop.get("owner") is None else None prop.pop("script_object" ) if not prop.get("script_object") is None else None if v == "": prop.pop(k) elif k == "insert_position": position = INSERT_TYPE.get(v.get("position", "").upper()) v["position"] = (position if position else unreal.ToolMenuInsertType.FIRST) v["name"] = v.get("name", "") prop[k] = unreal.ToolMenuInsert(**v) elif k == "type": typ = ENTRY_TYPE.get(str(v).upper()) prop[k] = typ if typ else unreal.MultiBlockType.MENU_ENTRY elif k == "user_interface_action_type": typ = ACTION_TYPE.get(str(v).upper()) prop.update({k: typ}) if typ else prop.pop(k) prop.setdefault("name", entry_name) prop.setdefault("type", unreal.MultiBlockType.MENU_ENTRY) entry = unreal.ToolMenuEntry(**prop) tooltip = config.get("tooltip") entry.set_tool_tip(tooltip) if tooltip else None entry.set_label(config.get("label", "untitle")) typ = COMMAND_TYPE.get(config.get("type", "").upper(), 0) command = config.get("command", "").format(**FORMAT_ARGS) entry.set_string_command(typ, "", string=command) menu.add_menu_entry(config.get("section", ""), entry) for entry_name, config in data.get("sub_menu", {}).items(): init = config.get("init", {}) owner = menu.get_name() section_name = init.get("section", "") name = init.get("name", entry_name) label = init.get("label", "") tooltip = init.get("tooltip", "") sub_menu = menu.add_sub_menu(owner, section_name, name, label, tooltip) config.setdefault("menu", sub_menu) handle_menu(config)
import unreal import os menus = unreal.ToolMenus.get() menu_name = "LevelEditor.LevelEditorToolBar" menu = menus.find_menu(menu_name) entry = unreal.ToolMenuEntry(type=unreal.MultiBlockType.TOOL_BAR_BUTTON) entry.set_label("BitCake Tools") typ = unreal.ToolMenuStringCommandType.PYTHON with open('{}/bitbaker_ui.py'.format(os.path.dirname(__file__)), 'r') as runwidget: pythoncode = runwidget.read() entry.set_string_command(typ, "", pythoncode) menu.add_menu_entry('File', entry) menus.refresh_all_widgets()