Skip to content

Commit

Permalink
Display errors when sending commands in UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
loociano committed May 31, 2020
1 parent 020b947 commit 4bed64d
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 17 deletions.
87 changes: 70 additions & 17 deletions src/MPSM2NetworkedPrinterOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
# pylint:disable=relative-beyond-top-level
from .GCodeWriteFileJob import GCodeWriteFileJob
from .MPSM2OutputController import MPSM2OutputController
from .messages.NetworkErrorMessage import NetworkErrorMessage
from .messages.PrintJobCancelErrorMessage import PrintJobCancelErrorMessage
from .messages.PrintJobPauseErrorMessage import PrintJobPauseErrorMessage
from .messages.PrintJobStartErrorMessage import PrintJobStartErrorMessage
from .messages.PrintJobUploadBlockedMessage \
import PrintJobUploadBlockedMessage
from .messages.PrintJobUploadCancelMessage \
Expand All @@ -36,6 +40,7 @@
import PrintJobUploadProgressMessage
from .messages.PrintJobUploadSuccessMessage \
import PrintJobUploadSuccessMessage
from .messages.SetTargetTemperatureErrorMessage import SetTargetTemperatureErrorMessage
from .models.MPSM2PrintJobOutputModel import MPSM2PrintJobOutputModel
from .models.MPSM2PrinterOutputModel import MPSM2PrinterOutputModel
from .models.MPSM2PrinterStatusModel import MPSM2PrinterStatusModel
Expand Down Expand Up @@ -107,7 +112,9 @@ def __init__(self, device_id: str, address: str, instance_number=1,
self.setAuthenticationState(AuthState.Authenticated)
self._load_monitor_tab()
self._set_ui_elements()
self._api_client.increase_upload_speed(self._on_increased_upload_speed)
self._api_client.increase_upload_speed(
self._on_increased_upload_speed,
self._on_increased_upload_speed_error)

@pyqtProperty(QObject, notify=printerStatusChanged)
def printer(self) -> MPSM2PrinterOutputModel:
Expand Down Expand Up @@ -220,7 +227,8 @@ def set_target_hotend_temperature(self, celsius: str) -> None:
try:
self._api_client.set_target_hotend_temperature(
int(celsius),
self._on_target_temperature_finished)
self._on_target_hotend_temperature_finished,
self._on_target_hotend_temperature_error)
self._requested_hotend_temperature = int(celsius)
self.hasTargetHotendInProgressChanged.emit()
except ValueError:
Expand All @@ -237,7 +245,8 @@ def set_target_bed_temperature(self, celsius: str) -> None:
try:
self._api_client.set_target_bed_temperature(
int(celsius),
self._on_target_temperature_finished)
self._on_target_bed_temperature_finished,
self._on_target_bed_temperature_error)
self._requested_bed_temperature = int(celsius)
self.hasTargetBedInProgressChanged.emit()
except ValueError:
Expand All @@ -247,7 +256,8 @@ def set_target_bed_temperature(self, celsius: str) -> None:
def start_print(self) -> None:
"""Prints the cached model in printer."""
Logger.log('d', 'Printing cache.gc.')
self._api_client.start_print(self._on_print_started)
self._api_client.start_print(self._on_print_started,
self._on_print_started_error)
self._requested_start_print = True
self.startPrintRequestChanged.emit()

Expand All @@ -263,15 +273,17 @@ def resume_print(self) -> None:
def pause_print(self) -> None:
"""Pauses the print job."""
Logger.log('d', 'Pausing print.')
self._api_client.pause_print(self._on_print_paused)
self._api_client.pause_print(self._on_print_paused,
self._on_print_paused_error)
self._requested_pause_print = True
self.pausePrintRequestChanged.emit()

@pyqtSlot(name='cancelPrint')
def cancel_print(self) -> None:
"""Cancels the print job."""
Logger.log('d', 'Cancelling print.')
self._api_client.cancel_print(self._on_print_cancelled)
self._api_client.cancel_print(self._on_print_cancelled,
self._on_print_cancelled_error)
self._requested_cancel_print = True
self.cancelPrintRequestChanged.emit()

Expand Down Expand Up @@ -408,7 +420,13 @@ def _on_print_resumed(self, response: str) -> None:
response: HTTP response to the resume request.
"""
if response.upper() != 'OK':
Logger.log('e', 'Could not resume print') # TODO message
self._on_print_started_error()

def _on_print_started_error(self) -> None:
"""Called if there was an error to communicate the printer to start printing."""
self._requested_start_print = False
PrintJobStartErrorMessage().show()
self.startPrintRequestChanged.emit()

def _on_print_paused(self, response: str) -> None:
"""Called when the user pauses the print job.
Expand All @@ -417,7 +435,13 @@ def _on_print_paused(self, response: str) -> None:
response: HTTP response to the pause request.
"""
if response.upper() != 'OK':
Logger.log('e', 'Could not pause print.') # TODO: message
self._on_print_paused_error()

def _on_print_paused_error(self) -> None:
"""Called if there was an error to communicate the printer to pause."""
self._requested_pause_print = False
PrintJobPauseErrorMessage().show()
self.pausePrintRequestChanged.emit()

def _on_print_cancelled(self, response: str) -> None:
"""Called when the user cancels the print job.
Expand All @@ -426,27 +450,55 @@ def _on_print_cancelled(self, response: str) -> None:
response: HTTP response to the cancel request.
"""
if response.upper() != 'OK':
Logger.log('e', 'Could not cancel print') # TODO: message
self._on_print_cancelled_error()

def _on_print_cancelled_error(self) -> None:
"""Called if there was an error to communicate the printer to cancel."""
self._requested_cancel_print = False
PrintJobCancelErrorMessage().show()
self.cancelPrintRequestChanged.emit()

def _on_target_hotend_temperature_finished(self, response: str) -> None:
"""Called when a request to set target hotend temperature completed.
Args:
response: HTTP response to the target temperature request.
"""
if response.upper() != 'OK':
self._on_target_hotend_temperature_error()

def _on_target_hotend_temperature_error(self) -> None:
"""Called if there was an error setting target hotend temperature."""
self._requested_hotend_temperature = False
SetTargetTemperatureErrorMessage().show()
self.hasTargetHotendInProgressChanged.emit()

def _on_target_temperature_finished(self, response: str) -> None:
"""Called when a request to set target temperature completed.
def _on_target_bed_temperature_finished(self, response: str) -> None:
"""Called when a request to set target bed temperature completed.
Args:
response: HTTP response to the target temperature request.
"""
if response.upper() != 'OK':
# TODO: UI message
Logger.log('e', 'Could not set target temperature.')
self._on_target_bed_temperature_error()

