diff --git a/cura/API/SidebarContextMenu.py b/cura/API/SidebarContextMenu.py new file mode 100644 index 0000000000..9c7ad4c4b6 --- /dev/null +++ b/cura/API/SidebarContextMenu.py @@ -0,0 +1,34 @@ +# Copyright (c) 2018 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + +from cura.CuraApplication import CuraApplication + +## The back-ups API provides a version-proof bridge between Cura's +# Sidebar Context Menu and plug-ins that hook into it. +# +# Usage: +# ``from cura.API import CuraAPI +# api = CuraAPI() +# api.sidebar_context_menu.getSidebarMenuItems() +# menu_actions = [] +# menu_actions.append("sidebarMenuItemOnClickHander") +# data = { +# "name": "My Plugin Action", +# "iconName": "my-plugin-icon", +# "actions": menu_actions, +# "menu_item": MyPluginAction(self) +# } +# api.sidebar_context_menu.addSidebarMenuItems([])`` +class SidebarContextMenu: + + _application = CuraApplication.getInstance() # type: CuraApplication + + ## Add items to the sidebar context menu. + # \param menu_item dict containing the menu item to add. + def addSidebarMenuItem(self, menu_items: dict) -> None: + self._application.addSidebarCustomMenuItem(menu_items) + + ## Get all custom items currently added to the sidebar context menu. + # \return List containing all custom context menu items. + def getSidebarMenuItems(self) -> list: + return self._application.getSidebarCustomMenuItems() \ No newline at end of file diff --git a/cura/API/__init__.py b/cura/API/__init__.py index 13f6722336..40c07b8371 100644 --- a/cura/API/__init__.py +++ b/cura/API/__init__.py @@ -2,6 +2,7 @@ # Cura is released under the terms of the LGPLv3 or higher. from UM.PluginRegistry import PluginRegistry from cura.API.Backups import Backups +from cura.API.SidebarContextMenu import SidebarContextMenu ## The official Cura API that plug-ins can use to interact with Cura. # @@ -16,3 +17,6 @@ class CuraAPI: # Backups API. backups = Backups() + + # Sidebar Context Menu API + sidebar_context_menu = SidebarContextMenu()