mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 10:09:02 +08:00
Merge branch 'machine-actions-improvement' of github.com:julianCast/Cura
This commit is contained in:
commit
ea16597dd6
@ -33,8 +33,11 @@ class MachineAction(QObject, PluginObject):
|
|||||||
self._qml_url = ""
|
self._qml_url = ""
|
||||||
self._view = None
|
self._view = None
|
||||||
self._finished = False
|
self._finished = False
|
||||||
|
self._open_as_dialog = True
|
||||||
|
self._visible = True
|
||||||
|
|
||||||
labelChanged = pyqtSignal()
|
labelChanged = pyqtSignal()
|
||||||
|
visibilityChanged = pyqtSignal()
|
||||||
onFinished = pyqtSignal()
|
onFinished = pyqtSignal()
|
||||||
|
|
||||||
def getKey(self) -> str:
|
def getKey(self) -> str:
|
||||||
@ -79,6 +82,15 @@ class MachineAction(QObject, PluginObject):
|
|||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def execute(self) -> None:
|
||||||
|
self._execute()
|
||||||
|
|
||||||
|
def _execute(self) -> None:
|
||||||
|
"""Protected implementation of execute."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def setFinished(self) -> None:
|
def setFinished(self) -> None:
|
||||||
self._finished = True
|
self._finished = True
|
||||||
@ -114,3 +126,31 @@ class MachineAction(QObject, PluginObject):
|
|||||||
@pyqtSlot(result = QObject)
|
@pyqtSlot(result = QObject)
|
||||||
def getDisplayItem(self) -> Optional["QObject"]:
|
def getDisplayItem(self) -> Optional["QObject"]:
|
||||||
return self._createViewFromQML()
|
return self._createViewFromQML()
|
||||||
|
|
||||||
|
@pyqtProperty(bool, constant=True)
|
||||||
|
def shouldOpenAsDialog(self) -> bool:
|
||||||
|
"""Whether this action will show a dialog.
|
||||||
|
|
||||||
|
If not, the action will directly run the function inside execute().
|
||||||
|
|
||||||
|
:return: Defaults to true to be in line with the old behaviour.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self._open_as_dialog
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def setVisible(self, visible: bool) -> None:
|
||||||
|
if self._visible != visible:
|
||||||
|
self._visible = visible
|
||||||
|
self.visibilityChanged.emit()
|
||||||
|
|
||||||
|
@pyqtProperty(bool, notify = visibilityChanged)
|
||||||
|
def visible(self) -> bool:
|
||||||
|
"""Whether this action button will be visible.
|
||||||
|
|
||||||
|
Example: Show only when isLoggedIn
|
||||||
|
|
||||||
|
:return: Defaults to true to be in line with the old behaviour.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._visible
|
@ -67,16 +67,21 @@ UM.ManagementPage
|
|||||||
{
|
{
|
||||||
width: Math.round(childrenRect.width + 2 * screenScaleFactor)
|
width: Math.round(childrenRect.width + 2 * screenScaleFactor)
|
||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
|
visible: machineActionRepeater.model[index].visible
|
||||||
Cura.SecondaryButton
|
Cura.SecondaryButton
|
||||||
{
|
{
|
||||||
text: machineActionRepeater.model[index].label
|
text: machineActionRepeater.model[index].label
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
var currentItem = machineActionRepeater.model[index]
|
var currentItem = machineActionRepeater.model[index]
|
||||||
actionDialog.loader.manager = currentItem
|
if (currentItem.shouldOpenAsDialog) {
|
||||||
actionDialog.loader.source = currentItem.qmlPath
|
actionDialog.loader.manager = currentItem
|
||||||
actionDialog.title = currentItem.label
|
actionDialog.loader.source = currentItem.qmlPath
|
||||||
actionDialog.show()
|
actionDialog.title = currentItem.label
|
||||||
|
actionDialog.show()
|
||||||
|
} else {
|
||||||
|
currentItem.execute()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user