pygui: updates to handle visibility toggles in relation to having nodes hidden, fix final position of a drawn edge when dragging to draw
This commit is contained in:
parent
4a21cd5789
commit
7871a678ca
5 changed files with 78 additions and 35 deletions
|
@ -293,7 +293,7 @@ class LinkConfigurationDialog(Dialog):
|
|||
|
||||
# update edge label
|
||||
self.edge.redraw()
|
||||
self.edge.check_options()
|
||||
self.edge.check_visibility()
|
||||
self.destroy()
|
||||
|
||||
def change_symmetry(self) -> None:
|
||||
|
|
|
@ -438,14 +438,18 @@ class Edge:
|
|||
if self.dst_shadow:
|
||||
self.dst_shadow.show()
|
||||
self.src.canvas.itemconfigure(self.id, state=tk.NORMAL)
|
||||
self.src.canvas.itemconfigure(self.src_label, state=tk.NORMAL)
|
||||
self.src.canvas.itemconfigure(self.dst_label, state=tk.NORMAL)
|
||||
self.src.canvas.itemconfigure(self.middle_label, state=tk.NORMAL)
|
||||
state = self.manager.show_link_labels.state()
|
||||
self.set_labels(state)
|
||||
|
||||
def set_labels(self, state: str) -> None:
|
||||
self.src.canvas.itemconfigure(self.src_label, state=state)
|
||||
self.src.canvas.itemconfigure(self.dst_label, state=state)
|
||||
self.src.canvas.itemconfigure(self.middle_label, state=state)
|
||||
if self.id2:
|
||||
self.dst.canvas.itemconfigure(self.id2, state=tk.NORMAL)
|
||||
self.dst.canvas.itemconfigure(self.src_label2, state=tk.NORMAL)
|
||||
self.dst.canvas.itemconfigure(self.dst_label2, state=tk.NORMAL)
|
||||
self.dst.canvas.itemconfigure(self.middle_label2, state=tk.NORMAL)
|
||||
self.dst.canvas.itemconfigure(self.id2, state=state)
|
||||
self.dst.canvas.itemconfigure(self.src_label2, state=state)
|
||||
self.dst.canvas.itemconfigure(self.dst_label2, state=state)
|
||||
self.dst.canvas.itemconfigure(self.middle_label2, state=state)
|
||||
|
||||
def other_node(self, node: "CanvasNode") -> "CanvasNode":
|
||||
if self.src == node:
|
||||
|
@ -576,26 +580,24 @@ class CanvasEdge(Edge):
|
|||
super().redraw()
|
||||
self.draw_labels()
|
||||
|
||||
def check_options(self) -> None:
|
||||
if not self.link.options:
|
||||
return
|
||||
if self.link.options.loss == EDGE_LOSS:
|
||||
def show(self) -> None:
|
||||
super().show()
|
||||
self.check_visibility()
|
||||
|
||||
def check_visibility(self) -> None:
|
||||
state = tk.NORMAL
|
||||
hide_links = self.manager.show_links.state() == tk.HIDDEN
|
||||
if self.linked_wireless or hide_links:
|
||||
state = tk.HIDDEN
|
||||
if self.id:
|
||||
self.src.canvas.addtag_withtag(tags.LOSS_EDGES, self.id)
|
||||
if self.id2:
|
||||
self.dst.canvas.addtag_withtag(tags.LOSS_EDGES, self.id2)
|
||||
else:
|
||||
state = tk.NORMAL
|
||||
if self.id:
|
||||
self.src.canvas.dtag(self.id, tags.LOSS_EDGES)
|
||||
if self.id2:
|
||||
self.dst.canvas.dtag(self.id2, tags.LOSS_EDGES)
|
||||
if self.manager.show_loss_links.state() == tk.HIDDEN:
|
||||
if self.id:
|
||||
self.src.canvas.itemconfigure(self.id, state=state)
|
||||
if self.id2:
|
||||
self.dst.canvas.itemconfigure(self.id2, state=state)
|
||||
elif self.link.options:
|
||||
hide_loss = self.manager.show_loss_links.state() == tk.HIDDEN
|
||||
should_hide = self.link.options.loss >= EDGE_LOSS
|
||||
if hide_loss and should_hide:
|
||||
state = tk.HIDDEN
|
||||
if self.id:
|
||||
self.src.canvas.itemconfigure(self.id, state=state)
|
||||
if self.id2:
|
||||
self.dst.canvas.itemconfigure(self.id2, state=state)
|
||||
|
||||
def set_throughput(self, throughput: float) -> None:
|
||||
throughput = 0.001 * throughput
|
||||
|
@ -641,7 +643,7 @@ class CanvasEdge(Edge):
|
|||
if not self.linked_wireless:
|
||||
self.arc_common_edges()
|
||||
self.draw_labels()
|
||||
self.check_options()
|
||||
self.check_visibility()
|
||||
self.app.core.save_edge(self)
|
||||
self.src.canvas.organize()
|
||||
if self.has_shadows():
|
||||
|
|
|
@ -240,6 +240,7 @@ class CanvasGraph(tk.Canvas):
|
|||
edge.delete()
|
||||
return
|
||||
# finalize edge creation
|
||||
edge.drawing(dst_node.position())
|
||||
edge.complete(dst_node)
|
||||
|
||||
def select_object(self, object_id: int, choose_multiple: bool = False) -> None:
|
||||
|
|
|
@ -38,6 +38,30 @@ class ShowVar(BooleanVar):
|
|||
canvas.itemconfigure(self.tag, state=self.state())
|
||||
|
||||
|
||||
class ShowNodeLabels(ShowVar):
|
||||
def click_handler(self) -> None:
|
||||
state = self.state()
|
||||
for canvas in self.manager.all():
|
||||
for node in canvas.nodes.values():
|
||||
if not node.hidden:
|
||||
node.set_label(state)
|
||||
|
||||
|
||||
class ShowLinks(ShowVar):
|
||||
def click_handler(self) -> None:
|
||||
for edge in self.manager.edges.values():
|
||||
if not edge.hidden:
|
||||
edge.check_visibility()
|
||||
|
||||
|
||||
class ShowLinkLabels(ShowVar):
|
||||
def click_handler(self) -> None:
|
||||
state = self.state()
|
||||
for edge in self.manager.edges.values():
|
||||
if not edge.hidden:
|
||||
edge.set_labels(state)
|
||||
|
||||
|
||||
class CanvasManager:
|
||||
def __init__(
|
||||
self, master: tk.BaseWidget, app: "Application", core: "CoreClient"
|
||||
|
@ -62,13 +86,17 @@ class CanvasManager:
|
|||
self.app.guiconfig.preferences.height,
|
||||
)
|
||||
self.current_dimensions: Tuple[int, int] = self.default_dimensions
|
||||
self.show_node_labels: ShowVar = ShowVar(self, tags.NODE_LABEL, value=True)
|
||||
self.show_link_labels: ShowVar = ShowVar(self, tags.LINK_LABEL, value=True)
|
||||
self.show_links: ShowVar = ShowVar(self, tags.EDGE, value=True)
|
||||
self.show_node_labels: ShowVar = ShowNodeLabels(
|
||||
self, tags.NODE_LABEL, value=True
|
||||
)
|
||||
self.show_link_labels: ShowVar = ShowLinkLabels(
|
||||
self, tags.LINK_LABEL, value=True
|
||||
)
|
||||
self.show_links: ShowVar = ShowLinks(self, tags.EDGE, value=True)
|
||||
self.show_wireless: ShowVar = ShowVar(self, tags.WIRELESS_EDGE, value=True)
|
||||
self.show_grid: ShowVar = ShowVar(self, tags.GRIDLINE, value=True)
|
||||
self.show_annotations: ShowVar = ShowVar(self, tags.ANNOTATION, value=True)
|
||||
self.show_loss_links: ShowVar = ShowVar(self, tags.LOSS_EDGES, value=True)
|
||||
self.show_loss_links: ShowVar = ShowLinks(self, tags.LOSS_EDGES, value=True)
|
||||
self.show_iface_names: BooleanVar = BooleanVar(value=False)
|
||||
self.show_ip4s: BooleanVar = BooleanVar(value=True)
|
||||
self.show_ip6s: BooleanVar = BooleanVar(value=True)
|
||||
|
@ -308,7 +336,7 @@ class CanvasManager:
|
|||
if edge:
|
||||
edge.link.options = deepcopy(link.options)
|
||||
edge.draw_link_options()
|
||||
edge.check_options()
|
||||
edge.check_visibility()
|
||||
|
||||
def delete_wired_edge(self, link: Link) -> None:
|
||||
token = create_edge_token(link)
|
||||
|
|
|
@ -305,7 +305,7 @@ class CanvasNode:
|
|||
edit_menu.add_command(label="Cut", command=self.click_cut)
|
||||
edit_menu.add_command(label="Copy", command=self.canvas_copy)
|
||||
edit_menu.add_command(label="Delete", command=self.canvas_delete)
|
||||
edit_menu.add_command(label="Hide", command=self.hide)
|
||||
edit_menu.add_command(label="Hide", command=self.click_hide)
|
||||
self.context.add_cascade(label="Edit", menu=edit_menu)
|
||||
self.context.tk_popup(event.x_root, event.y_root)
|
||||
|
||||
|
@ -313,6 +313,10 @@ class CanvasNode:
|
|||
self.canvas_copy()
|
||||
self.canvas_delete()
|
||||
|
||||
def click_hide(self) -> None:
|
||||
self.canvas.clear_selection()
|
||||
self.hide()
|
||||
|
||||
def click_unlink(self, edge: CanvasEdge) -> None:
|
||||
edge.delete()
|
||||
self.app.default_info()
|
||||
|
@ -426,6 +430,8 @@ class CanvasNode:
|
|||
self.hidden = True
|
||||
self.canvas.itemconfig(self.id, state=tk.HIDDEN)
|
||||
self.canvas.itemconfig(self.text_id, state=tk.HIDDEN)
|
||||
for antenna in self.antennas:
|
||||
self.canvas.itemconfig(antenna, state=tk.HIDDEN)
|
||||
for edge in self.edges:
|
||||
if not edge.hidden:
|
||||
edge.hide()
|
||||
|
@ -433,12 +439,18 @@ class CanvasNode:
|
|||
def show(self) -> None:
|
||||
self.hidden = False
|
||||
self.canvas.itemconfig(self.id, state=tk.NORMAL)
|
||||
self.canvas.itemconfig(self.text_id, state=tk.NORMAL)
|
||||
state = self.app.manager.show_node_labels.state()
|
||||
self.set_label(state)
|
||||
for antenna in self.antennas:
|
||||
self.canvas.itemconfig(antenna, state=tk.NORMAL)
|
||||
for edge in self.edges:
|
||||
other_node = edge.other_node(self)
|
||||
if edge.hidden and not other_node.hidden:
|
||||
edge.show()
|
||||
|
||||
def set_label(self, state: str) -> None:
|
||||
self.canvas.itemconfig(self.text_id, state=state)
|
||||
|
||||
def _service_action(self, service: str, action: ServiceAction) -> None:
|
||||
session_id = self.app.core.session.id
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue