Settings.py 1.3 KB

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