From a4ef5858654d858bf761f368ce515e4404a04b63 Mon Sep 17 00:00:00 2001 From: Huy Pham <42948410+hpham@users.noreply.github.com> Date: Wed, 27 Nov 2019 08:49:58 -0800 Subject: [PATCH] improve small logic in node deletion and wallpaper change --- coretk/coretk/dialogs/canvasbackground.py | 6 ++++-- coretk/coretk/dialogs/preferences.py | 12 ++++++++++++ coretk/coretk/nodedelete.py | 24 ++++++++++++----------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/coretk/coretk/dialogs/canvasbackground.py b/coretk/coretk/dialogs/canvasbackground.py index 8fb92c8b..84b0bdb6 100644 --- a/coretk/coretk/dialogs/canvasbackground.py +++ b/coretk/coretk/dialogs/canvasbackground.py @@ -12,6 +12,7 @@ from coretk.dialogs.dialog import Dialog from coretk.images import Images PADX = 5 +ABOVE_WALLPAPER = ["edge", "linkinfo", "wireless", "antenna", "nodename", "node"] class CanvasBackgroundDialog(Dialog): @@ -182,17 +183,18 @@ class CanvasBackgroundDialog(Dialog): self.canvas.wallpaper_file = None self.destroy() return - try: img = Image.open(filename) self.canvas.wallpaper = img self.canvas.wallpaper_file = filename self.canvas.redraw() + for component in ABOVE_WALLPAPER: + self.canvas.tag_raise(component) + except FileNotFoundError: logging.error("invalid background: %s", filename) if self.canvas.wallpaper_id: self.canvas.delete(self.canvas.wallpaper_id) self.canvas.wallpaper_id = None self.canvas.wallpaper_file = None - self.destroy() diff --git a/coretk/coretk/dialogs/preferences.py b/coretk/coretk/dialogs/preferences.py index 7298f727..d65b87c3 100644 --- a/coretk/coretk/dialogs/preferences.py +++ b/coretk/coretk/dialogs/preferences.py @@ -14,6 +14,8 @@ class PreferencesDialog(Dialog): self.theme = tk.StringVar(value=preferences["theme"]) self.terminal = tk.StringVar(value=preferences["terminal"]) self.gui3d = tk.StringVar(value=preferences["gui3d"]) + self.width = tk.StringVar(value="1000") + self.height = tk.StringVar(value="800") self.draw() def draw(self): @@ -58,6 +60,16 @@ class PreferencesDialog(Dialog): entry = ttk.Entry(frame, textvariable=self.gui3d) entry.grid(row=3, column=1, sticky="ew") + label = ttk.Label(frame, text="Canvas width (in pixel)") + label.grid(row=4, column=0, pady=2, padx=2, sticky="w") + entry = ttk.Entry(frame, textvariable=self.width) + entry.grid(row=4, column=1, sticky="ew") + + label = ttk.Label(frame, text="Canvas height (in pixel)") + label.grid(row=5, column=0, pady=2, padx=2, sticky="w") + entry = ttk.Entry(frame, textvariable=self.height) + entry.grid(row=5, column=1, sticky="ew") + def draw_buttons(self): frame = ttk.Frame(self.top) frame.grid(sticky="ew") diff --git a/coretk/coretk/nodedelete.py b/coretk/coretk/nodedelete.py index 92844aac..58e90170 100644 --- a/coretk/coretk/nodedelete.py +++ b/coretk/coretk/nodedelete.py @@ -75,17 +75,19 @@ class CanvasComponentManagement: neighbor = self.app.canvas_nodes[neighbor_id] if neighbor.core_node.type != core_pb2.NodeType.WIRELESS_LAN: neighbor.antenna_draw.delete_antenna() - for link_tuple in node_to_wlink[canvas_node.core_node.id]: - nid_one, nid_two = link_tuple - if link_tuple in self.canvas.wireless_draw.map: - self.canvas.delete(self.canvas.wireless_draw.map[link_tuple]) - link_cid = self.canvas.wireless_draw.map.pop(link_tuple, None) - canvas_node_one = self.app.canvas_nodes[nid_one] - canvas_node_two = self.app.canvas_nodes[nid_two] - if link_cid in canvas_node_one.wlans: - canvas_node_one.wlans.remove(link_cid) - if link_cid in canvas_node_two.wlans: - canvas_node_two.wlans.remove(link_cid) + + if canvas_node.core_node.id in node_to_wlink: + for link_tuple in node_to_wlink[canvas_node.core_node.id]: + nid_one, nid_two = link_tuple + if link_tuple in self.canvas.wireless_draw.map: + self.canvas.delete(self.canvas.wireless_draw.map[link_tuple]) + link_cid = self.canvas.wireless_draw.map.pop(link_tuple, None) + canvas_node_one = self.app.canvas_nodes[nid_one] + canvas_node_two = self.app.canvas_nodes[nid_two] + if link_cid in canvas_node_one.wlans: + canvas_node_one.wlans.remove(link_cid) + if link_cid in canvas_node_two.wlans: + canvas_node_two.wlans.remove(link_cid) for node_id in list(self.selected): bbox_id = self.selected[node_id]