def getThemes(self) -> List[Dict[str, str]]: themes = [] for path in Resources.getAllPathsForType(Resources.Themes): try: for file in os.listdir(path): folder = os.path.join(path, file) theme_file = os.path.join(folder, "theme.json") if os.path.isdir(folder) and os.path.isfile(theme_file): theme_id = os.path.basename(folder) with open(theme_file, encoding = "utf-8") as f: try: data = json.load(f) except json.decoder.JSONDecodeError: Logger.log("w", "Could not parse theme %s", theme_id) continue # do not add this theme to the list, but continue looking for other themes try: theme_name = data["metadata"]["name"] except KeyError: Logger.log("w", "Theme %s does not have a name; using its id instead", theme_id) theme_name = theme_id # fallback if no name is specified in json themes.append({ "id": theme_id, "name": theme_name }) except FileNotFoundError: pass themes.sort(key = lambda k: k["name"]) return themes
def loadProfiles(self): storage_path = Resources.getStoragePathForType(Resources.Profiles) dirs = Resources.getAllPathsForType(Resources.Profiles) for dir in dirs: if not os.path.isdir(dir): continue read_only = dir != storage_path for file_name in os.listdir(dir): path = os.path.join(dir, file_name) if os.path.isdir(path): continue profile = Profile(self, read_only) try: profile.loadFromFile(path) except Exception as e: Logger.log("e", "An exception occurred loading Profile %s: %s", path, str(e)) continue if not self.findProfile(profile.getName()): self._profiles.append(profile) profile.nameChanged.connect(self._onProfileNameChanged) profile = self.findProfile(Preferences.getInstance().getValue("machines/active_profile")) if profile: self.setActiveProfile(profile) self.profilesChanged.emit()
def loadMachineDefinitions(self): dirs = Resources.getAllPathsForType(Resources.MachineDefinitions) for dir in dirs: if not os.path.isdir(dir): continue for file_name in os.listdir(dir): data = None path = os.path.join(dir, file_name) if os.path.isdir(path): continue definition = MachineDefinition(self, path) try: definition.loadMetaData() except Exception as e: Logger.log("e", "An error occurred loading Machine Definition %s: %s", path, str(e)) continue # Only add the definition if it did not exist yet. This prevents duplicates. if not self.findMachineDefinition(definition.getId(), definition.getVariantName()): self._machine_definitions.append(definition) self.machineDefinitionsChanged.emit()
def loadMachineDefinitions(self): dirs = Resources.getAllPathsForType(Resources.MachineDefinitions) for dir in dirs: if not os.path.isdir(dir): continue for file_name in os.listdir(dir): data = None path = os.path.join(dir, file_name) if os.path.isdir(path): continue definition = MachineDefinition(self, path) try: definition.loadMetaData() except Exception as e: Logger.log( "e", "An error occurred loading Machine Definition %s: %s", path, str(e)) continue # Only add the definition if it did not exist yet. This prevents duplicates. if not self.findMachineDefinition(definition.getId(), definition.getVariantName()): self._machine_definitions.append(definition) self.machineDefinitionsChanged.emit()
def _update(self) -> None: """Fill the catalogue by loading the translated texts from file (again).""" if not self.__application: self.__require_update = True return if not self.__name: self.__name = self.__application.getApplicationName() if self.__language == "default": self.__language = self.__application.getApplicationLanguage() # Ask gettext for all the translations in the .mo files. for path in Resources.getAllPathsForType(Resources.i18n): if gettext.find(cast(str, self.__name), path, languages=[self.__language]): try: self.__translation = gettext.translation( cast(str, self.__name), path, languages=[self.__language]) except OSError: Logger.warning( "Corrupt or inaccessible translation file: {fname}". format(fname=self.__name)) self.__require_update = False
def loadMachineInstances(self): dirs = Resources.getAllPathsForType(Resources.MachineInstances) for dir in dirs: if not os.path.isdir(dir): continue for file_name in os.listdir(dir): path = os.path.join(dir, file_name) if os.path.isdir(path): continue instance = MachineInstance(self) try: instance.loadFromFile(path) except Exception as e: Logger.log( "e", "An exception occurred loading Machine Instance: %s: %s", path, str(e)) continue if not self.findMachineInstance(instance.getName()): self._machine_instances.append(instance) instance.nameChanged.connect(self._onInstanceNameChanged) instance = self.findMachineInstance( Preferences.getInstance().getValue("machines/active_instance")) if instance: self.setActiveMachineInstance(instance) self.machineInstancesChanged.emit()
def _updateModel(self): dirs = Resources.getAllPathsForType(Resources.Settings) for dir in dirs: if not os.path.isdir(dir): continue for file in os.listdir(dir): data = None path = os.path.join(dir, file) if os.path.isdir(path): continue with open(path, "rt", -1, "utf-8") as f: try: data = json.load(f) except ValueError as e: Logger.log("e", "Error when loading file {0}: {1}".format(file, e)) continue if not data.get("id"): continue # Any model without an ID is seen as an 'abstract' _file = file _id = data.get("id") _name = data.get("name") _pages = data.get("add_pages") while _pages == None: searchPath = os.path.join(dir, data.get("inherits")) json_data = open(searchPath).read() data = json.loads(json_data) _pages = data.get("add_pages") _pages = self._createPagesModel(_pages) self.appendItem({ "id": _id, "name": _name, "pages": _pages, "file": _file})
def getThemes(self): themes = [] for path in Resources.getAllPathsForType(Resources.Themes): try: for file in os.listdir(path): folder = os.path.join(path, file) theme_file = os.path.join(folder, "theme.json") if os.path.isdir(folder) and os.path.isfile(theme_file): theme_id = os.path.basename(folder) with open(theme_file, encoding = "utf-8") as f: try: data = json.load(f) except json.decoder.JSONDecodeError: Logger.log("w", "Could not parse theme %s", theme_id) continue # do not add this theme to the list, but continue looking for other themes try: theme_name = data["metadata"]["name"] except KeyError: Logger.log("w", "Theme %s does not have a name; using its id instead", theme_id) theme_name = theme_id # fallback if no name is specified in json themes.append({ "id": theme_id, "name": theme_name }) except FileNotFoundError: pass themes.sort(key = lambda k: k["name"]) return themes
def loadAllScripts(self) -> None: """Load all scripts from all paths where scripts can be found. This should probably only be done on init. """ if self._loaded_scripts: # Already loaded. return # The PostProcessingPlugin path is for built-in scripts. # The Resources path is where the user should store custom scripts. # The Preferences path is legacy, where the user may previously have stored scripts. resource_folders = [ PluginRegistry.getInstance().getPluginPath("PostProcessingPlugin"), Resources.getStoragePath(Resources.Preferences) ] resource_folders.extend( Resources.getAllPathsForType(Resources.Resources)) for root in resource_folders: if root is None: continue path = os.path.join(root, "scripts") if not os.path.isdir(path): try: os.makedirs(path) except OSError: Logger.log( "w", "Unable to create a folder for scripts: " + path) continue self.loadScripts(path)
def loadMachineInstances(self): dirs = Resources.getAllPathsForType(Resources.MachineInstances) for dir in dirs: if not os.path.isdir(dir): continue for file_name in os.listdir(dir): path = os.path.join(dir, file_name) if os.path.isdir(path): continue instance = MachineInstance(self) try: instance.loadFromFile(path) except Exception as e: Logger.log("e", "An exception occurred loading Machine Instance: %s: %s", path, str(e)) continue if not self.findMachineInstance(instance.getName()): self._machine_instances.append(instance) instance.nameChanged.connect(self._onInstanceNameChanged) instance = self.findMachineInstance(Preferences.getInstance().getValue("machines/active_instance")) if instance: self.setActiveMachineInstance(instance) self.machineInstancesChanged.emit()
def __init__(self, application: "QtApplication", parent: Optional[QObject] = None) -> None: super().__init__(parent) self._application = application self._container_registry = self._application.getContainerRegistry() self._plugin_registry = self._application.getPluginRegistry() # JSON files that keep track of all installed packages. self._user_package_management_file_path = None # type: Optional[str] self._bundled_package_management_file_paths = [] # type: List[str] for search_path in Resources.getAllPathsForType( Resources.BundledPackages): if not os.path.isdir(search_path): continue # Load all JSON files that are located in the bundled_packages directory. for file_name in os.listdir(search_path): if not file_name.endswith(".json"): continue file_path = os.path.join(search_path, file_name) if not os.path.isfile(file_path): continue self._bundled_package_management_file_paths.append(file_path) Logger.log( "i", "Found bundled packages JSON file: {location}".format( location=file_path)) for search_path in (Resources.getDataStoragePath(), Resources.getConfigStoragePath()): candidate_user_path = os.path.join(search_path, "packages.json") if os.path.exists(candidate_user_path): self._user_package_management_file_path = candidate_user_path if self._user_package_management_file_path is None: # Doesn't exist yet. self._user_package_management_file_path = os.path.join( Resources.getDataStoragePath(), "packages.json") self._installation_dirs_dict = { "plugins": os.path.abspath(Resources.getStoragePath(Resources.Plugins)) } # type: Dict[str, str] self._bundled_package_dict = { } # type: Dict[str, Dict[str, Any]] # A dict of all bundled packages self._installed_package_dict = { } # type: Dict[str, Dict[str, Any]] # A dict of all installed packages self._to_remove_package_set = set( ) # type: Set[str] # A set of packages that need to be removed at the next start self._to_install_package_dict = { } # type: Dict[str, Dict[str, Any]] # A dict of packages that need to be installed at the next start self._dismissed_packages = set( ) # type: Set[str] # A set of packages that are dismissed by the user # There can be plugins that provide remote packages (and thus, newer / different versions for a package). self._available_package_versions = { } # type: Dict[str, Set[UMVersion]] self._packages_with_update_available = set() # type: Set[str]
def loadProfiles(self): storage_path = Resources.getStoragePathForType(Resources.Profiles) dirs = Resources.getAllPathsForType(Resources.Profiles) for dir in dirs: if not os.path.isdir(dir): continue read_only = dir != storage_path for root, dirs, files in os.walk(dir): for file_name in files: path = os.path.join(root, file_name) if os.path.isdir(path): continue profile = Profile(self, read_only) try: profile.loadFromFile(path) except Exception as e: Logger.log("e", "An exception occurred loading Profile %s: %s", path, str(e)) continue if not self.findProfile(profile.getName(), variant_name = profile.getMachineVariantName(), material_name = profile.getMaterialName(), instance = self._active_machine): self._profiles.append(profile) profile.nameChanged.connect(self._onProfileNameChanged) for instance in self._machine_instances: try: file_name = urllib.parse.quote_plus(instance.getName()) + ".curaprofile" instance.getWorkingProfile().loadFromFile(Resources.getStoragePath(Resources.MachineInstanceProfiles, file_name)) except Exception as e: Logger.log("w", "Could not load working profile: %s: %s", file_name, str(e)) self._setDefaultVariantMaterialProfile(instance) self._protect_working_profile = True if self._active_machine: profile_name = self._active_machine.getActiveProfileName() if profile_name == "": profile_name = "Normal Quality" profile = self.findProfile(self._active_machine.getActiveProfileName(), instance = self._active_machine) if profile: self.setActiveProfile(profile) else: profiles = self.getProfiles(instance = self._active_machine) if len(profiles) > 0: self.setActiveProfile(profiles[0]) self.profilesChanged.emit() self._protect_working_profile = False
def _update(self): if not self.__application: self.__require_update = True return if not self.__name: self.__name = self.__application.getApplicationName() if self.__language == "default": self.__language = self.__application.getApplicationLanguage() for path in Resources.getAllPathsForType(Resources.i18n): if gettext.find(self.__name, path, languages = [self.__language]): # pylint: disable=bad-whitespace self.__translation = gettext.translation(self.__name, path, languages=[self.__language]) self.__require_update = False
def _update(self): if not self.__application: self.__require_update = True return if not self.__name: self.__name = self.__application.getApplicationName() if self.__language == "default": self.__language = self.__application.getApplicationLanguage() for path in Resources.getAllPathsForType(Resources.i18n): if gettext.find(self.__name, path, languages = [self.__language]): self.__translation = gettext.translation(self.__name, path, languages=[self.__language]) self.__require_update = False
def _update(self) -> None: if not self.__application: self.__require_update = True return if not self.__name: self.__name = self.__application.getApplicationName() if self.__language == "default": self.__language = self.__application.getApplicationLanguage() # Ask gettext for all the translations in the .mo files. for path in Resources.getAllPathsForType(Resources.i18n): if gettext.find(cast(str, self.__name), path, languages = [self.__language]): self.__translation = gettext.translation(cast(str, self.__name), path, languages = [self.__language]) self.__require_update = False
def __init__(self, application, parent=None): super().__init__(parent) self._application = application self._container_registry = self._application.getContainerRegistry() self._plugin_registry = self._application.getPluginRegistry() # JSON files that keep track of all installed packages. self._user_package_management_file_path = None # type: str self._bundled_package_management_file_paths = [] # type: List[str] for search_path in Resources.getAllPathsForType( Resources.BundledPackages): if not os.path.isdir(search_path): continue # Load all JSON files that are located in the bundled_packages directory. for file_name in os.listdir(search_path): if not file_name.endswith(".json"): continue file_path = os.path.join(search_path, file_name) if not os.path.isfile(file_path): continue self._bundled_package_management_file_paths.append(file_path) Logger.log( "i", "Found bundled packages JSON file: {location}".format( location=file_path)) for search_path in (Resources.getDataStoragePath(), Resources.getConfigStoragePath()): candidate_user_path = os.path.join(search_path, "packages.json") if os.path.exists(candidate_user_path): self._user_package_management_file_path = candidate_user_path if self._user_package_management_file_path is None: #Doesn't exist yet. self._user_package_management_file_path = os.path.join( Resources.getDataStoragePath(), "packages.json") self._installation_dirs_dict = { "plugins": os.path.abspath(Resources.getStoragePath(Resources.Plugins)) } # type: Dict[str, str] self._bundled_package_dict = {} # A dict of all bundled packages self._installed_package_dict = {} # A dict of all installed packages self._to_remove_package_set = set( ) # A set of packages that need to be removed at the next start self._to_install_package_dict = { } # A dict of packages that need to be installed at the next start
def _update(self) -> None: if not self.__name: self.__require_update = True return if not self.__name: self.__name = self.__name if self.__language == "default": self.__language = self.__language #Ask gettext for all the translations in the .mo files. for path in Resources.getAllPathsForType(Resources.i18n): if gettext.find(self.__name, path, languages=[self.__language]): self.__translation = gettext.translation( self.__name, path, languages=[self.__language]) self.__require_update = False
def getThemes(self) -> List[Dict[str, str]]: install_prefix = os.path.abspath( UM.Application.Application.getInstance().getInstallPrefix()) themes = [] for path in Resources.getAllPathsForType(Resources.Themes): if self._check_if_trusted and not TrustBasics.isPathInLocation( install_prefix, path): # This will prevent themes to load from outside 'bundled' folders, when `check_if_trusted` is True. # Note that this will be a lot less useful in newer versions supporting Qt 6, due to lack of QML Styles. Logger.warning( "Skipped indexing Theme from outside bundled folders: ", path) continue try: for file in os.listdir(path): folder = os.path.join(path, file) theme_file = os.path.join(folder, "theme.json") if os.path.isdir(folder) and os.path.isfile(theme_file): theme_id = os.path.basename(folder) with open(theme_file, encoding="utf-8") as f: try: data = json.load(f) except (UnicodeDecodeError, json.decoder.JSONDecodeError): Logger.log("w", "Could not parse theme %s", theme_id) continue # do not add this theme to the list, but continue looking for other themes try: theme_name = data["metadata"]["name"] except KeyError: Logger.log( "w", "Theme %s does not have a name; using its id instead", theme_id) theme_name = theme_id # fallback if no name is specified in json themes.append({"id": theme_id, "name": theme_name}) except EnvironmentError: pass themes.sort(key=lambda k: k["name"]) return themes
def _update(self) -> None: """Fill the catalogue by loading the translated texts from file (again).""" if not self.__application: self.__require_update = True return if not self.__name: self.__name = self.__application.getApplicationName() if self.__language == "default": self.__language = self.__application.getApplicationLanguage() # Ask gettext for all the translations in the .mo files. for path in Resources.getAllPathsForType(Resources.i18n): if gettext.find(cast(str, self.__name), path, languages = [self.__language]): self.__translation = gettext.translation(cast(str, self.__name), path, languages = [self.__language]) self.__require_update = False
def __init__(self, application: "QtApplication", parent: Optional[QObject] = None) -> None: super().__init__(parent) self._application = application self._container_registry = self._application.getContainerRegistry() self._plugin_registry = self._application.getPluginRegistry() # JSON files that keep track of all installed packages. self._user_package_management_file_path = None # type: Optional[str] self._bundled_package_management_file_paths = [] # type: List[str] for search_path in Resources.getAllPathsForType(Resources.BundledPackages): if not os.path.isdir(search_path): continue # Load all JSON files that are located in the bundled_packages directory. for file_name in os.listdir(search_path): if not file_name.endswith(".json"): continue file_path = os.path.join(search_path, file_name) if not os.path.isfile(file_path): continue self._bundled_package_management_file_paths.append(file_path) Logger.log("i", "Found bundled packages JSON file: {location}".format(location = file_path)) for search_path in (Resources.getDataStoragePath(), Resources.getConfigStoragePath()): candidate_user_path = os.path.join(search_path, "packages.json") if os.path.exists(candidate_user_path): self._user_package_management_file_path = candidate_user_path if self._user_package_management_file_path is None: # Doesn't exist yet. self._user_package_management_file_path = os.path.join(Resources.getDataStoragePath(), "packages.json") self._installation_dirs_dict = {"plugins": os.path.abspath(Resources.getStoragePath(Resources.Plugins))} # type: Dict[str, str] self._bundled_package_dict = {} # type: Dict[str, Dict[str, Any]] # A dict of all bundled packages self._installed_package_dict = {} # type: Dict[str, Dict[str, Any]] # A dict of all installed packages self._to_remove_package_set = set() # type: Set[str] # A set of packages that need to be removed at the next start self._to_install_package_dict = {} # type: Dict[str, Dict[str, Any]] # A dict of packages that need to be installed at the next start # There can be plugins that provide remote packages (and thus, newer / different versions for a package). self._available_package_versions = {} # type: Dict[str, Set[UMVersion]] self._packages_with_update_available = set() # type: Set[str]
def _updateModel(self): dirs = Resources.getAllPathsForType(Resources.Settings) for dir in dirs: if not os.path.isdir(dir): continue for file in os.listdir(dir): data = None path = os.path.join(dir, file) if os.path.isdir(path): continue with open(path, "rt", -1, "utf-8") as f: try: data = json.load(f) except ValueError as e: Logger.log( "e", "Error when loading file {0}: {1}".format(file, e)) continue if not data.get("id"): continue # Any model without an ID is seen as an 'abstract' _file = file _id = data.get("id") _name = data.get("name") _pages = data.get("add_pages") while _pages == None: searchPath = os.path.join(dir, data.get("inherits")) json_data = open(searchPath).read() data = json.loads(json_data) _pages = data.get("add_pages") _pages = self._createPagesModel(_pages) self.appendItem({ "id": _id, "name": _name, "pages": _pages, "file": _file })
def loadProfiles(self): storage_path = Resources.getStoragePathForType(Resources.Profiles) dirs = Resources.getAllPathsForType(Resources.Profiles) for dir in dirs: if not os.path.isdir(dir): continue read_only = dir != storage_path for file_name in os.listdir(dir): path = os.path.join(dir, file_name) if os.path.isdir(path): continue profile = Profile(self, read_only) try: profile.loadFromFile(path) except Exception as e: Logger.log("e", "An exception occurred loading Profile %s: %s", path, str(e)) continue if not self.findProfile(profile.getName()): self._profiles.append(profile) profile.nameChanged.connect(self._onProfileNameChanged) profile = self.findProfile( Preferences.getInstance().getValue("machines/active_profile")) if profile: self.setActiveProfile(profile) else: if Preferences.getInstance().getValue( "machines/active_profile") == "": for profile in self._profiles: self.setActiveProfile( profile) #default to first profile you can find break self.profilesChanged.emit()
def _updateModel(self): dirs = Resources.getAllPathsForType(Resources.Settings) for dir in dirs: if not os.path.isdir(dir): continue for file in os.listdir(dir): data = None path = os.path.join(dir, file) if os.path.isdir(path): continue with open(path, "rt", -1, "utf-8") as f: try: data = json.load(f) except ValueError as e: Logger.log("e", "Error when loading file {0}: {1}".format(file, e)) continue if not data.get("id"): #the base model (fdmprinter.json) has no id, but also doesn't represent a real printer profile, so we dump it continue _file = file _id = data.get("id") _name = data.get("name") _pages = data.get("add_pages") while _pages == None: searchPath = os.path.join(dir, data.get("inherits")) json_data = open(searchPath).read() data = json.loads(json_data) _pages = data.get("add_pages") _pages = self._createPagesModel(_pages) self.appendItem({ "id": _id, "name": _name, "pages": _pages, "file": _file})
def _updateModel(self): dirs = Resources.getAllPathsForType(Resources.Settings) _machines_by_ultimaker = [] _machines_by_other = [] for dir in dirs: if not os.path.isdir(dir): continue for file in os.listdir(dir): data = None path = os.path.join(dir, file) if os.path.isdir(path): continue with open(path, "rt", -1, "utf-8") as f: try: data = json.load(f) except ValueError as e: Logger.log("e", "Error when loading file {0}: {1}".format(file, e)) continue # Ignore any file that is explicitly marked as non-visible if not data.get("visible", True): continue # Ignore any file that is marked as non-visible for the current application. appname = Application.getInstance().getApplicationName() if appname in data: if not data[appname].get("visible", True): continue _id = data.get("id") _file = file _name = data.get("name") _manufacturer = data.get("manufacturer") _author = data.get("author") _pages = data.get("add_pages") while _pages == None: searchPath = os.path.join(dir, data.get("inherits")) json_data = open(searchPath).read() data = json.loads(json_data) _pages = data.get("add_pages") _pages = self._createPagesModel(_pages) #makes sure that if Cura tries to load a faulty settings file, that it ignores the file and that Cura at least still loads if _id == None or _file == None or _name == None or _manufacturer == None: continue #if the file is missing an author, it displays the author as "unspecified" instead of other if _author == None: _author = "unspecified" if _manufacturer != "Ultimaker": _machines_by_other.append([_manufacturer, _id, _file, _name, _author, _pages]) if _manufacturer == "Ultimaker": _machines_by_ultimaker.append([_id, _file, _name, _manufacturer, _author,_pages]) for item in sorted(_machines_by_ultimaker, key = lambda item: item[2]): self.appendItem({ "id": item[0], "file": item[1], "name": item[2], "manufacturer": item[3], "author": item[4],"pages": item[5]}) for item in sorted(_machines_by_other, key = lambda item: item[2]): self.appendItem({ "id": item[1], "file": item[2], "name": item[3], "manufacturer": item[0], "author": item[4],"pages": item[5]})
def __init__(self, application: "QtApplication", parent: Optional[QObject] = None) -> None: super().__init__(parent) self._application = application self._container_registry = self._application.getContainerRegistry() self._plugin_registry = self._application.getPluginRegistry() # JSON files that keep track of all installed packages. self._user_package_management_file_path: Optional[str] = None self._bundled_package_management_file_paths: List[str] = [] for search_path in Resources.getAllPathsForType( Resources.BundledPackages): if not os.path.isdir(search_path): continue # Load all JSON files that are located in the bundled_packages directory. try: for file_name in os.listdir(search_path): if not file_name.endswith(".json"): continue file_path = os.path.join(search_path, file_name) if not os.path.isfile(file_path): continue self._bundled_package_management_file_paths.append( file_path) Logger.log( "i", "Found bundled packages JSON file: {location}".format( location=file_path)) except EnvironmentError as e: # Unable to read directory. Could be corrupt disk or insufficient access to list the directory. Logger.log( "e", f"Unable to read package directory to search for packages JSON files: {str(e)}" ) pass for search_path in (Resources.getDataStoragePath(), Resources.getConfigStoragePath()): candidate_user_path = os.path.join(search_path, "packages.json") if os.path.exists(candidate_user_path): self._user_package_management_file_path = candidate_user_path if self._user_package_management_file_path is None: # Doesn't exist yet. self._user_package_management_file_path = os.path.join( Resources.getDataStoragePath(), "packages.json") self._installation_dirs_dict: Dict[str, str] = { "plugins": os.path.abspath(Resources.getStoragePath(Resources.Plugins)) } self._bundled_package_dict: PackageDataDict = { } # A dict of all bundled packages self._installed_package_dict: PackageDataDict = { } # A dict of all installed packages self._to_remove_package_set: Set[str] = set( ) # A set of packages that need to be removed at the next start self._to_install_package_dict: PackageDataDict = { } # A dict of packages that need to be installed at the next start self._dismissed_packages: Set[str] = set( ) # A set of packages that are dismissed by the user self._installed_packages: PackageDataDict = { } # A dict of packages that were installed during startup # There can be plugins that provide remote packages (and thus, newer / different versions for a package). self._available_package_versions: Dict[str, Set[UMVersion]] = {} self._packages_with_update_available: Set[str] = set()
def _updateModel(self): dirs = Resources.getAllPathsForType(Resources.Settings) _machines_by_ultimaker = [] _machines_by_other = [] for dir in dirs: if not os.path.isdir(dir): continue for file in os.listdir(dir): data = None path = os.path.join(dir, file) if os.path.isdir(path): continue with open(path, "rt", -1, "utf-8") as f: try: data = json.load(f) except ValueError as e: Logger.log( "e", "Error when loading file {0}: {1}".format(file, e)) continue # Ignore any file that is explicitly marked as non-visible if not data.get("visible", True): continue # Ignore any file that is marked as non-visible for the current application. appname = Application.getInstance().getApplicationName() if appname in data: if not data[appname].get("visible", True): continue _id = data.get("id") _file = file _name = data.get("name") _manufacturer = data.get("manufacturer") _author = data.get("author") _pages = data.get("add_pages") while _pages == None: searchPath = os.path.join(dir, data.get("inherits")) json_data = open(searchPath).read() data = json.loads(json_data) _pages = data.get("add_pages") _pages = self._createPagesModel(_pages) #makes sure that if Cura tries to load a faulty settings file, that it ignores the file and that Cura at least still loads if _id == None or _file == None or _name == None or _manufacturer == None: continue #if the file is missing an author, it displays the author as "unspecified" instead of other if _author == None: _author = "unspecified" if _manufacturer != "Ultimaker": _machines_by_other.append( [_manufacturer, _id, _file, _name, _author, _pages]) if _manufacturer == "Ultimaker": _machines_by_ultimaker.append( [_id, _file, _name, _manufacturer, _author, _pages]) for item in sorted(_machines_by_ultimaker, key=lambda item: item[2]): self.appendItem({ "id": item[0], "file": item[1], "name": item[2], "manufacturer": item[3], "author": item[4], "pages": item[5] }) for item in sorted(_machines_by_other, key=lambda item: item[2]): self.appendItem({ "id": item[1], "file": item[2], "name": item[3], "manufacturer": item[0], "author": item[4], "pages": item[5] })
def loadProfiles(self): storage_path = Resources.getStoragePathForType(Resources.Profiles) dirs = Resources.getAllPathsForType(Resources.Profiles) for dir in dirs: if not os.path.isdir(dir): continue read_only = dir != storage_path for root, dirs, files in os.walk(dir): for file_name in files: path = os.path.join(root, file_name) if os.path.isdir(path): continue # Bit of a hack, but we should only use cfg or curaprofile files in the profile folder. try: extension = path.split(".")[-1] if extension != "cfg" and extension != "curaprofile": continue except: continue # profile has no extension profile = Profile(self, read_only) try: profile.loadFromFile(path) except Exception as e: Logger.log( "e", "An exception occurred loading Profile %s: %s", path, str(e)) continue self._profiles.append(profile) profile.nameChanged.connect(self._onProfileNameChanged) for instance in self._machine_instances: try: file_name = urllib.parse.quote_plus( instance.getName()) + ".curaprofile" instance.getWorkingProfile().loadFromFile( Resources.getStoragePath(Resources.MachineInstanceProfiles, file_name)) except Exception as e: Logger.log("w", "Could not load working profile: %s: %s", file_name, str(e)) self._setDefaultVariantMaterialProfile(instance) self._protect_working_profile = True if self._active_machine: profile_name = self._active_machine.getActiveProfileName() if profile_name == "": profile_name = self._active_machine.getMachineDefinition( ).getPreference("prefered_profile") profile = self.findProfile( self._active_machine.getActiveProfileName(), instance=self._active_machine) if profile: self.setActiveProfile(profile) else: profiles = self.getProfiles(instance=self._active_machine) if len(profiles) > 0: self.setActiveProfile(profiles[0]) self.profilesChanged.emit() self._protect_working_profile = False
def loadProfiles(self): storage_path = Resources.getStoragePathForType(Resources.Profiles) dirs = Resources.getAllPathsForType(Resources.Profiles) for dir in dirs: if not os.path.isdir(dir): continue read_only = dir != storage_path for root, dirs, files in os.walk(dir): for file_name in files: path = os.path.join(root, file_name) if os.path.isdir(path): continue profile = Profile(self, read_only) try: profile.loadFromFile(path) except Exception as e: Logger.log( "e", "An exception occurred loading Profile %s: %s", path, str(e)) continue if not self.findProfile( profile.getName(), variant_name=profile.getMachineVariantName(), material_name=profile.getMaterialName(), instance=self._active_machine): self._profiles.append(profile) profile.nameChanged.connect(self._onProfileNameChanged) for instance in self._machine_instances: try: file_name = urllib.parse.quote_plus( instance.getName()) + ".curaprofile" instance.getWorkingProfile().loadFromFile( Resources.getStoragePath(Resources.MachineInstanceProfiles, file_name)) except Exception as e: Logger.log("w", "Could not load working profile: %s: %s", file_name, str(e)) self._setDefaultVariantMaterialProfile(instance) self._protect_working_profile = True if self._active_machine: profile_name = self._active_machine.getActiveProfileName() if profile_name == "": profile_name = "Normal Quality" profile = self.findProfile( self._active_machine.getActiveProfileName(), instance=self._active_machine) if profile: self.setActiveProfile(profile) else: profiles = self.getProfiles(instance=self._active_machine) if len(profiles) > 0: self.setActiveProfile(profiles[0]) self.profilesChanged.emit() self._protect_working_profile = False