From cf3b9050d0266a251d36feed1109a5e82d3b30c1 Mon Sep 17 00:00:00 2001 From: bettleChen <2207153529@qq.com> Date: Thu, 11 Jan 2024 09:06:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/dataSources.xml | 16 ++-------- NetworkAnalog/NetworkAnalog.py | 52 ++++++++++++++++++-------------- NetworkAnalog/SimObjs.py | 17 ++++++++--- NetworkAnalog/network.db | Bin 40960 -> 40960 bytes NetworkAnalog/test.py | 21 +++++++++++++ NetworkAnalog/tkTest.py | 34 --------------------- NetworkAnalog/x1_test.py | 53 ++++++++++++++++++++++++--------- NetworkAnalog/x2_test.py | 33 -------------------- 8 files changed, 105 insertions(+), 121 deletions(-) create mode 100644 NetworkAnalog/test.py delete mode 100644 NetworkAnalog/tkTest.py delete mode 100644 NetworkAnalog/x2_test.py diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index ba6eba2..427aed5 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -1,24 +1,12 @@ - + sqlite.xerial true org.sqlite.JDBC - jdbc:sqlite:$PROJECT_DIR$/../网络仿真/NetworkAnalog/network.db + jdbc:sqlite:$PROJECT_DIR$/NetworkAnalog/network.db $ProjectFileDir$ - - sqlite.xerial - true - org.sqlite.JDBC - jdbc:sqlite:D:\头哥\NetworkAnalog\datas\network.db - $ProjectFileDir$ - - - file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.40.1/org/xerial/sqlite-jdbc/3.40.1.0/sqlite-jdbc-3.40.1.0.jar - - - \ No newline at end of file diff --git a/NetworkAnalog/NetworkAnalog.py b/NetworkAnalog/NetworkAnalog.py index 3ab7bcc..c28b3a4 100644 --- a/NetworkAnalog/NetworkAnalog.py +++ b/NetworkAnalog/NetworkAnalog.py @@ -205,7 +205,7 @@ class NetWorkAnalog(Canvas): for tag_id, tag in self.AllSimObjs.items(): self.tag_bind(tag.ObjID, "", lambda event, tag=tag: show_menu(event, tag)) # 绑定右击事件 - def bind_event(self, component, name): + def add_sim_obj(self, component, name): # todo: 绑定事件 """ 绑定事件 @@ -305,9 +305,9 @@ class NetWorkAnalog(Canvas): conn_obj.ConfigCorrect = key[1] self.tag_bind_event() - def show_obj(self, AllSimObj, conns): + def show_obj(self, AllSimObj, AllSimConn): self.AllSimObjs = AllSimObj - self.conns = conns + self.conns = AllSimConn for key, sim_obj in self.AllSimObjs.items(): sim_obj.create_img() for conn in self.conns: @@ -517,7 +517,7 @@ class NetWorkAnalog(Canvas): addr_en.grid(row=1, column=3, padx=10) def commit(): self.chose_obj.config(datas) - self.message.show_message(f"组件 {self.chose_obj} 网络配置成功!") + self.message.show_message(f"组件 {self.chose_obj.ObjLabel} 网络配置成功!") child_r.destroy() tk.Button(ifs_frame_YN, text='确定', font=('黑体', 16), height=1, command=commit).grid(row=0, column=0, @@ -855,42 +855,50 @@ class NetWorkAnalog(Canvas): sticky='e', pady=10) def create_config_button(self): + font_size = 16 + font_style = ("Arial", font_size) + style = ttk.Style() + style.configure("TMenubutton", font=font_style) # 创建一个菜单栏,这里我们可以把他理解成一个容器,在窗口的上方 - menubar = tk.Menu(root) + menubar = tk.Menu(root, font=font_style) # 定义一个空菜单单元 - setMenu = tk.Menu(menubar, tearoff=0) - menubar.add_cascade(label='删除与修改', menu=setMenu) + setMenu = tk.Menu(menubar, tearoff=0, font=font_style) + menubar.add_cascade(label='删除与修改', menu=setMenu, font=font_style) setMenu.add_command(label='删除对象', command=self.delete_obj) setMenu.add_command(label='删除连接线', command=self.delete_line) setMenu.add_command(label='修改标签', command=self.update_tag_name) # # 定义一个空菜单单元 - setMenu = tk.Menu(menubar, tearoff=0) - menubar.add_cascade(label='基础配置', menu=setMenu) + setMenu = tk.Menu(menubar, tearoff=0, font=font_style) + menubar.add_cascade(label='基础配置', menu=setMenu, font=font_style) setMenu.add_command(label='网络配置', command=self.network_config) setMenu.add_command(label='路由表配置', command=self.router_table_config) setMenu.add_command(label='交换表配置', command=self.mac_table_config) root.config(menu=menubar) # 定义一个空菜单单元 - setMenu = tk.Menu(menubar, tearoff=0) - menubar.add_cascade(label='显示设置', menu=setMenu) + setMenu = tk.Menu(menubar, tearoff=0, font=font_style) + menubar.add_cascade(label='显示设置', menu=setMenu, font=font_style) setMenu.add_command(label='显示/不显示标签', command=self.show_label) setMenu.add_command(label='显示/不显示接口', command=self.show_interface) setMenu.add_command(label='显示网络配置信息', command=self.show_network_config) setMenu.add_command(label='显示路由/交换表信息', command=self.show_router_config) # 定义一个空菜单单元 - setMenu = tk.Menu(menubar, tearoff=0) - menubar.add_cascade(label='发送数据包', menu=setMenu) + setMenu = tk.Menu(menubar, tearoff=0, font=font_style) + menubar.add_cascade(label='发送数据包', menu=setMenu, font=font_style) setMenu.add_command(label='发送数据包', command=self.send_packet) setMenu.add_command(label='批量发送数据包', command=self.send_packet_list) - menubar.add_command(label='清除屏幕', command=self.clear_canvas) - menubar.add_command(label='导出数据', command=self.export_data) - menubar.add_command(label='导入数据', command=self.import_data) - menubar.add_command(label='校验', command=self.check_network) + menubar.add_command(label='清除屏幕', command=self.clear_canvas, font=font_style) + menubar.add_command(label='导出数据', command=self.export_data, font=font_style) + menubar.add_command(label='导入数据', command=self.import_data, font=font_style) + menubar.add_command(label='校验', command=self.check_network, font=font_style) + # 设置字体大小 + for menu in menubar.winfo_children(): + menu.config(font=font_style) + for item in menu.winfo_children(): + item.config(font=font_style) root.config(menu=menubar) def create_widget(self): - # todo: 创建页面 """ 创建整体页面布局 :return: @@ -911,10 +919,10 @@ class NetWorkAnalog(Canvas): hub = self.create_image(img_height, split_width * 3, image=self.hub_img, anchor="nw") self.create_text(text_height, split_width * 4 + 40, text="主机", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字 host = self.create_image(img_height, split_width * 4, image=self.host_img, anchor="nw") - self.bind_event(router, "路由器") - self.bind_event(switch, "交换机") - self.bind_event(hub, "集线器") - self.bind_event(host, "主机") + self.add_sim_obj(router, "路由器") + self.add_sim_obj(switch, "交换机") + self.add_sim_obj(hub, "集线器") + self.add_sim_obj(host, "主机") if __name__ == '__main__': diff --git a/NetworkAnalog/SimObjs.py b/NetworkAnalog/SimObjs.py index 4eedab3..bf08d68 100644 --- a/NetworkAnalog/SimObjs.py +++ b/NetworkAnalog/SimObjs.py @@ -303,9 +303,17 @@ class AllSimConnect(): nodex_update_sql = f""" update conn_config set ip='{node.interface[ifs - 1]["ip"]}', - mac='{node.interface[ifs - 1]["mac"]}', - conn_port='{node.interface[ifs - 1]["conn_port"]}', - addr='{node.interface[ifs - 1]["addr"]}' + mac='{node.interface[ifs - 1]["mac"]}' + """ + if not node.interface[ifs - 1]["conn_port"] == "NULL": + nodex_update_sql += f""" + ,conn_port='{int(node.interface[ifs - 1]["conn_port"])}' + """ + if not node.interface[ifs - 1]["addr"] == "NULL": + nodex_update_sql += f""" + ,addr='{node.interface[ifs - 1]["addr"]}' + """ + nodex_update_sql += f""" where node_id='{node.ObjID}' and node_ifs={ifs} """ execute_sql(nodex_update_sql) @@ -319,7 +327,8 @@ class AllSimConnect(): """ execute_sql(update_sql) except Exception as E: - pass + print(E) + self.canvas.message.show_message(f"{E}") def check_config(self): """ diff --git a/NetworkAnalog/network.db b/NetworkAnalog/network.db index 6f4a422d66c83320aff5be1c309d35a366b945f8..e7747640dbfb9879ea02cda3308df2ce258f1589 100644 GIT binary patch literal 40960 zcmeHQdyHJwd7nG)J9B5Q*N#~Xws#g|?8V&Wp2vMbc&umFUYoVoti2FSVfQ{^0o!0Z zJklV7Lm!D0H4QCQQ6Ds-swygxR;@_>Xj3&!TPcx96E&idBBl9*BvsQCsg0@%RsGI= z&0XxpXNERK=*)UNbLO7!JKy&^-+A80@A#byYv;pWbmr_S_k53(HkBl)bbGH?D#<@z zDwSIBmf>B7_tWsM!aI9O*_Vw!LB}-hb=r@W8uGqUx1s!9`>ED%v~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