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

@ -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()