Some final tweaks

Contributes to CURA-5595
This commit is contained in:
Ian Paschal 2018-08-10 16:28:02 +02:00
parent 6d237b09e8
commit 16db297613
4 changed files with 40 additions and 15 deletions

View file

@ -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.

View file

@ -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()
return self.application.getSidebarCustomMenuItems()

View file

@ -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()

View file

@ -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()