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:
Blake Harnden 2021-01-02 00:10:23 -08:00
parent 62d111b74c
commit a7d7b94215
6 changed files with 40 additions and 34 deletions

View file

@ -105,9 +105,13 @@ class FindDialog(Dialog):
self.tree.selection_set(results[0]) self.tree.selection_set(results[0])
def close_dialog(self) -> None: def close_dialog(self) -> None:
self.app.canvas.delete("find") self.clear_find()
self.destroy() 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: def click_select(self, _event: tk.Event = None) -> None:
""" """
find the node that matches search criteria, circle around that node find the node that matches search criteria, circle around that node
@ -116,13 +120,13 @@ class FindDialog(Dialog):
""" """
item = self.tree.selection() item = self.tree.selection()
if item: if item:
self.app.canvas.delete("find") self.clear_find()
node_id = int(self.tree.item(item, "text")) node_id = int(self.tree.item(item, "text"))
canvas_node = self.app.core.get_canvas_node(node_id) canvas_node = self.app.core.get_canvas_node(node_id)
self.app.manager.select(canvas_node.canvas.id)
x0, y0, x1, y1 = self.app.canvas.bbox(canvas_node.id) x0, y0, x1, y1 = canvas_node.canvas.bbox(canvas_node.id)
dist = 5 * self.app.guiconfig.scale dist = 5 * self.app.guiconfig.scale
self.app.canvas.create_oval( canvas_node.canvas.create_oval(
x0 - dist, x0 - dist,
y0 - dist, y0 - dist,
x1 + dist, x1 + dist,
@ -132,9 +136,9 @@ class FindDialog(Dialog):
width=3.0 * self.app.guiconfig.scale, width=3.0 * self.app.guiconfig.scale,
) )
_x, _y, _, _ = self.app.canvas.bbox(canvas_node.id) _x, _y, _, _ = canvas_node.canvas.bbox(canvas_node.id)
oid = self.app.canvas.find_withtag("rectangle") oid = canvas_node.canvas.find_withtag("rectangle")
x0, y0, x1, y1 = self.app.canvas.bbox(oid[0]) x0, y0, x1, y1 = canvas_node.canvas.bbox(oid[0])
logging.debug("Dist to most left: %s", abs(x0 - _x)) logging.debug("Dist to most left: %s", abs(x0 - _x))
logging.debug("White canvas width: %s", abs(x0 - x1)) logging.debug("White canvas width: %s", abs(x0 - x1))
@ -150,5 +154,5 @@ class FindDialog(Dialog):
xscroll_fraction = xscroll_fraction - 0.05 xscroll_fraction = xscroll_fraction - 0.05
if yscroll_fraction > 0.05: if yscroll_fraction > 0.05:
yscroll_fraction = yscroll_fraction - 0.05 yscroll_fraction = yscroll_fraction - 0.05
self.app.canvas.xview_moveto(xscroll_fraction) canvas_node.canvas.xview_moveto(xscroll_fraction)
self.app.canvas.yview_moveto(yscroll_fraction) canvas_node.canvas.yview_moveto(yscroll_fraction)

View file

@ -70,10 +70,10 @@ class LinkConfigurationDialog(Dialog):
def draw(self) -> None: def draw(self) -> None:
self.top.columnconfigure(0, weight=1) 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: if self.edge.link.iface1:
src_label += f":{self.edge.link.iface1.name}" 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: if self.edge.link.iface2:
dst_label += f":{self.edge.link.iface2.name}" dst_label += f":{self.edge.link.iface2.name}"
label = ttk.Label( label = ttk.Label(
@ -316,10 +316,8 @@ class LinkConfigurationDialog(Dialog):
""" """
populate link config to the table populate link config to the table
""" """
width = self.app.canvas.itemcget(self.edge.id, "width") self.width.set(self.edge.width)
self.width.set(width) self.color.set(self.edge.color)
color = self.app.canvas.itemcget(self.edge.id, "fill")
self.color.set(color)
link = self.edge.link link = self.edge.link
if link.options: if link.options:
self.bandwidth.set(str(link.options.bandwidth)) self.bandwidth.set(str(link.options.bandwidth))

View file

@ -79,15 +79,13 @@ class WirelessEdgeInfoFrame(InfoFrameBase):
def draw(self) -> None: def draw(self) -> None:
link = self.edge.link link = self.edge.link
src_canvas_node = self.app.canvas.nodes[self.edge.src] src_node = self.edge.src.core_node
src_node = src_canvas_node.core_node dst_node = self.edge.dst.core_node
dst_canvas_node = self.app.canvas.nodes[self.edge.dst]
dst_node = dst_canvas_node.core_node
# find interface for each node connected to network # find interface for each node connected to network
net_id = link.network_id net_id = link.network_id
iface1 = get_iface(src_canvas_node, net_id) iface1 = get_iface(self.edge.src, net_id)
iface2 = get_iface(dst_canvas_node, net_id) iface2 = get_iface(self.edge.dst, net_id)
frame = DetailsFrame(self) frame = DetailsFrame(self)
frame.grid(sticky=tk.EW) frame.grid(sticky=tk.EW)

View file

@ -510,11 +510,11 @@ class CanvasEdge(Edge):
return self.width != EDGE_WIDTH or self.color != EDGE_COLOR return self.width != EDGE_WIDTH or self.color != EDGE_COLOR
def set_binding(self) -> None: 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, "<ButtonRelease-3>", show_context)
self.src.canvas.tag_bind(self.id, "<Button-1>", self.show_info) self.src.canvas.tag_bind(self.id, "<Button-1>", self.show_info)
if self.dst and not self.is_same_canvas(): 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, "<ButtonRelease-3>", show_context)
self.dst.canvas.tag_bind(self.id2, "<Button-1>", self.show_info) self.dst.canvas.tag_bind(self.id2, "<Button-1>", self.show_info)

View file

@ -82,7 +82,8 @@ class CanvasManager:
# widget # widget
self.notebook: Optional[ttk.Notebook] = None 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.draw()
self.setup_bindings() self.setup_bindings()
@ -95,18 +96,22 @@ class CanvasManager:
def tab_change(self, _event: tk.Event) -> None: def tab_change(self, _event: tk.Event) -> None:
# ignore tab change events before tab data has been setup # ignore tab change events before tab data has been setup
unique_id = self.notebook.select() 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 return
canvas = self.current() canvas = self.current()
self.app.statusbar.set_zoom(canvas.ratio) 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: def draw(self) -> None:
self.notebook = ttk.Notebook(self.master) self.notebook = ttk.Notebook(self.master)
self.notebook.grid(sticky=tk.NSEW, pady=1) self.notebook.grid(sticky=tk.NSEW, pady=1)
def _next_id(self) -> int: def _next_id(self) -> int:
_id = 1 _id = 1
canvas_ids = set(self.unique_ids.values()) canvas_ids = set(self.canvas_ids.values())
while _id in canvas_ids: while _id in canvas_ids:
_id += 1 _id += 1
return _id return _id
@ -114,7 +119,7 @@ class CanvasManager:
def current(self) -> CanvasGraph: def current(self) -> CanvasGraph:
unique_id = self.notebook.select() unique_id = self.notebook.select()
logging.info("current selected id: %s", unique_id) 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) return self.get(canvas_id)
def all(self) -> ValuesView[CanvasGraph]: def all(self) -> ValuesView[CanvasGraph]:
@ -137,7 +142,8 @@ class CanvasManager:
self.notebook.add(tab, text=f"Canvas {canvas_id}") self.notebook.add(tab, text=f"Canvas {canvas_id}")
unique_id = self.notebook.tabs()[-1] unique_id = self.notebook.tabs()[-1]
logging.info("creating canvas(%s) unique(%s)", canvas_id, unique_id) 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 # create canvas
canvas = CanvasGraph( canvas = CanvasGraph(
@ -161,7 +167,7 @@ class CanvasManager:
return return
unique_id = self.notebook.select() unique_id = self.notebook.select()
self.notebook.forget(unique_id) 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) self.canvases.pop(canvas_id)
# TODO: handle clearing out canvas related nodes and links from core client # 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(): for canvas_id in self.notebook.tabs():
self.notebook.forget(canvas_id) self.notebook.forget(canvas_id)
self.canvases.clear() self.canvases.clear()
self.canvas_ids.clear()
self.unique_ids.clear() self.unique_ids.clear()
logging.info("cleared canvases") logging.info("cleared canvases")

View file

@ -349,15 +349,14 @@ class CanvasNode:
def has_emane_link(self, iface_id: int) -> Node: def has_emane_link(self, iface_id: int) -> Node:
result = None result = None
for edge in self.edges: for edge in self.edges:
if self.id == edge.src: if self.id == edge.src.id:
other_id = edge.dst other_node = edge.dst
edge_iface_id = edge.link.iface1.id edge_iface_id = edge.link.iface1.id
else: else:
other_id = edge.src other_node = edge.src
edge_iface_id = edge.link.iface2.id edge_iface_id = edge.link.iface2.id
if edge_iface_id != iface_id: if edge_iface_id != iface_id:
continue continue
other_node = self.canvas.nodes[other_id]
if other_node.core_node.type == NodeType.EMANE: if other_node.core_node.type == NodeType.EMANE:
result = other_node.core_node result = other_node.core_node
break break