master
bettleChen 1 year ago
parent 3eb07c0b57
commit 33f627beb9

@ -2,6 +2,7 @@ import math
import sys import sys
import threading import threading
from time import sleep from time import sleep
from tkinter import Tk
from ttkbootstrap import * from ttkbootstrap import *
from uuid import uuid4 from uuid import uuid4
@ -12,6 +13,27 @@ from PIL import ImageTk, Image
from dbUtil import search, execute_sql from dbUtil import search, execute_sql
host_img = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/主机.png").resize((60, 60)))
host_img_tm = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/主机_tm.png").resize((60, 60)))
router_img = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/路由器.png").resize((60, 60)))
router_img_tm = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/路由器_tm.png").resize((60, 60)))
switch_img = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/交换机.png").resize((60, 60)))
switch_img_tm = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/交换机_tm.png").resize((60, 60)))
hub_img = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/集线器.png").resize((60, 60)))
hub_img_tm = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/集线器_tm.png").resize((60, 60)))
class SimBase(): class SimBase():
# todo: 组件父类 # todo: 组件父类
""" """
@ -93,6 +115,18 @@ class SimBase():
创建图片 创建图片
:return: :return:
""" """
if self.ObjType == 1:
self.img = host_img
self.img_tm = host_img_tm
elif self.ObjType == 2:
self.img = router_img
self.img_tm = router_img_tm
elif self.ObjType == 3:
self.img = switch_img
self.img_tm = switch_img_tm
else:
self.img = hub_img
self.img_tm = hub_img_tm
self.canvas.delete("L") self.canvas.delete("L")
id = self.canvas.create_image(self.ObjX - 30, self.ObjY - 30, id = self.canvas.create_image(self.ObjX - 30, self.ObjY - 30,
image=self.img if self.ConfigCorrect == 1 else self.img_tm, anchor="nw", image=self.img if self.ConfigCorrect == 1 else self.img_tm, anchor="nw",
@ -453,10 +487,6 @@ class SimHost(SimBase):
self.ObjLabel = label if label is not None else self.set_default_name() self.ObjLabel = label if label is not None else self.set_default_name()
self.interface = [{}] self.interface = [{}]
self.connections = [None] self.connections = [None]
self.img = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/主机.png").resize((60, 60)))
self.img_tm = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/主机_tm.png").resize((60, 60)))
self.set_default_config() self.set_default_config()
def create_packet(self, ip, mac, message): def create_packet(self, ip, mac, message):
@ -516,10 +546,6 @@ class SimRouter(SimBase):
super().__init__(canvas, x, y, self.ObjID, config, label) super().__init__(canvas, x, y, self.ObjID, config, label)
self.ObjType = 2 self.ObjType = 2
self.ObjLabel = label if label is not None else self.set_default_name() self.ObjLabel = label if label is not None else self.set_default_name()
self.img = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/路由器.png").resize((60, 60)))
self.img_tm = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/路由器_tm.png").resize((60, 60)))
self.router_table = {} self.router_table = {}
self.set_default_router_table() self.set_default_router_table()
@ -625,10 +651,6 @@ class SimSwitch(SimBase):
super().__init__(canvas, x, y, self.ObjID, config, label) super().__init__(canvas, x, y, self.ObjID, config, label)
self.ObjType = 3 self.ObjType = 3
self.ObjLabel = label if label is not None else self.set_default_name() self.ObjLabel = label if label is not None else self.set_default_name()
self.img = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/交换机.png").resize((60, 60)))
self.img_tm = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/交换机_tm.png").resize((60, 60)))
self.mac_table = {} self.mac_table = {}
self.set_default_mac_table() self.set_default_mac_table()
@ -720,10 +742,6 @@ class SimHub(SimBase):
super().__init__(canvas, x, y, self.ObjID, config, label) super().__init__(canvas, x, y, self.ObjID, config, label)
self.ObjType = 4 self.ObjType = 4
self.ObjLabel = label if label is not None else self.set_default_name() self.ObjLabel = label if label is not None else self.set_default_name()
self.img = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/集线器.png").resize((60, 60)))
self.img_tm = ImageTk.PhotoImage(
Image.open(sys.path[0] + "/../datas/images/集线器_tm.png").resize((60, 60)))
def transmit(self, packet: SimPacket): def transmit(self, packet: SimPacket):
""" """

Binary file not shown.

@ -1,19 +1,8 @@
from tkinter import * import sys
import platform
from PIL import Image
def get_platform(): path = sys.path[0] + "/../datas/images/packet.png"
import platform
sys_platform = platform.platform().lower()
if "windows" in sys_platform:
print("Windows")
elif "macos" in sys_platform:
print("Mac os")
elif "linux" in sys_platform:
print("Linux")
else:
print("其他系统")
Image.open(path).resize((60, 60)).save(path)
if __name__ == "__main__":
get_platform()

Loading…
Cancel
Save