mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 23:46:22 -06:00
Refactor code to use constants in CuraConstants
CURA-6005
This commit is contained in:
parent
8e4ad23da1
commit
2275e5c71f
3 changed files with 17 additions and 55 deletions
|
@ -115,6 +115,8 @@ from cura.ObjectsModel import ObjectsModel
|
||||||
|
|
||||||
from cura.PrinterOutput.NetworkMJPGImage import NetworkMJPGImage
|
from cura.PrinterOutput.NetworkMJPGImage import NetworkMJPGImage
|
||||||
|
|
||||||
|
from cura import CuraConstants
|
||||||
|
|
||||||
from UM.FlameProfiler import pyqtSlot
|
from UM.FlameProfiler import pyqtSlot
|
||||||
from UM.Decorators import override
|
from UM.Decorators import override
|
||||||
|
|
||||||
|
@ -127,15 +129,6 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
numpy.seterr(all = "ignore")
|
numpy.seterr(all = "ignore")
|
||||||
|
|
||||||
try:
|
|
||||||
from cura.CuraVersion import CuraAppDisplayName, CuraVersion, CuraBuildType, CuraDebugMode, CuraSDKVersion # type: ignore
|
|
||||||
except ImportError:
|
|
||||||
CuraAppDisplayName = "Ultimaker Cura"
|
|
||||||
CuraVersion = "master" # [CodeStyle: Reflecting imported value]
|
|
||||||
CuraBuildType = ""
|
|
||||||
CuraDebugMode = False
|
|
||||||
CuraSDKVersion = "5.0.0"
|
|
||||||
|
|
||||||
|
|
||||||
class CuraApplication(QtApplication):
|
class CuraApplication(QtApplication):
|
||||||
# SettingVersion represents the set of settings available in the machine/extruder definitions.
|
# SettingVersion represents the set of settings available in the machine/extruder definitions.
|
||||||
|
@ -162,11 +155,11 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(name = "cura",
|
super().__init__(name = "cura",
|
||||||
app_display_name = CuraAppDisplayName,
|
app_display_name = CuraConstants.CuraAppDisplayName,
|
||||||
version = CuraVersion,
|
version = CuraConstants.CuraVersion,
|
||||||
api_version = CuraSDKVersion,
|
api_version = CuraConstants.CuraSDKVersion,
|
||||||
buildtype = CuraBuildType,
|
buildtype = CuraConstants.CuraBuildType,
|
||||||
is_debug_mode = CuraDebugMode,
|
is_debug_mode = CuraConstants.CuraDebugMode,
|
||||||
tray_icon_name = "cura-icon-32.png",
|
tray_icon_name = "cura-icon-32.png",
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
@ -937,7 +930,7 @@ class CuraApplication(QtApplication):
|
||||||
engine.rootContext().setContextProperty("CuraApplication", self)
|
engine.rootContext().setContextProperty("CuraApplication", self)
|
||||||
engine.rootContext().setContextProperty("PrintInformation", self._print_information)
|
engine.rootContext().setContextProperty("PrintInformation", self._print_information)
|
||||||
engine.rootContext().setContextProperty("CuraActions", self._cura_actions)
|
engine.rootContext().setContextProperty("CuraActions", self._cura_actions)
|
||||||
engine.rootContext().setContextProperty("CuraSDKVersion", CuraSDKVersion)
|
engine.rootContext().setContextProperty("CuraSDKVersion", CuraConstants.CuraSDKVersion)
|
||||||
|
|
||||||
qmlRegisterUncreatableType(CuraApplication, "Cura", 1, 0, "ResourceTypes", "Just an Enum type")
|
qmlRegisterUncreatableType(CuraApplication, "Cura", 1, 0, "ResourceTypes", "Just an Enum type")
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
# Copyright (c) 2018 Ultimaker B.V.
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
from UM import i18nCatalog
|
from UM import i18nCatalog
|
||||||
|
|
||||||
|
from cura import CuraConstants
|
||||||
|
|
||||||
|
|
||||||
class Settings:
|
class Settings:
|
||||||
"""
|
"""
|
||||||
Keeps the application settings.
|
Keeps the application settings.
|
||||||
"""
|
"""
|
||||||
UM_CLOUD_API_ROOT = "https://api.ultimaker.com"
|
|
||||||
DRIVE_API_VERSION = 1
|
DRIVE_API_VERSION = 1
|
||||||
DRIVE_API_URL = "{}/cura-drive/v{}".format(UM_CLOUD_API_ROOT, str(DRIVE_API_VERSION))
|
DRIVE_API_URL = "{}/cura-drive/v{}".format(CuraConstants.CuraCloudAPIRoot, str(DRIVE_API_VERSION))
|
||||||
|
|
||||||
AUTO_BACKUP_ENABLED_PREFERENCE_KEY = "cura_drive/auto_backup_enabled"
|
AUTO_BACKUP_ENABLED_PREFERENCE_KEY = "cura_drive/auto_backup_enabled"
|
||||||
AUTO_BACKUP_LAST_DATE_PREFERENCE_KEY = "cura_drive/auto_backup_date"
|
AUTO_BACKUP_LAST_DATE_PREFERENCE_KEY = "cura_drive/auto_backup_date"
|
||||||
|
|
|
@ -18,6 +18,7 @@ from UM.i18n import i18nCatalog
|
||||||
from UM.Version import Version
|
from UM.Version import Version
|
||||||
|
|
||||||
import cura
|
import cura
|
||||||
|
from cura import CuraConstants
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
|
|
||||||
from .AuthorsModel import AuthorsModel
|
from .AuthorsModel import AuthorsModel
|
||||||
|
@ -39,9 +40,9 @@ class Toolbox(QObject, Extension):
|
||||||
|
|
||||||
self._application = application # type: CuraApplication
|
self._application = application # type: CuraApplication
|
||||||
|
|
||||||
self._sdk_version = None # type: Optional[Union[str, int]]
|
self._sdk_version = CuraConstants.CuraSDKVersion # type: Union[str, int]
|
||||||
self._cloud_api_version = None # type: Optional[int]
|
self._cloud_api_version = CuraConstants.CuraCloudAPIVersion # type: int
|
||||||
self._cloud_api_root = None # type: Optional[str]
|
self._cloud_api_root = CuraConstants.CuraCloudAPIRoot # type: str
|
||||||
self._api_url = None # type: Optional[str]
|
self._api_url = None # type: Optional[str]
|
||||||
|
|
||||||
# Network:
|
# Network:
|
||||||
|
@ -168,9 +169,6 @@ class Toolbox(QObject, Extension):
|
||||||
def _onAppInitialized(self) -> None:
|
def _onAppInitialized(self) -> None:
|
||||||
self._plugin_registry = self._application.getPluginRegistry()
|
self._plugin_registry = self._application.getPluginRegistry()
|
||||||
self._package_manager = self._application.getPackageManager()
|
self._package_manager = self._application.getPackageManager()
|
||||||
self._sdk_version = self._getSDKVersion()
|
|
||||||
self._cloud_api_version = self._getCloudAPIVersion()
|
|
||||||
self._cloud_api_root = self._getCloudAPIRoot()
|
|
||||||
self._api_url = "{cloud_api_root}/cura-packages/v{cloud_api_version}/cura/v{sdk_version}".format(
|
self._api_url = "{cloud_api_root}/cura-packages/v{cloud_api_version}/cura/v{sdk_version}".format(
|
||||||
cloud_api_root = self._cloud_api_root,
|
cloud_api_root = self._cloud_api_root,
|
||||||
cloud_api_version = self._cloud_api_version,
|
cloud_api_version = self._cloud_api_version,
|
||||||
|
@ -186,36 +184,6 @@ class Toolbox(QObject, Extension):
|
||||||
"materials_generic": QUrl("{base_url}/packages?package_type=material&tags=generic".format(base_url = self._api_url))
|
"materials_generic": QUrl("{base_url}/packages?package_type=material&tags=generic".format(base_url = self._api_url))
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the API root for the packages API depending on Cura version settings.
|
|
||||||
def _getCloudAPIRoot(self) -> str:
|
|
||||||
if not hasattr(cura, "CuraVersion"):
|
|
||||||
return self.DEFAULT_CLOUD_API_ROOT
|
|
||||||
if not hasattr(cura.CuraVersion, "CuraCloudAPIRoot"): # type: ignore
|
|
||||||
return self.DEFAULT_CLOUD_API_ROOT
|
|
||||||
if not cura.CuraVersion.CuraCloudAPIRoot: # type: ignore
|
|
||||||
return self.DEFAULT_CLOUD_API_ROOT
|
|
||||||
return cura.CuraVersion.CuraCloudAPIRoot # type: ignore
|
|
||||||
|
|
||||||
# Get the cloud API version from CuraVersion
|
|
||||||
def _getCloudAPIVersion(self) -> int:
|
|
||||||
if not hasattr(cura, "CuraVersion"):
|
|
||||||
return self.DEFAULT_CLOUD_API_VERSION
|
|
||||||
if not hasattr(cura.CuraVersion, "CuraCloudAPIVersion"): # type: ignore
|
|
||||||
return self.DEFAULT_CLOUD_API_VERSION
|
|
||||||
if not cura.CuraVersion.CuraCloudAPIVersion: # type: ignore
|
|
||||||
return self.DEFAULT_CLOUD_API_VERSION
|
|
||||||
return cura.CuraVersion.CuraCloudAPIVersion # type: ignore
|
|
||||||
|
|
||||||
# Get the packages version depending on Cura version settings.
|
|
||||||
def _getSDKVersion(self) -> Union[int, str]:
|
|
||||||
if not hasattr(cura, "CuraVersion"):
|
|
||||||
return self._application.getAPIVersion().getMajor()
|
|
||||||
if not hasattr(cura.CuraVersion, "CuraSDKVersion"): # type: ignore
|
|
||||||
return self._application.getAPIVersion().getMajor()
|
|
||||||
if not cura.CuraVersion.CuraSDKVersion: # type: ignore
|
|
||||||
return self._application.getAPIVersion().getMajor()
|
|
||||||
return cura.CuraVersion.CuraSDKVersion # type: ignore
|
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def browsePackages(self) -> None:
|
def browsePackages(self) -> None:
|
||||||
# Create the network manager:
|
# Create the network manager:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue