Fixes for better decorators using pyqtProperty

This commit is contained in:
Julian 2022-09-23 11:49:30 +02:00
parent 75840426d7
commit df16108938
2 changed files with 16 additions and 9 deletions

View File

@ -34,8 +34,10 @@ class MachineAction(QObject, PluginObject):
self._view = None self._view = None
self._finished = False self._finished = False
self._open_as_dialog = True 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:
@ -125,8 +127,8 @@ class MachineAction(QObject, PluginObject):
def getDisplayItem(self) -> Optional["QObject"]: def getDisplayItem(self) -> Optional["QObject"]:
return self._createViewFromQML() return self._createViewFromQML()
@pyqtSlot(result = bool) @pyqtProperty(bool, constant=True)
def openAsDialog(self) -> bool: def shouldOpenAsDialog(self) -> bool:
"""Whether this action will show a dialog. """Whether this action will show a dialog.
If not, the action will directly run the function inside execute(). If not, the action will directly run the function inside execute().
@ -136,8 +138,14 @@ class MachineAction(QObject, PluginObject):
return self._open_as_dialog return self._open_as_dialog
@pyqtSlot(result = bool) @pyqtSlot()
def isVisible(self) -> bool: 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. """Whether this action button will be visible.
Example: Show only when isLoggedIn 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: Defaults to true to be in line with the old behaviour.
""" """
return True self._visible

View File

@ -67,14 +67,14 @@ 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].isVisible() 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]
if (currentItem.openAsDialog()) { if (currentItem.shouldOpenAsDialog) {
actionDialog.loader.manager = currentItem actionDialog.loader.manager = currentItem
actionDialog.loader.source = currentItem.qmlPath actionDialog.loader.source = currentItem.qmlPath
actionDialog.title = currentItem.label actionDialog.title = currentItem.label