CURA-5035 Added material authors + icons

This commit is contained in:
Ian Paschal 2018-04-17 17:07:06 +02:00
parent b763b2a5a0
commit 7a0fe74989
6 changed files with 68 additions and 22 deletions

View file

@ -69,7 +69,6 @@ class CuraPackageManager(QObject):
# (for initialize) Removes all packages that have been scheduled to be removed.
def _removeAllScheduledPackages(self) -> None:
print("Will purge", self._to_remove_package_set)
for package_id in self._to_remove_package_set:
self._purgePackage(package_id)
self._to_remove_package_set.clear()
@ -223,11 +222,7 @@ class CuraPackageManager(QObject):
if package_id in self._to_install_package_dict:
del self._to_install_package_dict[package_id]
# If the package has already been installed, 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
# Schedule for a delayed removal:
self._to_remove_package_set.add(package_id)
self._saveManagementData()
@ -235,7 +230,6 @@ class CuraPackageManager(QObject):
# Removes everything associated with the given package ID.
def _purgePackage(self, package_id: str) -> None:
print("Purging",package_id)
# Get all folders that need to be checked for installed packages, including:
# - materials
# - qualities
@ -249,7 +243,6 @@ class CuraPackageManager(QObject):
for root_dir in dirs_to_check:
package_dir = os.path.join(root_dir, package_id)
print(package_dir)
if os.path.exists(package_dir):
Logger.log("i", "Removing '%s' for package [%s]", package_dir, package_id)
shutil.rmtree(package_dir)

View file

@ -83,24 +83,25 @@ Item
}
onExited:
{
thumbnail.border.color = UM.Theme.getColor("text")
thumbnail.border.color = UM.Theme.getColor("lining")
highlight.opacity = 0.0
}
onClicked:
{
console.log(model.icon_url)
if ( toolbox.viewCategory == "material" )
{
toolbox.viewSelection = model.name
toolbox.viewPage = "author"
toolbox.filterModelByProp("authors", "name", model.name)
toolbox.filterModelByProp("packages", "author_name", model.name)
toolbox.filterModelByProp("authors", "name", model.name)
}
else
{
toolbox.viewSelection = model.id
toolbox.viewPage = "detail"
toolbox.filterModelByProp("authors", "name", model.author_name)
toolbox.filterModelByProp("packages", "id", model.id)
toolbox.filterModelByProp("authors", "name", model.author_name)
}
}
}

View file

@ -77,7 +77,17 @@ Item
}
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
height: 24
wrapMode: Text.WordWrap

View file

@ -19,7 +19,8 @@ class AuthorsModel(ListModel):
self.addRoleName(Qt.UserRole + 2, "email")
self.addRoleName(Qt.UserRole + 3, "website")
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.
self._filter = {} # type: Dict[str,str]
@ -34,10 +35,11 @@ class AuthorsModel(ListModel):
for author in self._metadata:
items.append({
"name": author["name"],
"email": author["email"],
"website": author["website"],
"type": author["type"],
"packages_count": author["packages_count"]
"email": author["email"] if "email" in author else None,
"website": author["website"] if "website" in author else None,
"type": author["type"] if "type" in author else None,
"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.

View file

@ -47,7 +47,7 @@ class PackagesModel(ListModel):
"name": package["display_name"],
"version": package["package_version"],
"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"],
"icon_url": package["icon_url"] if "icon_url" in package else None,
"image_urls": package["image_urls"] if "image_urls" in package else None,

View file

@ -75,6 +75,7 @@ class Toolbox(QObject, Extension):
"email": "ian.paschal@gmail.com",
"website": "ultimaker.com",
"type": "material",
"icon": None,
"packages_count": 7
},
{
@ -82,6 +83,7 @@ class Toolbox(QObject, Extension):
"email": "contact@dsm.nl",
"website": "www.dsm.nl",
"type": "material",
"icon": None,
"packages_count": 0
},
{
@ -89,6 +91,7 @@ class Toolbox(QObject, Extension):
"email": "contact@basf.de",
"website": "www.basf.de",
"type": "material",
"icon": None,
"packages_count": 0
}
],
@ -217,6 +220,9 @@ class Toolbox(QObject, Extension):
self._dialog = self._createDialog("Toolbox.qml")
self._dialog.show()
# Apply enabled/disabled state to installed plugins
self.enabledChanged.emit()
def _createDialog(self, qml_name):
Logger.log("d", "Toolbox: Creating dialog [%s].", qml_name)
path = os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "resources", "qml", qml_name)
@ -359,7 +365,6 @@ class Toolbox(QObject, Extension):
return
if reply.operation() == QNetworkAccessManager.GetOperation:
# TODO: In the future use the following to build any model from any
# request. Right now this doesn't work because the packages request
# is also responsible for populating other models.
@ -367,6 +372,14 @@ class Toolbox(QObject, Extension):
# if reply.url() == url:
# try:
# 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]:
# Logger.log("e", "Could not find the %s model.", type)
# break
@ -382,9 +395,17 @@ class Toolbox(QObject, Extension):
if reply.url() == self._request_urls["packages"]:
try:
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:
if not self._models["packages"]:
self._models["packages"] = PackagesModel(self)
print(json_data["data"])
self._metadata["packages"] = json_data["data"]
self._models["packages"].setMetadata(self._metadata["packages"])
self.metadataChanged.emit()
@ -394,11 +415,23 @@ class Toolbox(QObject, Extension):
self._models["authors"] = AuthorsModel()
# TODO: Replace this with a proper API call:
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"]:
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"])
for author in self._models["authors"].items:
print(author["icon_url"])
self.metadataChanged.emit()
if not self._models["materials_showcase"]:
@ -409,7 +442,7 @@ class Toolbox(QObject, Extension):
# This part is also needed for comparing downloaded packages to
# installed packages.
self._models["packages"].setMetadata(self._metadata["packages"])
self._models["packages"].setFilter({"type": "plugin"})
self.metadataChanged.emit()
@ -423,6 +456,13 @@ class Toolbox(QObject, Extension):
if reply.url() == self._request_urls["plugins_showcase"]:
try:
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:
if not self._models["plugins_showcase"]:
self._models["plugins_showcase"] = PackagesModel()