예제 #1
0
    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()
예제 #2
0
    def importProfile(self, url):
        path = url.toLocalFile()
        if not path:
            return

        profile = Profile(self._manager, read_only=False)
        try:
            profile.loadFromFile(path)
            self._manager.addProfile(profile)
        except SettingsError.DuplicateProfileError as e:
            count = 2
            name = "{0} {1}".format(profile.getName(), count)
            while (self._manager.findProfile(name) != None):
                count += 1
                name = "{0} {1}".format(profile.getName(), count)
            profile.setName(name)
            self._manager.addProfile(profile)
            return {
                "status":
                "duplicate",
                "message":
                catalog.i18nc("@info:status", "Profile was imported as {0}",
                              name)
            }
        except Exception as e:
            return {
                "status":
                "error",
                "message":
                catalog.i18nc(
                    "@info:status",
                    "Failed to import profile from file <filename>{0}</filename>: <message>{1}</message>",
                    path, str(e))
            }
        else:
            return {
                "status":
                "ok",
                "message":
                catalog.i18nc("@info:status",
                              "Successfully imported profile {0}",
                              profile.getName())
            }
예제 #3
0
    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
예제 #4
0
    def importProfile(self, url):
        path = url.toLocalFile()
        if not path:
            return

        profile = Profile(self._manager, read_only = False)
        try:
            profile.loadFromFile(path)
            self._manager.addProfile(profile)
        except SettingsError.DuplicateProfileError as e:
            count = 2
            name = "{0} {1}".format(profile.getName(), count)
            while(self._manager.findProfile(name) != None):
                count += 1
                name = "{0} {1}".format(profile.getName(), count)
            profile.setName(name)
            self._manager.addProfile(profile)
            return { "status": "duplicate", "message": catalog.i18nc("@info:status", "Profile was imported as {0}", name) }
        except Exception as e:
            return { "status": "error", "message": catalog.i18nc("@info:status", "Failed to import profile from file <filename>{0}</filename>: <message>{1}</message>", path, str(e)) }
        else:
            return { "status": "ok", "message": catalog.i18nc("@info:status", "Successfully imported profile {0}", profile.getName()) }
예제 #5
0
    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()
예제 #6
0
    def importProfile(self, url):
        path = url.toLocalFile()
        if not path:
            return

        profile = Profile(self._manager, read_only = False)
        try:
            profile.loadFromFile(path)
        except Exception as e:
            m = Message(catalog.i18nc("@info:status", "Failed to import profile from file <filename>{0}</filename>: <message>{1}</message>", path, str(e)))
            m.show()
        else:
            m = Message(catalog.i18nc("@info:status", "Successfully imported profile {0}", profile.getName()))
            m.show()
            self._manager.addProfile(profile)
예제 #7
0
    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