mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-10 08:17:49 -06:00
Added missing typing to toolbox
This commit is contained in:
parent
4f30dffaf9
commit
301605c30c
1 changed files with 43 additions and 48 deletions
|
@ -6,7 +6,7 @@ import json
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import platform
|
import platform
|
||||||
from typing import cast, List
|
from typing import cast, List, TYPE_CHECKING, Tuple, Optional
|
||||||
|
|
||||||
from PyQt5.QtCore import QUrl, QObject, pyqtProperty, pyqtSignal, pyqtSlot
|
from PyQt5.QtCore import QUrl, QObject, pyqtProperty, pyqtSignal, pyqtSlot
|
||||||
from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply
|
from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply
|
||||||
|
@ -20,9 +20,13 @@ from UM.Version import Version
|
||||||
|
|
||||||
import cura
|
import cura
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
|
|
||||||
from .AuthorsModel import AuthorsModel
|
from .AuthorsModel import AuthorsModel
|
||||||
from .PackagesModel import PackagesModel
|
from .PackagesModel import PackagesModel
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from cura.Settings.GlobalStack import GlobalStack
|
||||||
|
|
||||||
i18n_catalog = i18nCatalog("cura")
|
i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,7 +38,7 @@ class Toolbox(QObject, Extension):
|
||||||
def __init__(self, application: CuraApplication) -> None:
|
def __init__(self, application: CuraApplication) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self._application = application #type: CuraApplication
|
self._application = application # type: CuraApplication
|
||||||
|
|
||||||
self._sdk_version = None # type: Optional[int]
|
self._sdk_version = None # type: Optional[int]
|
||||||
self._cloud_api_version = None # type: Optional[int]
|
self._cloud_api_version = None # type: Optional[int]
|
||||||
|
@ -42,11 +46,11 @@ class Toolbox(QObject, Extension):
|
||||||
self._api_url = None # type: Optional[str]
|
self._api_url = None # type: Optional[str]
|
||||||
|
|
||||||
# Network:
|
# Network:
|
||||||
self._download_request = None #type: Optional[QNetworkRequest]
|
self._download_request = None # type: Optional[QNetworkRequest]
|
||||||
self._download_reply = None #type: Optional[QNetworkReply]
|
self._download_reply = None # type: Optional[QNetworkReply]
|
||||||
self._download_progress = 0 #type: float
|
self._download_progress = 0 # type: float
|
||||||
self._is_downloading = False #type: bool
|
self._is_downloading = False # type: bool
|
||||||
self._network_manager = None #type: Optional[QNetworkAccessManager]
|
self._network_manager = None # type: Optional[QNetworkAccessManager]
|
||||||
self._request_header = [
|
self._request_header = [
|
||||||
b"User-Agent",
|
b"User-Agent",
|
||||||
str.encode(
|
str.encode(
|
||||||
|
@ -93,32 +97,30 @@ class Toolbox(QObject, Extension):
|
||||||
# View category defines which filter to use, and therefore effectively
|
# View category defines which filter to use, and therefore effectively
|
||||||
# which category is currently being displayed. For example, possible
|
# which category is currently being displayed. For example, possible
|
||||||
# values include "plugin" or "material", but also "installed".
|
# values include "plugin" or "material", but also "installed".
|
||||||
self._view_category = "plugin" #type: str
|
self._view_category = "plugin" # type: str
|
||||||
|
|
||||||
# View page defines which type of page layout to use. For example,
|
# View page defines which type of page layout to use. For example,
|
||||||
# possible values include "overview", "detail" or "author".
|
# possible values include "overview", "detail" or "author".
|
||||||
self._view_page = "loading" #type: str
|
self._view_page = "loading" # type: str
|
||||||
|
|
||||||
# Active package refers to which package is currently being downloaded,
|
# Active package refers to which package is currently being downloaded,
|
||||||
# installed, or otherwise modified.
|
# installed, or otherwise modified.
|
||||||
self._active_package = None # type: Optional[Dict[str, Any]]
|
self._active_package = None # type: Optional[Dict[str, Any]]
|
||||||
|
|
||||||
self._dialog = None #type: Optional[QObject]
|
self._dialog = None # type: Optional[QObject]
|
||||||
self._confirm_reset_dialog = None #type: Optional[QObject]
|
self._confirm_reset_dialog = None # type: Optional[QObject]
|
||||||
self._resetUninstallVariables()
|
self._resetUninstallVariables()
|
||||||
|
|
||||||
self._restart_required = False #type: bool
|
self._restart_required = False # type: bool
|
||||||
|
|
||||||
# variables for the license agreement dialog
|
# variables for the license agreement dialog
|
||||||
self._license_dialog_plugin_name = "" #type: str
|
self._license_dialog_plugin_name = "" # type: str
|
||||||
self._license_dialog_license_content = "" #type: str
|
self._license_dialog_license_content = "" # type: str
|
||||||
self._license_dialog_plugin_file_location = "" #type: str
|
self._license_dialog_plugin_file_location = "" # type: str
|
||||||
self._restart_dialog_message = "" #type: str
|
self._restart_dialog_message = "" # type: str
|
||||||
|
|
||||||
self._application.initializationFinished.connect(self._onAppInitialized)
|
self._application.initializationFinished.connect(self._onAppInitialized)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Signals:
|
# Signals:
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Downloading changes
|
# Downloading changes
|
||||||
|
@ -137,11 +139,11 @@ class Toolbox(QObject, Extension):
|
||||||
showLicenseDialog = pyqtSignal()
|
showLicenseDialog = pyqtSignal()
|
||||||
uninstallVariablesChanged = pyqtSignal()
|
uninstallVariablesChanged = pyqtSignal()
|
||||||
|
|
||||||
def _resetUninstallVariables(self):
|
def _resetUninstallVariables(self) -> None:
|
||||||
self._package_id_to_uninstall = None
|
self._package_id_to_uninstall = None # type: Optional[str]
|
||||||
self._package_name_to_uninstall = ""
|
self._package_name_to_uninstall = ""
|
||||||
self._package_used_materials = []
|
self._package_used_materials = [] # type: List[Tuple[GlobalStack, str, str]]
|
||||||
self._package_used_qualities = []
|
self._package_used_qualities = [] # type: List[Tuple[GlobalStack, str, str]]
|
||||||
|
|
||||||
@pyqtSlot(result = str)
|
@pyqtSlot(result = str)
|
||||||
def getLicenseDialogPluginName(self) -> str:
|
def getLicenseDialogPluginName(self) -> str:
|
||||||
|
@ -344,26 +346,26 @@ class Toolbox(QObject, Extension):
|
||||||
self.uninstall(package_id)
|
self.uninstall(package_id)
|
||||||
|
|
||||||
@pyqtProperty(str, notify = uninstallVariablesChanged)
|
@pyqtProperty(str, notify = uninstallVariablesChanged)
|
||||||
def pluginToUninstall(self):
|
def pluginToUninstall(self) -> str:
|
||||||
return self._package_name_to_uninstall
|
return self._package_name_to_uninstall
|
||||||
|
|
||||||
@pyqtProperty(str, notify = uninstallVariablesChanged)
|
@pyqtProperty(str, notify = uninstallVariablesChanged)
|
||||||
def uninstallUsedMaterials(self):
|
def uninstallUsedMaterials(self) -> str:
|
||||||
return "\n".join(["%s (%s)" % (str(global_stack.getName()), material) for global_stack, extruder_nr, material in self._package_used_materials])
|
return "\n".join(["%s (%s)" % (str(global_stack.getName()), material) for global_stack, extruder_nr, material in self._package_used_materials])
|
||||||
|
|
||||||
@pyqtProperty(str, notify = uninstallVariablesChanged)
|
@pyqtProperty(str, notify = uninstallVariablesChanged)
|
||||||
def uninstallUsedQualities(self):
|
def uninstallUsedQualities(self) -> str:
|
||||||
return "\n".join(["%s (%s)" % (str(global_stack.getName()), quality) for global_stack, extruder_nr, quality in self._package_used_qualities])
|
return "\n".join(["%s (%s)" % (str(global_stack.getName()), quality) for global_stack, extruder_nr, quality in self._package_used_qualities])
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def closeConfirmResetDialog(self):
|
def closeConfirmResetDialog(self) -> None:
|
||||||
if self._confirm_reset_dialog is not None:
|
if self._confirm_reset_dialog is not None:
|
||||||
self._confirm_reset_dialog.close()
|
self._confirm_reset_dialog.close()
|
||||||
|
|
||||||
## Uses "uninstall variables" to reset qualities and materials, then uninstall
|
## Uses "uninstall variables" to reset qualities and materials, then uninstall
|
||||||
# It's used as an action on Confirm reset on Uninstall
|
# It's used as an action on Confirm reset on Uninstall
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def resetMaterialsQualitiesAndUninstall(self):
|
def resetMaterialsQualitiesAndUninstall(self) -> None:
|
||||||
application = CuraApplication.getInstance()
|
application = CuraApplication.getInstance()
|
||||||
material_manager = application.getMaterialManager()
|
material_manager = application.getMaterialManager()
|
||||||
quality_manager = application.getQualityManager()
|
quality_manager = application.getQualityManager()
|
||||||
|
@ -376,8 +378,8 @@ class Toolbox(QObject, Extension):
|
||||||
default_quality_group = quality_manager.getDefaultQualityType(global_stack)
|
default_quality_group = quality_manager.getDefaultQualityType(global_stack)
|
||||||
machine_manager.setQualityGroup(default_quality_group, global_stack = global_stack)
|
machine_manager.setQualityGroup(default_quality_group, global_stack = global_stack)
|
||||||
|
|
||||||
|
if self._package_id_to_uninstall is not None:
|
||||||
self._markPackageMaterialsAsToBeUninstalled(self._package_id_to_uninstall)
|
self._markPackageMaterialsAsToBeUninstalled(self._package_id_to_uninstall)
|
||||||
|
|
||||||
self.uninstall(self._package_id_to_uninstall)
|
self.uninstall(self._package_id_to_uninstall)
|
||||||
self._resetUninstallVariables()
|
self._resetUninstallVariables()
|
||||||
self.closeConfirmResetDialog()
|
self.closeConfirmResetDialog()
|
||||||
|
@ -686,7 +688,7 @@ class Toolbox(QObject, Extension):
|
||||||
self._temp_plugin_file.close()
|
self._temp_plugin_file.close()
|
||||||
self._onDownloadComplete(file_path)
|
self._onDownloadComplete(file_path)
|
||||||
|
|
||||||
def _onDownloadComplete(self, file_path: str):
|
def _onDownloadComplete(self, file_path: str) -> None:
|
||||||
Logger.log("i", "Toolbox: Download complete.")
|
Logger.log("i", "Toolbox: Download complete.")
|
||||||
package_info = self._package_manager.getPackageInfo(file_path)
|
package_info = self._package_manager.getPackageInfo(file_path)
|
||||||
if not package_info:
|
if not package_info:
|
||||||
|
@ -745,9 +747,7 @@ class Toolbox(QObject, Extension):
|
||||||
def viewPage(self) -> str:
|
def viewPage(self) -> str:
|
||||||
return self._view_page
|
return self._view_page
|
||||||
|
|
||||||
|
# Exposed Models:
|
||||||
|
|
||||||
# Expose Models:
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
@pyqtProperty(QObject, notify = metadataChanged)
|
@pyqtProperty(QObject, notify = metadataChanged)
|
||||||
def authorsModel(self) -> AuthorsModel:
|
def authorsModel(self) -> AuthorsModel:
|
||||||
|
@ -785,8 +785,6 @@ class Toolbox(QObject, Extension):
|
||||||
def materialsGenericModel(self) -> PackagesModel:
|
def materialsGenericModel(self) -> PackagesModel:
|
||||||
return cast(PackagesModel, self._models["materials_generic"])
|
return cast(PackagesModel, self._models["materials_generic"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Filter Models:
|
# Filter Models:
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
@pyqtSlot(str, str, str)
|
@pyqtSlot(str, str, str)
|
||||||
|
@ -813,11 +811,9 @@ class Toolbox(QObject, Extension):
|
||||||
self._models[model_type].setFilter({})
|
self._models[model_type].setFilter({})
|
||||||
self.filterChanged.emit()
|
self.filterChanged.emit()
|
||||||
|
|
||||||
|
|
||||||
# HACK(S):
|
# HACK(S):
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
def buildMaterialsModels(self) -> None:
|
def buildMaterialsModels(self) -> None:
|
||||||
|
|
||||||
self._metadata["materials_showcase"] = []
|
self._metadata["materials_showcase"] = []
|
||||||
self._metadata["materials_available"] = []
|
self._metadata["materials_available"] = []
|
||||||
|
|
||||||
|
@ -841,7 +837,6 @@ class Toolbox(QObject, Extension):
|
||||||
self._models["materials_available"].setMetadata(self._metadata["materials_available"])
|
self._models["materials_available"].setMetadata(self._metadata["materials_available"])
|
||||||
|
|
||||||
def buildPluginsModels(self) -> None:
|
def buildPluginsModels(self) -> None:
|
||||||
|
|
||||||
self._metadata["plugins_showcase"] = []
|
self._metadata["plugins_showcase"] = []
|
||||||
self._metadata["plugins_available"] = []
|
self._metadata["plugins_available"] = []
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue