IconFont
⋔ Inheritance diagram
graph TD
1473245629488["iconprovider.IconFont"]
140713234304496["builtins.object"]
140713234304496 --> 1473245629488
🛈 DocStrings
Class describing an Icon font.
Source code in prettyqt\iconprovider\__init__.py
| @dataclass
class IconFont:
"""Class describing an Icon font."""
prefix: str
font_path: str
charmap_path: str
md5: str
stylename: str | None = None
path: pathlib.Path = paths.ICON_FONT_PATH
def __post_init__(self):
hash_val = None if SYSTEM_FONTS else self.md5
id_ = gui.FontDatabase.add_font(self.path / self.font_path, ttf_hash=hash_val)
loaded_font_families = gui.FontDatabase.applicationFontFamilies(id_)
self.font_id = id_
self.font_name = loaded_font_families[0]
with (self.path / self.charmap_path).open("r") as codes:
self.charmap = json.load(codes, object_hook=hook)
def __dir__(self):
icons = [i.replace("-", "_") for i in self.charmap]
return list(super().__dir__()) + icons
def __getattr__(self, name: str):
return f"{self.prefix}.{name.replace('_', '-')}"
def is_valid(self) -> bool:
return len(gui.FontDatabase.applicationFontFamilies(self.font_id)) > 0
def get_font(self, size: float) -> gui.Font:
font = gui.Font(self.font_name)
font.setPixelSize(round(size))
if self.stylename: # solid style
font.setStyleName(self.stylename)
return font
|