跳转到主要内容

iconify for python. 通用的图标框架

项目描述

pyconify

License PyPI Conda Python Version CI codecov

Iconify API的Python封装。

Iconify是一个多功能的图标框架,包括100多个图标集,包含来自FontAwesome、Material Design Icons、DashIcons、Feather Icons、EmojiOne、Noto Emoji等多个开源图标集的超过10万个图标。

在:https://icon-sets.iconify.design 搜索图标

安装

pip install pyconify
# or
conda install -c conda-forge pyconify

用法

import pyconify

# Info on available collections
collections = pyconify.collections()

# Info on specific collection(s)
details = pyconify.collection("fa", "fa-brands")

# Search for icons
hits = pyconify.search("python")

# Get icon data
data = pyconify.icon_data("fa-brands", "python")

# Get SVG
svg = pyconify.svg("fa-brands", "python")

# Get path to SVG on disk
# will either return cached version, or write to temp file
file_name = pyconify.svg_path("fa-brands", "python")

# Get CSS
css = pyconify.css("fa-brands", "python")

# Keywords
pyconify.keywords('home')

# API version
pyconify.iconify_version()

请参阅Iconify API文档中每个结果的详细信息。

缓存

虽然获取任何给定SVG的第一次请求需要互联网访问,但pyconfiy会缓存SVG以加快检索和离线使用。要查看或清除缓存目录

import pyconify

# reveal location of cache
# will be ~/.cache/pyconify on linux and macos
# will be %LOCALAPPDATA%\pyconify on windows
# falls back to ~/.pyconify if none of the above are available
pyconify.get_cache_directory()

# remove the cache directory (and all its contents)
pyconify.clear_cache()

如果您想预缓存多个SVG,当前建议使用svg()函数

import pyconify

import pyconify

ICONS_TO_STORE = {"mdi:bell", "mdi:bell-off", "mdi:bell-outline"}
for key in ICONS_TO_STORE:
    pyconify.svg(key)

后续对svg()的调用将使用缓存的值。

要指定自定义缓存目录,将PYCONIFY_CACHE环境变量设置为您希望的目标目录。要完全禁用缓存,将PYCONIFY_CACHE环境变量设置为false0

freedesktop主题

pyconify包含一个便利函数,用于根据freedesktop图标主题规范生成SVG文件目录

它接受从图标命名规范中的名称到iconify键的映射(例如"prefix:icon")。图标将根据图标名称放置在适当的freedesktop子目录中。未知图标将放置在other子目录中。

from pyconify import freedesktop_theme
from pyconify.api import svg
icons = {
    "edit-copy": "ic:sharp-content-copy",
    "edit-delete": {"key": "ic:sharp-delete", "color": "red"},
    "weather-overcast": "ic:sharp-cloud",
    "weather-clear": "ic:sharp-wb-sunny",
    "bell": "bi:bell",
}
folder = freedesktop_theme(
    "mytheme",
    icons,
    base_directory="~/Desktop/icons",
)

将创建

~/Desktop/icons/
├── mytheme
│   ├── actions
│   │   ├── edit-copy.svg
│   │   └── edit-delete.svg
│   ├── status
│   │   ├── weather-clear.svg
│   │   └── weather-overcast.svg
│   └── other
│       └── bell.svg
└── index.theme

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

pyconify-0.1.6.tar.gz (22.2 kB 查看哈希)

上传时间

构建分布

pyconify-0.1.6-py3-none-any.whl (18.9 kB 查看哈希)

上传时间 Python 3

支持