From 7927169da159bfa4f1b35abdda33b1881d35e327 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 15 Jul 2019 17:27:23 +0200 Subject: [PATCH 1/4] Add peripheral class It has a non-human-readable type for the plug-ins to use and a human-readable name which can be requested with the peripherals() property. Contributes to issue CURA-6651. --- cura/PrinterOutput/Peripheral.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 cura/PrinterOutput/Peripheral.py diff --git a/cura/PrinterOutput/Peripheral.py b/cura/PrinterOutput/Peripheral.py new file mode 100644 index 0000000000..3f6a20baed --- /dev/null +++ b/cura/PrinterOutput/Peripheral.py @@ -0,0 +1,17 @@ +# Copyright (c) 2019 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + +## Data class that represents a peripheral for a printer. +# +# Output device plug-ins may specify that the printer has a certain set of +# peripherals. This set is then possibly shown in the interface of the monitor +# stage. +class Peripheral: + ## Constructs the peripheral. + # \param id A unique ID for the peripheral object, like a MAC address or + # some hardware ID. + # \param type A unique ID for the type of peripheral. + # \param name A human-readable name for the peripheral. + def __init__(self, type: str, name: str): + self.type = type + self.name = name \ No newline at end of file From fed275024a8235b01a556d5cb3ba4798e904abc9 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 15 Jul 2019 17:29:30 +0200 Subject: [PATCH 2/4] Add slot to store peripherals You can get the list of names of peripherals this way. Contributes to issue CURA-6651. --- .../Models/PrinterOutputModel.py | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/cura/PrinterOutput/Models/PrinterOutputModel.py b/cura/PrinterOutput/Models/PrinterOutputModel.py index 4004a90a33..13fe85e674 100644 --- a/cura/PrinterOutput/Models/PrinterOutputModel.py +++ b/cura/PrinterOutput/Models/PrinterOutputModel.py @@ -2,13 +2,13 @@ # Cura is released under the terms of the LGPLv3 or higher. from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant, pyqtSlot, QUrl -from typing import List, Dict, Optional +from typing import List, Dict, Optional, TYPE_CHECKING from UM.Math.Vector import Vector +from cura.PrinterOutput.Peripheral import Peripheral from cura.PrinterOutput.Models.PrinterConfigurationModel import PrinterConfigurationModel from cura.PrinterOutput.Models.ExtruderOutputModel import ExtruderOutputModel -MYPY = False -if MYPY: +if TYPE_CHECKING: from cura.PrinterOutput.Models.PrintJobOutputModel import PrintJobOutputModel from cura.PrinterOutput.PrinterOutputController import PrinterOutputController @@ -45,6 +45,7 @@ class PrinterOutputModel(QObject): self._is_preheating = False self._printer_type = "" self._buildplate = "" + self._peripherals = [] # type: List[Peripheral] self._printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in self._extruders] @@ -294,4 +295,18 @@ class PrinterOutputModel(QObject): def printerConfiguration(self) -> Optional[PrinterConfigurationModel]: if self._printer_configuration.isValid(): return self._printer_configuration - return None \ No newline at end of file + return None + + peripheralsChanged = pyqtSignal() + + @pyqtProperty(str, notify = peripheralsChanged) + def peripherals(self) -> str: + return ", ".join(*[peripheral.name for peripheral in self._peripherals]) + + def addPeripheral(self, peripheral: Peripheral) -> None: + self._peripherals.append(peripheral) + self.peripheralsChanged.emit() + + def removePeripheral(self, peripheral: Peripheral) -> None: + self._peripherals.remove(peripheral) + self.peripheralsChanged.emit() \ No newline at end of file From f402235406823771ab627debe8b79bceca380990 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Tue, 16 Jul 2019 10:27:50 +0200 Subject: [PATCH 3/4] Fix shadowed use of builtin type CURA-6651 --- cura/PrinterOutput/Peripheral.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cura/PrinterOutput/Peripheral.py b/cura/PrinterOutput/Peripheral.py index 3f6a20baed..93178ba6d1 100644 --- a/cura/PrinterOutput/Peripheral.py +++ b/cura/PrinterOutput/Peripheral.py @@ -1,6 +1,7 @@ # Copyright (c) 2019 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. + ## Data class that represents a peripheral for a printer. # # Output device plug-ins may specify that the printer has a certain set of @@ -8,10 +9,8 @@ # stage. class Peripheral: ## Constructs the peripheral. - # \param id A unique ID for the peripheral object, like a MAC address or - # some hardware ID. # \param type A unique ID for the type of peripheral. # \param name A human-readable name for the peripheral. - def __init__(self, type: str, name: str): - self.type = type - self.name = name \ No newline at end of file + def __init__(self, peripheral_type: str, name: str): + self.type = peripheral_type + self.name = name From 6a843866a0dcb8506fbfa9f5b7a9139f68eb7411 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 18 Jul 2019 11:57:05 +0200 Subject: [PATCH 4/4] Fix code style CURA-6651 --- cura/PrinterOutput/Peripheral.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/PrinterOutput/Peripheral.py b/cura/PrinterOutput/Peripheral.py index 93178ba6d1..2693b82c36 100644 --- a/cura/PrinterOutput/Peripheral.py +++ b/cura/PrinterOutput/Peripheral.py @@ -11,6 +11,6 @@ class Peripheral: ## Constructs the peripheral. # \param type A unique ID for the type of peripheral. # \param name A human-readable name for the peripheral. - def __init__(self, peripheral_type: str, name: str): + def __init__(self, peripheral_type: str, name: str) -> None: self.type = peripheral_type self.name = name