pygui: able to start session with multiple canvases, just using 1 canvas for now
This commit is contained in:
parent
6f43d0e88f
commit
9621df6bc4
5 changed files with 34 additions and 24 deletions
|
@ -145,7 +145,7 @@ class Edge:
|
|||
text=text,
|
||||
tags=tags.LINK_LABEL,
|
||||
justify=tk.CENTER,
|
||||
state=self.canvas.show_link_labels.state(),
|
||||
state=self.canvas.manager.show_link_labels.state(),
|
||||
)
|
||||
else:
|
||||
self.canvas.itemconfig(self.middle_label, text=text)
|
||||
|
@ -177,7 +177,7 @@ class Edge:
|
|||
justify=tk.CENTER,
|
||||
font=self.canvas.app.edge_font,
|
||||
tags=tags.LINK_LABEL,
|
||||
state=self.canvas.show_link_labels.state(),
|
||||
state=self.canvas.manager.show_link_labels.state(),
|
||||
)
|
||||
else:
|
||||
self.canvas.itemconfig(self.src_label, text=text)
|
||||
|
@ -191,7 +191,7 @@ class Edge:
|
|||
justify=tk.CENTER,
|
||||
font=self.canvas.app.edge_font,
|
||||
tags=tags.LINK_LABEL,
|
||||
state=self.canvas.show_link_labels.state(),
|
||||
state=self.canvas.manager.show_link_labels.state(),
|
||||
)
|
||||
else:
|
||||
self.canvas.itemconfig(self.dst_label, text=text)
|
||||
|
@ -256,7 +256,7 @@ class CanvasWirelessEdge(Edge):
|
|||
self.width: float = WIRELESS_WIDTH
|
||||
color = link.color if link.color else WIRELESS_COLOR
|
||||
self.color: str = color
|
||||
self.draw(src_pos, dst_pos, self.canvas.show_wireless.state())
|
||||
self.draw(src_pos, dst_pos, self.canvas.manager.show_wireless.state())
|
||||
if link.label:
|
||||
self.middle_label_text(link.label)
|
||||
self.set_binding()
|
||||
|
@ -311,12 +311,12 @@ class CanvasEdge(Edge):
|
|||
|
||||
def iface_label(self, iface: Interface) -> str:
|
||||
label = ""
|
||||
if iface.name and self.canvas.show_iface_names.get():
|
||||
if iface.name and self.canvas.manager.show_iface_names.get():
|
||||
label = f"{iface.name}"
|
||||
if iface.ip4 and self.canvas.show_ip4s.get():
|
||||
if iface.ip4 and self.canvas.manager.show_ip4s.get():
|
||||
label = f"{label}\n" if label else ""
|
||||
label += f"{iface.ip4}/{iface.ip4_mask}"
|
||||
if iface.ip6 and self.canvas.show_ip6s.get():
|
||||
if iface.ip6 and self.canvas.manager.show_ip6s.get():
|
||||
label = f"{label}\n" if label else ""
|
||||
label += f"{iface.ip6}/{iface.ip6_mask}"
|
||||
return label
|
||||
|
@ -350,7 +350,7 @@ class CanvasEdge(Edge):
|
|||
else:
|
||||
state = tk.NORMAL
|
||||
self.canvas.dtag(self.id, tags.LOSS_EDGES)
|
||||
if self.canvas.show_loss_links.state() == tk.HIDDEN:
|
||||
if self.canvas.manager.show_loss_links.state() == tk.HIDDEN:
|
||||
self.canvas.itemconfigure(self.id, state=state)
|
||||
|
||||
def set_throughput(self, throughput: float) -> None:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import logging
|
||||
import tkinter as tk
|
||||
from tkinter import BooleanVar, messagebox, ttk
|
||||
from typing import TYPE_CHECKING, Dict, Optional, Set, Tuple
|
||||
from typing import TYPE_CHECKING, Dict, Optional, Set, Tuple, ValuesView
|
||||
|
||||
from core.api.grpc.wrappers import Session
|
||||
from core.gui.graph import tags
|
||||
|
@ -77,20 +77,28 @@ class CanvasManager:
|
|||
self.notebook = ttk.Notebook(self.master)
|
||||
self.notebook.grid(sticky=tk.NSEW, pady=1)
|
||||
|
||||
def next_id(self) -> int:
|
||||
def _next_id(self) -> int:
|
||||
_id = 1
|
||||
tab_ids = set(self.unique_ids.values())
|
||||
while _id in tab_ids:
|
||||
_id += 1
|
||||
return _id
|
||||
|
||||
def current(self) -> CanvasGraph:
|
||||
unique_id = self.notebook.select()
|
||||
tab_id = self.unique_ids[unique_id]
|
||||
return self.canvases[tab_id]
|
||||
|
||||
def all(self) -> ValuesView[CanvasGraph]:
|
||||
return self.canvases.values()
|
||||
|
||||
def add_canvas(self) -> CanvasGraph:
|
||||
# create tab frame
|
||||
tab = ttk.Frame(self.notebook, padding=0)
|
||||
tab.grid(sticky=tk.NSEW)
|
||||
tab.columnconfigure(0, weight=1)
|
||||
tab.rowconfigure(0, weight=1)
|
||||
tab_id = self.next_id()
|
||||
tab_id = self._next_id()
|
||||
self.notebook.add(tab, text=f"Canvas {tab_id}")
|
||||
unique_id = self.notebook.tabs()[-1]
|
||||
logging.info("tab(%s) is %s", unique_id, tab_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue