From 33f627beb9bfdb8b2b7bceb578b899a8bc1804ff Mon Sep 17 00:00:00 2001 From: bettleChen <2207153529@qq.com> Date: Mon, 17 Jul 2023 09:56:44 +0800 Subject: [PATCH] update --- NetworkAnalog/SimObjs.py | 50 ++++++++++++++++++++++++++------------- NetworkAnalog/network.db | Bin 40960 -> 40960 bytes NetworkAnalog/tkTest.py | 19 ++++----------- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/NetworkAnalog/SimObjs.py b/NetworkAnalog/SimObjs.py index be8ff8f..24904bb 100644 --- a/NetworkAnalog/SimObjs.py +++ b/NetworkAnalog/SimObjs.py @@ -2,6 +2,7 @@ import math import sys import threading from time import sleep +from tkinter import Tk from ttkbootstrap import * from uuid import uuid4 @@ -12,6 +13,27 @@ from PIL import ImageTk, Image 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(): # todo: 组件父类 """ @@ -93,6 +115,18 @@ class SimBase(): 创建图片 :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") id = self.canvas.create_image(self.ObjX - 30, self.ObjY - 30, 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.interface = [{}] 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() def create_packet(self, ip, mac, message): @@ -516,10 +546,6 @@ class SimRouter(SimBase): super().__init__(canvas, x, y, self.ObjID, config, label) self.ObjType = 2 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.set_default_router_table() @@ -625,10 +651,6 @@ class SimSwitch(SimBase): super().__init__(canvas, x, y, self.ObjID, config, label) self.ObjType = 3 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.set_default_mac_table() @@ -720,10 +742,6 @@ class SimHub(SimBase): super().__init__(canvas, x, y, self.ObjID, config, label) self.ObjType = 4 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): """ diff --git a/NetworkAnalog/network.db b/NetworkAnalog/network.db index 98817aef9ba55504424ae7c31b589cce64da6ec6..9e93d8641e004372f5d59a013e4d414a0c85f9e0 100644 GIT binary patch delta 83 zcmV-Z0IdIjzyg540+1U4Kam_m0Y9-|ByI!)?*W68h;B0jHvxi^zHVm&i~%8H3A1!0T%)S36pV~B?nVTRYEZVSChzZGy|^y)3g6?0WkI-7~TK? diff --git a/NetworkAnalog/tkTest.py b/NetworkAnalog/tkTest.py index 8cd1853..f9e6f84 100644 --- a/NetworkAnalog/tkTest.py +++ b/NetworkAnalog/tkTest.py @@ -1,19 +1,8 @@ -from tkinter import * -import platform +import sys +from PIL import Image -def get_platform(): - 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("其他系统") +path = sys.path[0] + "/../datas/images/packet.png" +Image.open(path).resize((60, 60)).save(path) -if __name__ == "__main__": - get_platform()