def _updateModel(self):
        dirs = Resources.getLocation(Resources.SettingsLocation)

        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

                self.appendItem({ "name": data["name"], "type": file })

                self.sort(lambda e: e["name"])
Exemple #2
0
    def _updateLanguage(self):
        languages = []
        if self._language == "default":
            languages.append(self._getDefaultLanguage())
        else:
            languages.append(self._language)

        for path in Resources.getLocation(Resources.i18nLocation):
            if gettext.find(self._name, path, languages = languages):
                self.__translation = gettext.translation(self._name, path, languages=languages)
                break
        else:
            self.__translation = None
Exemple #3
0
    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.getLocation(Resources.i18nLocation):
            if gettext.find(self.__name, path, languages = [self.__language]):
                self.__translation = gettext.translation(self.__name, path, languages=[self.__language])

        self.__require_update = False
Exemple #4
0
    def __init__(self, name, language = "default"):
        languages = []
        if language == "default":
            envlang = os.getenv("LANGUAGE")
            if envlang:
                languages.append(envlang)
            else:
                preflang = Preferences.getInstance().getValue("general/language")
                if preflang:
                    languages.append(preflang)
        else:
            languages.append(language)

        for path in Resources.getLocation(Resources.i18nLocation):
            if gettext.find(name, path, languages = languages):
                self.__translation = gettext.translation(name, path, languages=languages)
                break
        else:
            self.__translation = None
    def _updateModel(self):
        dirs = Resources.getLocation(Resources.SettingsLocation)

        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.getLocation(Resources.SettingsLocation)
        _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]})