def _on_target_bed_temperature_error(self) -> None:
"""Called if there was an error setting target bed temperature."""
self._requested_bed_temperature = False
SetTargetTemperatureErrorMessage().show()
self.hasTargetBedInProgressChanged.emit()

def _on_increased_upload_speed(self, response: str) -> None:
"""Called when a request to increate upload speed completed.
"""Called when a request to increase upload speed completed.
Args:
response: HTTP response to the gcode command request.
"""
if response.upper() != 'OK':
# TODO: UI message
Logger.log('e', 'Could not increase the upload speed.')
self._on_increased_upload_speed_error()

def _on_increased_upload_speed_error(self) -> None:
NetworkErrorMessage().show()

def _set_ui_elements(self) -> None:
"""Sets Cura UI elements corresponding to this device."""
Expand Down Expand Up @@ -548,7 +600,8 @@ def _update_printer_output_model(
self.pausePrintRequestChanged.emit()

else:
Logger.log('e', 'Unknown printer status.') # TODO: message
Logger.log('e', 'Unknown printer status.')
NetworkErrorMessage().show()

def _update_model_temperatures(
self,
Expand Down
20 changes: 20 additions & 0 deletions src/messages/NetworkErrorMessage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Copyright 2020 Luc Rubio <[email protected]>
Plugin is licensed under the GNU Lesser General Public License v3.0.
"""
from UM import i18nCatalog
from UM.Message import Message

I18N_CATALOG = i18nCatalog('cura')


class NetworkErrorMessage(Message):
"""Message displayed when there was an network error."""

def __init__(self) -> None:
super().__init__(
title=I18N_CATALOG.i18nc('@info:title', 'Network error'),
text=I18N_CATALOG.i18nc(
'@info:text',
'There was a problem communicating with the printer.'),
lifetime=10)
20 changes: 20 additions & 0 deletions src/messages/PrintJobCancelErrorMessage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Copyright 2020 Luc Rubio <[email protected]>
Plugin is licensed under the GNU Lesser General Public License v3.0.
"""
from UM import i18nCatalog
from UM.Message import Message

I18N_CATALOG = i18nCatalog('cura')


class PrintJobCancelErrorMessage(Message):
"""Message displayed when there is an error cancelling the print job."""

def __init__(self) -> None:
super().__init__(
title=I18N_CATALOG.i18nc('@info:title', 'Network error'),
text=I18N_CATALOG.i18nc(
'@info:text',
'Could not cancel the print. Please make sure the printer is online and try again.'),
lifetime=10)
20 changes: 20 additions & 0 deletions src/messages/PrintJobPauseErrorMessage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Copyright 2020 Luc Rubio <[email protected]>
Plugin is licensed under the GNU Lesser General Public License v3.0.
"""
from UM import i18nCatalog
from UM.Message import Message

I18N_CATALOG = i18nCatalog('cura')


class PrintJobPauseErrorMessage(Message):
"""Message displayed when there is an error pausing the print job."""

def __init__(self) -> None:
super().__init__(
title=I18N_CATALOG.i18nc('@info:title', 'Network error'),
text=I18N_CATALOG.i18nc(
'@info:text',
'Could not pause the print. Please make sure the printer is online and try again.'),
lifetime=10)
20 changes: 20 additions & 0 deletions src/messages/PrintJobStartErrorMessage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Copyright 2020 Luc Rubio <[email protected]>
Plugin is licensed under the GNU Lesser General Public License v3.0.
"""
from UM import i18nCatalog
from UM.Message import Message

I18N_CATALOG = i18nCatalog('cura')


class PrintJobStartErrorMessage(Message):
"""Message displayed when there is an error starting the print job."""

def __init__(self) -> None:
super().__init__(
title=I18N_CATALOG.i18nc('@info:title', 'Network error'),
text=I18N_CATALOG.i18nc(
'@info:text',
'Could not start printing. Please make sure the printer is online and try again.'),
lifetime=10)
20 changes: 20 additions & 0 deletions src/messages/SetTargetTemperatureErrorMessage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Copyright 2020 Luc Rubio <[email protected]>
Plugin is licensed under the GNU Lesser General Public License v3.0.
"""
from UM import i18nCatalog
from UM.Message import Message

I18N_CATALOG = i18nCatalog('cura')


class SetTargetTemperatureErrorMessage(Message):
"""Message displayed when there is an error setting target temperature."""

def __init__(self) -> None:
super().__init__(
title=I18N_CATALOG.i18nc('@info:title', 'Network error'),
text=I18N_CATALOG.i18nc(
'@info:text',
'Could not set target temperature. Please make sure the printer is online and try again.'),
lifetime=10)

0 comments on commit 4bed64d

Please sign in to comment.