Merge pull request #4975 from Ultimaker/CURA-6011_connection_types

[4.0] Every output device should define its connection type
This commit is contained in:
Lipu Fei 2018-12-18 13:23:02 +01:00 committed by GitHub
commit 71e71e0a4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 183 additions and 104 deletions

View file

@ -7,7 +7,7 @@ from UM.i18n import i18nCatalog
from UM.Qt.Duration import DurationFormat
from cura.CuraApplication import CuraApplication
from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState
from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState, ConnectionType
from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
from cura.PrinterOutput.PrintJobOutputModel import PrintJobOutputModel
from cura.PrinterOutput.GenericOutputController import GenericOutputController
@ -29,7 +29,7 @@ catalog = i18nCatalog("cura")
class USBPrinterOutputDevice(PrinterOutputDevice):
def __init__(self, serial_port: str, baud_rate: Optional[int] = None) -> None:
super().__init__(serial_port)
super().__init__(serial_port, connection_type = ConnectionType.UsbConnection)
self.setName(catalog.i18nc("@item:inmenu", "USB printing"))
self.setShortDescription(catalog.i18nc("@action:button Preceded by 'Ready to'.", "Print via USB"))
self.setDescription(catalog.i18nc("@info:tooltip", "Print via USB"))
@ -179,7 +179,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
return
CuraApplication.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerStackChanged)
self._onGlobalContainerStackChanged()
self.setConnectionState(ConnectionState.connected)
self.setConnectionState(ConnectionState.Connected)
self._update_thread.start()
def _onGlobalContainerStackChanged(self):
@ -208,7 +208,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
self._sendCommand(command)
def _sendCommand(self, command: Union[str, bytes]):
if self._serial is None or self._connection_state != ConnectionState.connected:
if self._serial is None or self._connection_state != ConnectionState.Connected:
return
new_command = cast(bytes, command) if type(command) is bytes else cast(str, command).encode() # type: bytes
@ -222,7 +222,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
self._command_received.set()
def _update(self):
while self._connection_state == ConnectionState.connected and self._serial is not None:
while self._connection_state == ConnectionState.Connected and self._serial is not None:
try:
line = self._serial.readline()
except:

View file

@ -66,7 +66,7 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin):
return
changed_device = self._usb_output_devices[serial_port]
if changed_device.connectionState == ConnectionState.connected:
if changed_device.connectionState == ConnectionState.Connected:
self.getOutputDeviceManager().addOutputDevice(changed_device)
else:
self.getOutputDeviceManager().removeOutputDevice(serial_port)