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
|
@ -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…
Add table
Add a link
Reference in a new issue