mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-14 10:17:52 -06:00
Fixed some bugs and added the color_code field to the named tuple
This commit is contained in:
parent
2497325d60
commit
481ca8cd2f
2 changed files with 15 additions and 6 deletions
|
@ -23,6 +23,7 @@ LocalMaterial = namedtuple('LocalMaterial', [
|
||||||
'brand',
|
'brand',
|
||||||
'material',
|
'material',
|
||||||
'color_name',
|
'color_name',
|
||||||
|
'color_code',
|
||||||
'description',
|
'description',
|
||||||
'adhesion_info',
|
'adhesion_info',
|
||||||
'approximate_diameter',
|
'approximate_diameter',
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from typing import Dict, TYPE_CHECKING, Set
|
from typing import Dict, TYPE_CHECKING, Set
|
||||||
|
|
||||||
|
@ -19,7 +20,6 @@ from .Models import ClusterMaterial, LocalMaterial
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .ClusterUM3OutputDevice import ClusterUM3OutputDevice
|
from .ClusterUM3OutputDevice import ClusterUM3OutputDevice
|
||||||
|
|
||||||
|
|
||||||
## Asynchronous job to send material profiles to the printer.
|
## Asynchronous job to send material profiles to the printer.
|
||||||
#
|
#
|
||||||
# This way it won't freeze up the interface while sending those materials.
|
# This way it won't freeze up the interface while sending those materials.
|
||||||
|
@ -50,7 +50,7 @@ class SendMaterialJob(Job):
|
||||||
self._sendMissingMaterials(remote_materials_by_guid)
|
self._sendMissingMaterials(remote_materials_by_guid)
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
Logger.logException("w", "Error parsing materials from printer")
|
Logger.logException("w", "Error parsing materials from printer")
|
||||||
except KeyError:
|
except TypeError:
|
||||||
Logger.logException("w", "Error parsing materials from printer")
|
Logger.logException("w", "Error parsing materials from printer")
|
||||||
|
|
||||||
## Determine which materials should be updated and send them to the printer.
|
## Determine which materials should be updated and send them to the printer.
|
||||||
|
@ -75,7 +75,8 @@ class SendMaterialJob(Job):
|
||||||
|
|
||||||
## From the local and remote materials, determine which ones should be synchronized.
|
## From the local and remote materials, determine which ones should be synchronized.
|
||||||
#
|
#
|
||||||
# Makes a Set containing only the materials that are not on the printer yet or the ones that are newer in Cura.
|
# Makes a Set of id's containing only the id's of the materials that are not on the printer yet or the ones that
|
||||||
|
# are newer in Cura.
|
||||||
#
|
#
|
||||||
# \param local_materials The local materials by GUID.
|
# \param local_materials The local materials by GUID.
|
||||||
# \param remote_materials The remote materials by GUID.
|
# \param remote_materials The remote materials by GUID.
|
||||||
|
@ -157,7 +158,7 @@ class SendMaterialJob(Job):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parseReply(cls, reply: QNetworkReply) -> Dict[str, ClusterMaterial]:
|
def _parseReply(cls, reply: QNetworkReply) -> Dict[str, ClusterMaterial]:
|
||||||
remote_materials = json.loads(reply.readAll().data().decode("utf-8"))
|
remote_materials = json.loads(reply.readAll().data().decode("utf-8"))
|
||||||
return {material["id"]: ClusterMaterial(**material) for material in remote_materials}
|
return {material["guid"]: ClusterMaterial(**material) for material in remote_materials}
|
||||||
|
|
||||||
## Retrieves a list of local materials
|
## Retrieves a list of local materials
|
||||||
#
|
#
|
||||||
|
@ -170,12 +171,19 @@ class SendMaterialJob(Job):
|
||||||
material_containers = container_registry.findContainersMetadata(type = "material")
|
material_containers = container_registry.findContainersMetadata(type = "material")
|
||||||
|
|
||||||
# Find the latest version of all material containers in the registry.
|
# Find the latest version of all material containers in the registry.
|
||||||
local_materials = {} # type: Dict[str, LocalMaterial]
|
|
||||||
for material in material_containers:
|
for material in material_containers:
|
||||||
try:
|
try:
|
||||||
material = LocalMaterial(**material)
|
material = LocalMaterial(**material)
|
||||||
|
|
||||||
|
# material version must be an int
|
||||||
|
if not re.match("\d+", material.version):
|
||||||
|
Logger.logException("w", "Local material {} has invalid version '{}'."
|
||||||
|
.format(material["id"], material.version))
|
||||||
|
continue
|
||||||
|
|
||||||
if material.GUID not in result or material.version > result.get(material.GUID).version:
|
if material.GUID not in result or material.version > result.get(material.GUID).version:
|
||||||
local_materials[material.GUID] = material
|
result[material.GUID] = material
|
||||||
except ValueError:
|
except ValueError:
|
||||||
Logger.logException("w", "Local material {} has invalid values.".format(material["id"]))
|
Logger.logException("w", "Local material {} has invalid values.".format(material["id"]))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue