Added machine action dialog optional

Based on this change, users will be able to run their machine action plugins code just by clicking the action button, so without having to open a modal.
This commit is contained in:
Julian 2022-09-07 16:32:58 +02:00
parent ed14e3bd44
commit 75840426d7
2 changed files with 29 additions and 4 deletions

View File

@ -33,6 +33,7 @@ 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
labelChanged = pyqtSignal() labelChanged = pyqtSignal()
onFinished = pyqtSignal() onFinished = pyqtSignal()
@ -79,6 +80,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
@ -115,6 +125,17 @@ class MachineAction(QObject, PluginObject):
def getDisplayItem(self) -> Optional["QObject"]: def getDisplayItem(self) -> Optional["QObject"]:
return self._createViewFromQML() return self._createViewFromQML()
@pyqtSlot(result = bool)
def openAsDialog(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(result = bool) @pyqtSlot(result = bool)
def isVisible(self) -> bool: def isVisible(self) -> bool:
"""Whether this action button will be visible. """Whether this action button will be visible.

View File

@ -74,10 +74,14 @@ UM.ManagementPage
onClicked: onClicked:
{ {
var currentItem = machineActionRepeater.model[index] var currentItem = machineActionRepeater.model[index]
actionDialog.loader.manager = currentItem if (currentItem.openAsDialog()) {
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()
}
} }
} }
} }