Actions are now added as buttons to machinePages

CURA-1385
This commit is contained in:
Jaime van Kessel 2016-06-20 13:46:05 +02:00
parent 83c1ee8082
commit 8237047907
4 changed files with 29 additions and 8 deletions

View File

@ -387,9 +387,9 @@ class CuraApplication(QtApplication):
self.exec_() self.exec_()
## Get the machine action manager ## Get the machine action manager
# We ignore any **kwargs given to this, as we also register the machine manager as qml singleton. # We ignore any *args given to this, as we also register the machine manager as qml singleton.
# It wants to give this function an engine and script engine, but we don't care about that. # It wants to give this function an engine and script engine, but we don't care about that.
def getMachineActionManager(self, **kwargs): def getMachineActionManager(self, *args):
return self._machine_action_manager return self._machine_action_manager
## Handle Qt events ## Handle Qt events

View File

@ -1,7 +1,7 @@
# Copyright (c) 2016 Ultimaker B.V. # Copyright (c) 2016 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher. # Cura is released under the terms of the AGPLv3 or higher.
from PyQt5.QtCore import QObject, pyqtSlot from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
from UM.PluginObject import PluginObject from UM.PluginObject import PluginObject
@ -11,12 +11,20 @@ class MachineAction(QObject, PluginObject):
self._key = key self._key = key
self._label = label self._label = label
labelChanged = pyqtSignal()
def getKey(self): def getKey(self):
return self._key return self._key
def getLabel(self): @pyqtProperty(str, notify = labelChanged)
def label(self):
return self._label return self._label
def setLabel(self, label):
if self._label != label:
self._label = label
self.labelChanged.emit()
@pyqtSlot() @pyqtSlot()
def execute(self): def execute(self):
self._execute() self._execute()

View File

@ -61,7 +61,7 @@ class MachineActionManager(QObject):
else: else:
self._required_actions[machine_id] = {self._machine_actions[action_key]} self._required_actions[machine_id] = {self._machine_actions[action_key]}
else: else:
raise UnknownMachineAction("Action %s, which is required for %s is not known." % (action_key, machine_id.getKey())) raise UnknownMachineAction("Action %s, which is required for %s is not known." % (action_key, machine_id))
## Add a supported action to a machine. ## Add a supported action to a machine.
def addSupportedAction(self, machine_id, action_key): def addSupportedAction(self, machine_id, action_key):
@ -71,7 +71,7 @@ class MachineActionManager(QObject):
else: else:
self._supported_actions[machine_id] = {self._machine_actions[action_key]} self._supported_actions[machine_id] = {self._machine_actions[action_key]}
else: else:
Logger.log("W", "Unable to add %s to %s, as the action is not recognised", action_key, machine_id.getKey()) Logger.log("w", "Unable to add %s to %s, as the action is not recognised", action_key, machine_id)
## Add an action to the first start list of a machine. ## Add an action to the first start list of a machine.
def addFirstStartAction(self, machine_id, action_key, index = None): def addFirstStartAction(self, machine_id, action_key, index = None):
@ -84,7 +84,7 @@ class MachineActionManager(QObject):
else: else:
self._first_start_actions[machine_id] = [self._machine_actions[action_key]] self._first_start_actions[machine_id] = [self._machine_actions[action_key]]
else: else:
Logger.log("W", "Unable to add %s to %s, as the action is not recognised", action_key, machine_id.getKey()) Logger.log("w", "Unable to add %s to %s, as the action is not recognised", action_key, machine_id)
## Add a (unique) MachineAction ## Add a (unique) MachineAction
# if the Key of the action is not unique, an exception is raised. # if the Key of the action is not unique, an exception is raised.
@ -100,7 +100,7 @@ class MachineActionManager(QObject):
@pyqtSlot(str, result = "QVariantList") @pyqtSlot(str, result = "QVariantList")
def getSupportedActions(self, machine_id): def getSupportedActions(self, machine_id):
if machine_id in self._supported_actions: if machine_id in self._supported_actions:
return self._supported_actions[machine_id] return list(self._supported_actions[machine_id])
else: else:
return set() return set()

View File

@ -41,6 +41,19 @@ UM.ManagementPage
anchors.fill: parent; anchors.fill: parent;
spacing: UM.Theme.getSize("default_margin").height; spacing: UM.Theme.getSize("default_margin").height;
Row
{
Repeater
{
id: machineActionRepeater
model: Cura.MachineActionManager.getSupportedActions(Cura.MachineManager.activeDefinitionId)
Button
{
text: machineActionRepeater.model[index].label;
}
}
}
Label Label
{ {
text: base.currentItem && base.currentItem.name ? base.currentItem.name : "" text: base.currentItem && base.currentItem.name ? base.currentItem.name : ""