reload custom node image when open xml, if the gui doesn't know about the custom image, use a default one

This commit is contained in:
Huy Pham 2020-01-27 16:27:21 -08:00
parent b4b71eda0e
commit 4c0254ec10
3 changed files with 57 additions and 11 deletions

View file

@ -1,4 +1,5 @@
from enum import Enum
from tkinter import messagebox
from PIL import Image, ImageTk
@ -22,15 +23,32 @@ class Images:
cls.images[image.stem] = str(image)
@classmethod
def get(cls, image_enum: Enum, width: int, height: int = None):
def get(
cls, image_enum: Enum, width: int, height: int = None
) -> ImageTk.PhotoImage:
file_path = cls.images[image_enum.value]
return cls.create(file_path, width, height)
@classmethod
def get_custom(cls, name: str, width: int, height: int = None):
file_path = cls.images[name]
def get_with_image_file(
cls, stem: str, width: int, height: int = None
) -> ImageTk.PhotoImage:
file_path = cls.images[stem]
return cls.create(file_path, width, height)
@classmethod
def get_custom(
cls, name: str, width: int, height: int = None
) -> ImageTk.PhotoImage:
try:
file_path = cls.images[name]
return cls.create(file_path, width, height)
except KeyError:
messagebox.showwarning(
"Missing image file",
f"{name}.png is missing at daemon/core/gui/data/icons, drop image file at daemon/core/gui/data/icons and restart the gui",
)
class ImageEnum(Enum):
SWITCH = "lanswitch"