2019-10-10 17:02:28 -07:00
|
|
|
from enum import Enum
|
2019-09-18 11:26:26 -07:00
|
|
|
|
2019-09-15 23:45:13 -07:00
|
|
|
from PIL import Image, ImageTk
|
|
|
|
|
2019-12-19 09:30:21 -08:00
|
|
|
from core.gui.appconfig import LOCAL_ICONS_PATH
|
2019-09-18 11:20:22 -07:00
|
|
|
|
2019-09-15 23:45:13 -07:00
|
|
|
|
|
|
|
class Images:
|
|
|
|
images = {}
|
|
|
|
|
2019-11-02 23:47:43 -07:00
|
|
|
@classmethod
|
2019-11-12 17:32:34 -08:00
|
|
|
def create(cls, file_path, width, height=None):
|
|
|
|
if height is None:
|
|
|
|
height = width
|
2019-11-02 23:47:43 -07:00
|
|
|
image = Image.open(file_path)
|
2019-11-12 17:32:34 -08:00
|
|
|
image = image.resize((width, height), Image.ANTIALIAS)
|
2019-11-02 23:47:43 -07:00
|
|
|
return ImageTk.PhotoImage(image)
|
|
|
|
|
2019-11-01 10:45:47 -07:00
|
|
|
@classmethod
|
|
|
|
def load_all(cls):
|
2019-11-01 16:31:40 -07:00
|
|
|
for image in LOCAL_ICONS_PATH.glob("*"):
|
2019-11-12 17:32:34 -08:00
|
|
|
cls.images[image.stem] = str(image)
|
2019-09-15 23:45:13 -07:00
|
|
|
|
|
|
|
@classmethod
|
2019-11-12 17:32:34 -08:00
|
|
|
def get(cls, image_enum, width, height=None):
|
|
|
|
file_path = cls.images[image_enum.value]
|
|
|
|
return cls.create(file_path, width, height)
|
2019-10-01 16:25:26 -07:00
|
|
|
|
2019-11-07 11:33:40 -08:00
|
|
|
@classmethod
|
2019-11-15 10:22:30 -08:00
|
|
|
def get_custom(cls, name, width, height=None):
|
2019-11-12 17:32:34 -08:00
|
|
|
file_path = cls.images[name]
|
|
|
|
return cls.create(file_path, width, height)
|
2019-11-07 11:33:40 -08:00
|
|
|
|
2019-10-01 16:25:26 -07:00
|
|
|
|
2019-10-10 17:02:28 -07:00
|
|
|
class ImageEnum(Enum):
|
|
|
|
SWITCH = "lanswitch"
|
|
|
|
CORE = "core-icon"
|
|
|
|
START = "start"
|
|
|
|
MARKER = "marker"
|
|
|
|
ROUTER = "router"
|
|
|
|
SELECT = "select"
|
|
|
|
LINK = "link"
|
|
|
|
HUB = "hub"
|
|
|
|
WLAN = "wlan"
|
2019-11-01 08:35:14 -07:00
|
|
|
EMANE = "emane"
|
2019-10-10 17:02:28 -07:00
|
|
|
RJ45 = "rj45"
|
|
|
|
TUNNEL = "tunnel"
|
|
|
|
OVAL = "oval"
|
|
|
|
RECTANGLE = "rectangle"
|
|
|
|
TEXT = "text"
|
|
|
|
HOST = "host"
|
|
|
|
PC = "pc"
|
|
|
|
MDR = "mdr"
|
2019-11-21 12:33:43 -08:00
|
|
|
PROUTER = "prouter"
|
2019-10-10 17:02:28 -07:00
|
|
|
OVS = "OVS"
|
2019-11-21 12:33:43 -08:00
|
|
|
EDITNODE = "edit-node"
|
2019-10-10 17:02:28 -07:00
|
|
|
PLOT = "plot"
|
|
|
|
TWONODE = "twonode"
|
2019-11-27 08:48:21 -08:00
|
|
|
PAUSE = "pause"
|
2019-10-10 17:02:28 -07:00
|
|
|
STOP = "stop"
|
|
|
|
OBSERVE = "observe"
|
|
|
|
RUN = "run"
|
2019-10-18 16:42:00 -07:00
|
|
|
DOCUMENTNEW = "document-new"
|
2019-11-11 16:34:41 -08:00
|
|
|
DOCUMENTSAVE = "document-save"
|
2019-10-18 16:42:00 -07:00
|
|
|
FILEOPEN = "fileopen"
|
|
|
|
EDITDELETE = "edit-delete"
|
|
|
|
ANTENNA = "antenna"
|
2019-11-15 13:09:53 -08:00
|
|
|
DOCKER = "docker"
|
|
|
|
LXC = "lxc"
|
2019-12-12 10:49:52 -08:00
|
|
|
ALERT = "alert"
|