Beispiel #1
0
 def __init__(self, app: CuraApplication,
              on_error: Callable[[List[CloudError]], None]) -> None:
     super().__init__()
     self._app = app
     self._account = app.getCuraAPI().account
     self._scope = JsonDecoratorScope(UltimakerCloudScope(app))
     self._http = HttpRequestManager.getInstance()
     self._on_error = on_error
     self._upload = None  # type: Optional[ToolPathUploader]
Beispiel #2
0
    def __init__(self, app: CuraApplication) -> None:
        if self.__instance is not None:
            raise RuntimeError("This is a Singleton. use getInstance()")

        self._scope = JsonDecoratorScope(
            UltimakerCloudScope(app))  # type: JsonDecoratorScope

        app.getPackageManager().packageInstalled.connect(
            self._onPackageInstalled)
    def _openSelectedFile(self, temp_dir: str, project_name: str, file_name: str, download_url: str) -> None:
        """ Downloads, then opens, the single specified file.

        :param temp_dir: The already created temporary directory where the files will be stored.
        :param project_name: Name of the project the file belongs to (used for error reporting).
        :param file_name: Name of the file to be downloaded and opened (used for error reporting).
        :param download_url: This url will be downloaded, then the downloaded file will be opened in Cura.
        """
        if not download_url:
            Logger.log("e", "No download url for file '{}'".format(file_name))
            return

        progress_message = Message(text = "{0}/{1}".format(project_name, file_name), dismissable = False, lifetime = 0,
                                   progress = 0, title = "Downloading...")
        progress_message.setProgress(0)
        progress_message.show()

        def progressCallback(rx: int, rt: int) -> None:
            progress_message.setProgress(math.floor(rx * 100.0 / rt))

        def finishedCallback(reply: QNetworkReply) -> None:
            progress_message.hide()
            try:
                with open(os.path.join(temp_dir, file_name), "wb+") as temp_file:
                    bytes_read = reply.read(self.DISK_WRITE_BUFFER_SIZE)
                    while bytes_read:
                        temp_file.write(bytes_read)
                        bytes_read = reply.read(self.DISK_WRITE_BUFFER_SIZE)
                        CuraApplication.getInstance().processEvents()
                    temp_file_name = temp_file.name
            except IOError as ex:
                Logger.logException("e", "Can't write Digital Library file {0}/{1} download to temp-directory {2}.",
                                    ex, project_name, file_name, temp_dir)
                Message(
                        text = "Failed to write to temporary file for '{}'.".format(file_name),
                        title = "File-system error",
                        lifetime = 10
                ).show()
                return

            CuraApplication.getInstance().readLocalFile(
                    QUrl.fromLocalFile(temp_file_name), add_to_recent_files = False)

        def errorCallback(reply: QNetworkReply, error: QNetworkReply.NetworkError, p = project_name,
                          f = file_name) -> None:
            progress_message.hide()
            Logger.error("An error {0} {1} occurred while downloading {2}/{3}".format(str(error), str(reply), p, f))
            Message(
                    text = "Failed Digital Library download for '{}'.".format(f),
                    title = "Network error {}".format(error),
                    lifetime = 10
            ).show()

        download_manager = HttpRequestManager.getInstance()
        download_manager.get(download_url, callback = finishedCallback, download_progress_callback = progressCallback,
                             error_callback = errorCallback, scope = UltimakerCloudScope(CuraApplication.getInstance()))
 def __init__(self, material_sync: "CloudMaterialSync"):
     super().__init__()
     self._material_sync = material_sync
     self._scope = JsonDecoratorScope(
         UltimakerCloudScope(cura.CuraApplication.CuraApplication.
                             getInstance()))  # type: JsonDecoratorScope
     self._archive_filename = None  # type: Optional[str]
     self._archive_remote_id = None  # type: Optional[str]  # ID that the server gives to this archive. Used to communicate about the archive to the server.
     self._printer_sync_status = {}  # type: Dict[str, str]
     self._printer_metadata = []  # type: List[Dict[str, Any]]
     self.processProgressChanged.connect(self._onProcessProgressChanged)
    def __init__(self, application: CuraApplication) -> None:
        super().__init__()

        self.discrepancies = Signal()  # Emits SubscribedPackagesModel
        self._application = application  # type: CuraApplication
        self._scope = JsonDecoratorScope(UltimakerCloudScope(application))
        self._model = SubscribedPackagesModel()
        self._message = None  # type: Optional[Message]

        self._application.initializationFinished.connect(self._onAppInitialized)
        self._i18n_catalog = i18nCatalog("cura")
        self._sdk_version = ApplicationMetadata.CuraSDKVersion
Beispiel #6
0
    def __init__(self, app: CuraApplication) -> None:
        # Emits (Dict[str, str], List[str]) # (success_items, error_items)
        # Dict{success_package_id, temp_file_path}
        # List[errored_package_id]
        self.done = Signal()

        self._app = app
        self._scope = UltimakerCloudScope(app)

        self._started = False
        self._progress_message = self._createProgressMessage()
        self._progress = {}  # type: Dict[str, Dict[str, Any]] # package_id, Dict
        self._error = []  # type: List[str] # package_id
Beispiel #7
0
    def __init__(self, application: CuraApplication) -> None:
        super().__init__()

        self.discrepancies = Signal()  # Emits SubscribedPackagesModel
        self._application = application  # type: CuraApplication
        self._scope = JsonDecoratorScope(UltimakerCloudScope(application))
        self._model = SubscribedPackagesModel()
        self._message = None  # type: Optional[Message]

        self._application.initializationFinished.connect(self._onAppInitialized)
        self._i18n_catalog = i18nCatalog("cura")
        self._sdk_version = ApplicationMetadata.CuraSDKVersion
        self._last_notified_packages = set()  # type: Set[str]
        """Packages for which a notification has been shown. No need to bother the user twice fo equal content"""
Beispiel #8
0
    def __init__(self, app: CuraApplication,
                 on_error: Callable[[List[CloudError]], None]) -> None:
        """Initializes a new cloud API client.

        :param app:
        :param account: The user's account object
        :param on_error: The callback to be called whenever we receive errors from the server.
        """
        super().__init__()
        self._app = app
        self._account = app.getCuraAPI().account
        self._scope = JsonDecoratorScope(UltimakerCloudScope(app))
        self._http = HttpRequestManager.getInstance()
        self._on_error = on_error
        self._upload = None  # type: Optional[ToolPathUploader]
Beispiel #9
0
    def __init__(self, api_backup_url: str) -> None:
        """ Create a new backup Job. start the job by calling start()

        :param api_backup_url: The url of the 'backups' endpoint of the Cura Drive Api
        """

        super().__init__()

        self._api_backup_url = api_backup_url
        self._json_cloud_scope = JsonDecoratorScope(UltimakerCloudScope(CuraApplication.getInstance()))

        self._backup_zip = None  # type: Optional[bytes]
        self._job_done = threading.Event()
        """Set when the job completes. Does not indicate success."""
        self.backup_upload_error_message = ""
        """After the job completes, an empty string indicates success. Othrerwise, the value is a translated message."""
Beispiel #10
0
    def __init__(self,
                 application: CuraApplication,
                 on_error: Callable[[List[CloudError]], None],
                 projects_limit_per_page: Optional[int] = None) -> None:
        """Initializes a new digital factory API client.

        :param application:
        :param on_error: The callback to be called whenever we receive errors from the server.
        """
        super().__init__()
        self._application = application
        self._account = application.getCuraAPI().account
        self._scope = JsonDecoratorScope(UltimakerCloudScope(application))
        self._http = HttpRequestManager.getInstance()
        self._on_error = on_error
        self._file_uploader = None  # type: Optional[DFFileUploader]

        self._projects_pagination_mgr = PaginationManager(
            limit=projects_limit_per_page
        ) if projects_limit_per_page else None  # type: Optional[PaginationManager]
Beispiel #11
0
    def __init__(self, parent: Optional["QObject"] = None) -> None:
        super().__init__(parent)
        self._package_manager: CuraPackageManager = cast(
            CuraPackageManager,
            CuraApplication.getInstance().getPackageManager())
        self._plugin_registry: PluginRegistry = CuraApplication.getInstance(
        ).getPluginRegistry()
        self._account = CuraApplication.getInstance().getCuraAPI().account
        self._error_message = ""
        self.addRoleName(self.PackageRole, "package")
        self._is_loading = False
        self._has_more = False
        self._has_footer = True
        self._to_install: Dict[str, str] = {}

        self._ongoing_requests: Dict[str, Optional[HttpRequestData]] = {
            "download_package": None
        }
        self._scope = JsonDecoratorScope(
            UltimakerCloudScope(CuraApplication.getInstance()))
        self._license_dialogs: Dict[str, QObject] = {}
Beispiel #12
0
    def __init__(self, application: CuraApplication) -> None:
        super().__init__()

        self._application = application  # type: CuraApplication

        # Network:
        self._download_request_data = None  # type: Optional[HttpRequestData]
        self._download_progress = 0  # type: float
        self._is_downloading = False  # type: bool
        self._cloud_scope = UltimakerCloudScope(
            application)  # type: UltimakerCloudScope
        self._json_scope = JsonDecoratorScope(
            self._cloud_scope)  # type: JsonDecoratorScope

        self._request_urls = {}  # type: Dict[str, str]
        self._to_update = [
        ]  # type: List[str] # Package_ids that are waiting to be updated
        self._old_plugin_ids = set()  # type: Set[str]
        self._old_plugin_metadata = dict()  # type: Dict[str, Dict[str, Any]]

        # The responses as given by the server parsed to a list.
        self._server_response_data = {
            "authors": [],
            "packages": [],
            "updates": []
        }  # type: Dict[str, List[Any]]

        # Models:
        self._models = {
            "authors": AuthorsModel(self),
            "packages": PackagesModel(self),
            "updates": PackagesModel(self)
        }  # type: Dict[str, Union[AuthorsModel, PackagesModel]]

        self._plugins_showcase_model = PackagesModel(self)
        self._plugins_available_model = PackagesModel(self)
        self._plugins_installed_model = PackagesModel(self)
        self._plugins_installed_model.setFilter({"is_bundled": "False"})
        self._plugins_bundled_model = PackagesModel(self)
        self._plugins_bundled_model.setFilter({"is_bundled": "True"})
        self._materials_showcase_model = AuthorsModel(self)
        self._materials_available_model = AuthorsModel(self)
        self._materials_installed_model = PackagesModel(self)
        self._materials_installed_model.setFilter({"is_bundled": "False"})
        self._materials_bundled_model = PackagesModel(self)
        self._materials_bundled_model.setFilter({"is_bundled": "True"})
        self._materials_generic_model = PackagesModel(self)

        self._license_model = LicenseModel()

        # These properties are for keeping track of the UI state:
        # ----------------------------------------------------------------------
        # View category defines which filter to use, and therefore effectively
        # which category is currently being displayed. For example, possible
        # values include "plugin" or "material", but also "installed".
        self._view_category = "plugin"  # type: str

        # View page defines which type of page layout to use. For example,
        # possible values include "overview", "detail" or "author".
        self._view_page = "welcome"  # type: str

        # Active package refers to which package is currently being downloaded,
        # installed, or otherwise modified.
        self._active_package = None  # type: Optional[Dict[str, Any]]

        self._dialog = None  # type: Optional[QObject]
        self._confirm_reset_dialog = None  # type: Optional[QObject]
        self._resetUninstallVariables()

        self._restart_required = False  # type: bool

        # variables for the license agreement dialog
        self._license_dialog_plugin_file_location = ""  # type: str

        self._application.initializationFinished.connect(
            self._onAppInitialized)
 def __init__(self) -> None:
     self._cura_api = CuraApplication.getInstance().getCuraAPI()
     self._json_cloud_scope = JsonDecoratorScope(
         UltimakerCloudScope(CuraApplication.getInstance()))