mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Fix some crashes and issues in the Toolbox when working with no
internet connection.
This commit is contained in:
parent
675b5b1997
commit
fa97d5830b
3 changed files with 52 additions and 45 deletions
|
@ -24,7 +24,8 @@ Item
|
||||||
ToolboxTabButton
|
ToolboxTabButton
|
||||||
{
|
{
|
||||||
text: catalog.i18nc("@title:tab", "Plugins")
|
text: catalog.i18nc("@title:tab", "Plugins")
|
||||||
active: toolbox.viewCategory == "plugin"
|
active: toolbox.viewCategory == "plugin" && enabled
|
||||||
|
enabled: toolbox.viewPage != "loading" && toolbox.viewPage != "errored"
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
toolbox.filterModelByProp("packages", "type", "plugin")
|
toolbox.filterModelByProp("packages", "type", "plugin")
|
||||||
|
@ -35,7 +36,8 @@ Item
|
||||||
ToolboxTabButton
|
ToolboxTabButton
|
||||||
{
|
{
|
||||||
text: catalog.i18nc("@title:tab", "Materials")
|
text: catalog.i18nc("@title:tab", "Materials")
|
||||||
active: toolbox.viewCategory == "material"
|
active: toolbox.viewCategory == "material" && enabled
|
||||||
|
enabled: toolbox.viewPage != "loading" && toolbox.viewPage != "errored"
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
toolbox.filterModelByProp("authors", "package_types", "material")
|
toolbox.filterModelByProp("authors", "package_types", "material")
|
||||||
|
|
|
@ -43,7 +43,7 @@ Button
|
||||||
return UM.Theme.getColor("topbar_button_text_inactive");
|
return UM.Theme.getColor("topbar_button_text_inactive");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
font: control.active ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium")
|
font: control.enabled ? (control.active ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium")) : UM.Theme.getFont("default_italic")
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
}
|
}
|
||||||
|
|
|
@ -333,8 +333,8 @@ class Toolbox(QObject, Extension):
|
||||||
|
|
||||||
# Handlers for Network Events
|
# Handlers for Network Events
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
def _onNetworkAccessibleChanged(self, accessible: int) -> None:
|
def _onNetworkAccessibleChanged(self, network_accessibility: QNetworkAccessManager.NetworkAccessibility) -> None:
|
||||||
if accessible == 0:
|
if network_accessibility == QNetworkAccessManager.NotAccessible:
|
||||||
self.resetDownload()
|
self.resetDownload()
|
||||||
|
|
||||||
def _onRequestFinished(self, reply: QNetworkReply) -> None:
|
def _onRequestFinished(self, reply: QNetworkReply) -> None:
|
||||||
|
@ -354,50 +354,55 @@ class Toolbox(QObject, Extension):
|
||||||
if reply.operation() == QNetworkAccessManager.GetOperation:
|
if reply.operation() == QNetworkAccessManager.GetOperation:
|
||||||
for type, url in self._request_urls.items():
|
for type, url in self._request_urls.items():
|
||||||
if reply.url() == url:
|
if reply.url() == url:
|
||||||
try:
|
if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) == 200:
|
||||||
json_data = json.loads(bytes(reply.readAll()).decode("utf-8"))
|
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
|
||||||
|
|
||||||
|
# HACK: Eventually get rid of the code from here...
|
||||||
|
if type is "plugins_showcase" or type is "materials_showcase":
|
||||||
|
self._metadata["plugins_showcase"] = json_data["data"]["plugin"]["packages"]
|
||||||
|
self._models["plugins_showcase"].setMetadata(self._metadata["plugins_showcase"])
|
||||||
|
self._metadata["materials_showcase"] = json_data["data"]["material"]["authors"]
|
||||||
|
self._models["materials_showcase"].setMetadata(self._metadata["materials_showcase"])
|
||||||
|
else:
|
||||||
|
# ...until here.
|
||||||
|
# This hack arises for multiple reasons but the main
|
||||||
|
# one is because there are not separate API calls
|
||||||
|
# for different kinds of showcases.
|
||||||
|
self._metadata[type] = json_data["data"]
|
||||||
|
self._models[type].setMetadata(self._metadata[type])
|
||||||
|
|
||||||
|
# Do some auto filtering
|
||||||
|
# TODO: Make multiple API calls in the future to handle this
|
||||||
|
if type is "packages":
|
||||||
|
self._models[type].setFilter({"type": "plugin"})
|
||||||
|
if type is "authors":
|
||||||
|
self._models[type].setFilter({"package_types": "material"})
|
||||||
|
|
||||||
|
self.metadataChanged.emit()
|
||||||
|
|
||||||
|
if self.loadingComplete() is True:
|
||||||
|
self.setViewPage("overview")
|
||||||
|
|
||||||
# Check for errors:
|
|
||||||
if "errors" in json_data:
|
|
||||||
for error in json_data["errors"]:
|
|
||||||
Logger.log("e", "%s", error["title"])
|
|
||||||
return
|
return
|
||||||
|
except json.decoder.JSONDecodeError:
|
||||||
# Create model and apply metadata:
|
Logger.log("w", "Toolbox: Received invalid JSON for %s.", type)
|
||||||
if not self._models[type]:
|
|
||||||
Logger.log("e", "Could not find the %s model.", type)
|
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
# HACK: Eventually get rid of the code from here...
|
self.setViewPage("errored")
|
||||||
if type is "plugins_showcase" or type is "materials_showcase":
|
self.resetDownload()
|
||||||
self._metadata["plugins_showcase"] = json_data["data"]["plugin"]["packages"]
|
|
||||||
self._models["plugins_showcase"].setMetadata(self._metadata["plugins_showcase"])
|
|
||||||
self._metadata["materials_showcase"] = json_data["data"]["material"]["authors"]
|
|
||||||
self._models["materials_showcase"].setMetadata(self._metadata["materials_showcase"])
|
|
||||||
else:
|
|
||||||
# ...until here.
|
|
||||||
# This hack arises for multiple reasons but the main
|
|
||||||
# one is because there are not separate API calls
|
|
||||||
# for different kinds of showcases.
|
|
||||||
self._metadata[type] = json_data["data"]
|
|
||||||
self._models[type].setMetadata(self._metadata[type])
|
|
||||||
|
|
||||||
# Do some auto filtering
|
|
||||||
# TODO: Make multiple API calls in the future to handle this
|
|
||||||
if type is "packages":
|
|
||||||
self._models[type].setFilter({"type": "plugin"})
|
|
||||||
if type is "authors":
|
|
||||||
self._models[type].setFilter({"package_types": "material"})
|
|
||||||
|
|
||||||
self.metadataChanged.emit()
|
|
||||||
|
|
||||||
if self.loadingComplete() is True:
|
|
||||||
self.setViewPage("overview")
|
|
||||||
|
|
||||||
return
|
return
|
||||||
except json.decoder.JSONDecodeError:
|
|
||||||
Logger.log("w", "Toolbox: Received invalid JSON for %s.", type)
|
|
||||||
break
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Ignore any operation that is not a get operation
|
# Ignore any operation that is not a get operation
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue