improve small logic in node deletion and wallpaper change
This commit is contained in:
parent
b0ea6b2530
commit
a4ef585865
3 changed files with 29 additions and 13 deletions
|
@ -12,6 +12,7 @@ from coretk.dialogs.dialog import Dialog
|
||||||
from coretk.images import Images
|
from coretk.images import Images
|
||||||
|
|
||||||
PADX = 5
|
PADX = 5
|
||||||
|
ABOVE_WALLPAPER = ["edge", "linkinfo", "wireless", "antenna", "nodename", "node"]
|
||||||
|
|
||||||
|
|
||||||
class CanvasBackgroundDialog(Dialog):
|
class CanvasBackgroundDialog(Dialog):
|
||||||
|
@ -182,17 +183,18 @@ class CanvasBackgroundDialog(Dialog):
|
||||||
self.canvas.wallpaper_file = None
|
self.canvas.wallpaper_file = None
|
||||||
self.destroy()
|
self.destroy()
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
img = Image.open(filename)
|
img = Image.open(filename)
|
||||||
self.canvas.wallpaper = img
|
self.canvas.wallpaper = img
|
||||||
self.canvas.wallpaper_file = filename
|
self.canvas.wallpaper_file = filename
|
||||||
self.canvas.redraw()
|
self.canvas.redraw()
|
||||||
|
for component in ABOVE_WALLPAPER:
|
||||||
|
self.canvas.tag_raise(component)
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logging.error("invalid background: %s", filename)
|
logging.error("invalid background: %s", filename)
|
||||||
if self.canvas.wallpaper_id:
|
if self.canvas.wallpaper_id:
|
||||||
self.canvas.delete(self.canvas.wallpaper_id)
|
self.canvas.delete(self.canvas.wallpaper_id)
|
||||||
self.canvas.wallpaper_id = None
|
self.canvas.wallpaper_id = None
|
||||||
self.canvas.wallpaper_file = None
|
self.canvas.wallpaper_file = None
|
||||||
|
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
|
@ -14,6 +14,8 @@ class PreferencesDialog(Dialog):
|
||||||
self.theme = tk.StringVar(value=preferences["theme"])
|
self.theme = tk.StringVar(value=preferences["theme"])
|
||||||
self.terminal = tk.StringVar(value=preferences["terminal"])
|
self.terminal = tk.StringVar(value=preferences["terminal"])
|
||||||
self.gui3d = tk.StringVar(value=preferences["gui3d"])
|
self.gui3d = tk.StringVar(value=preferences["gui3d"])
|
||||||
|
self.width = tk.StringVar(value="1000")
|
||||||
|
self.height = tk.StringVar(value="800")
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
@ -58,6 +60,16 @@ class PreferencesDialog(Dialog):
|
||||||
entry = ttk.Entry(frame, textvariable=self.gui3d)
|
entry = ttk.Entry(frame, textvariable=self.gui3d)
|
||||||
entry.grid(row=3, column=1, sticky="ew")
|
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):
|
def draw_buttons(self):
|
||||||
frame = ttk.Frame(self.top)
|
frame = ttk.Frame(self.top)
|
||||||
frame.grid(sticky="ew")
|
frame.grid(sticky="ew")
|
||||||
|
|
|
@ -75,17 +75,19 @@ class CanvasComponentManagement:
|
||||||
neighbor = self.app.canvas_nodes[neighbor_id]
|
neighbor = self.app.canvas_nodes[neighbor_id]
|
||||||
if neighbor.core_node.type != core_pb2.NodeType.WIRELESS_LAN:
|
if neighbor.core_node.type != core_pb2.NodeType.WIRELESS_LAN:
|
||||||
neighbor.antenna_draw.delete_antenna()
|
neighbor.antenna_draw.delete_antenna()
|
||||||
for link_tuple in node_to_wlink[canvas_node.core_node.id]:
|
|
||||||
nid_one, nid_two = link_tuple
|
if canvas_node.core_node.id in node_to_wlink:
|
||||||
if link_tuple in self.canvas.wireless_draw.map:
|
for link_tuple in node_to_wlink[canvas_node.core_node.id]:
|
||||||
self.canvas.delete(self.canvas.wireless_draw.map[link_tuple])
|
nid_one, nid_two = link_tuple
|
||||||
link_cid = self.canvas.wireless_draw.map.pop(link_tuple, None)
|
if link_tuple in self.canvas.wireless_draw.map:
|
||||||
canvas_node_one = self.app.canvas_nodes[nid_one]
|
self.canvas.delete(self.canvas.wireless_draw.map[link_tuple])
|
||||||
canvas_node_two = self.app.canvas_nodes[nid_two]
|
link_cid = self.canvas.wireless_draw.map.pop(link_tuple, None)
|
||||||
if link_cid in canvas_node_one.wlans:
|
canvas_node_one = self.app.canvas_nodes[nid_one]
|
||||||
canvas_node_one.wlans.remove(link_cid)
|
canvas_node_two = self.app.canvas_nodes[nid_two]
|
||||||
if link_cid in canvas_node_two.wlans:
|
if link_cid in canvas_node_one.wlans:
|
||||||
canvas_node_two.wlans.remove(link_cid)
|
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):
|
for node_id in list(self.selected):
|
||||||
bbox_id = self.selected[node_id]
|
bbox_id = self.selected[node_id]
|
||||||
|
|
Loading…
Add table
Reference in a new issue