improve small logic in node deletion and wallpaper change

This commit is contained in:
Huy Pham 2019-11-27 08:49:58 -08:00
parent b0ea6b2530
commit a4ef585865
3 changed files with 29 additions and 13 deletions

View file

@ -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()

View file

@ -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")

View file

@ -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]