Beispiel #1
0
    def getImage(self, imageId, requestedSize):
        #log.debug("ICON!")
        #log.debug(imageId)
        try:
            #TODO: theme name caching ?
            themeFolder = self.gui.modrana.paths.getThemesFolderPath()
            # fullIconPath = os.path.join(themeFolder, imageId)
            # the path is constructed like this in QML
            # so we can safely just split it like this
            splitPath = imageId.split("/")
            # remove any Ambiance specific garbage appended by Silica
            splitPath[-1] = splitPath[-1].rsplit("?")[0]
            fullIconPath = os.path.join(themeFolder, *splitPath)

            if not utils.internal_isfile(fullIconPath):
                if splitPath[0] == constants.DEFAULT_THEME_ID:
                    # already on default theme and icon path does not exist
                    log.error("Icon not found in default theme:")
                    log.error(fullIconPath)
                    return None
                else:  # try to get the icon from default theme
                    splitPath[0] = constants.DEFAULT_THEME_ID
                    fullIconPath = os.path.join(themeFolder, *splitPath)
                    if not utils.internal_isfile(fullIconPath):
                        # icon not found even in the default theme
                        log.error("Icon not found even in default theme:")
                        log.error(fullIconPath)
                        return None
            return utils.internal_get_file_contents(fullIconPath), (
                -1, -1), pyotherside.format_data
        except Exception:
            log.exception("icon image provider: loading icon failed, id:\n%s" %
                          imageId)
Beispiel #2
0
    def getImage(self, imageId, requestedSize):
        #log.debug("ICON!")
        #log.debug(imageId)
        try:
            #TODO: theme name caching ?
            themeFolder = self.gui.modrana.paths.getThemesFolderPath()
            # fullIconPath = os.path.join(themeFolder, imageId)
            # the path is constructed like this in QML
            # so we can safely just split it like this
            splitPath = imageId.split("/")
            # remove any Ambiance specific garbage appended by Silica
            splitPath[-1] = splitPath[-1].rsplit("?")[0]
            fullIconPath = os.path.join(themeFolder, *splitPath)

            if not utils.internal_isfile(fullIconPath):
                if splitPath[0] == constants.DEFAULT_THEME_ID:
                    # already on default theme and icon path does not exist
                    log.error("Icon not found in default theme:")
                    log.error(fullIconPath)
                    return None
                else:  # try to get the icon from default theme
                    splitPath[0] = constants.DEFAULT_THEME_ID
                    fullIconPath = os.path.join(themeFolder, *splitPath)
                    if not utils.internal_isfile(fullIconPath):
                        # icon not found even in the default theme
                        log.error("Icon not found even in default theme:")
                        log.error(fullIconPath)
                        return None
            return utils.internal_get_file_contents(fullIconPath), (-1,-1), pyotherside.format_data
        except Exception:
            log.exception("icon image provider: loading icon failed, id:\n%s" % imageId)
Beispiel #3
0
    def getImage(self, imageId, requestedSize):
        #log.debug("ICON!")
        #log.debug(imageId)
        try:
            #TODO: theme name caching ?
            themeFolder = self.gui.modrana.paths.getThemesFolderPath()
            # fullIconPath = os.path.join(themeFolder, imageId)
            # the path is constructed like this in QML
            # so we can safely just split it like this
            splitPath = imageId.split("/")
            # remove any Ambiance specific garbage appended by Silica
            splitPath[-1] = splitPath[-1].rsplit("?")[0]
            fullIconPath = os.path.join(themeFolder, *splitPath)
            extension = os.path.splitext(fullIconPath)[1]
            # set correct data format based on the extension
            if extension.lower() == ".svg":
                data_format = pyotherside.format_svg_data
            else:
                data_format = pyotherside.format_data

            if not utils.internal_isfile(fullIconPath):
                if splitPath[0] == constants.DEFAULT_THEME_ID:
                    # already on default theme and icon path does not exist
                    log.error("Icon not found in default theme:")
                    log.error(fullIconPath)
                    return None
                else:  # try to get the icon from default theme
                    splitPath[0] = constants.DEFAULT_THEME_ID
                    fullIconPath = os.path.join(themeFolder, *splitPath)
                    if not utils.internal_isfile(fullIconPath):
                        # icon not found even in the default theme
                        log.error("Icon not found even in default theme:")
                        log.error(fullIconPath)
                        return None
            # We only set height or else SVG icons would be squished if a square icon
            # has been requested but the SVG icon is not square. If just height is
            # we the clever SVG handling code (which I wrote ;-) ) will handle this correctly. :)
            return utils.internal_get_file_contents(fullIconPath), (
                -1, requestedSize[1]), data_format
        except Exception:
            log.exception("icon image provider: loading icon failed, id:\n%s" %
                          imageId)
Beispiel #4
0
    def _loadConfigFile(self, path):
        """load color definitions from file"""

        try:
            if qrc.is_qrc:
                if utils.internal_isfile(path):
                    config_content = utils.internal_get_file_contents(path)
                    config = ConfigObj(
                        config_content.decode('utf-8').split("\n"))
                else:
                    log.error("theme config file %s does not exist", path)
                    return
            else:
                # Python 2.5 lack the bytearray builtin and Android where qrc is
                # needed is Python 3 only, so just access the theme conf directly
                # when not running from qrc
                config = ConfigObj(path)

        except Exception:
            log.exception("loading theme config file from %s failed", path)
            return

        # try to get theme name from the config
        try:
            name = config['theme']['name']
            if name:
                self._name = name
        except KeyError:
            pass

        # load color definitions
        if 'colors' in config:
            colors = config['colors']
            colorObjects = {}
            for key, color in colors.items():
                if len(color
                       ) == 2:  # hex color/color name and alpha as float 0-1
                    colorString = color[0]
                    colorObjects[key] = colorString
                    # TODO: alpha support, other formats
                    # TODO: use the Color object
            self._colors = colorObjects
        else:
            self._colors = {}
Beispiel #5
0
    def _loadConfigFile(self, path):
        """load color definitions from file"""

        try:
            if qrc.is_qrc:
                if utils.internal_isfile(path):
                    config_content = utils.internal_get_file_contents(path)
                    config = ConfigObj(config_content.decode("utf-8").split("\n"))
                else:
                    log.error("theme config file %s does not exist", path)
                    return
            else:
                # Python 2.5 lack the bytearray builtin and Android where qrc is
                # needed is Python 3 only, so just access the theme conf directly
                # when not running from qrc
                config = ConfigObj(path)

        except Exception:
            log.exception("loading theme config file from %s failed", path)
            return

        # try to get theme name from the config
        try:
            name = config["theme"]["name"]
            if name:
                self._name = name
        except KeyError:
            pass

        # load color definitions
        if "colors" in config:
            colors = config["colors"]
            colorObjects = {}
            for key, color in six.iteritems(colors):
                if len(color) == 2:  # hex color/color name and alpha as float 0-1
                    colorString = color[0]
                    colorObjects[key] = colorString
                    # TODO: alpha support, other formats
                    # TODO: use the Color object
            self._colors = colorObjects
        else:
            self._colors = {}