Initial implementation for the Compatibility Dialog window

CURA-7038
This commit is contained in:
Dimitriovski 2019-12-23 15:18:09 +01:00
parent 9cf5a388f3
commit bd8c1e4c96
No known key found for this signature in database
GPG key ID: 4E62757E2B0D304D
3 changed files with 115 additions and 155 deletions

View file

@ -13,27 +13,63 @@ import UM 1.1 as UM
import Cura 1.6 as Cura import Cura 1.6 as Cura
UM.Dialog UM.Dialog{
{
visible: true visible: true
title: "Changes from your account"
Label{
text: "Some text here"
height: 50
}
Rectangle
{
id: compatibleRectangle
width: parent.width
height: 300
Label{
text: "Some text here"
height: 50
}
title: "Some title"
minimumWidth: UM.Theme.getSize("license_window_minimum").width
minimumHeight: UM.Theme.getSize("license_window_minimum").height
width: minimumWidth
height: minimumHeight
ListView
{ // Compatible packages
id: listView Column{
id: compatibleColumn
anchors.fill: parent
spacing: 2
Repeater{
model: toolbox.subscribedPackagesModel
delegate: Rectangle{
id: someRect
width: parent.width
height: 50
border.color: "black"
Image{
source: model.icon_url || "../../images/logobot.svg"
width: 50
height: parent.height
//anchors.left: parent.left
//anchors.right: packageName.left
anchors.rightMargin: 20
}
Text{
id: packageName
text: model.name
anchors.centerIn: parent
}
MouseArea{
anchors.fill: parent anchors.fill: parent
onClicked: {
console.log("Clicked!")
model: toolbox.subscribedPackagesModel
delegate: Label
{
text: "A :)"
} }
} }
}
}
}
}
} }

View file

@ -19,142 +19,32 @@ class SubscribedPackagesModel(ListModel):
def __init__(self, parent = None): def __init__(self, parent = None):
super().__init__(parent) super().__init__(parent)
# self._metadata = None
self.addRoleName(Qt.UserRole + 1, "name") self.addRoleName(Qt.UserRole + 1, "name")
self.addRoleName(Qt.UserRole + 2, "icon_url") self.addRoleName(Qt.UserRole + 2, "icon_url")
self.addRoleName(Qt.UserRole + 3, "is_compatible") self.addRoleName(Qt.UserRole + 3, "is_compatible")
# List of filters for queries. The result is the union of the each list of results.
self._filter = {} # type: Dict[str, str]
#
# def setMetadata(self, data):
# if self._metadata != data:
# self._metadata = data
# self._update()
def update(self): def update(self):
print("---- in update function") # items1 = []
items1 = [] # items2 = []
items2 = []
# if self._metadata is None:
# Logger.logException("w", "Failed to load packages for Marketplace")
# self.setItems(items)
# return
toolbox = PluginRegistry.getInstance().getPluginObject("Toolbox") toolbox = PluginRegistry.getInstance().getPluginObject("Toolbox")
print(toolbox.subscribed_compatible_packages) # print("Compatible: {}".format(toolbox.subscribed_compatible_packages))
print(toolbox.subscribed_incompatible_packages) # print("Incompatible: {}".format(toolbox.subscribed_incompatible_packages))
for incompatible in toolbox.subscribed_incompatible_packages: # for incompatible in toolbox.subscribed_incompatible_packages:
items1.append({ # items1.append({
"name": incompatible.package_id # "name": incompatible.package_id,
}) # "icon_url": incompatible.icon_url
for compatible in toolbox.subscribed_compatible_packages:
items2.append({
"name": compatible.package_id
})
print("======================0----------------------")
print(items1)
print(items2)
# for package in self._metadata:
# has_configs = False
# configs_model = None
#
# links_dict = {}
# if "data" in package:
# if "supported_configs" in package["data"]:
# if len(package["data"]["supported_configs"]) > 0:
# has_configs = True
# configs_model = ConfigsModel()
# configs_model.setConfigs(package["data"]["supported_configs"])
#
# # Links is a list of dictionaries with "title" and "url". Convert this list into a dict so it's easier
# # to process.
# link_list = package["data"]["links"] if "links" in package["data"] else []
# links_dict = {d["title"]: d["url"] for d in link_list}
#
# if "author_id" not in package["author"] or "display_name" not in package["author"]:
# package["author"]["author_id"] = ""
# package["author"]["display_name"] = ""
#
# items.append({
# "id": package["package_id"],
# "type": package["package_type"],
# "name": package["display_name"],
# "version": package["package_version"],
# "author_id": package["author"]["author_id"],
# "author_name": package["author"]["display_name"],
# "author_email": package["author"]["email"] if "email" in package["author"] else None,
# "description": package["description"] if "description" 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,
# "download_url": package["download_url"] if "download_url" in package else None,
# "last_updated": package["last_updated"] if "last_updated" in package else None,
# "is_bundled": package["is_bundled"] if "is_bundled" in package else False,
# "is_active": package["is_active"] if "is_active" in package else False,
# "is_installed": package["is_installed"] if "is_installed" in package else False,
# "has_configs": has_configs,
# "supported_configs": configs_model,
# "download_count": package["download_count"] if "download_count" in package else 0,
# "tags": package["tags"] if "tags" in package else [],
# "links": links_dict,
# "website": package["website"] if "website" in package else None,
# "login_required": "login-required" in package.get("tags", []),
# "average_rating": float(package.get("rating", {}).get("average", 0)),
# "num_ratings": package.get("rating", {}).get("count", 0),
# "user_rating": package.get("rating", {}).get("user_rating", 0)
# }) # })
# #
# # Filter on all the key-word arguments. # for compatible in toolbox.subscribed_compatible_packages:
# for key, value in self._filter.items(): # items2.append({
# if key == "tags": # "name": compatible.package_id,
# key_filter = lambda item, v = value: v in item["tags"] # "icon_url": compatible.icon_url
# elif "*" in value: # })
# key_filter = lambda candidate, k = key, v = value: self._matchRegExp(candidate, k, v)
# else:
# key_filter = lambda candidate, k = key, v = value: self._matchString(candidate, k, v)
# items = filter(key_filter, items)
#
# # Execute all filters.
# filtered_items = list(items)
#
# filtered_items.sort(key = lambda k: k["name"])
# self.setItems(filtered_items)
final_list = items1 + items2
print(final_list)
self.setItems(final_list)
## Set the filter of this model based on a string. print("self.subscribed_packages: {}".format(toolbox.subscribed_packages))
# \param filter_dict \type{Dict} Dictionary to do the filtering by.
def setFilter(self, filter_dict: Dict[str, str]) -> None:
if filter_dict != self._filter:
self._filter = filter_dict
self._update()
@pyqtProperty("QVariantMap", fset = setFilter, constant = True) # final_list = items1 + items2
def filter(self) -> Dict[str, str]: self.setItems(toolbox.subscribed_packages)
return self._filter # self.setItems(final_list)
# Check to see if a container matches with a regular expression
def _matchRegExp(self, metadata, property_name, value):
if property_name not in metadata:
return False
value = re.escape(value) #Escape for regex patterns.
value = "^" + value.replace("\\*", ".*") + "$" #Instead of (now escaped) asterisks, match on any string. Also add anchors for a complete match.
if self._ignore_case:
value_pattern = re.compile(value, re.IGNORECASE)
else:
value_pattern = re.compile(value)
return value_pattern.match(str(metadata[property_name]))
# Check to see if a container matches with a string
def _matchString(self, metadata, property_name, value):
if property_name not in metadata:
return False
return value.lower() == str(metadata[property_name]).lower()

View file

@ -63,8 +63,9 @@ class Toolbox(QObject, Extension):
self._old_plugin_ids = set() # type: Set[str] self._old_plugin_ids = set() # type: Set[str]
self._old_plugin_metadata = dict() # type: Dict[str, Dict[str, Any]] self._old_plugin_metadata = dict() # type: Dict[str, Dict[str, Any]]
self.subscribed_compatible_packages = [] # type: List[str] # self.subscribed_compatible_packages = [] # type: List[str]
self.subscribed_incompatible_packages = [] # type: List[str] # self.subscribed_incompatible_packages = [] # type: List[str]
self.subscribed_packages = [] # type: List[Dict[str, str]]
# The responses as given by the server parsed to a list. # The responses as given by the server parsed to a list.
self._server_response_data = { self._server_response_data = {
@ -689,20 +690,53 @@ class Toolbox(QObject, Extension):
self._package_manager.setPackagesWithUpdate(packages) self._package_manager.setPackagesWithUpdate(packages)
elif response_type == "subscribed_packages": elif response_type == "subscribed_packages":
import collections # import collections
Package = collections.namedtuple("Package", ["package_id", "sdk_versions"]) # Package = collections.namedtuple("Package", ["package_id", "icon_url", "sdk_versions", "is_compatible"])
# Package.__new__.__defaults__ = (None, ) * len(Package._fields)
user_subscribed = [Package(plugin['package_id'], plugin['sdk_versions']) for plugin in json_data["data"]] # There is not always an ICON_URL in the response payload !
# user_subscribed = [Package(plugin['package_id'], plugin.get("icon_url", ""), plugin['sdk_versions']) for plugin in json_data["data"]]
user_subscribed_list = [plugin["package_id"] for plugin in json_data["data"]] user_subscribed_list = [plugin["package_id"] for plugin in json_data["data"]]
self.subscribed_compatible_packages.clear() all_subscribed_packages = []
self.subscribed_incompatible_packages.clear()
for subscribed in user_subscribed: self.subscribed_packages.clear()
if self._sdk_version not in subscribed.sdk_versions:
self.subscribed_incompatible_packages.append(subscribed) for package in json_data["data"]:
packagex = {
"name": package["package_id"],
"sdk_versions": package["sdk_versions"]
}
# packagex = Package(package["package_id"], package["sdk_versions"], )
if self._sdk_version not in package["sdk_versions"]:
packagex.update({"is_compatible": False})
# packagex._replace(is_compatible=0)
# packagex.is_compatible = "1"
else: else:
self.subscribed_compatible_packages.append(subscribed) # packagex._replace(is_compatible="1")
# packagex.is_compatible = "0"
packagex.update({"is_compatible": True})
try:
packagex.update({"icon_url": package["icon_url"]})
except KeyError: # There is no 'icon_url" in the response payload for this package
packagex.update({"icon_url": ""})
self.subscribed_packages.append(packagex)
# all_subscribed_packages.append(packagex)
# print("ALL PACKAGES: {}".format(all_subscribed_packages))
# self.subscribed_compatible_packages.clear()
# self.subscribed_incompatible_packages.clear()
# for subscribed in user_subscribed:
# if self._sdk_version not in subscribed.sdk_versions:
# self.subscribed_incompatible_packages.append(subscribed)
# else:
# self.subscribed_compatible_packages.append(subscribed)
self._models["subscribed_packages"].update() self._models["subscribed_packages"].update()