pygui: initial canvas manager with a single tab by default, updates to how throughputs are handled related to canvases
This commit is contained in:
parent
2f9c169e66
commit
f9a4fe3331
8 changed files with 59 additions and 61 deletions
|
@ -357,9 +357,9 @@ class CanvasEdge(Edge):
|
|||
throughput = 0.001 * throughput
|
||||
text = f"{throughput:.3f} kbps"
|
||||
self.middle_label_text(text)
|
||||
if throughput > self.canvas.throughput_threshold:
|
||||
color = self.canvas.throughput_color
|
||||
width = self.canvas.throughput_width
|
||||
if throughput > self.canvas.manager.throughput_threshold:
|
||||
color = self.canvas.manager.throughput_color
|
||||
width = self.canvas.manager.throughput_width
|
||||
else:
|
||||
color = self.color
|
||||
width = self.scaled_width()
|
||||
|
|
|
@ -7,14 +7,7 @@ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Tuple
|
|||
from PIL import Image
|
||||
from PIL.ImageTk import PhotoImage
|
||||
|
||||
from core.api.grpc.wrappers import (
|
||||
Interface,
|
||||
Link,
|
||||
LinkType,
|
||||
Node,
|
||||
Session,
|
||||
ThroughputsEvent,
|
||||
)
|
||||
from core.api.grpc.wrappers import Interface, Link, LinkType, Node, Session
|
||||
from core.gui import appconfig
|
||||
from core.gui.dialogs.shapemod import ShapeDialog
|
||||
from core.gui.graph import tags
|
||||
|
@ -90,11 +83,6 @@ class CanvasGraph(tk.Canvas):
|
|||
self.scale_option: tk.IntVar = tk.IntVar(value=1)
|
||||
self.adjust_to_dim: tk.BooleanVar = tk.BooleanVar(value=False)
|
||||
|
||||
# throughput related
|
||||
self.throughput_threshold: float = 250.0
|
||||
self.throughput_width: int = 10
|
||||
self.throughput_color: str = "#FF0000"
|
||||
|
||||
# bindings
|
||||
self.setup_bindings()
|
||||
|
||||
|
@ -171,16 +159,6 @@ class CanvasGraph(tk.Canvas):
|
|||
valid_bottomright = self.inside_canvas(x2, y2)
|
||||
return valid_topleft and valid_bottomright
|
||||
|
||||
def set_throughputs(self, throughputs_event: ThroughputsEvent) -> None:
|
||||
for iface_throughput in throughputs_event.iface_throughputs:
|
||||
node_id = iface_throughput.node_id
|
||||
iface_id = iface_throughput.iface_id
|
||||
throughput = iface_throughput.throughput
|
||||
iface_to_edge_id = (node_id, iface_id)
|
||||
edge = self.core.iface_to_edge.get(iface_to_edge_id)
|
||||
if edge:
|
||||
edge.set_throughput(throughput)
|
||||
|
||||
def draw_grid(self) -> None:
|
||||
"""
|
||||
Create grid.
|
||||
|
|
|
@ -3,7 +3,7 @@ import tkinter as tk
|
|||
from tkinter import BooleanVar, messagebox, ttk
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Set, Tuple, ValuesView
|
||||
|
||||
from core.api.grpc.wrappers import LinkType, Session
|
||||
from core.api.grpc.wrappers import LinkType, Session, ThroughputsEvent
|
||||
from core.gui.graph import tags
|
||||
from core.gui.graph.enums import GraphMode
|
||||
from core.gui.graph.graph import CanvasGraph
|
||||
|
@ -74,6 +74,9 @@ class CanvasManager:
|
|||
self.unique_ids: Dict[str, int] = {}
|
||||
self.draw()
|
||||
|
||||
# start with a single tab by default
|
||||
self.add_canvas()
|
||||
|
||||
def draw(self) -> None:
|
||||
self.notebook = ttk.Notebook(self.master)
|
||||
self.notebook.grid(sticky=tk.NSEW, pady=1)
|
||||
|
@ -225,3 +228,18 @@ class CanvasManager:
|
|||
continue
|
||||
canvas = self.get(canvas_id)
|
||||
canvas.parse_metadata(canvas_config)
|
||||
|
||||
def set_throughputs(self, throughputs_event: ThroughputsEvent):
|
||||
for iface_throughput in throughputs_event.iface_throughputs:
|
||||
node_id = iface_throughput.node_id
|
||||
iface_id = iface_throughput.iface_id
|
||||
throughput = iface_throughput.throughput
|
||||
iface_to_edge_id = (node_id, iface_id)
|
||||
edge = self.core.iface_to_edge.get(iface_to_edge_id)
|
||||
if edge:
|
||||
edge.set_throughput(throughput)
|
||||
|
||||
def clear_throughputs(self) -> None:
|
||||
for canvas in self.all():
|
||||
for edge in canvas.edges.values():
|
||||
edge.clear_throughput()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue