mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
It's now possible to send print jobs to cluster again
CL-541
This commit is contained in:
parent
cfc6a3ad48
commit
9084dfd6bd
3 changed files with 59 additions and 17 deletions
|
@ -7,14 +7,14 @@ from UM.Logger import Logger
|
||||||
from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState
|
from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState
|
||||||
|
|
||||||
from PyQt5.QtNetwork import QHttpMultiPart, QHttpPart, QNetworkRequest, QNetworkAccessManager, QNetworkReply
|
from PyQt5.QtNetwork import QHttpMultiPart, QHttpPart, QNetworkRequest, QNetworkAccessManager, QNetworkReply
|
||||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QTimer, pyqtSignal, QUrl
|
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, pyqtSignal, QUrl, QCoreApplication
|
||||||
|
|
||||||
from time import time
|
from time import time
|
||||||
from typing import Callable, Any, Optional
|
from typing import Callable, Any, Optional
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import os
|
import os # To get the username
|
||||||
|
import gzip
|
||||||
|
|
||||||
class AuthState(IntEnum):
|
class AuthState(IntEnum):
|
||||||
NotAuthenticated = 1
|
NotAuthenticated = 1
|
||||||
|
@ -63,6 +63,16 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
||||||
def authenticationState(self):
|
def authenticationState(self):
|
||||||
return self._authentication_state
|
return self._authentication_state
|
||||||
|
|
||||||
|
def _compressDataAndNotifyQt(self, data_to_append):
|
||||||
|
compressed_data = gzip.compress(data_to_append.encode("utf-8"))
|
||||||
|
self._progress_message.setProgress(-1) # Tickle the message so that it's clear that it's still being used.
|
||||||
|
QCoreApplication.processEvents() # Ensure that the GUI does not freeze.
|
||||||
|
|
||||||
|
# Pretend that this is a response, as zipping might take a bit of time.
|
||||||
|
# If we don't do this, the device might trigger a timeout.
|
||||||
|
self._last_response_time = time()
|
||||||
|
return compressed_data
|
||||||
|
|
||||||
def _compressGCode(self):
|
def _compressGCode(self):
|
||||||
self._compressing_gcode = True
|
self._compressing_gcode = True
|
||||||
|
|
||||||
|
@ -81,12 +91,12 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
||||||
# Compressing line by line in this case is extremely slow, so we need to batch them.
|
# Compressing line by line in this case is extremely slow, so we need to batch them.
|
||||||
if len(batched_line) < max_chars_per_line:
|
if len(batched_line) < max_chars_per_line:
|
||||||
continue
|
continue
|
||||||
byte_array_file_data += self.__compressDataAndNotifyQt(batched_line)
|
byte_array_file_data += self._compressDataAndNotifyQt(batched_line)
|
||||||
batched_line = ""
|
batched_line = ""
|
||||||
|
|
||||||
# Don't miss the last batch (If any)
|
# Don't miss the last batch (If any)
|
||||||
if batched_line:
|
if batched_line:
|
||||||
byte_array_file_data += self.__compressDataAndNotifyQt(batched_line)
|
byte_array_file_data += self._compressDataAndNotifyQt(batched_line)
|
||||||
|
|
||||||
self._compressing_gcode = False
|
self._compressing_gcode = False
|
||||||
return byte_array_file_data
|
return byte_array_file_data
|
||||||
|
|
|
@ -16,6 +16,8 @@ from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply
|
||||||
from PyQt5.QtGui import QDesktopServices
|
from PyQt5.QtGui import QDesktopServices
|
||||||
from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty
|
from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty
|
||||||
|
|
||||||
|
from time import time
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -61,6 +63,9 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||||
# Unable to find g-code. Nothing to send
|
# Unable to find g-code. Nothing to send
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# TODO; DEBUG
|
||||||
|
self.sendPrintJob()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def sendPrintJob(self):
|
def sendPrintJob(self):
|
||||||
Logger.log("i", "Sending print job to printer.")
|
Logger.log("i", "Sending print job to printer.")
|
||||||
|
@ -83,8 +88,46 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||||
# Abort was called.
|
# Abort was called.
|
||||||
return
|
return
|
||||||
|
|
||||||
|
parts = []
|
||||||
|
|
||||||
|
# If a specific printer was selected, it should be printed with that machine.
|
||||||
|
require_printer_name = "" # Todo; actually needs to be set
|
||||||
|
if require_printer_name:
|
||||||
|
parts.append(self._createFormPart("name=require_printer_name", bytes(require_printer_name, "utf-8"), "text/plain"))
|
||||||
|
|
||||||
|
# Add user name to the print_job
|
||||||
|
parts.append(self._createFormPart("name=owner", bytes(self._getUserName(), "utf-8"), "text/plain"))
|
||||||
|
|
||||||
|
file_name = "%s.gcode.gz" % Application.getInstance().getPrintInformation().jobName
|
||||||
|
|
||||||
|
parts.append(self._createFormPart("name=\"file\"; filename=\"%s\"" % file_name, compressed_gcode))
|
||||||
|
|
||||||
|
self.postFormWithParts("print_jobs/", parts, onFinished=self._onPostPrintJobFinished, onProgress=self._onUploadPrintJobProgress)
|
||||||
|
|
||||||
|
def _onPostPrintJobFinished(self, reply):
|
||||||
|
print("POST PRINTJOB DONE! YAY!", reply.readAll())
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _onUploadPrintJobProgress(self, bytes_sent, bytes_total):
|
||||||
|
if bytes_total > 0:
|
||||||
|
new_progress = bytes_sent / bytes_total * 100
|
||||||
|
# Treat upload progress as response. Uploading can take more than 10 seconds, so if we don't, we can get
|
||||||
|
# timeout responses if this happens.
|
||||||
|
self._last_response_time = time()
|
||||||
|
if new_progress > self._progress_message.getProgress():
|
||||||
|
self._progress_message.show() # Ensure that the message is visible.
|
||||||
|
self._progress_message.setProgress(bytes_sent / bytes_total * 100)
|
||||||
|
else:
|
||||||
|
self._progress_message.setProgress(0)
|
||||||
|
self._progress_message.hide()
|
||||||
|
|
||||||
|
def _progressMessageActionTriggered(self, message_id=None, action_id=None):
|
||||||
|
if action_id == "Abort":
|
||||||
|
Logger.log("d", "User aborted sending print to remote.")
|
||||||
|
self._progress_message.hide()
|
||||||
|
self._compressing_gcode = False
|
||||||
|
self._sending_gcode = False
|
||||||
|
Application.getInstance().showPrintMonitor.emit(False)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def openPrintJobControlPanel(self):
|
def openPrintJobControlPanel(self):
|
||||||
|
|
|
@ -21,8 +21,7 @@ from .LegacyUM3PrinterOutputController import LegacyUM3PrinterOutputController
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os # To get the username
|
|
||||||
import gzip
|
|
||||||
|
|
||||||
|
|
||||||
i18n_catalog = i18nCatalog("cura")
|
i18n_catalog = i18nCatalog("cura")
|
||||||
|
@ -259,16 +258,6 @@ class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||||
self._progress_message.hide()
|
self._progress_message.hide()
|
||||||
self._sending_gcode = False
|
self._sending_gcode = False
|
||||||
|
|
||||||
def __compressDataAndNotifyQt(self, data_to_append):
|
|
||||||
compressed_data = gzip.compress(data_to_append.encode("utf-8"))
|
|
||||||
self._progress_message.setProgress(-1) # Tickle the message so that it's clear that it's still being used.
|
|
||||||
QCoreApplication.processEvents() # Ensure that the GUI does not freeze.
|
|
||||||
|
|
||||||
# Pretend that this is a response, as zipping might take a bit of time.
|
|
||||||
# If we don't do this, the device might trigger a timeout.
|
|
||||||
self._last_response_time = time()
|
|
||||||
return compressed_data
|
|
||||||
|
|
||||||
def _onUploadPrintJobProgress(self, bytes_sent, bytes_total):
|
def _onUploadPrintJobProgress(self, bytes_sent, bytes_total):
|
||||||
if bytes_total > 0:
|
if bytes_total > 0:
|
||||||
new_progress = bytes_sent / bytes_total * 100
|
new_progress = bytes_sent / bytes_total * 100
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue