mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-12 09:17:50 -06:00
CURA-5035 Added material authors + icons
This commit is contained in:
parent
b763b2a5a0
commit
7a0fe74989
6 changed files with 68 additions and 22 deletions
|
@ -69,7 +69,6 @@ class CuraPackageManager(QObject):
|
||||||
|
|
||||||
# (for initialize) Removes all packages that have been scheduled to be removed.
|
# (for initialize) Removes all packages that have been scheduled to be removed.
|
||||||
def _removeAllScheduledPackages(self) -> None:
|
def _removeAllScheduledPackages(self) -> None:
|
||||||
print("Will purge", self._to_remove_package_set)
|
|
||||||
for package_id in self._to_remove_package_set:
|
for package_id in self._to_remove_package_set:
|
||||||
self._purgePackage(package_id)
|
self._purgePackage(package_id)
|
||||||
self._to_remove_package_set.clear()
|
self._to_remove_package_set.clear()
|
||||||
|
@ -223,11 +222,7 @@ class CuraPackageManager(QObject):
|
||||||
if package_id in self._to_install_package_dict:
|
if package_id in self._to_install_package_dict:
|
||||||
del self._to_install_package_dict[package_id]
|
del self._to_install_package_dict[package_id]
|
||||||
|
|
||||||
# If the package has already been installed, schedule for a delayed removal
|
# Schedule for a delayed removal:
|
||||||
# if package_id in self._installed_package_dict:
|
|
||||||
# self._to_remove_package_set.add(package_id)
|
|
||||||
# "Or rather don't because sometimes packages are not making it into the
|
|
||||||
# dict I guess." - Ian
|
|
||||||
self._to_remove_package_set.add(package_id)
|
self._to_remove_package_set.add(package_id)
|
||||||
|
|
||||||
self._saveManagementData()
|
self._saveManagementData()
|
||||||
|
@ -235,7 +230,6 @@ class CuraPackageManager(QObject):
|
||||||
|
|
||||||
# Removes everything associated with the given package ID.
|
# Removes everything associated with the given package ID.
|
||||||
def _purgePackage(self, package_id: str) -> None:
|
def _purgePackage(self, package_id: str) -> None:
|
||||||
print("Purging",package_id)
|
|
||||||
# Get all folders that need to be checked for installed packages, including:
|
# Get all folders that need to be checked for installed packages, including:
|
||||||
# - materials
|
# - materials
|
||||||
# - qualities
|
# - qualities
|
||||||
|
@ -249,7 +243,6 @@ class CuraPackageManager(QObject):
|
||||||
|
|
||||||
for root_dir in dirs_to_check:
|
for root_dir in dirs_to_check:
|
||||||
package_dir = os.path.join(root_dir, package_id)
|
package_dir = os.path.join(root_dir, package_id)
|
||||||
print(package_dir)
|
|
||||||
if os.path.exists(package_dir):
|
if os.path.exists(package_dir):
|
||||||
Logger.log("i", "Removing '%s' for package [%s]", package_dir, package_id)
|
Logger.log("i", "Removing '%s' for package [%s]", package_dir, package_id)
|
||||||
shutil.rmtree(package_dir)
|
shutil.rmtree(package_dir)
|
||||||
|
|
|
@ -83,24 +83,25 @@ Item
|
||||||
}
|
}
|
||||||
onExited:
|
onExited:
|
||||||
{
|
{
|
||||||
thumbnail.border.color = UM.Theme.getColor("text")
|
thumbnail.border.color = UM.Theme.getColor("lining")
|
||||||
highlight.opacity = 0.0
|
highlight.opacity = 0.0
|
||||||
}
|
}
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
|
console.log(model.icon_url)
|
||||||
if ( toolbox.viewCategory == "material" )
|
if ( toolbox.viewCategory == "material" )
|
||||||
{
|
{
|
||||||
toolbox.viewSelection = model.name
|
toolbox.viewSelection = model.name
|
||||||
toolbox.viewPage = "author"
|
toolbox.viewPage = "author"
|
||||||
toolbox.filterModelByProp("authors", "name", model.name)
|
|
||||||
toolbox.filterModelByProp("packages", "author_name", model.name)
|
toolbox.filterModelByProp("packages", "author_name", model.name)
|
||||||
|
toolbox.filterModelByProp("authors", "name", model.name)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
toolbox.viewSelection = model.id
|
toolbox.viewSelection = model.id
|
||||||
toolbox.viewPage = "detail"
|
toolbox.viewPage = "detail"
|
||||||
toolbox.filterModelByProp("authors", "name", model.author_name)
|
|
||||||
toolbox.filterModelByProp("packages", "id", model.id)
|
toolbox.filterModelByProp("packages", "id", model.id)
|
||||||
|
toolbox.filterModelByProp("authors", "name", model.author_name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,17 @@ Item
|
||||||
}
|
}
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
text: "<a href=\"mailto:"+model.author_email+"?Subject=Cura: "+model.name+"\">"+model.author_name+"</a>"
|
text:
|
||||||
|
{
|
||||||
|
if (model.author_email)
|
||||||
|
{
|
||||||
|
return "<a href=\"mailto:"+model.author_email+"?Subject=Cura: "+model.name+"\">"+model.author_name+"</a>"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return model.author_name
|
||||||
|
}
|
||||||
|
}
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: 24
|
height: 24
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
|
|
|
@ -19,7 +19,8 @@ class AuthorsModel(ListModel):
|
||||||
self.addRoleName(Qt.UserRole + 2, "email")
|
self.addRoleName(Qt.UserRole + 2, "email")
|
||||||
self.addRoleName(Qt.UserRole + 3, "website")
|
self.addRoleName(Qt.UserRole + 3, "website")
|
||||||
self.addRoleName(Qt.UserRole + 4, "type")
|
self.addRoleName(Qt.UserRole + 4, "type")
|
||||||
self.addRoleName(Qt.UserRole + 5, "packages_count")
|
self.addRoleName(Qt.UserRole + 5, "icon_url")
|
||||||
|
self.addRoleName(Qt.UserRole + 6, "packages_count")
|
||||||
|
|
||||||
# List of filters for queries. The result is the union of the each list of results.
|
# List of filters for queries. The result is the union of the each list of results.
|
||||||
self._filter = {} # type: Dict[str,str]
|
self._filter = {} # type: Dict[str,str]
|
||||||
|
@ -34,10 +35,11 @@ class AuthorsModel(ListModel):
|
||||||
for author in self._metadata:
|
for author in self._metadata:
|
||||||
items.append({
|
items.append({
|
||||||
"name": author["name"],
|
"name": author["name"],
|
||||||
"email": author["email"],
|
"email": author["email"] if "email" in author else None,
|
||||||
"website": author["website"],
|
"website": author["website"] if "website" in author else None,
|
||||||
"type": author["type"],
|
"type": author["type"] if "type" in author else None,
|
||||||
"packages_count": author["packages_count"]
|
"icon_url": author["icon_url"] if "icon_url" in author else None,
|
||||||
|
"packages_count": author["packages_count"] if "packages_count" in author else 0
|
||||||
})
|
})
|
||||||
|
|
||||||
# Filter on all the key-word arguments.
|
# Filter on all the key-word arguments.
|
||||||
|
|
|
@ -47,7 +47,7 @@ class PackagesModel(ListModel):
|
||||||
"name": package["display_name"],
|
"name": package["display_name"],
|
||||||
"version": package["package_version"],
|
"version": package["package_version"],
|
||||||
"author_name": package["author"]["name"],
|
"author_name": package["author"]["name"],
|
||||||
"author_email": package["author"]["email"],
|
"author_email": package["author"]["email"] if "email" in package["author"] else None,
|
||||||
"description": package["description"],
|
"description": package["description"],
|
||||||
"icon_url": package["icon_url"] if "icon_url" in package else None,
|
"icon_url": package["icon_url"] if "icon_url" in package else None,
|
||||||
"image_urls": package["image_urls"] if "image_urls" in package else None,
|
"image_urls": package["image_urls"] if "image_urls" in package else None,
|
||||||
|
|
|
@ -75,6 +75,7 @@ class Toolbox(QObject, Extension):
|
||||||
"email": "ian.paschal@gmail.com",
|
"email": "ian.paschal@gmail.com",
|
||||||
"website": "ultimaker.com",
|
"website": "ultimaker.com",
|
||||||
"type": "material",
|
"type": "material",
|
||||||
|
"icon": None,
|
||||||
"packages_count": 7
|
"packages_count": 7
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -82,6 +83,7 @@ class Toolbox(QObject, Extension):
|
||||||
"email": "contact@dsm.nl",
|
"email": "contact@dsm.nl",
|
||||||
"website": "www.dsm.nl",
|
"website": "www.dsm.nl",
|
||||||
"type": "material",
|
"type": "material",
|
||||||
|
"icon": None,
|
||||||
"packages_count": 0
|
"packages_count": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -89,6 +91,7 @@ class Toolbox(QObject, Extension):
|
||||||
"email": "contact@basf.de",
|
"email": "contact@basf.de",
|
||||||
"website": "www.basf.de",
|
"website": "www.basf.de",
|
||||||
"type": "material",
|
"type": "material",
|
||||||
|
"icon": None,
|
||||||
"packages_count": 0
|
"packages_count": 0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -217,6 +220,9 @@ class Toolbox(QObject, Extension):
|
||||||
self._dialog = self._createDialog("Toolbox.qml")
|
self._dialog = self._createDialog("Toolbox.qml")
|
||||||
self._dialog.show()
|
self._dialog.show()
|
||||||
|
|
||||||
|
# Apply enabled/disabled state to installed plugins
|
||||||
|
self.enabledChanged.emit()
|
||||||
|
|
||||||
def _createDialog(self, qml_name):
|
def _createDialog(self, qml_name):
|
||||||
Logger.log("d", "Toolbox: Creating dialog [%s].", qml_name)
|
Logger.log("d", "Toolbox: Creating dialog [%s].", qml_name)
|
||||||
path = os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "resources", "qml", qml_name)
|
path = os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "resources", "qml", qml_name)
|
||||||
|
@ -359,7 +365,6 @@ class Toolbox(QObject, Extension):
|
||||||
return
|
return
|
||||||
|
|
||||||
if reply.operation() == QNetworkAccessManager.GetOperation:
|
if reply.operation() == QNetworkAccessManager.GetOperation:
|
||||||
|
|
||||||
# TODO: In the future use the following to build any model from any
|
# TODO: In the future use the following to build any model from any
|
||||||
# request. Right now this doesn't work because the packages request
|
# request. Right now this doesn't work because the packages request
|
||||||
# is also responsible for populating other models.
|
# is also responsible for populating other models.
|
||||||
|
@ -367,6 +372,14 @@ class Toolbox(QObject, Extension):
|
||||||
# if reply.url() == url:
|
# if reply.url() == url:
|
||||||
# try:
|
# try:
|
||||||
# json_data = json.loads(bytes(reply.readAll()).decode("utf-8"))
|
# json_data = json.loads(bytes(reply.readAll()).decode("utf-8"))
|
||||||
|
#
|
||||||
|
# # Check for errors:
|
||||||
|
# if "errors" in json_data:
|
||||||
|
# for error in json_data["errors"]:
|
||||||
|
# Logger.log("e", "%s", error["title"])
|
||||||
|
# return
|
||||||
|
#
|
||||||
|
# # Create model and apply metadata:
|
||||||
# if not self._models[type]:
|
# if not self._models[type]:
|
||||||
# Logger.log("e", "Could not find the %s model.", type)
|
# Logger.log("e", "Could not find the %s model.", type)
|
||||||
# break
|
# break
|
||||||
|
@ -382,9 +395,17 @@ class Toolbox(QObject, Extension):
|
||||||
if reply.url() == self._request_urls["packages"]:
|
if reply.url() == self._request_urls["packages"]:
|
||||||
try:
|
try:
|
||||||
json_data = json.loads(bytes(reply.readAll()).decode("utf-8"))
|
json_data = json.loads(bytes(reply.readAll()).decode("utf-8"))
|
||||||
|
|
||||||
|
# Check for errors:
|
||||||
|
if "errors" in json_data:
|
||||||
|
for error in json_data["errors"]:
|
||||||
|
Logger.log("e", "%s", error["title"])
|
||||||
|
return
|
||||||
|
|
||||||
# Create packages model with all packages:
|
# Create packages model with all packages:
|
||||||
if not self._models["packages"]:
|
if not self._models["packages"]:
|
||||||
self._models["packages"] = PackagesModel(self)
|
self._models["packages"] = PackagesModel(self)
|
||||||
|
print(json_data["data"])
|
||||||
self._metadata["packages"] = json_data["data"]
|
self._metadata["packages"] = json_data["data"]
|
||||||
self._models["packages"].setMetadata(self._metadata["packages"])
|
self._models["packages"].setMetadata(self._metadata["packages"])
|
||||||
self.metadataChanged.emit()
|
self.metadataChanged.emit()
|
||||||
|
@ -394,11 +415,23 @@ class Toolbox(QObject, Extension):
|
||||||
self._models["authors"] = AuthorsModel()
|
self._models["authors"] = AuthorsModel()
|
||||||
# TODO: Replace this with a proper API call:
|
# TODO: Replace this with a proper API call:
|
||||||
for package in self._metadata["packages"]:
|
for package in self._metadata["packages"]:
|
||||||
package["author"]["type"] = package["package_type"]
|
|
||||||
package["author"]["packages_count"] = 1
|
|
||||||
if package["author"] not in self._metadata["authors"]:
|
if package["author"] not in self._metadata["authors"]:
|
||||||
self._metadata["authors"].append(package["author"])
|
self._metadata["authors"].append(package["author"])
|
||||||
|
|
||||||
|
for author in self._metadata["authors"]:
|
||||||
|
if "package_count" not in author:
|
||||||
|
author["package_count"] = 0
|
||||||
|
|
||||||
|
for package in self._metadata["packages"]:
|
||||||
|
if package["author"]["name"] == author["name"]:
|
||||||
|
author["package_count"] += 1
|
||||||
|
author["type"] = package["package_type"]
|
||||||
|
if "icon_url" in package:
|
||||||
|
author["icon_url"] = package["icon_url"]
|
||||||
|
|
||||||
self._models["authors"].setMetadata(self._metadata["authors"])
|
self._models["authors"].setMetadata(self._metadata["authors"])
|
||||||
|
for author in self._models["authors"].items:
|
||||||
|
print(author["icon_url"])
|
||||||
self.metadataChanged.emit()
|
self.metadataChanged.emit()
|
||||||
|
|
||||||
if not self._models["materials_showcase"]:
|
if not self._models["materials_showcase"]:
|
||||||
|
@ -409,7 +442,7 @@ class Toolbox(QObject, Extension):
|
||||||
# This part is also needed for comparing downloaded packages to
|
# This part is also needed for comparing downloaded packages to
|
||||||
# installed packages.
|
# installed packages.
|
||||||
self._models["packages"].setMetadata(self._metadata["packages"])
|
self._models["packages"].setMetadata(self._metadata["packages"])
|
||||||
|
self._models["packages"].setFilter({"type": "plugin"})
|
||||||
|
|
||||||
self.metadataChanged.emit()
|
self.metadataChanged.emit()
|
||||||
|
|
||||||
|
@ -423,6 +456,13 @@ class Toolbox(QObject, Extension):
|
||||||
if reply.url() == self._request_urls["plugins_showcase"]:
|
if reply.url() == self._request_urls["plugins_showcase"]:
|
||||||
try:
|
try:
|
||||||
json_data = json.loads(bytes(reply.readAll()).decode("utf-8"))
|
json_data = json.loads(bytes(reply.readAll()).decode("utf-8"))
|
||||||
|
|
||||||
|
# Check for errors:
|
||||||
|
if "errors" in json_data:
|
||||||
|
for error in json_data["errors"]:
|
||||||
|
Logger.log("e", "%s", error["title"])
|
||||||
|
return
|
||||||
|
|
||||||
# Create packages model with all packages:
|
# Create packages model with all packages:
|
||||||
if not self._models["plugins_showcase"]:
|
if not self._models["plugins_showcase"]:
|
||||||
self._models["plugins_showcase"] = PackagesModel()
|
self._models["plugins_showcase"] = PackagesModel()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue