pygui: update to allow custom nodes to use icons from any directory

This commit is contained in:
Blake Harnden 2021-02-19 09:31:58 -08:00
parent 93813358b5
commit 2387812a76
8 changed files with 36 additions and 40 deletions

View file

@ -17,7 +17,11 @@ IMAGES: Dict[str, str] = {}
def load_all() -> None:
for image in LOCAL_ICONS_PATH.glob("*"):
IMAGES[image.stem] = str(image)
try:
ImageEnum(image.stem)
IMAGES[image.stem] = str(image)
except ValueError:
pass
def from_file(
@ -39,13 +43,6 @@ def from_enum(
return from_file(file_path, width=width, height=height, scale=scale)
def from_name(
name: str, *, width: int, height: int = None, scale: float = 1.0
) -> PhotoImage:
file_path = IMAGES[name]
return from_file(file_path, width=width, height=height, scale=scale)
class ImageEnum(Enum):
SWITCH = "lanswitch"
CORE = "core-icon"