pygui: cleaned up how edges get drawn to reuse logic, fixed clearing canvas manager edges between changing sessions, fixed deleting edge check for link interfaces
This commit is contained in:
parent
77e2b08d76
commit
a2d9659fb7
3 changed files with 33 additions and 49 deletions
|
@ -199,7 +199,10 @@ class SessionsDialog(Dialog):
|
|||
logging.debug("delete session: %s", self.selected_session)
|
||||
self.tree.delete(self.selected_id)
|
||||
self.app.core.delete_session(self.selected_session)
|
||||
if self.selected_session == self.app.core.session.id:
|
||||
session_id = None
|
||||
if self.app.core.session:
|
||||
session_id = self.app.core.session.id
|
||||
if self.selected_session == session_id:
|
||||
self.click_new()
|
||||
self.destroy()
|
||||
self.click_select()
|
||||
|
|
|
@ -209,48 +209,36 @@ class Edge:
|
|||
return self.src.canvas == self.dst.canvas
|
||||
|
||||
def draw(self, state: str) -> None:
|
||||
src_pos = self.src.position()
|
||||
if self.is_same_canvas():
|
||||
dst_pos = src_pos
|
||||
if self.dst:
|
||||
dst_pos = self.dst.position()
|
||||
arc_pos = self._get_arcpoint(src_pos, dst_pos)
|
||||
self.id = self.src.canvas.create_line(
|
||||
*src_pos,
|
||||
*arc_pos,
|
||||
*dst_pos,
|
||||
smooth=True,
|
||||
tags=self.tag,
|
||||
width=self.scaled_width(),
|
||||
fill=self.color,
|
||||
state=state,
|
||||
)
|
||||
self.id = self.draw_edge(self.src.canvas, self.src, self.src, state)
|
||||
else:
|
||||
# draw shadow nodes and 2 lines
|
||||
dst_pos = self.dst.position()
|
||||
arc_pos = self._get_arcpoint(src_pos, dst_pos)
|
||||
self.src_shadow = ShadowNode(self.app, self.dst.canvas, self.src)
|
||||
self.dst_shadow = ShadowNode(self.app, self.src.canvas, self.dst)
|
||||
self.id = self.src.canvas.create_line(
|
||||
*src_pos,
|
||||
*arc_pos,
|
||||
*dst_pos,
|
||||
smooth=True,
|
||||
tags=self.tag,
|
||||
width=self.scaled_width(),
|
||||
fill=self.color,
|
||||
state=state,
|
||||
)
|
||||
self.id2 = self.dst.canvas.create_line(
|
||||
*src_pos,
|
||||
*arc_pos,
|
||||
*dst_pos,
|
||||
smooth=True,
|
||||
tags=self.tag,
|
||||
width=self.scaled_width(),
|
||||
fill=self.color,
|
||||
state=state,
|
||||
)
|
||||
self.id = self.draw_edge(self.src.canvas, self.src, self.dst, state)
|
||||
self.id2 = self.draw_edge(self.dst.canvas, self.src, self.dst, state)
|
||||
logging.info(
|
||||
"drawed edge: src shadow(%s) dst shadow(%s)",
|
||||
self.src_shadow,
|
||||
self.dst_shadow,
|
||||
)
|
||||
|
||||
def draw_edge(
|
||||
self, canvas: "CanvasGraph", src: "CanvasNode", dst: "CanvasNode", state: str
|
||||
) -> int:
|
||||
src_pos = src.position()
|
||||
dst_pos = dst.position()
|
||||
arc_pos = self._get_arcpoint(src_pos, dst_pos)
|
||||
return canvas.create_line(
|
||||
*src_pos,
|
||||
*arc_pos,
|
||||
*dst_pos,
|
||||
smooth=True,
|
||||
tags=self.tag,
|
||||
width=self.scaled_width(),
|
||||
fill=self.color,
|
||||
state=state,
|
||||
)
|
||||
|
||||
def redraw(self) -> None:
|
||||
self.src.canvas.itemconfig(self.id, width=self.scaled_width(), fill=self.color)
|
||||
|
@ -688,10 +676,10 @@ class CanvasEdge(Edge):
|
|||
def delete(self) -> None:
|
||||
super().delete()
|
||||
self.src.edges.discard(self)
|
||||
if self.link.iface1:
|
||||
del self.src.ifaces[self.link.iface1.id]
|
||||
if self.dst:
|
||||
self.dst.edges.discard(self)
|
||||
if self.link.iface1:
|
||||
del self.src.ifaces[self.link.iface1.id]
|
||||
if self.link.iface2:
|
||||
del self.dst.ifaces[self.link.iface2.id]
|
||||
src_wireless = NodeUtils.is_wireless_node(self.src.core_node.type)
|
||||
|
|
|
@ -118,7 +118,6 @@ class CanvasManager:
|
|||
|
||||
def current(self) -> CanvasGraph:
|
||||
unique_id = self.notebook.select()
|
||||
logging.info("current selected id: %s", unique_id)
|
||||
canvas_id = self.canvas_ids[unique_id]
|
||||
return self.get(canvas_id)
|
||||
|
||||
|
@ -178,6 +177,8 @@ class CanvasManager:
|
|||
self.canvases.clear()
|
||||
self.canvas_ids.clear()
|
||||
self.unique_ids.clear()
|
||||
self.edges.clear()
|
||||
self.wireless_edges.clear()
|
||||
logging.info("cleared canvases")
|
||||
|
||||
# reset settings
|
||||
|
@ -206,20 +207,12 @@ class CanvasManager:
|
|||
|
||||
# draw existing links
|
||||
for link in session.links:
|
||||
logging.debug("drawing link: %s", link)
|
||||
node1 = self.core.get_canvas_node(link.node1_id)
|
||||
node2 = self.core.get_canvas_node(link.node2_id)
|
||||
if link.type == LinkType.WIRELESS:
|
||||
self.add_wireless_edge(node1, node2, link)
|
||||
else:
|
||||
self.add_wired_edge(node1, node2, link)
|
||||
# if node1.canvas == node2.canvas:
|
||||
# if link.type == LinkType.WIRELESS:
|
||||
# self.add_wireless_edge(node1, node2, link)
|
||||
# else:
|
||||
# self.add_wired_edge(node1, node2, link)
|
||||
# else:
|
||||
# logging.error("cant handle nodes linked between canvases")
|
||||
|
||||
# parse metadata and organize canvases
|
||||
self.core.parse_metadata()
|
||||
|
|
Loading…
Reference in a new issue