pygui: further updates to support hiding nodes and related edges, added hidden nodes to metadata sent to daemon and parsed when joining a session
This commit is contained in:
parent
313768ea56
commit
6f3246e329
5 changed files with 74 additions and 17 deletions
|
@ -330,7 +330,7 @@ class CoreClient:
|
|||
canvas_config = json.loads(canvas_config)
|
||||
self.app.manager.parse_metadata(canvas_config)
|
||||
|
||||
# load saved shapes
|
||||
# load saved shapes
|
||||
shapes_config = config.get("shapes")
|
||||
if shapes_config:
|
||||
shapes_config = json.loads(shapes_config)
|
||||
|
@ -349,6 +349,17 @@ class CoreClient:
|
|||
edge.color = edge_config["color"]
|
||||
edge.redraw()
|
||||
|
||||
# read hidden nodes
|
||||
hidden = config.get("hidden")
|
||||
if hidden:
|
||||
hidden = json.loads(hidden)
|
||||
for _id in hidden:
|
||||
canvas_node = self.canvas_nodes.get(_id)
|
||||
if canvas_node:
|
||||
canvas_node.hide()
|
||||
else:
|
||||
logging.warning("invalid node to hide: %s", _id)
|
||||
|
||||
def create_new_session(self) -> None:
|
||||
"""
|
||||
Create a new session
|
||||
|
@ -533,8 +544,14 @@ class CoreClient:
|
|||
edges_config.append(edge_config)
|
||||
edges_config = json.dumps(edges_config)
|
||||
|
||||
# create hidden metadata
|
||||
hidden = [x.core_node.id for x in self.canvas_nodes.values() if x.hidden]
|
||||
hidden = json.dumps(hidden)
|
||||
|
||||
# save metadata
|
||||
metadata = dict(canvas=canvas_config, shapes=shapes, edges=edges_config)
|
||||
metadata = dict(
|
||||
canvas=canvas_config, shapes=shapes, edges=edges_config, hidden=hidden
|
||||
)
|
||||
response = self.client.set_session_metadata(self.session.id, metadata)
|
||||
logging.debug("set session metadata %s, result: %s", metadata, response)
|
||||
|
||||
|
|
|
@ -150,6 +150,14 @@ class ShadowNode:
|
|||
self.canvas.delete(self.id)
|
||||
self.canvas.delete(self.text_id)
|
||||
|
||||
def hide(self) -> None:
|
||||
self.canvas.itemconfig(self.id, state=tk.HIDDEN)
|
||||
self.canvas.itemconfig(self.text_id, state=tk.HIDDEN)
|
||||
|
||||
def show(self) -> None:
|
||||
self.canvas.itemconfig(self.id, state=tk.NORMAL)
|
||||
self.canvas.itemconfig(self.text_id, state=tk.NORMAL)
|
||||
|
||||
|
||||
class Edge:
|
||||
tag: str = tags.EDGE
|
||||
|
@ -176,6 +184,7 @@ class Edge:
|
|||
self.color: str = EDGE_COLOR
|
||||
self.width: int = EDGE_WIDTH
|
||||
self.linked_wireless: bool = False
|
||||
self.hidden: bool = False
|
||||
if self.dst:
|
||||
self.linked_wireless = self.src.is_wireless() or self.dst.is_wireless()
|
||||
|
||||
|
@ -479,6 +488,38 @@ class Edge:
|
|||
self.dst_label2 = None
|
||||
self.manager.edges.pop(self.token, None)
|
||||
|
||||
def hide(self) -> None:
|
||||
self.hidden = True
|
||||
if self.src_shadow:
|
||||
self.src_shadow.hide()
|
||||
if self.dst_shadow:
|
||||
self.dst_shadow.hide()
|
||||
self.src.canvas.itemconfigure(self.id, state=tk.HIDDEN)
|
||||
self.src.canvas.itemconfigure(self.src_label, state=tk.HIDDEN)
|
||||
self.src.canvas.itemconfigure(self.dst_label, state=tk.HIDDEN)
|
||||
self.src.canvas.itemconfigure(self.middle_label, state=tk.HIDDEN)
|
||||
if self.id2:
|
||||
self.dst.canvas.itemconfigure(self.id2, state=tk.HIDDEN)
|
||||
self.dst.canvas.itemconfigure(self.src_label2, state=tk.HIDDEN)
|
||||
self.dst.canvas.itemconfigure(self.dst_label2, state=tk.HIDDEN)
|
||||
self.dst.canvas.itemconfigure(self.middle_label2, state=tk.HIDDEN)
|
||||
|
||||
def show(self) -> None:
|
||||
self.hidden = False
|
||||
if self.src_shadow:
|
||||
self.src_shadow.show()
|
||||
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)
|
||||
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)
|
||||
|
||||
|
||||
class CanvasWirelessEdge(Edge):
|
||||
tag = tags.WIRELESS_EDGE
|
||||
|
|
|
@ -307,30 +307,19 @@ class CanvasGraph(tk.Canvas):
|
|||
self.core.deleted_canvas_nodes(nodes)
|
||||
|
||||
def hide_selected_objects(self) -> None:
|
||||
edges = set()
|
||||
for object_id in self.selection:
|
||||
# delete selection box
|
||||
selection_id = self.selection[object_id]
|
||||
self.delete(selection_id)
|
||||
|
||||
# hide node and related edges
|
||||
if object_id in self.nodes:
|
||||
canvas_node = self.nodes[object_id]
|
||||
canvas_node.hide()
|
||||
# hide related edges
|
||||
for edge in canvas_node.edges:
|
||||
if edge in edges:
|
||||
continue
|
||||
edges.add(edge)
|
||||
|
||||
def show_hidden(self) -> None:
|
||||
edges = set()
|
||||
for node in self.nodes.values():
|
||||
node.show()
|
||||
for edge in node.edges:
|
||||
if edge in edges:
|
||||
continue
|
||||
edges.add(edge)
|
||||
if node.hidden:
|
||||
node.show()
|
||||
|
||||
def zoom(self, event: tk.Event, factor: float = None) -> None:
|
||||
if not factor:
|
||||
|
|
|
@ -292,6 +292,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)
|
||||
self.context.add_cascade(label="Edit", menu=edit_menu)
|
||||
self.context.tk_popup(event.x_root, event.y_root)
|
||||
|
||||
|
@ -415,8 +416,17 @@ class CanvasNode:
|
|||
self.hidden = True
|
||||
self.canvas.itemconfig(self.id, state=tk.HIDDEN)
|
||||
self.canvas.itemconfig(self.text_id, state=tk.HIDDEN)
|
||||
for edge in self.edges:
|
||||
if not edge.hidden:
|
||||
edge.hide()
|
||||
|
||||
def show(self) -> None:
|
||||
self.hidden = False
|
||||
self.canvas.itemconfig(self.id, state=tk.NORMAL)
|
||||
self.canvas.itemconfig(self.text_id, state=tk.NORMAL)
|
||||
for edge in self.edges:
|
||||
other_node = edge.src
|
||||
if edge.src == self:
|
||||
other_node = edge.dst
|
||||
if edge.hidden and not other_node.hidden:
|
||||
edge.show()
|
||||
|
|
|
@ -431,8 +431,8 @@ class Menubar(tk.Menu):
|
|||
canvas.delete_selected_objects()
|
||||
|
||||
def click_show_hidden(self, _event: tk.Event = None) -> None:
|
||||
canvas = self.manager.current()
|
||||
canvas.show_hidden()
|
||||
for canvas in self.manager.all():
|
||||
canvas.show_hidden()
|
||||
|
||||
def click_session_options(self) -> None:
|
||||
logging.debug("Click options")
|
||||
|
|
Loading…
Reference in a new issue