mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 07:33:57 -06:00
Add typing for MachineAction
CURA-5812
This commit is contained in:
parent
9b94db8957
commit
c1b9d527bb
1 changed files with 20 additions and 14 deletions
|
@ -1,13 +1,13 @@
|
||||||
# Copyright (c) 2016 Ultimaker B.V.
|
# Copyright (c) 2016 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
|
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
|
||||||
|
|
||||||
|
from UM.Logger import Logger
|
||||||
from UM.PluginObject import PluginObject
|
from UM.PluginObject import PluginObject
|
||||||
from UM.PluginRegistry import PluginRegistry
|
from UM.PluginRegistry import PluginRegistry
|
||||||
from UM.Application import Application
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
## Machine actions are actions that are added to a specific machine type. Examples of such actions are
|
## Machine actions are actions that are added to a specific machine type. Examples of such actions are
|
||||||
|
@ -19,7 +19,7 @@ class MachineAction(QObject, PluginObject):
|
||||||
## Create a new Machine action.
|
## Create a new Machine action.
|
||||||
# \param key unique key of the machine action
|
# \param key unique key of the machine action
|
||||||
# \param label Human readable label used to identify the machine action.
|
# \param label Human readable label used to identify the machine action.
|
||||||
def __init__(self, key, label = ""):
|
def __init__(self, key: str, label: str = "") -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._key = key
|
self._key = key
|
||||||
self._label = label
|
self._label = label
|
||||||
|
@ -30,14 +30,14 @@ class MachineAction(QObject, PluginObject):
|
||||||
labelChanged = pyqtSignal()
|
labelChanged = pyqtSignal()
|
||||||
onFinished = pyqtSignal()
|
onFinished = pyqtSignal()
|
||||||
|
|
||||||
def getKey(self):
|
def getKey(self) -> str:
|
||||||
return self._key
|
return self._key
|
||||||
|
|
||||||
@pyqtProperty(str, notify = labelChanged)
|
@pyqtProperty(str, notify = labelChanged)
|
||||||
def label(self):
|
def label(self) -> str:
|
||||||
return self._label
|
return self._label
|
||||||
|
|
||||||
def setLabel(self, label):
|
def setLabel(self, label: str) -> None:
|
||||||
if self._label != label:
|
if self._label != label:
|
||||||
self._label = label
|
self._label = label
|
||||||
self.labelChanged.emit()
|
self.labelChanged.emit()
|
||||||
|
@ -46,29 +46,35 @@ class MachineAction(QObject, PluginObject):
|
||||||
# This should not be re-implemented by child classes, instead re-implement _reset.
|
# This should not be re-implemented by child classes, instead re-implement _reset.
|
||||||
# /sa _reset
|
# /sa _reset
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def reset(self):
|
def reset(self) -> None:
|
||||||
self._finished = False
|
self._finished = False
|
||||||
self._reset()
|
self._reset()
|
||||||
|
|
||||||
## Protected implementation of reset.
|
## Protected implementation of reset.
|
||||||
# /sa reset()
|
# /sa reset()
|
||||||
def _reset(self):
|
def _reset(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def setFinished(self):
|
def setFinished(self) -> None:
|
||||||
self._finished = True
|
self._finished = True
|
||||||
self._reset()
|
self._reset()
|
||||||
self.onFinished.emit()
|
self.onFinished.emit()
|
||||||
|
|
||||||
@pyqtProperty(bool, notify = onFinished)
|
@pyqtProperty(bool, notify = onFinished)
|
||||||
def finished(self):
|
def finished(self) -> bool:
|
||||||
return self._finished
|
return self._finished
|
||||||
|
|
||||||
## Protected helper to create a view object based on provided QML.
|
## Protected helper to create a view object based on provided QML.
|
||||||
def _createViewFromQML(self):
|
def _createViewFromQML(self) -> None:
|
||||||
path = os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), self._qml_url)
|
plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId())
|
||||||
self._view = Application.getInstance().createQmlComponent(path, {"manager": self})
|
if plugin_path is None:
|
||||||
|
Logger.log("e", "Cannot create QML view: cannot find plugin path for plugin [%s]", self.getPluginId())
|
||||||
|
return
|
||||||
|
path = os.path.join(plugin_path, self._qml_url)
|
||||||
|
|
||||||
|
from cura.CuraApplication import CuraApplication
|
||||||
|
self._view = CuraApplication.getInstance().createQmlComponent(path, {"manager": self})
|
||||||
|
|
||||||
@pyqtProperty(QObject, constant = True)
|
@pyqtProperty(QObject, constant = True)
|
||||||
def displayItem(self):
|
def displayItem(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue