Settings.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. ## The Interface.Settings API provides a version-proof bridge between Cura's
  7. # (currently) sidebar UI and plug-ins that hook into it.
  8. #
  9. # Usage:
  10. # ``from cura.API import CuraAPI
  11. # api = CuraAPI()
  12. # api.interface.settings.getContextMenuItems()
  13. # data = {
  14. # "name": "My Plugin Action",
  15. # "iconName": "my-plugin-icon",
  16. # "actions": my_menu_actions,
  17. # "menu_item": MyPluginAction(self)
  18. # }
  19. # api.interface.settings.addContextMenuItem(data)``
  20. class Settings:
  21. def __init__(self, application: "CuraApplication") -> None:
  22. self.application = application
  23. ## Add items to the sidebar context menu.
  24. # \param menu_item dict containing the menu item to add.
  25. def addContextMenuItem(self, menu_item: dict) -> None:
  26. self.application.addSidebarCustomMenuItem(menu_item)
  27. ## Get all custom items currently added to the sidebar context menu.
  28. # \return List containing all custom context menu items.
  29. def getContextMenuItems(self) -> list:
  30. return self.application.getSidebarCustomMenuItems()