From ed14e3bd44890ff15406f7f53c7199f3fa6018e6 Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 7 Sep 2022 16:29:55 +0200 Subject: [PATCH 1/3] Added machine action buttons dynamic visibility Based on this change, users now will be able to manage the visibility of their machine action plugin implementations. For example, a machine action only visible when loggedIn. --- cura/MachineAction.py | 12 ++++++++++++ resources/qml/Preferences/MachinesPage.qml | 1 + 2 files changed, 13 insertions(+) diff --git a/cura/MachineAction.py b/cura/MachineAction.py index c38be5261f..98e156d834 100644 --- a/cura/MachineAction.py +++ b/cura/MachineAction.py @@ -114,3 +114,15 @@ class MachineAction(QObject, PluginObject): @pyqtSlot(result = QObject) def getDisplayItem(self) -> Optional["QObject"]: return self._createViewFromQML() + + @pyqtSlot(result = bool) + def isVisible(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. + """ + + return True + \ No newline at end of file diff --git a/resources/qml/Preferences/MachinesPage.qml b/resources/qml/Preferences/MachinesPage.qml index 258b45292e..d728be6dfa 100644 --- a/resources/qml/Preferences/MachinesPage.qml +++ b/resources/qml/Preferences/MachinesPage.qml @@ -67,6 +67,7 @@ UM.ManagementPage { width: Math.round(childrenRect.width + 2 * screenScaleFactor) height: childrenRect.height + visible: machineActionRepeater.model[index].isVisible() Cura.SecondaryButton { text: machineActionRepeater.model[index].label From 75840426d735ddc421b594e6fa2378ed03ad2364 Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 7 Sep 2022 16:32:58 +0200 Subject: [PATCH 2/3] 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. --- cura/MachineAction.py | 21 +++++++++++++++++++++ resources/qml/Preferences/MachinesPage.qml | 12 ++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cura/MachineAction.py b/cura/MachineAction.py index 98e156d834..8ca9b63679 100644 --- a/cura/MachineAction.py +++ b/cura/MachineAction.py @@ -33,6 +33,7 @@ class MachineAction(QObject, PluginObject): self._qml_url = "" self._view = None self._finished = False + self._open_as_dialog = True labelChanged = pyqtSignal() onFinished = pyqtSignal() @@ -79,6 +80,15 @@ class MachineAction(QObject, PluginObject): pass + @pyqtSlot() + def execute(self) -> None: + self._execute() + + def _execute(self) -> None: + """Protected implementation of execute.""" + + pass + @pyqtSlot() def setFinished(self) -> None: self._finished = True @@ -115,6 +125,17 @@ class MachineAction(QObject, PluginObject): def getDisplayItem(self) -> Optional["QObject"]: 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) def isVisible(self) -> bool: """Whether this action button will be visible. diff --git a/resources/qml/Preferences/MachinesPage.qml b/resources/qml/Preferences/MachinesPage.qml index d728be6dfa..4ecc70b404 100644 --- a/resources/qml/Preferences/MachinesPage.qml +++ b/resources/qml/Preferences/MachinesPage.qml @@ -74,10 +74,14 @@ UM.ManagementPage onClicked: { var currentItem = machineActionRepeater.model[index] - actionDialog.loader.manager = currentItem - actionDialog.loader.source = currentItem.qmlPath - actionDialog.title = currentItem.label - actionDialog.show() + if (currentItem.openAsDialog()) { + actionDialog.loader.manager = currentItem + actionDialog.loader.source = currentItem.qmlPath + actionDialog.title = currentItem.label + actionDialog.show() + } else { + currentItem.execute() + } } } } From df16108938c63900cab2d9acf4c106648016c3eb Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 23 Sep 2022 11:49:30 +0200 Subject: [PATCH 3/3] Fixes for better decorators using pyqtProperty --- cura/MachineAction.py | 21 ++++++++++++++------- resources/qml/Preferences/MachinesPage.qml | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cura/MachineAction.py b/cura/MachineAction.py index 8ca9b63679..fa1fb01e02 100644 --- a/cura/MachineAction.py +++ b/cura/MachineAction.py @@ -34,8 +34,10 @@ class MachineAction(QObject, PluginObject): self._view = None self._finished = False self._open_as_dialog = True + self._visible = True labelChanged = pyqtSignal() + visibilityChanged = pyqtSignal() onFinished = pyqtSignal() def getKey(self) -> str: @@ -125,8 +127,8 @@ class MachineAction(QObject, PluginObject): def getDisplayItem(self) -> Optional["QObject"]: return self._createViewFromQML() - @pyqtSlot(result = bool) - def openAsDialog(self) -> bool: + @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(). @@ -135,9 +137,15 @@ class MachineAction(QObject, PluginObject): """ return self._open_as_dialog - - @pyqtSlot(result = bool) - def isVisible(self) -> bool: + + @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 @@ -145,5 +153,4 @@ class MachineAction(QObject, PluginObject): :return: Defaults to true to be in line with the old behaviour. """ - return True - \ No newline at end of file + self._visible \ No newline at end of file diff --git a/resources/qml/Preferences/MachinesPage.qml b/resources/qml/Preferences/MachinesPage.qml index 4ecc70b404..960dc75904 100644 --- a/resources/qml/Preferences/MachinesPage.qml +++ b/resources/qml/Preferences/MachinesPage.qml @@ -67,14 +67,14 @@ UM.ManagementPage { width: Math.round(childrenRect.width + 2 * screenScaleFactor) height: childrenRect.height - visible: machineActionRepeater.model[index].isVisible() + visible: machineActionRepeater.model[index].visible Cura.SecondaryButton { text: machineActionRepeater.model[index].label onClicked: { var currentItem = machineActionRepeater.model[index] - if (currentItem.openAsDialog()) { + if (currentItem.shouldOpenAsDialog) { actionDialog.loader.manager = currentItem actionDialog.loader.source = currentItem.qmlPath actionDialog.title = currentItem.label