mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-13 01:37:51 -06:00
Show a message to the user when the connection with the printer is lost
CURA-1851
This commit is contained in:
parent
113129eaca
commit
f052129171
1 changed files with 14 additions and 1 deletions
|
@ -77,6 +77,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
|
|
||||||
self._progress_message = None
|
self._progress_message = None
|
||||||
self._error_message = None
|
self._error_message = None
|
||||||
|
self._connection_message = None
|
||||||
|
|
||||||
self._update_timer = QTimer()
|
self._update_timer = QTimer()
|
||||||
self._update_timer.setInterval(2000) # TODO; Add preference for update interval
|
self._update_timer.setInterval(2000) # TODO; Add preference for update interval
|
||||||
|
@ -190,12 +191,15 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
# Go into timeout state.
|
# Go into timeout state.
|
||||||
Logger.log("d", "We did not receive a response for %s seconds, so it seems the printer is no longer accesible.", time() - self._last_response_time)
|
Logger.log("d", "We did not receive a response for %s seconds, so it seems the printer is no longer accesible.", time() - self._last_response_time)
|
||||||
self._connection_state_before_timeout = self._connection_state
|
self._connection_state_before_timeout = self._connection_state
|
||||||
|
self._connection_message = Message(i18n_catalog.i18nc("@info:status", "The connection with the printer was lost.Check your network-connections."))
|
||||||
|
self._connection_message.show()
|
||||||
self.setConnectionState(ConnectionState.error)
|
self.setConnectionState(ConnectionState.error)
|
||||||
|
|
||||||
if self._authentication_state == AuthState.NotAuthenticated:
|
if self._authentication_state == AuthState.NotAuthenticated:
|
||||||
self._verifyAuthentication() # We don't know if we are authenticated; check if we have correct auth.
|
self._verifyAuthentication() # We don't know if we are authenticated; check if we have correct auth.
|
||||||
elif self._authentication_state == AuthState.AuthenticationRequested:
|
elif self._authentication_state == AuthState.AuthenticationRequested:
|
||||||
self._checkAuthentication() # We requested authentication at some point. Check if we got permission.
|
self._checkAuthentication() # We requested authentication at some point. Check if we got permission.
|
||||||
|
|
||||||
## Request 'general' printer data
|
## Request 'general' printer data
|
||||||
url = QUrl("http://" + self._address + self._api_prefix + "printer")
|
url = QUrl("http://" + self._address + self._api_prefix + "printer")
|
||||||
printer_request = QNetworkRequest(url)
|
printer_request = QNetworkRequest(url)
|
||||||
|
@ -423,6 +427,10 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
self._last_response_time = time()
|
self._last_response_time = time()
|
||||||
|
|
||||||
status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
|
status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
|
||||||
|
if not status_code:
|
||||||
|
# Received no or empty reply
|
||||||
|
return
|
||||||
|
|
||||||
if reply.operation() == QNetworkAccessManager.GetOperation:
|
if reply.operation() == QNetworkAccessManager.GetOperation:
|
||||||
if "printer" in reply.url().toString(): # Status update from printer.
|
if "printer" in reply.url().toString(): # Status update from printer.
|
||||||
if status_code == 200:
|
if status_code == 200:
|
||||||
|
@ -431,6 +439,11 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
self._json_printer_state = json.loads(bytes(reply.readAll()).decode("utf-8"))
|
self._json_printer_state = json.loads(bytes(reply.readAll()).decode("utf-8"))
|
||||||
|
|
||||||
self._spliceJSONData()
|
self._spliceJSONData()
|
||||||
|
|
||||||
|
# Hide connection error message if the connection was restored
|
||||||
|
if self._connection_message:
|
||||||
|
self._connection_message.hide()
|
||||||
|
self._connection_message = None
|
||||||
else:
|
else:
|
||||||
Logger.log("w", "We got an unexpected status (%s) while requesting printer state", status_code)
|
Logger.log("w", "We got an unexpected status (%s) while requesting printer state", status_code)
|
||||||
pass # TODO: Handle errors
|
pass # TODO: Handle errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue