Skip to content

Commit

Permalink
non-functional code-style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrygribenchuk committed Mar 22, 2024
1 parent 37d9373 commit 707069a
Show file tree
Hide file tree
Showing 312 changed files with 2,291 additions and 2,176 deletions.
33 changes: 17 additions & 16 deletions cura/API/Account.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2022 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.

import enum
from datetime import datetime
import json
Expand Down Expand Up @@ -76,7 +77,7 @@ class Account(QObject):
"library.project.read library.project.write cura.printjob.read cura.printjob.write " \
"cura.mesh.read cura.mesh.write"

def __init__(self, application: "CuraApplication", parent = None) -> None:
def __init__(self, application: "CuraApplication", parent=None) -> None:
super().__init__(parent)
self._application = application
self._new_cloud_printers_detected = False
Expand All @@ -96,7 +97,7 @@ def __init__(self, application: "CuraApplication", parent = None) -> None:
self._oauth_root = UltimakerCloudConstants.CuraCloudAccountAPIRoot

self._oauth_settings = OAuth2Settings(
OAUTH_SERVER_URL= self._oauth_root,
OAUTH_SERVER_URL=self._oauth_root,
CALLBACK_PORT=self._callback_port,
CALLBACK_URL="http://localhost:{}/callback".format(self._callback_port),
CLIENT_ID="um----------------------------ultimaker_cura",
Expand Down Expand Up @@ -196,8 +197,8 @@ def _onLoginStateChanged(self, logged_in: bool = False, error_message: Optional[
self._error_message.hide()
Logger.log("w", "Failed to login: %s", error_message)
self._error_message = Message(error_message,
title = i18n_catalog.i18nc("@info:title", "Login failed"),
message_type = Message.MessageType.ERROR)
title=i18n_catalog.i18nc("@info:title", "Login failed"),
message_type=Message.MessageType.ERROR)
self._error_message.show()
self._logged_in = False
self.loginStateChanged.emit(False)
Expand Down Expand Up @@ -261,13 +262,13 @@ def login(self, force_logout_before_login: bool = False) -> None:
return
self._authorization_service.startAuthorizationFlow(force_logout_before_login)

@pyqtProperty(str, notify = userProfileChanged)
@pyqtProperty(str, notify=userProfileChanged)
def userName(self):
if not self._user_profile:
return ""
return self._user_profile.username

@pyqtProperty(str, notify = userProfileChanged)
@pyqtProperty(str, notify=userProfileChanged)
def profileImageUrl(self):
if not self._user_profile:
return ""
Expand All @@ -277,7 +278,7 @@ def profileImageUrl(self):
def accessToken(self) -> Optional[str]:
return self._authorization_service.getAccessToken()

@pyqtProperty("QVariantMap", notify = userProfileChanged)
@pyqtProperty("QVariantMap", notify=userProfileChanged)
def userProfile(self) -> Dict[str, Optional[str]]:
"""None if no user is logged in otherwise the logged in user as a dict containing containing user_id, username and profile_image_url """
if not self._user_profile:
Expand Down Expand Up @@ -320,21 +321,21 @@ def logout(self) -> None:

self._authorization_service.deleteAuthData()

@deprecated("Get permissions from the 'permissions' property", since = "5.2.0")
@deprecated("Get permissions from the 'permissions' property", since="5.2.0")
def updateAdditionalRight(self, **kwargs) -> None:
"""Update the additional rights of the account.
The argument(s) are the rights that need to be set"""
self._additional_rights.update(kwargs)
self.additionalRightsChanged.emit(self._additional_rights)

@deprecated("Get permissions from the 'permissions' property", since = "5.2.0")
@pyqtProperty("QVariantMap", notify = additionalRightsChanged)
@deprecated("Get permissions from the 'permissions' property", since="5.2.0")
@pyqtProperty("QVariantMap", notify=additionalRightsChanged)
def additionalRights(self) -> Dict[str, Any]:
"""A dictionary which can be queried for additional account rights."""
return self._additional_rights

permissionsChanged = pyqtSignal()
@pyqtProperty("QVariantList", notify = permissionsChanged)
@pyqtProperty("QVariantList", notify=permissionsChanged)
def permissions(self) -> List[str]:
"""
The permission keys that the user has in his account.
Expand Down Expand Up @@ -373,10 +374,10 @@ def error_callback(reply: "QNetworkReply", error: "QNetworkReply.NetworkError"):
Logger.error(f"Request for user permissions list failed. Network error: {error}")

HttpRequestManager.getInstance().get(
url = f"{self._oauth_root}/users/permissions",
scope = JsonDecoratorScope(UltimakerCloudScope(self._application)),
callback = callback,
error_callback = error_callback,
timeout = 10
url=f"{self._oauth_root}/users/permissions",
scope=JsonDecoratorScope(UltimakerCloudScope(self._application)),
callback=callback,
error_callback=error_callback,
timeout=10
)

1 change: 1 addition & 0 deletions cura/API/Backups.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.

from typing import Tuple, Optional, TYPE_CHECKING, Dict, Any

from cura.Backups.BackupsManager import BackupsManager
Expand Down
6 changes: 4 additions & 2 deletions cura/API/ConnectionStatus.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.

from typing import Optional

from PyQt6.QtCore import QObject, pyqtSignal, pyqtProperty
Expand Down Expand Up @@ -30,12 +33,11 @@ def __init__(self, parent: Optional["QObject"] = None) -> None:
self._is_internet_reachable = manager.isInternetReachable # type: bool
manager.internetReachableChanged.connect(self._onInternetReachableChanged)

@pyqtProperty(bool, notify = internetReachableChanged)
@pyqtProperty(bool, notify=internetReachableChanged)
def isInternetReachable(self) -> bool:
return self._is_internet_reachable

def _onInternetReachableChanged(self, reachable: bool):
if reachable != self._is_internet_reachable:
self._is_internet_reachable = reachable
self.internetReachableChanged.emit()

9 changes: 5 additions & 4 deletions cura/API/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.

from typing import Optional, TYPE_CHECKING

from PyQt6.QtCore import QObject, pyqtProperty
Expand Down Expand Up @@ -31,15 +32,15 @@ class CuraAPI(QObject):
# Since the API is intended to be used by plugins, the cura application should have already created this.
def __new__(cls, application: Optional["CuraApplication"] = None):
if cls.__instance is not None:
raise RuntimeError("Tried to create singleton '{class_name}' more than once.".format(class_name = CuraAPI.__name__))
raise RuntimeError("Tried to create singleton '{class_name}' more than once.".format(class_name=CuraAPI.__name__))
if application is None:
raise RuntimeError("Upon first time creation, the application must be set.")
instance = super(CuraAPI, cls).__new__(cls)
cls._application = application
return instance

def __init__(self, application: Optional["CuraApplication"] = None) -> None:
super().__init__(parent = CuraAPI._application)
super().__init__(parent=CuraAPI._application)
CuraAPI.__instance = self

self._account = Account(self._application)
Expand All @@ -54,13 +55,13 @@ def __init__(self, application: Optional["CuraApplication"] = None) -> None:
def initialize(self) -> None:
self._account.initialize()

@pyqtProperty(QObject, constant = True)
@pyqtProperty(QObject, constant=True)
def account(self) -> "Account":
"""Accounts API"""

return self._account

@pyqtProperty(QObject, constant = True)
@pyqtProperty(QObject, constant=True)
def connectionStatus(self) -> "ConnectionStatus":
return self._connectionStatus

Expand Down
13 changes: 7 additions & 6 deletions cura/Arranging/ArrangeObjectsJob.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.

from typing import List

from UM.Application import Application
Expand All @@ -26,10 +27,10 @@ def __init__(self, nodes: List[SceneNode], fixed_nodes: List[SceneNode], min_off
def run(self):
found_solution_for_all = False
status_message = Message(i18n_catalog.i18nc("@info:status", "Finding new location for objects"),
lifetime = 0,
dismissable = False,
progress = 0,
title = i18n_catalog.i18nc("@info:title", "Finding Location"))
lifetime=0,
dismissable=False,
progress=0,
title=i18n_catalog.i18nc("@info:title", "Finding Location"))
status_message.show()

if self._grid_arrange:
Expand All @@ -51,8 +52,8 @@ def run(self):
no_full_solution_message = Message(
i18n_catalog.i18nc("@info:status",
"Unable to find a location within the build volume for all objects"),
title = i18n_catalog.i18nc("@info:title", "Can't Find Location"),
message_type = Message.MessageType.ERROR)
title=i18n_catalog.i18nc("@info:title", "Can't Find Location"),
message_type=Message.MessageType.ERROR)
no_full_solution_message.show()

self.finished.emit(self)
3 changes: 3 additions & 0 deletions cura/Arranging/Arranger.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.

from typing import List, TYPE_CHECKING, Optional, Tuple, Set

if TYPE_CHECKING:
Expand Down
3 changes: 3 additions & 0 deletions cura/Arranging/GridArrange.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.

import math
from typing import List, TYPE_CHECKING, Tuple, Set, Union

Expand Down
6 changes: 3 additions & 3 deletions cura/Arranging/ShapeArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ def fromNode(cls, node: "SceneNode", min_offset: float, scale: float = 0.5, incl
offset_points = copy.deepcopy(offset_verts._points) # x, y
offset_points[:, 0] = numpy.add(offset_points[:, 0], -transform_x)
offset_points[:, 1] = numpy.add(offset_points[:, 1], -transform_y)
offset_shape_arr = ShapeArray.fromPolygon(offset_points, scale = scale)
offset_shape_arr = ShapeArray.fromPolygon(offset_points, scale=scale)

hull_points = copy.deepcopy(hull_verts._points)
hull_points[:, 0] = numpy.add(hull_points[:, 0], -transform_x)
hull_points[:, 1] = numpy.add(hull_points[:, 1], -transform_y)
hull_shape_arr = ShapeArray.fromPolygon(hull_points, scale = scale) # x, y
hull_shape_arr = ShapeArray.fromPolygon(hull_points, scale=scale) # x, y

return offset_shape_arr, hull_shape_arr

Expand All @@ -110,7 +110,7 @@ def arrayFromPolygon(cls, shape: Union[Tuple[int, int], numpy.ndarray], vertices
:return: numpy array with dimensions defined by shape
"""

base_array = numpy.zeros(shape, dtype = numpy.int32) # type: ignore # Initialize your array of zeros
base_array = numpy.zeros(shape, dtype=numpy.int32) # type: ignore # Initialize your array of zeros

fill = numpy.ones(base_array.shape) * True # Initialize boolean array defining shape fill

Expand Down
14 changes: 7 additions & 7 deletions cura/BackendPlugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2023 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.

import socket
import os
import subprocess
Expand Down Expand Up @@ -100,22 +101,22 @@ def start(self) -> bool:
Logger.log("e", f"Couldn't start EnginePlugin: {self._plugin_id} No permission to execute process.")
self._showMessage(self.catalog.i18nc("@info:plugin_failed",
f"Couldn't start EnginePlugin: {self._plugin_id}\nNo permission to execute process."),
message_type = Message.MessageType.ERROR)
message_type=Message.MessageType.ERROR)
except FileNotFoundError:
Logger.logException("e", f"Unable to find local EnginePlugin server executable for: {self._plugin_id}")
self._showMessage(self.catalog.i18nc("@info:plugin_failed",
f"Unable to find local EnginePlugin server executable for: {self._plugin_id}"),
message_type = Message.MessageType.ERROR)
message_type=Message.MessageType.ERROR)
except BlockingIOError:
Logger.logException("e", f"Couldn't start EnginePlugin: {self._plugin_id} Resource is temporarily unavailable")
self._showMessage(self.catalog.i18nc("@info:plugin_failed",
f"Couldn't start EnginePlugin: {self._plugin_id}\nResource is temporarily unavailable"),
message_type = Message.MessageType.ERROR)
message_type=Message.MessageType.ERROR)
except OSError as e:
Logger.logException("e", f"Couldn't start EnginePlugin {self._plugin_id} Operating system is blocking it (antivirus?)")
self._showMessage(self.catalog.i18nc("@info:plugin_failed",
f"Couldn't start EnginePlugin: {self._plugin_id}\nOperating system is blocking it (antivirus?)"),
message_type = Message.MessageType.ERROR)
message_type=Message.MessageType.ERROR)
return False

def stop(self) -> bool:
Expand All @@ -133,9 +134,8 @@ def stop(self) -> bool:
Logger.log("e", f"Unable to kill running EnginePlugin: {self._plugin_id} Access is denied.")
self._showMessage(self.catalog.i18nc("@info:plugin_failed",
f"Unable to kill running EnginePlugin: {self._plugin_id}\nAccess is denied."),
message_type = Message.MessageType.ERROR)
message_type=Message.MessageType.ERROR)
return False

def _showMessage(self, message: str, message_type: Message.MessageType = Message.MessageType.ERROR) -> None:
Message(message, title=self.catalog.i18nc("@info:title", "EnginePlugin"), message_type = message_type).show()

Message(message, title=self.catalog.i18nc("@info:title", "EnginePlugin"), message_type=message_type).show()
14 changes: 7 additions & 7 deletions cura/Backups/Backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ def _makeArchive(self, buffer: "io.BytesIO", root_path: str) -> Optional[ZipFile
Logger.log("e", "Could not create archive from user data directory: %s", error)
self._showMessage(self.catalog.i18nc("@info:backup_failed",
"Could not create archive from user data directory: {}".format(error)),
message_type = Message.MessageType.ERROR)
message_type=Message.MessageType.ERROR)
return None

def _showMessage(self, message: str, message_type: Message.MessageType = Message.MessageType.NEUTRAL) -> None:
"""Show a UI message."""

Message(message, title=self.catalog.i18nc("@info:title", "Backup"), message_type = message_type).show()
Message(message, title=self.catalog.i18nc("@info:title", "Backup"), message_type=message_type).show()

def restore(self) -> bool:
"""Restore this back-up.
Expand All @@ -132,18 +132,18 @@ def restore(self) -> bool:
Logger.log("w", "Tried to restore a Cura backup without having proper data or meta data.")
self._showMessage(self.catalog.i18nc("@info:backup_failed",
"Tried to restore a Cura backup without having proper data or meta data."),
message_type = Message.MessageType.ERROR)
message_type=Message.MessageType.ERROR)
return False

current_version = Version(self._application.getVersion())
version_to_restore = Version(self.meta_data.get("cura_release", "dev"))

if current_version < version_to_restore:
# Cannot restore version newer than current because settings might have changed.
Logger.log("d", "Tried to restore a Cura backup of version {version_to_restore} with cura version {current_version}".format(version_to_restore = version_to_restore, current_version = current_version))
Logger.log("d", "Tried to restore a Cura backup of version {version_to_restore} with cura version {current_version}".format(version_to_restore=version_to_restore, current_version=current_version))
self._showMessage(self.catalog.i18nc("@info:backup_failed",
"Tried to restore a Cura backup that is higher than the current version."),
message_type = Message.MessageType.ERROR)
message_type=Message.MessageType.ERROR)
return False

# Get the current secrets and store since the back-up doesn't contain those
Expand All @@ -156,8 +156,8 @@ def restore(self) -> bool:
Logger.log("d", f"The following error occurred while trying to restore a Cura backup: {str(e)}")
Message(self.catalog.i18nc("@info:backup_failed",
"The following error occurred while trying to restore a Cura backup:") + str(e),
title = self.catalog.i18nc("@info:title", "Backup"),
message_type = Message.MessageType.ERROR).show()
title=self.catalog.i18nc("@info:title", "Backup"),
message_type=Message.MessageType.ERROR).show()

return False
extracted = self._extractArchive(archive, version_data_dir)
Expand Down
4 changes: 2 additions & 2 deletions cura/Backups/BackupsManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def restoreBackup(self, zip_file: bytes, meta_data: Dict[str, str]) -> None:

self._disableAutoSave()

backup = Backup(self._application, zip_file = zip_file, meta_data = meta_data)
backup = Backup(self._application, zip_file=zip_file, meta_data=meta_data)
restored = backup.restore()

if restored:
# At this point, Cura will need to restart for the changes to take effect.
# We don't want to store the data at this point as that would override the just-restored backup.
self._application.windowClosed(save_data = False)
self._application.windowClosed(save_data=False)

def _disableAutoSave(self) -> None:
"""Here we (try to) disable the saving as it might interfere with restoring a back-up."""
Expand Down
Loading

0 comments on commit 707069a

Please sign in to comment.