示例#1
0
    def _read(self):
        """Get the theme icon,extensions and size. Save all of that to icon."""
        from src.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 src.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 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:
            if theme_icon != output_icon:
                symlink_file(theme_icon, output_icon)
        elif ext_theme == "svg" and ext_orig == "png":
            from src.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)

            mchown(output_icon)
示例#4
0
    def _validate(self):
        """
            Check wether a folder path exists or not.
        """
        from src.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)
示例#5
0
                    help=_("fix hardcoded tray icons"))
parser.add_argument("--revert", "-r", action='store_true',
                    help=_("revert fixed hardcoded tray icons"))
parser.add_argument("--conversion-tool", "-ct",
                    help=_("Which of conversion tool to use"),
                    type=str, choices=ConversionTools.choices())
parser.add_argument('--change-color', "-cc", type=str, nargs='+',
                    help=_("Replace a color with an other one, "
                           "works only with SVG."))
parser.add_argument("--clear-cache", action="store_true",
                    help=_("Clear backup files"))

args = parser.parse_args()
App.set_args(args)

if (not DESKTOP_ENV or DESKTOP_ENV == "other") and not App.icon_size():
    exit(_("You need to run the script using 'sudo -E'.\nPlease try again"))

print(_("Welcome to Hardcode-Tray!"))
print(_("Desktop Environment: {}").format(DESKTOP_ENV.title()))
print(_("Scaling Factor: {}").format(App.scaling_factor()))
print(_("Icon Size: {}").format(App.icon_size()))
if not isinstance(App.theme(), dict):
    print(_("Icon Theme: {}").format(App.theme()))
else:
    print(_("Dark Icon Theme: {}").format(App.theme("dark")))
    print(_("Light Icon Theme: {}").format(App.theme("light")))
print(_("Conversion Tool: {}").format(App.svg()))
print(_("To Do: "), end="")
print(", ".join(map(lambda x: x.title(), App.get("only")))
      if App.get("only") else _("All"))