Merge branch 'master' into CURA-7454_Add_remove_printers_button_in_removed_printers_from_account_message

This commit is contained in:
Kostas Karmas 2020-06-09 15:03:23 +02:00
commit 8e1ed6cd29
4 changed files with 74 additions and 105 deletions

View file

@ -886,6 +886,7 @@ class CuraApplication(QtApplication):
# Initialize camera tool # Initialize camera tool
camera_tool = controller.getTool("CameraTool") camera_tool = controller.getTool("CameraTool")
if camera_tool:
camera_tool.setOrigin(Vector(0, 100, 0)) camera_tool.setOrigin(Vector(0, 100, 0))
camera_tool.setZoomRange(0.1, 2000) camera_tool.setZoomRange(0.1, 2000)

View file

@ -100,7 +100,8 @@ class QualitySettingsModel(ListModel):
# the settings in that quality_changes_group. # the settings in that quality_changes_group.
if quality_changes_group is not None: if quality_changes_group is not None:
container_registry = ContainerRegistry.getInstance() container_registry = ContainerRegistry.getInstance()
global_containers = container_registry.findContainers(id = quality_changes_group.metadata_for_global["id"]) metadata_for_global = quality_changes_group.metadata_for_global
global_containers = container_registry.findContainers(id = metadata_for_global["id"])
global_container = None if len(global_containers) == 0 else global_containers[0] global_container = None if len(global_containers) == 0 else global_containers[0]
extruders_containers = {pos: container_registry.findContainers(id = quality_changes_group.metadata_per_extruder[pos]["id"]) for pos in quality_changes_group.metadata_per_extruder} extruders_containers = {pos: container_registry.findContainers(id = quality_changes_group.metadata_per_extruder[pos]["id"]) for pos in quality_changes_group.metadata_per_extruder}
extruders_container = {pos: None if not containers else containers[0] for pos, containers in extruders_containers.items()} extruders_container = {pos: None if not containers else containers[0] for pos, containers in extruders_containers.items()}

View file

@ -20,9 +20,6 @@ class ToolPathUploader:
# The HTTP codes that should trigger a retry. # The HTTP codes that should trigger a retry.
RETRY_HTTP_CODES = {500, 502, 503, 504} RETRY_HTTP_CODES = {500, 502, 503, 504}
# The amount of bytes to send per request
BYTES_PER_REQUEST = 256 * 1024
def __init__(self, http: HttpRequestManager, print_job: CloudPrintJobResponse, data: bytes, def __init__(self, http: HttpRequestManager, print_job: CloudPrintJobResponse, data: bytes,
on_finished: Callable[[], Any], on_progress: Callable[[int], Any], on_error: Callable[[], Any] on_finished: Callable[[], Any], on_progress: Callable[[int], Any], on_error: Callable[[], Any]
) -> None: ) -> None:
@ -44,7 +41,6 @@ class ToolPathUploader:
self._on_progress = on_progress self._on_progress = on_progress
self._on_error = on_error self._on_error = on_error
self._sent_bytes = 0
self._retries = 0 self._retries = 0
self._finished = False self._finished = False
@ -54,50 +50,34 @@ class ToolPathUploader:
return self._print_job return self._print_job
def _chunkRange(self) -> Tuple[int, int]:
"""Determines the bytes that should be uploaded next.
:return: A tuple with the first and the last byte to upload.
"""
last_byte = min(len(self._data), self._sent_bytes + self.BYTES_PER_REQUEST)
return self._sent_bytes, last_byte
def start(self) -> None: def start(self) -> None:
"""Starts uploading the mesh.""" """Starts uploading the mesh."""
if self._finished: if self._finished:
# reset state. # reset state.
self._sent_bytes = 0
self._retries = 0 self._retries = 0
self._finished = False self._finished = False
self._uploadChunk() self._upload()
def stop(self): def stop(self):
"""Stops uploading the mesh, marking it as finished.""" """Stops uploading the mesh, marking it as finished."""
Logger.log("i", "Stopped uploading") Logger.log("i", "Finished uploading")
self._finished = True self._finished = True # Signal to any ongoing retries that we should stop retrying.
self._on_finished()
def _uploadChunk(self) -> None:
"""Uploads a chunk of the mesh to the cloud."""
def _upload(self) -> None:
"""
Uploads the print job to the cloud printer.
"""
if self._finished: if self._finished:
raise ValueError("The upload is already finished") raise ValueError("The upload is already finished")
first_byte, last_byte = self._chunkRange() Logger.log("i", "Uploading print to {upload_url}".format(upload_url = self._print_job.upload_url))
content_range = "bytes {}-{}/{}".format(first_byte, last_byte - 1, len(self._data))
headers = {
"Content-Type": cast(str, self._print_job.content_type),
"Content-Range": content_range
} # type: Dict[str, str]
Logger.log("i", "Uploading %s to %s", content_range, self._print_job.upload_url)
self._http.put( self._http.put(
url = cast(str, self._print_job.upload_url), url = cast(str, self._print_job.upload_url),
headers_dict = headers, headers_dict = {"Content-Type": cast(str, self._print_job.content_type)},
data = self._data[first_byte:last_byte], data = self._data,
callback = self._finishedCallback, callback = self._finishedCallback,
error_callback = self._errorCallback, error_callback = self._errorCallback,
upload_progress_callback = self._progressCallback upload_progress_callback = self._progressCallback
@ -109,10 +89,9 @@ class ToolPathUploader:
:param bytes_sent: The amount of bytes sent in the current request. :param bytes_sent: The amount of bytes sent in the current request.
:param bytes_total: The amount of bytes to send in the current request. :param bytes_total: The amount of bytes to send in the current request.
""" """
Logger.log("i", "Progress callback %s / %s", bytes_sent, bytes_total) Logger.debug("Cloud upload progress %s / %s", bytes_sent, bytes_total)
if bytes_total: if bytes_total:
total_sent = self._sent_bytes + bytes_sent self._on_progress(int(bytes_sent / len(self._data) * 100))
self._on_progress(int(total_sent / len(self._data) * 100))
## Handles an error uploading. ## Handles an error uploading.
def _errorCallback(self, reply: QNetworkReply, error: QNetworkReply.NetworkError) -> None: def _errorCallback(self, reply: QNetworkReply, error: QNetworkReply.NetworkError) -> None:
@ -136,7 +115,7 @@ class ToolPathUploader:
self._retries += 1 self._retries += 1
Logger.log("i", "Retrying %s/%s request %s", self._retries, self.MAX_RETRIES, reply.url().toString()) Logger.log("i", "Retrying %s/%s request %s", self._retries, self.MAX_RETRIES, reply.url().toString())
try: try:
self._uploadChunk() self._upload()
except ValueError: # Asynchronously it could have completed in the meanwhile. except ValueError: # Asynchronously it could have completed in the meanwhile.
pass pass
return return
@ -148,16 +127,5 @@ class ToolPathUploader:
Logger.log("d", "status_code: %s, Headers: %s, body: %s", status_code, Logger.log("d", "status_code: %s, Headers: %s, body: %s", status_code,
[bytes(header).decode() for header in reply.rawHeaderList()], bytes(reply.readAll()).decode()) [bytes(header).decode() for header in reply.rawHeaderList()], bytes(reply.readAll()).decode())
self._chunkUploaded()
def _chunkUploaded(self) -> None:
"""Handles a chunk of data being uploaded, starting the next chunk if needed."""
# We got a successful response. Let's start the next chunk or report the upload is finished.
first_byte, last_byte = self._chunkRange()
self._sent_bytes += last_byte - first_byte
if self._sent_bytes >= len(self._data):
self.stop() self.stop()
self._on_finished()
else:
self._uploadChunk()

View file

@ -4,6 +4,7 @@
import QtQuick 2.10 import QtQuick 2.10
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import QtQuick.Controls.Styles 1.4 import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.3
import UM 1.2 as UM import UM 1.2 as UM
import Cura 1.0 as Cura import Cura 1.0 as Cura
@ -37,19 +38,16 @@ Cura.ExpandablePopup
headerItem: Item headerItem: Item
{ {
// Horizontal list that shows the extruders and their materials // Horizontal list that shows the extruders and their materials
ListView RowLayout
{ {
id: extrudersList
orientation: ListView.Horizontal
anchors.fill: parent anchors.fill: parent
Repeater
{
model: extrudersModel model: extrudersModel
visible: Cura.MachineManager.activeMachine.hasMaterials
delegate: Item delegate: Item
{ {
height: parent.height Layout.fillWidth: true
width: Math.round(ListView.view.width / extrudersModel.count) Layout.fillHeight: true
// Extruder icon. Shows extruder index and has the same color as the active material. // Extruder icon. Shows extruder index and has the same color as the active material.
Cura.ExtruderIcon Cura.ExtruderIcon
@ -105,6 +103,7 @@ Cura.ExpandablePopup
} }
} }
} }
}
// Placeholder text if there is a configuration to select but no materials (so we can't show the materials per extruder). // Placeholder text if there is a configuration to select but no materials (so we can't show the materials per extruder).
Label Label