pygui: fixed edge context, fixed node context, updated find to leverage multi canvas changes and select canvas of found node
This commit is contained in:
parent
62d111b74c
commit
a7d7b94215
6 changed files with 40 additions and 34 deletions
|
@ -105,9 +105,13 @@ class FindDialog(Dialog):
|
|||
self.tree.selection_set(results[0])
|
||||
|
||||
def close_dialog(self) -> None:
|
||||
self.app.canvas.delete("find")
|
||||
self.clear_find()
|
||||
self.destroy()
|
||||
|
||||
def clear_find(self):
|
||||
for canvas in self.app.manager.all():
|
||||
canvas.delete("find")
|
||||
|
||||
def click_select(self, _event: tk.Event = None) -> None:
|
||||
"""
|
||||
find the node that matches search criteria, circle around that node
|
||||
|
@ -116,13 +120,13 @@ class FindDialog(Dialog):
|
|||
"""
|
||||
item = self.tree.selection()
|
||||
if item:
|
||||
self.app.canvas.delete("find")
|
||||
self.clear_find()
|
||||
node_id = int(self.tree.item(item, "text"))
|
||||
canvas_node = self.app.core.get_canvas_node(node_id)
|
||||
|
||||
x0, y0, x1, y1 = self.app.canvas.bbox(canvas_node.id)
|
||||
self.app.manager.select(canvas_node.canvas.id)
|
||||
x0, y0, x1, y1 = canvas_node.canvas.bbox(canvas_node.id)
|
||||
dist = 5 * self.app.guiconfig.scale
|
||||
self.app.canvas.create_oval(
|
||||
canvas_node.canvas.create_oval(
|
||||
x0 - dist,
|
||||
y0 - dist,
|
||||
x1 + dist,
|
||||
|
@ -132,9 +136,9 @@ class FindDialog(Dialog):
|
|||
width=3.0 * self.app.guiconfig.scale,
|
||||
)
|
||||
|
||||
_x, _y, _, _ = self.app.canvas.bbox(canvas_node.id)
|
||||
oid = self.app.canvas.find_withtag("rectangle")
|
||||
x0, y0, x1, y1 = self.app.canvas.bbox(oid[0])
|
||||
_x, _y, _, _ = canvas_node.canvas.bbox(canvas_node.id)
|
||||
oid = canvas_node.canvas.find_withtag("rectangle")
|
||||
x0, y0, x1, y1 = canvas_node.canvas.bbox(oid[0])
|
||||
logging.debug("Dist to most left: %s", abs(x0 - _x))
|
||||
logging.debug("White canvas width: %s", abs(x0 - x1))
|
||||
|
||||
|
@ -150,5 +154,5 @@ class FindDialog(Dialog):
|
|||
xscroll_fraction = xscroll_fraction - 0.05
|
||||
if yscroll_fraction > 0.05:
|
||||
yscroll_fraction = yscroll_fraction - 0.05
|
||||
self.app.canvas.xview_moveto(xscroll_fraction)
|
||||
self.app.canvas.yview_moveto(yscroll_fraction)
|
||||
canvas_node.canvas.xview_moveto(xscroll_fraction)
|
||||
canvas_node.canvas.yview_moveto(yscroll_fraction)
|
||||
|
|
|
@ -70,10 +70,10 @@ class LinkConfigurationDialog(Dialog):
|
|||
|
||||
def draw(self) -> None:
|
||||
self.top.columnconfigure(0, weight=1)
|
||||
src_label = self.app.canvas.nodes[self.edge.src].core_node.name
|
||||
src_label = self.edge.src.core_node.name
|
||||
if self.edge.link.iface1:
|
||||
src_label += f":{self.edge.link.iface1.name}"
|
||||
dst_label = self.app.canvas.nodes[self.edge.dst].core_node.name
|
||||
dst_label = self.edge.dst.core_node.name
|
||||
if self.edge.link.iface2:
|
||||
dst_label += f":{self.edge.link.iface2.name}"
|
||||
label = ttk.Label(
|
||||
|
@ -316,10 +316,8 @@ class LinkConfigurationDialog(Dialog):
|
|||
"""
|
||||
populate link config to the table
|
||||
"""
|
||||
width = self.app.canvas.itemcget(self.edge.id, "width")
|
||||
self.width.set(width)
|
||||
color = self.app.canvas.itemcget(self.edge.id, "fill")
|
||||
self.color.set(color)
|
||||
self.width.set(self.edge.width)
|
||||
self.color.set(self.edge.color)
|
||||
link = self.edge.link
|
||||
if link.options:
|
||||
self.bandwidth.set(str(link.options.bandwidth))
|
||||
|
|
|
@ -79,15 +79,13 @@ class WirelessEdgeInfoFrame(InfoFrameBase):
|
|||
|
||||
def draw(self) -> None:
|
||||
link = self.edge.link
|
||||
src_canvas_node = self.app.canvas.nodes[self.edge.src]
|
||||
src_node = src_canvas_node.core_node
|
||||
dst_canvas_node = self.app.canvas.nodes[self.edge.dst]
|
||||
dst_node = dst_canvas_node.core_node
|
||||
src_node = self.edge.src.core_node
|
||||
dst_node = self.edge.dst.core_node
|
||||
|
||||
# find interface for each node connected to network
|
||||
net_id = link.network_id
|
||||
iface1 = get_iface(src_canvas_node, net_id)
|
||||
iface2 = get_iface(dst_canvas_node, net_id)
|
||||
iface1 = get_iface(self.edge.src, net_id)
|
||||
iface2 = get_iface(self.edge.dst, net_id)
|
||||
|
||||
frame = DetailsFrame(self)
|
||||
frame.grid(sticky=tk.EW)
|
||||
|
|
|
@ -510,11 +510,11 @@ class CanvasEdge(Edge):
|
|||
return self.width != EDGE_WIDTH or self.color != EDGE_COLOR
|
||||
|
||||
def set_binding(self) -> None:
|
||||
show_context = functools.partial(self.show_info, self.src.canvas)
|
||||
show_context = functools.partial(self.show_context, self.src.canvas)
|
||||
self.src.canvas.tag_bind(self.id, "<ButtonRelease-3>", show_context)
|
||||
self.src.canvas.tag_bind(self.id, "<Button-1>", self.show_info)
|
||||
if self.dst and not self.is_same_canvas():
|
||||
show_context = functools.partial(self.show_info, self.dst.canvas)
|
||||
show_context = functools.partial(self.show_context, self.dst.canvas)
|
||||
self.dst.canvas.tag_bind(self.id2, "<ButtonRelease-3>", show_context)
|
||||
self.dst.canvas.tag_bind(self.id2, "<Button-1>", self.show_info)
|
||||
|
||||
|
|
|
@ -82,7 +82,8 @@ class CanvasManager:
|
|||
|
||||
# widget
|
||||
self.notebook: Optional[ttk.Notebook] = None
|
||||
self.unique_ids: Dict[str, int] = {}
|
||||
self.canvas_ids: Dict[str, int] = {}
|
||||
self.unique_ids: Dict[int, str] = {}
|
||||
self.draw()
|
||||
|
||||
self.setup_bindings()
|
||||
|
@ -95,18 +96,22 @@ class CanvasManager:
|
|||
def tab_change(self, _event: tk.Event) -> None:
|
||||
# ignore tab change events before tab data has been setup
|
||||
unique_id = self.notebook.select()
|
||||
if not unique_id or unique_id not in self.unique_ids:
|
||||
if not unique_id or unique_id not in self.canvas_ids:
|
||||
return
|
||||
canvas = self.current()
|
||||
self.app.statusbar.set_zoom(canvas.ratio)
|
||||
|
||||
def select(self, tab_id: int):
|
||||
unique_id = self.unique_ids.get(tab_id)
|
||||
self.notebook.select(unique_id)
|
||||
|
||||
def draw(self) -> None:
|
||||
self.notebook = ttk.Notebook(self.master)
|
||||
self.notebook.grid(sticky=tk.NSEW, pady=1)
|
||||
|
||||
def _next_id(self) -> int:
|
||||
_id = 1
|
||||
canvas_ids = set(self.unique_ids.values())
|
||||
canvas_ids = set(self.canvas_ids.values())
|
||||
while _id in canvas_ids:
|
||||
_id += 1
|
||||
return _id
|
||||
|
@ -114,7 +119,7 @@ class CanvasManager:
|
|||
def current(self) -> CanvasGraph:
|
||||
unique_id = self.notebook.select()
|
||||
logging.info("current selected id: %s", unique_id)
|
||||
canvas_id = self.unique_ids[unique_id]
|
||||
canvas_id = self.canvas_ids[unique_id]
|
||||
return self.get(canvas_id)
|
||||
|
||||
def all(self) -> ValuesView[CanvasGraph]:
|
||||
|
@ -137,7 +142,8 @@ class CanvasManager:
|
|||
self.notebook.add(tab, text=f"Canvas {canvas_id}")
|
||||
unique_id = self.notebook.tabs()[-1]
|
||||
logging.info("creating canvas(%s) unique(%s)", canvas_id, unique_id)
|
||||
self.unique_ids[unique_id] = canvas_id
|
||||
self.canvas_ids[unique_id] = canvas_id
|
||||
self.unique_ids[canvas_id] = unique_id
|
||||
|
||||
# create canvas
|
||||
canvas = CanvasGraph(
|
||||
|
@ -161,7 +167,7 @@ class CanvasManager:
|
|||
return
|
||||
unique_id = self.notebook.select()
|
||||
self.notebook.forget(unique_id)
|
||||
canvas_id = self.unique_ids.pop(unique_id)
|
||||
canvas_id = self.canvas_ids.pop(unique_id)
|
||||
self.canvases.pop(canvas_id)
|
||||
# TODO: handle clearing out canvas related nodes and links from core client
|
||||
|
||||
|
@ -170,6 +176,7 @@ class CanvasManager:
|
|||
for canvas_id in self.notebook.tabs():
|
||||
self.notebook.forget(canvas_id)
|
||||
self.canvases.clear()
|
||||
self.canvas_ids.clear()
|
||||
self.unique_ids.clear()
|
||||
logging.info("cleared canvases")
|
||||
|
||||
|
|
|
@ -349,15 +349,14 @@ class CanvasNode:
|
|||
def has_emane_link(self, iface_id: int) -> Node:
|
||||
result = None
|
||||
for edge in self.edges:
|
||||
if self.id == edge.src:
|
||||
other_id = edge.dst
|
||||
if self.id == edge.src.id:
|
||||
other_node = edge.dst
|
||||
edge_iface_id = edge.link.iface1.id
|
||||
else:
|
||||
other_id = edge.src
|
||||
other_node = edge.src
|
||||
edge_iface_id = edge.link.iface2.id
|
||||
if edge_iface_id != iface_id:
|
||||
continue
|
||||
other_node = self.canvas.nodes[other_id]
|
||||
if other_node.core_node.type == NodeType.EMANE:
|
||||
result = other_node.core_node
|
||||
break
|
||||
|
|
Loading…
Reference in a new issue