updated throughput dialog to load and set values from graph class

This commit is contained in:
Blake Harnden 2019-12-26 21:32:30 -08:00
parent 3512eedc60
commit 5dd08c283a
2 changed files with 40 additions and 41 deletions

View file

@ -1,26 +1,26 @@
""" """
throughput dialog throughput dialog
""" """
import logging
import tkinter as tk import tkinter as tk
from tkinter import ttk from tkinter import ttk
from core.gui.dialogs.colorpicker import ColorPickerDialog from core.gui.dialogs.colorpicker import ColorPickerDialog
from core.gui.dialogs.dialog import Dialog from core.gui.dialogs.dialog import Dialog
from core.gui.themes import FRAME_PAD, PADY from core.gui.themes import FRAME_PAD, PADX, PADY
class ThroughputDialog(Dialog): class ThroughputDialog(Dialog):
def __init__(self, master, app): def __init__(self, master, app):
super().__init__(master, app, "Throughput Config", modal=False) super().__init__(master, app, "Throughput Config", modal=False)
self.app = app self.app = app
self.canvas = app.canvas
self.show_throughput = tk.IntVar(value=1) self.show_throughput = tk.IntVar(value=1)
self.exponential_weight = tk.IntVar(value=1) self.exponential_weight = tk.IntVar(value=1)
self.transmission = tk.IntVar(value=1) self.transmission = tk.IntVar(value=1)
self.reception = tk.IntVar(value=1) self.reception = tk.IntVar(value=1)
self.threshold = tk.DoubleVar(value=250.0) self.threshold = tk.DoubleVar(value=self.canvas.throughput_threshold)
self.width = tk.IntVar(value=10) self.width = tk.IntVar(value=self.canvas.throughput_width)
self.color = "#FF0000" self.color = self.canvas.throughput_color
self.color_button = None self.color_button = None
self.top.columnconfigure(0, weight=1) self.top.columnconfigure(0, weight=1)
self.draw() self.draw()
@ -31,39 +31,25 @@ class ThroughputDialog(Dialog):
variable=self.show_throughput, variable=self.show_throughput,
text="Show Throughput Level On Every Link", text="Show Throughput Level On Every Link",
) )
button.grid(row=0, column=0, sticky="ew") button.grid(sticky="ew")
button = ttk.Checkbutton( button = ttk.Checkbutton(
self.top, self.top,
variable=self.exponential_weight, variable=self.exponential_weight,
text="Use Exponential Weighted Moving Average", text="Use Exponential Weighted Moving Average",
) )
button.grid(row=1, column=0, sticky="ew") button.grid(sticky="ew")
button = ttk.Checkbutton( button = ttk.Checkbutton(
self.top, variable=self.transmission, text="Include Transmissions" self.top, variable=self.transmission, text="Include Transmissions"
) )
button.grid(row=2, column=0, sticky="ew") button.grid(sticky="ew")
button = ttk.Checkbutton( button = ttk.Checkbutton(
self.top, variable=self.reception, text="Include Receptions" self.top, variable=self.reception, text="Include Receptions"
) )
button.grid(row=3, column=0, sticky="ew") button.grid(sticky="ew")
label_frame = ttk.LabelFrame(self.top, text="Link Highlight", padding=FRAME_PAD) label_frame = ttk.LabelFrame(self.top, text="Link Highlight", padding=FRAME_PAD)
label_frame.columnconfigure(0, weight=1) label_frame.columnconfigure(0, weight=1)
label_frame.grid(row=4, column=0, sticky="ew") label_frame.grid(sticky="ew")
label = ttk.Label(label_frame, text="Highlight Link Throughput")
label.grid(row=0, column=0, sticky="ew")
frame = ttk.Frame(label_frame)
frame.columnconfigure(0, weight=2)
frame.columnconfigure(1, weight=1)
frame.columnconfigure(2, weight=1)
frame.grid(row=1, column=0, sticky="ew")
label = ttk.Label(frame, text="Threshold (0 for disabled)")
label.grid(row=0, column=0, sticky="ew")
entry = ttk.Entry(frame, textvariable=self.threshold)
entry.grid(row=0, column=1, sticky="ew")
label = ttk.Label(frame, text="kbps")
label.grid(row=0, column=2, sticky="ew")
scale = ttk.Scale( scale = ttk.Scale(
label_frame, label_frame,
@ -73,23 +59,21 @@ class ThroughputDialog(Dialog):
orient=tk.HORIZONTAL, orient=tk.HORIZONTAL,
variable=self.threshold, variable=self.threshold,
) )
scale.grid(row=2, column=0, sticky="ew", pady=PADY) scale.grid(sticky="ew", pady=PADY)
frame = ttk.Frame(label_frame) frame = ttk.Frame(label_frame)
frame.columnconfigure(0, weight=1) frame.grid(sticky="ew")
frame.columnconfigure(1, weight=1) frame.columnconfigure(1, weight=1)
frame.grid(row=3, column=0, sticky="nsew") label = ttk.Label(frame, text="Threshold Kbps (0 disabled)")
label = ttk.Label(frame, text="Highlight Link Width") label.grid(row=0, column=0, sticky="ew", padx=PADX)
label.grid(row=0, column=0, sticky="ew") entry = ttk.Entry(frame, textvariable=self.threshold)
entry.grid(row=0, column=1, sticky="ew", pady=PADY)
label = ttk.Label(frame, text="Width")
label.grid(row=1, column=0, sticky="ew", padx=PADX)
entry = ttk.Entry(frame, textvariable=self.width) entry = ttk.Entry(frame, textvariable=self.width)
entry.grid(row=0, column=1, sticky="ew") entry.grid(row=1, column=1, sticky="ew", pady=PADY)
frame = ttk.Frame(label_frame)
frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=1)
frame.grid(row=4, column=0, sticky="ew")
label = ttk.Label(frame, text="Color") label = ttk.Label(frame, text="Color")
label.grid(row=0, column=0, sticky="ew") label.grid(row=2, column=0, sticky="ew", padx=PADX)
self.color_button = tk.Button( self.color_button = tk.Button(
frame, frame,
text=self.color, text=self.color,
@ -97,16 +81,26 @@ class ThroughputDialog(Dialog):
bg=self.color, bg=self.color,
highlightthickness=0, highlightthickness=0,
) )
self.color_button.grid(row=0, column=1, sticky="ew") self.color_button.grid(row=2, column=1, sticky="ew")
button = ttk.Button(self.top, text="OK", command=self.ok) self.draw_spacer()
button.grid(row=5, column=0, sticky="ew")
frame = ttk.Frame(self.top)
frame.grid(sticky="ew")
for i in range(2):
frame.columnconfigure(i, weight=1)
button = ttk.Button(frame, text="Save", command=self.click_save)
button.grid(row=0, column=0, sticky="ew", padx=PADX)
button = ttk.Button(frame, text="Cancel", command=self.destroy)
button.grid(row=0, column=1, sticky="ew")
def click_color(self): def click_color(self):
color_picker = ColorPickerDialog(self, self.app, self.color) color_picker = ColorPickerDialog(self, self.app, self.color)
self.color = color_picker.askcolor() self.color = color_picker.askcolor()
self.color_button.config(bg=self.color, text=self.color, bd=0) self.color_button.config(bg=self.color, text=self.color, bd=0)
def ok(self): def click_save(self):
logging.debug("click ok") self.canvas.throughput_threshold = self.threshold.get()
self.canvas.throughput_width = self.width.get()
self.canvas.throughput_color = self.color
self.destroy() self.destroy()

View file

@ -57,6 +57,11 @@ class CanvasGraph(tk.Canvas):
self.show_grid = tk.BooleanVar(value=True) self.show_grid = tk.BooleanVar(value=True)
self.adjust_to_dim = tk.BooleanVar(value=False) self.adjust_to_dim = tk.BooleanVar(value=False)
# throughput related
self.throughput_threshold = 250.0
self.throughput_width = 10
self.throughput_color = "#FF0000"
# bindings # bindings
self.setup_bindings() self.setup_bindings()