예제 #1
0
    def _read(self):
        """Get the theme icon,extensions and size. Save all of that to icon."""
        from HardcodeTray.app import App

        if isinstance(self.icon_data, str):
            orig_icon = theme_icon = self.icon_data
        else:
            orig_icon = self.icon_data["original"]
            theme_icon = self.icon_data["theme"]

        base_name = path.splitext(theme_icon)[0]
        theme = Icon.get_theme(orig_icon)
        theme_icon = theme.lookup_icon(base_name, App.icon_size(), 0)

        if theme_icon:
            self.original = orig_icon
            self.theme = theme_icon.get_filename()
            self.theme_ext = get_extension(self.theme)
            self.orig_ext = get_extension(orig_icon)
            self.icon_size = self.get_icon_size(App.icon_size())
            self._exists = True

            if (not isinstance(self.icon_data, str)
                    and self.icon_data.get("symlinks")):
                symlinks = get_iterated_icons(self.icon_data["symlinks"])
                # Make sure that symlinks have the right extension
                for symlink in symlinks:
                    if not get_extension(symlink):
                        symlink += ".{0}".format(self.theme_ext)
                    self.symlinks.append(symlink)
예제 #2
0
def get_pngbytes(icon):
    """Return the pngbytes of a svg/png icon."""
    from HardcodeTray.app import App
    icon_for_replace = icon.theme
    icon_extension = icon.theme_ext
    icon_size = icon.icon_size
    if icon_extension == 'svg':
        if icon_size != App.icon_size():
            png_bytes = App.svg().to_bin(icon_for_replace, App.icon_size())
        else:
            png_bytes = App.svg().to_bin(icon_for_replace)
    elif icon_extension == "png":
        with open(icon_for_replace, 'rb') as png_file:
            png_bytes = png_file.read()
    else:
        png_bytes = None
    return png_bytes
예제 #3
0
def get_pngbytes(icon):
    """Return the pngbytes of a svg/png icon."""
    from HardcodeTray.app import App
    icon_for_replace = icon.theme
    icon_extension = icon.theme_ext
    icon_size = icon.icon_size
    if icon_extension == 'svg':
        if icon_size != App.icon_size():
            png_bytes = App.svg().to_bin(icon_for_replace,
                                         App.icon_size())
        else:
            png_bytes = App.svg().to_bin(icon_for_replace)
    elif icon_extension == "png":
        with open(icon_for_replace, 'rb') as png_file:
            png_bytes = png_file.read()
    else:
        png_bytes = None
    return png_bytes
예제 #4
0
    def install_icon(self, icon, icon_path):
        """Install icon to the current directory."""
        ext_orig = icon.orig_ext
        theme_icon = icon.theme
        ext_theme = icon.theme_ext
        icon_size = icon.icon_size
        output_icon = path.join(str(icon_path), icon.original)

        # Backup the output_icon
        if not self.backup_ignore:
            self.backup.create(output_icon)

        if ext_theme == ext_orig and theme_icon != output_icon:
            symlink_file(theme_icon, output_icon)
        elif ext_theme == "svg" and ext_orig == "png":
            from HardcodeTray.app import App
            if icon_size != App.icon_size():
                App.svg().to_png(theme_icon, output_icon, App.icon_size())
            else:
                App.svg().to_png(theme_icon, output_icon)
예제 #5
0
    def install_icon(self, icon, icon_path):
        """Install icon to the current directory."""
        ext_orig = icon.orig_ext
        theme_icon = icon.theme
        ext_theme = icon.theme_ext
        icon_size = icon.icon_size
        output_icon = path.join(str(icon_path), icon.original)

        # Backup the output_icon
        if not self.backup_ignore:
            self.backup.create(output_icon)

        if ext_theme == ext_orig and theme_icon != output_icon:
            symlink_file(theme_icon, output_icon)
        elif ext_theme == "svg" and ext_orig == "png":
            from HardcodeTray.app import App
            if icon_size != App.icon_size():
                App.svg().to_png(theme_icon, output_icon, App.icon_size())
            else:
                App.svg().to_png(theme_icon, output_icon)
예제 #6
0
    def _validate(self):
        """Check whether a folder path exists or not."""

        Path.DB_VARIABLES["{size}"] = str(App.icon_size())

        for key, value in Path.DB_VARIABLES.items():
            if key in self.path:
                # Check whether it's a function or not
                if value.endswith("_callback"):
                    self._validate_with_callback(key, value)
                else:
                    self.path = self.path.replace(key, str(value))

        if self.parser.script and self.type == "icons_path":
            binary_file = path.join(self.path, self.parser.binary)
            self._exists = path.exists(self.path) and path.exists(binary_file)
        else:
            self._exists = path.exists(self.path)
예제 #7
0
    def _validate(self):
        """
            Check wether a folder path exists or not.
        """
        from HardcodeTray.app import App

        Path.DB_VARIABLES["{size}"] = str(App.icon_size())

        for key, value in Path.DB_VARIABLES.items():
            if key in self.path:
                if value.endswith("_callback"):  # Check wether it's a function or not
                    self._validate_with_callback(key, value)
                else:
                    self.path = self.path.replace(key, str(value))

        if self.parser.script and self.type == "icons_path":
            binary_file = path.join(self.path, self.parser.binary)
            self._exists = path.exists(self.path) and path.exists(binary_file)
        else:
            self._exists = path.exists(self.path)
예제 #8
0
    def install_icon(self, icon, icon_path):
        """Install the icon."""
        icon.icon_size = App.icon_size()

        png_bytes = get_pngbytes(icon)

        if png_bytes:
            # Read a target file
            asar = AsarFile(path.join(str(icon_path), self.binary))
            target = B64ElectronApplication.get_real_path(self.file)
            file_content = asar.read_file(target).decode()
            # Create new base64 binary file
            base64_icon = b64encode(App.svg().to_bin(icon.theme, icon.icon_size, icon.icon_size))
            # Build new icon
            new_icon = "data:image/png;base64," + base64_icon.decode()
            # Replace the original icon with newly built one
            file_content = file_content.replace(icon.original, new_icon)
            bytes = file_content.encode()
            self.set_icon(target, icon_path, bytes, True)
        else:
            Logger.error("Icon file was not found.")