omnipython-iconkit 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iconkit/__init__.py +112 -0
- iconkit/__init__.pyi +20 -0
- iconkit/_a8_24.py +404 -0
- iconkit/_a8_48.py +116 -0
- iconkit/gfx.py +89 -0
- iconkit/gfx.pyi +17 -0
- iconkit/icons_24.txt +149 -0
- iconkit/icons_48.txt +36 -0
- iconkit/lvicons.py +72 -0
- iconkit/lvicons.pyi +12 -0
- iconkit/py.typed +0 -0
- omnipython_iconkit-0.1.0.dist-info/METADATA +165 -0
- omnipython_iconkit-0.1.0.dist-info/RECORD +17 -0
- omnipython_iconkit-0.1.0.dist-info/WHEEL +5 -0
- omnipython_iconkit-0.1.0.dist-info/licenses/LICENSE +21 -0
- omnipython_iconkit-0.1.0.dist-info/licenses/LICENSE-ICONS +202 -0
- omnipython_iconkit-0.1.0.dist-info/top_level.txt +1 -0
iconkit/__init__.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Material Design icons as 8-bit alpha masks that stay in flash.
|
|
5
|
+
|
|
6
|
+
``mask("home")`` gives the antialiased shape of an icon as a slice of one big
|
|
7
|
+
constant in a frozen module, so an icon costs no RAM. Draw the mask with
|
|
8
|
+
`iconkit.lvicons` in LVGL or `iconkit.gfx` in pygraphics. This module imports
|
|
9
|
+
neither.
|
|
10
|
+
|
|
11
|
+
Two sets ship: 129 icons at 24 px and 33 app-tile icons at 48 px. An app with
|
|
12
|
+
icons of its own builds a module with ``tools/make_icons.py`` and registers it
|
|
13
|
+
with `add`.
|
|
14
|
+
|
|
15
|
+
Example::
|
|
16
|
+
|
|
17
|
+
import iconkit
|
|
18
|
+
view, w, h = iconkit.mask("wifi") # w * h alpha bytes, row by row
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
# Sizes that have a module of their own, ``iconkit._a8_<size>``.
|
|
22
|
+
_BUILTIN = (24, 48)
|
|
23
|
+
|
|
24
|
+
# size -> [module, ...]; the shipped module comes first.
|
|
25
|
+
_mods = {}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _modules(size):
|
|
29
|
+
mods = _mods.get(size)
|
|
30
|
+
if mods is None:
|
|
31
|
+
if size not in _BUILTIN:
|
|
32
|
+
raise ValueError(
|
|
33
|
+
"iconkit has no icons at %r px: the shipped sizes are %s. Build a module of your own "
|
|
34
|
+
"with tools/make_icons.py and register it with iconkit.add()." % (size, _BUILTIN)
|
|
35
|
+
)
|
|
36
|
+
mods = _mods[size] = [__import__("iconkit._a8_%d" % size, None, None, ("DATA",))]
|
|
37
|
+
return mods
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def mask(name, size=24):
|
|
41
|
+
"""The alpha mask of icon *name*.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
name (str): A Material icon name such as ``"home"``.
|
|
45
|
+
size (int): 24 or 48, or the size of a module added with `add`.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
``(data, w, h)``: a memoryview of ``w * h`` alpha bytes, row by row, and the size.
|
|
49
|
+
|
|
50
|
+
Raises:
|
|
51
|
+
ValueError: *name* isn't in any module of that size, or no module has that size.
|
|
52
|
+
"""
|
|
53
|
+
for m in _modules(size):
|
|
54
|
+
ns = m.NAMES
|
|
55
|
+
if name in ns:
|
|
56
|
+
n = size * size
|
|
57
|
+
i = ns.index(name) * n
|
|
58
|
+
return m.DATA[i : i + n], size, size
|
|
59
|
+
raise ValueError(
|
|
60
|
+
"no icon named %r at %d px; iconkit.names(%d) lists the %d there. Build it into a module "
|
|
61
|
+
"with tools/make_icons.py and register it with iconkit.add()." % (name, size, size, len(_all(size)))
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _all(size):
|
|
66
|
+
out = ()
|
|
67
|
+
for m in _modules(size):
|
|
68
|
+
out += tuple(m.NAMES)
|
|
69
|
+
return out
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def names(size=24):
|
|
73
|
+
"""Every icon name at *size*, in the order of its module(s).
|
|
74
|
+
|
|
75
|
+
Raises:
|
|
76
|
+
ValueError: no module has that size.
|
|
77
|
+
"""
|
|
78
|
+
return _all(size)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def add(module):
|
|
82
|
+
"""Register an icon module built by ``tools/make_icons.py`` for *module*'s size.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
module: A module with ``SIZE``, ``NAMES`` and ``DATA``.
|
|
86
|
+
|
|
87
|
+
Raises:
|
|
88
|
+
ValueError: A name is already taken at that size, or ``DATA`` isn't
|
|
89
|
+
``len(NAMES) * SIZE * SIZE`` bytes.
|
|
90
|
+
"""
|
|
91
|
+
size = module.SIZE
|
|
92
|
+
if len(module.DATA) != len(module.NAMES) * size * size:
|
|
93
|
+
raise ValueError(
|
|
94
|
+
"icon module has %d bytes of DATA for %d names at %d px; it should have %d. "
|
|
95
|
+
"Rebuild it with tools/make_icons.py." % (len(module.DATA), len(module.NAMES), size, len(module.NAMES) * size * size)
|
|
96
|
+
)
|
|
97
|
+
if size in _BUILTIN:
|
|
98
|
+
mods = _modules(size)
|
|
99
|
+
else:
|
|
100
|
+
mods = _mods.setdefault(size, [])
|
|
101
|
+
if module in mods:
|
|
102
|
+
raise ValueError("icon module %r is already added" % (module,))
|
|
103
|
+
taken = set()
|
|
104
|
+
for m in mods:
|
|
105
|
+
taken.update(m.NAMES)
|
|
106
|
+
clash = [n for n in module.NAMES if n in taken]
|
|
107
|
+
if clash:
|
|
108
|
+
raise ValueError(
|
|
109
|
+
"icon names already taken at %d px: %s. Rename them in your module's list and rebuild it."
|
|
110
|
+
% (size, ", ".join(clash))
|
|
111
|
+
)
|
|
112
|
+
mods.append(module)
|
iconkit/__init__.pyi
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Material Design icons as 8-bit alpha masks that stay in flash."""
|
|
5
|
+
|
|
6
|
+
from typing import Protocol
|
|
7
|
+
|
|
8
|
+
class _IconModule(Protocol):
|
|
9
|
+
SIZE: int
|
|
10
|
+
NAMES: tuple[str, ...] | list[str]
|
|
11
|
+
DATA: bytes | memoryview
|
|
12
|
+
|
|
13
|
+
def mask(name: str, size: int = 24) -> tuple[memoryview, int, int]:
|
|
14
|
+
"""The alpha mask of icon `name`: `(data, w, h)`, `w * h` alpha bytes row by row."""
|
|
15
|
+
|
|
16
|
+
def names(size: int = 24) -> tuple[str, ...]:
|
|
17
|
+
"""Every icon name at `size`, in the order of its module(s)."""
|
|
18
|
+
|
|
19
|
+
def add(module: _IconModule) -> None:
|
|
20
|
+
"""Register an icon module built by `tools/make_icons.py` for the module's size."""
|