diff --git a/cura/API/Backups.py b/cura/API/Backups.py index 5964557264..f31933c844 100644 --- a/cura/API/Backups.py +++ b/cura/API/Backups.py @@ -13,6 +13,7 @@ from cura.Backups.BackupsManager import BackupsManager # api = CuraAPI() # api.backups.createBackup() # api.backups.restoreBackup(my_zip_file, {"cura_release": "3.1"})`` + class Backups: manager = BackupsManager() # Re-used instance of the backups manager. diff --git a/cura/API/Sidebar.py b/cura/API/Interface/Settings.py similarity index 56% rename from cura/API/Sidebar.py rename to cura/API/Interface/Settings.py index dd001739f5..2889db7022 100644 --- a/cura/API/Sidebar.py +++ b/cura/API/Interface/Settings.py @@ -3,32 +3,31 @@ from cura.CuraApplication import CuraApplication -## The sidebar context menu API provides a version-proof bridge between Cura's -# Sidebar Context Menu and plug-ins that hook into it. +## The Interface.Settings API provides a version-proof bridge between Cura's +# (currently) sidebar UI and plug-ins that hook into it. # # Usage: # ``from cura.API import CuraAPI # api = CuraAPI() -# api.sidebar.getContextMenuItems() -# menu_actions = [] -# menu_actions.append("sidebarMenuItemOnClickHandler") +# api.interface.settings.getContextMenuItems() # data = { # "name": "My Plugin Action", # "iconName": "my-plugin-icon", -# "actions": menu_actions, +# "actions": my_menu_actions, # "menu_item": MyPluginAction(self) # } -# api.sidebar.addContextMenuItem(data)`` -class Sidebar: +# api.interface.settings.addContextMenuItem(data)`` - _application = CuraApplication.getInstance() # type: CuraApplication +class Settings: + # Re-used instance of Cura: + application = CuraApplication.getInstance() # type: CuraApplication ## Add items to the sidebar context menu. # \param menu_item dict containing the menu item to add. def addContextMenuItem(self, menu_item: dict) -> None: - self._application.addSidebarCustomMenuItem(menu_item) + self.application.addSidebarCustomMenuItem(menu_item) ## Get all custom items currently added to the sidebar context menu. # \return List containing all custom context menu items. def getContextMenuItems(self) -> list: - return self._application.getSidebarCustomMenuItems() \ No newline at end of file + return self.application.getSidebarCustomMenuItems() \ No newline at end of file diff --git a/cura/API/Interface/__init__.py b/cura/API/Interface/__init__.py new file mode 100644 index 0000000000..b38118949b --- /dev/null +++ b/cura/API/Interface/__init__.py @@ -0,0 +1,24 @@ +# Copyright (c) 2018 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + +from UM.PluginRegistry import PluginRegistry +from cura.API.Interface.Settings import Settings + +## The Interface class serves as a common root for the specific API +# methods for each interface element. +# +# Usage: +# ``from cura.API import CuraAPI +# api = CuraAPI() +# api.interface.settings.addContextMenuItem() +# api.interface.viewport.addOverlay() # Not implemented, just a hypothetical +# api.interface.toolbar.getToolButtonCount() # Not implemented, just a hypothetical +# # etc.`` + +class Interface: + + # For now we use the same API version to be consistent. + VERSION = PluginRegistry.APIVersion + + # API methods specific to the settings portion of the UI + settings = Settings() diff --git a/cura/API/__init__.py b/cura/API/__init__.py index 4cd0c9436a..64d636903d 100644 --- a/cura/API/__init__.py +++ b/cura/API/__init__.py @@ -2,7 +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.Sidebar import Sidebar +from cura.API.Interface import Interface ## The official Cura API that plug-ins can use to interact with Cura. # @@ -10,13 +10,14 @@ from cura.API.Sidebar import Sidebar # this API provides a version-safe interface with proper deprecation warnings # etc. Usage of any other methods than the ones provided in this API can cause # plug-ins to be unstable. + class CuraAPI: # For now we use the same API version to be consistent. VERSION = PluginRegistry.APIVersion - # Backups API. + # Backups API backups = Backups() - # Sidebar Context Menu API - sidebar = Sidebar() + # Interface API + interface = Interface()