mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Store online status of printer in the printer's metadata
It's a little bit weird with the hidden global stack system when there's a cluster of various types of printers. But it should behave the same way. Contributes to issue CURA-8609.
This commit is contained in:
parent
75c7d5c4f5
commit
0bf4a3d944
2 changed files with 29 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Copyright (c) 2021 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from UM.FileHandler.FileHandler import FileHandler #For typing.
|
||||
|
@ -114,6 +114,11 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
|||
return b"".join(file_data_bytes_list)
|
||||
|
||||
def _update(self) -> None:
|
||||
"""
|
||||
Update the connection state of this device.
|
||||
|
||||
This is called on regular intervals.
|
||||
"""
|
||||
if self._last_response_time:
|
||||
time_since_last_response = time() - self._last_response_time
|
||||
else:
|
||||
|
@ -127,11 +132,11 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
|||
if time_since_last_response > self._timeout_time >= time_since_last_request:
|
||||
# Go (or stay) into timeout.
|
||||
if self._connection_state_before_timeout is None:
|
||||
self._connection_state_before_timeout = self._connection_state
|
||||
self._connection_state_before_timeout = self.connectionState
|
||||
|
||||
self.setConnectionState(ConnectionState.Closed)
|
||||
|
||||
elif self._connection_state == ConnectionState.Closed:
|
||||
elif self.connectionState == ConnectionState.Closed:
|
||||
# Go out of timeout.
|
||||
if self._connection_state_before_timeout is not None: # sanity check, but it should never be None here
|
||||
self.setConnectionState(self._connection_state_before_timeout)
|
||||
|
@ -361,7 +366,7 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
|||
|
||||
self._last_response_time = time()
|
||||
|
||||
if self._connection_state == ConnectionState.Connecting:
|
||||
if self.connectionState == ConnectionState.Connecting:
|
||||
self.setConnectionState(ConnectionState.Connected)
|
||||
|
||||
callback_key = reply.url().toString() + str(reply.operation())
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Copyright (c) 2021 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from enum import IntEnum
|
||||
from typing import Callable, List, Optional, Union
|
||||
|
||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, QObject, QTimer, QUrl
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
|
||||
import cura.CuraApplication # Imported like this to prevent circular imports.
|
||||
from UM.Logger import Logger
|
||||
from UM.Signal import signalemitter
|
||||
from UM.Qt.QtApplication import QtApplication
|
||||
|
@ -120,11 +122,22 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
|||
callback(QMessageBox.Yes)
|
||||
|
||||
def isConnected(self) -> bool:
|
||||
return self._connection_state != ConnectionState.Closed and self._connection_state != ConnectionState.Error
|
||||
"""
|
||||
Returns whether we could theoretically send commands to this printer.
|
||||
:return: `True` if we are connected, or `False` if not.
|
||||
"""
|
||||
return self.connectionState != ConnectionState.Closed and self.connectionState != ConnectionState.Error
|
||||
|
||||
def setConnectionState(self, connection_state: "ConnectionState") -> None:
|
||||
if self._connection_state != connection_state:
|
||||
"""
|
||||
Store the connection state of the printer.
|
||||
|
||||
Causes everything that displays the connection state to update its QML models.
|
||||
:param connection_state: The new connection state to store.
|
||||
"""
|
||||
if self.connectionState != connection_state:
|
||||
self._connection_state = connection_state
|
||||
cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack().setMetaDataEntry("is_online", self.isConnected())
|
||||
self.connectionStateChanged.emit(self._id)
|
||||
|
||||
@pyqtProperty(int, constant = True)
|
||||
|
@ -133,6 +146,10 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
|||
|
||||
@pyqtProperty(int, notify = connectionStateChanged)
|
||||
def connectionState(self) -> "ConnectionState":
|
||||
"""
|
||||
Get the connection state of the printer, e.g. whether it is connected, still connecting, error state, etc.
|
||||
:return: The current connection state of this output device.
|
||||
"""
|
||||
return self._connection_state
|
||||
|
||||
def _update(self) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue