Settings.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from cura.CuraApplication import CuraApplication
  4. ## The Interface.Settings API provides a version-proof bridge between Cura's
  5. # (currently) sidebar UI and plug-ins that hook into it.
  6. #
  7. # Usage:
  8. # ``from cura.API import CuraAPI
  9. # api = CuraAPI()
  10. # api.interface.settings.getContextMenuItems()
  11. # data = {
  12. # "name": "My Plugin Action",
  13. # "iconName": "my-plugin-icon",
  14. # "actions": my_menu_actions,
  15. # "menu_item": MyPluginAction(self)
  16. # }
  17. # api.interface.settings.addContextMenuItem(data)``
  18. class Settings:
  19. # Re-used instance of Cura:
  20. application = CuraApplication.getInstance() # type: CuraApplication
  21. ## Add items to the sidebar context menu.
  22. # \param menu_item dict containing the menu item to add.
  23. def addContextMenuItem(self, menu_item: dict) -> None:
  24. self.application.addSidebarCustomMenuItem(menu_item)
  25. ## Get all custom items currently added to the sidebar context menu.
  26. # \return List containing all custom context menu items.
  27. def getContextMenuItems(self) -> list:
  28. return self.application.getSidebarCustomMenuItems()