updates to leverage theming, initially using a dark theme, updated all dialogs to be contained within a frame to help provide consistent theming

This commit is contained in:
Blake Harnden 2019-11-13 10:45:43 -08:00
parent 21d116c4c0
commit ca798215e4
23 changed files with 298 additions and 309 deletions

View file

@ -1,8 +1,9 @@
import logging
import tkinter as tk
from functools import partial
from tkinter import ttk
from coretk import appconfig
from coretk import appconfig, themes
from coretk.coreclient import CoreClient
from coretk.graph import CanvasGraph
from coretk.images import ImageEnum, Images
@ -14,7 +15,8 @@ from coretk.toolbar import Toolbar
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
Images.load_all()
self.style = ttk.Style()
self.setup_theme()
self.menubar = None
self.toolbar = None
self.canvas = None
@ -33,6 +35,14 @@ class Application(tk.Frame):
self.draw()
self.core.set_up()
def setup_theme(self):
themes.load(self.style)
self.style.theme_use(themes.DARK)
func = partial(themes.update_menu, self.style)
self.master.bind_class("Menu", "<<ThemeChanged>>", func)
func = partial(themes.update_toplevel, self.style)
self.master.bind_class("Toplevel", "<<ThemeChanged>>", func)
def setup_app(self):
self.master.title("CORE")
self.master.geometry("1000x800")
@ -78,6 +88,7 @@ class Application(tk.Frame):
if __name__ == "__main__":
log_format = "%(asctime)s - %(levelname)s - %(module)s:%(funcName)s - %(message)s"
logging.basicConfig(level=logging.DEBUG, format=log_format)
Images.load_all()
appconfig.check_directory()
app = Application()
app.mainloop()

View file

@ -1,6 +1,8 @@
import tkinter as tk
from tkinter import ttk
from coretk.themes import Styles
class CanvasTooltip:
"""
@ -17,16 +19,13 @@ class CanvasTooltip:
Alberto Vassena on 2016.12.10.
"""
def __init__(
self, canvas, *, bg="#FFFFEA", pad=(5, 3, 5, 3), waittime=400, wraplength=600
):
def __init__(self, canvas, *, pad=(5, 3, 5, 3), waittime=400, wraplength=600):
# in miliseconds, originally 500
self.waittime = waittime
# in pixels, originally 180
self.wraplength = wraplength
self.canvas = canvas
self.text = tk.StringVar()
self.bg = bg
self.pad = pad
self.id = None
self.tw = None
@ -78,7 +77,6 @@ class CanvasTooltip:
y1 = 0
return x1, y1
bg = self.bg
pad = self.pad
canvas = self.canvas
@ -87,20 +85,16 @@ class CanvasTooltip:
# Leaves only the label and removes the app window
self.tw.wm_overrideredirect(True)
win = tk.Frame(self.tw, background=bg, borderwidth=0)
win = ttk.Frame(self.tw, style=Styles.tooltip_frame, padding=3)
win.grid()
label = ttk.Label(
win,
textvariable=self.text,
justify=tk.LEFT,
background=bg,
relief=tk.SOLID,
borderwidth=0,
wraplength=self.wraplength,
style=Styles.tooltip,
)
label.grid(padx=(pad[0], pad[2]), pady=(pad[1], pad[3]), sticky=tk.NSEW)
x, y = tip_pos_calculator(canvas, label)
x, y = tip_pos_calculator(canvas, label, pad=pad)
self.tw.wm_geometry("+%d+%d" % (x, y))
def hide(self):

View file

@ -40,7 +40,7 @@ class CanvasBackgroundDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
self.draw_image()
self.draw_image_label()
self.draw_image_selection()
@ -50,16 +50,16 @@ class CanvasBackgroundDialog(Dialog):
def draw_image(self):
self.image_label = ttk.Label(
self, text="(image preview)", width=32, anchor=tk.CENTER
self.top, text="(image preview)", width=32, anchor=tk.CENTER
)
self.image_label.grid(row=0, column=0, pady=5)
def draw_image_label(self):
label = ttk.Label(self, text="Image filename: ")
label = ttk.Label(self.top, text="Image filename: ")
label.grid(row=1, column=0, sticky="ew")
def draw_image_selection(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.columnconfigure(0, weight=2)
frame.columnconfigure(1, weight=1)
frame.columnconfigure(2, weight=1)
@ -76,7 +76,7 @@ class CanvasBackgroundDialog(Dialog):
button.grid(row=0, column=2, sticky="ew")
def draw_options(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=1)
frame.columnconfigure(2, weight=1)
@ -105,12 +105,12 @@ class CanvasBackgroundDialog(Dialog):
def draw_additional_options(self):
checkbutton = ttk.Checkbutton(
self, text="Show grid", variable=self.show_grid_var
self.top, text="Show grid", variable=self.show_grid_var
)
checkbutton.grid(row=4, column=0, sticky="ew", padx=PADX)
checkbutton = ttk.Checkbutton(
self,
self.top,
text="Adjust canvas size to image dimensions",
variable=self.adjust_to_dim_var,
command=self.click_adjust_canvas,
@ -121,7 +121,7 @@ class CanvasBackgroundDialog(Dialog):
self.adjust_to_dim_var.set(0)
def draw_buttons(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(row=6, column=0, pady=5, sticky="ew")
frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=1)

View file

@ -44,7 +44,7 @@ class SizeAndScaleDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
self.draw_size()
self.draw_scale()
self.draw_reference_point()
@ -52,7 +52,7 @@ class SizeAndScaleDialog(Dialog):
self.draw_buttons()
def draw_size(self):
label_frame = ttk.Labelframe(self, text="Size", padding=FRAME_BAD)
label_frame = ttk.Labelframe(self.top, text="Size", padding=FRAME_BAD)
label_frame.grid(sticky="ew")
label_frame.columnconfigure(0, weight=1)
@ -89,7 +89,7 @@ class SizeAndScaleDialog(Dialog):
label.grid(row=0, column=4, sticky="w")
def draw_scale(self):
label_frame = ttk.Labelframe(self, text="Scale", padding=FRAME_BAD)
label_frame = ttk.Labelframe(self.top, text="Scale", padding=FRAME_BAD)
label_frame.grid(sticky="ew")
label_frame.columnconfigure(0, weight=1)
@ -104,7 +104,9 @@ class SizeAndScaleDialog(Dialog):
label.grid(row=0, column=2, sticky="w")
def draw_reference_point(self):
label_frame = ttk.Labelframe(self, text="Reference Point", padding=FRAME_BAD)
label_frame = ttk.Labelframe(
self.top, text="Reference Point", padding=FRAME_BAD
)
label_frame.grid(sticky="ew")
label_frame.columnconfigure(0, weight=1)
@ -156,12 +158,12 @@ class SizeAndScaleDialog(Dialog):
def draw_save_as_default(self):
button = ttk.Checkbutton(
self, text="Save as default?", variable=self.save_default
self.top, text="Save as default?", variable=self.save_default
)
button.grid(sticky="w", pady=3)
def draw_buttons(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=1)
frame.grid(sticky="ew")

View file

@ -19,10 +19,10 @@ class ServicesSelectDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
self.top.rowconfigure(0, weight=1)
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(stick="nsew")
frame.rowconfigure(0, weight=1)
for i in range(3):
@ -44,7 +44,7 @@ class ServicesSelectDialog(Dialog):
for service in sorted(self.current_services):
self.current.listbox.insert(tk.END, service)
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(stick="ew")
for i in range(2):
frame.columnconfigure(i, weight=1)
@ -96,19 +96,19 @@ class CustomNodesDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
self.top.rowconfigure(0, weight=1)
self.draw_node_config()
self.draw_node_buttons()
self.draw_buttons()
def draw_node_config(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(sticky="nsew")
frame.columnconfigure(0, weight=1)
frame.rowconfigure(0, weight=1)
self.nodes_list = ListboxScroll(frame)
self.nodes_list = ListboxScroll(frame, text="Nodes")
self.nodes_list.grid(row=0, column=0, sticky="nsew")
self.nodes_list.listbox.bind("<<ListboxSelect>>", self.handle_node_select)
for name in sorted(self.app.core.custom_nodes):
@ -125,7 +125,7 @@ class CustomNodesDialog(Dialog):
button.grid(sticky="ew")
def draw_node_buttons(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(pady=2, sticky="ew")
for i in range(3):
frame.columnconfigure(i, weight=1)
@ -144,7 +144,7 @@ class CustomNodesDialog(Dialog):
self.delete_button.grid(row=0, column=2, sticky="ew")
def draw_buttons(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(sticky="ew")
for i in range(2):
frame.columnconfigure(i, weight=1)

View file

@ -1,4 +1,5 @@
import tkinter as tk
from tkinter import ttk
from coretk.images import ImageEnum, Images
@ -7,7 +8,7 @@ DIALOG_PAD = 5
class Dialog(tk.Toplevel):
def __init__(self, master, app, title, modal=False):
super().__init__(master, padx=DIALOG_PAD, pady=DIALOG_PAD)
super().__init__(master)
self.withdraw()
self.app = app
self.modal = modal
@ -15,6 +16,10 @@ class Dialog(tk.Toplevel):
self.protocol("WM_DELETE_WINDOW", self.destroy)
image = Images.get(ImageEnum.CORE, 16)
self.tk.call("wm", "iconphoto", self._w, image)
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.top = ttk.Frame(self, padding=DIALOG_PAD)
self.top.grid(sticky="nsew")
def show(self):
self.transient(self.master)

View file

@ -55,10 +55,10 @@ class EmaneConfiguration(Dialog):
return var
def choose_core(self):
print("not implemented")
logging.info("not implemented")
def node_name_and_image(self):
f = ttk.Frame(self)
f = ttk.Frame(self.top)
lbl = ttk.Label(f, text="Node name:")
lbl.grid(row=0, column=0, padx=2, pady=2)
@ -90,13 +90,15 @@ class EmaneConfiguration(Dialog):
logging.info("emane config: %s", response)
self.options = response.config
self.emane_dialog.columnconfigure(0, weight=1)
self.emane_dialog.rowconfigure(0, weight=1)
self.emane_config_frame = ConfigFrame(self.emane_dialog, config=self.options)
self.emane_dialog.top.columnconfigure(0, weight=1)
self.emane_dialog.top.rowconfigure(0, weight=1)
self.emane_config_frame = ConfigFrame(
self.emane_dialog.top, config=self.options
)
self.emane_config_frame.draw_config()
self.emane_config_frame.grid(sticky="nsew")
frame = ttk.Frame(self.emane_dialog)
frame = ttk.Frame(self.emane_dialog.top)
frame.grid(sticky="ew")
for i in range(2):
frame.columnconfigure(i, weight=1)
@ -152,8 +154,8 @@ class EmaneConfiguration(Dialog):
self.emane_model_dialog = Dialog(
self, self.app, f"{model_name} configuration", modal=False
)
self.emane_model_dialog.columnconfigure(0, weight=1)
self.emane_model_dialog.rowconfigure(0, weight=1)
self.emane_model_dialog.top.columnconfigure(0, weight=1)
self.emane_model_dialog.top.rowconfigure(0, weight=1)
# query for configurations
session_id = self.app.core.session_id
@ -165,12 +167,12 @@ class EmaneConfiguration(Dialog):
self.model_options = response.config
self.model_config_frame = ConfigFrame(
self.emane_model_dialog, config=self.model_options
self.emane_model_dialog.top, config=self.model_options
)
self.model_config_frame.grid(sticky="nsew")
self.model_config_frame.draw_config()
frame = ttk.Frame(self.emane_model_dialog)
frame = ttk.Frame(self.emane_model_dialog.top)
frame.grid(sticky="ew")
for i in range(2):
frame.columnconfigure(i, weight=1)
@ -268,22 +270,24 @@ class EmaneConfiguration(Dialog):
:return: nothing
"""
# draw label
lbl = ttk.Label(self, text="Emane")
lbl = ttk.Label(self.top, text="Emane")
lbl.grid(row=1, column=0)
# main frame that has emane wiki, a short description, emane models and the configure buttons
f = ttk.Frame(self)
f = ttk.Frame(self.top)
f.columnconfigure(0, weight=1)
image = Images.get(ImageEnum.EDITNODE, 16)
b = ttk.Button(
f,
image=Images.get(ImageEnum.EDITNODE, 8),
image=image,
text="EMANE Wiki",
compound=tk.RIGHT,
command=lambda: webbrowser.open_new(
"https://github.com/adjacentlink/emane/wiki"
),
)
b.image = image
b.grid(row=0, column=0, sticky="w")
lbl = ttk.Label(
@ -302,8 +306,8 @@ class EmaneConfiguration(Dialog):
f.grid(row=2, column=0, sticky="nsew")
def draw_ip_subnets(self):
self.draw_text_label_and_entry(self, "IPv4 subnet", "")
self.draw_text_label_and_entry(self, "IPv6 subnet", "")
self.draw_text_label_and_entry(self.top, "IPv4 subnet", "")
self.draw_text_label_and_entry(self.top, "IPv6 subnet", "")
def emane_options(self):
"""
@ -311,7 +315,7 @@ class EmaneConfiguration(Dialog):
:return:
"""
f = ttk.Frame(self)
f = ttk.Frame(self.top)
f.columnconfigure(0, weight=1)
f.columnconfigure(1, weight=1)
b = ttk.Button(f, text="Link to all routers")
@ -326,7 +330,7 @@ class EmaneConfiguration(Dialog):
self.destroy()
def draw_apply_and_cancel(self):
f = ttk.Frame(self)
f = ttk.Frame(self.top)
f.columnconfigure(0, weight=1)
f.columnconfigure(1, weight=1)
b = ttk.Button(f, text="Apply", command=self.apply)

View file

@ -15,11 +15,11 @@ class HookDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
self.top.columnconfigure(0, weight=1)
self.top.rowconfigure(1, weight=1)
# name and states
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(row=0, sticky="ew", pady=2)
frame.columnconfigure(0, weight=2)
frame.columnconfigure(1, weight=7)
@ -39,7 +39,7 @@ class HookDialog(Dialog):
combobox.bind("<<ComboboxSelected>>", self.state_change)
# data
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.columnconfigure(0, weight=1)
frame.rowconfigure(0, weight=1)
frame.grid(row=1, sticky="nsew", pady=2)
@ -59,7 +59,7 @@ class HookDialog(Dialog):
scrollbar.config(command=self.data.yview)
# button row
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(row=2, sticky="ew", pady=2)
for i in range(2):
frame.columnconfigure(i, weight=1)
@ -99,14 +99,16 @@ class HooksDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.listbox = tk.Listbox(self)
self.top.columnconfigure(0, weight=1)
self.top.rowconfigure(0, weight=1)
self.listbox = tk.Listbox(self.top)
self.listbox.grid(row=0, sticky="nsew")
self.listbox.bind("<<ListboxSelect>>", self.select)
for hook_file in self.app.core.hooks:
self.listbox.insert(tk.END, hook_file)
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(row=1, sticky="ew")
for i in range(4):
frame.columnconfigure(i, weight=1)

View file

@ -15,10 +15,10 @@ class IconDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
# row one
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(row=0, column=0, pady=2, sticky="ew")
frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=3)
@ -30,11 +30,11 @@ class IconDialog(Dialog):
button.grid(row=0, column=2)
# row two
self.image_label = ttk.Label(self, image=self.image, anchor=tk.CENTER)
self.image_label = ttk.Label(self.top, image=self.image, anchor=tk.CENTER)
self.image_label.grid(row=1, column=0, pady=2, sticky="ew")
# row three
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(row=2, column=0, sticky="ew")
frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=1)

View file

@ -1,7 +1,7 @@
"""
mobility configuration
"""
import logging
import tkinter as tk
from tkinter import filedialog, ttk
@ -9,7 +9,7 @@ from coretk import appconfig
from coretk.dialogs.dialog import Dialog
class MobilityConfiguration(Dialog):
class MobilityConfigDialog(Dialog):
def __init__(self, master, app, canvas_node):
"""
create an instance of mobility configuration
@ -19,7 +19,7 @@ class MobilityConfiguration(Dialog):
"""
super().__init__(master, app, "ns2script configuration", modal=True)
self.canvas_node = canvas_node
print(app.canvas.core.mobilityconfig_management.configurations)
logging.info(app.canvas.core.mobilityconfig_management.configurations)
self.node_config = app.canvas.core.mobilityconfig_management.configurations[
canvas_node.core_id
]
@ -57,11 +57,11 @@ class MobilityConfiguration(Dialog):
def create_label_entry_filebrowser(
self, parent_frame, text_label, entry_text, filebrowser=False
):
f = ttk.Frame(parent_frame, bg="#d9d9d9")
lbl = ttk.Label(f, text=text_label, bg="#d9d9d9")
f = ttk.Frame(parent_frame)
lbl = ttk.Label(f, text=text_label)
lbl.grid(padx=3, pady=3)
# f.grid()
e = ttk.Entry(f, textvariable=self.create_string_var(entry_text), bg="#ffffff")
e = ttk.Entry(f, textvariable=self.create_string_var(entry_text))
e.grid(row=0, column=1, padx=3, pady=3)
if filebrowser:
b = ttk.Button(f, text="...", command=lambda: self.open_file(e))
@ -69,16 +69,14 @@ class MobilityConfiguration(Dialog):
f.grid(sticky=tk.E)
def mobility_script_parameters(self):
lbl = ttk.Label(self, text="node ns2script")
lbl = ttk.Label(self.top, text="node ns2script")
lbl.grid(sticky="ew")
sb = ttk.Scrollbar(self, orient=tk.VERTICAL)
sb = ttk.Scrollbar(self.top, orient=tk.VERTICAL)
sb.grid(row=1, column=1, sticky="ns")
f = ttk.Frame(self, bg="#d9d9d9")
lbl = ttk.Label(
f, text="ns-2 Mobility Scripts Parameters", bg="#d9d9d9", relief=tk.RAISED
)
f = ttk.Frame(self.top)
lbl = ttk.Label(f, text="ns-2 Mobility Scripts Parameters")
lbl.grid(row=0, column=0, sticky=tk.W)
f1 = tk.Canvas(
@ -229,7 +227,7 @@ class MobilityConfiguration(Dialog):
:return: nothing
"""
f = ttk.Frame(self)
f = ttk.Frame(self.top)
b = ttk.Button(f, text="Apply", command=self.ns2script_apply)
b.grid()
b = ttk.Button(f, text="Cancel", command=self.destroy)

View file

@ -26,13 +26,13 @@ class NodeConfigDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
self.draw_first_row()
self.draw_second_row()
self.draw_third_row()
def draw_first_row(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(row=0, column=0, pady=2, sticky="ew")
frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=1)
@ -55,7 +55,7 @@ class NodeConfigDialog(Dialog):
combobox.grid(row=0, column=2, sticky="ew")
def draw_second_row(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(row=1, column=0, pady=2, sticky="ew")
frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=1)
@ -73,7 +73,7 @@ class NodeConfigDialog(Dialog):
self.image_button.grid(row=0, column=1, sticky="ew")
def draw_third_row(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(row=2, column=0, sticky="ew")
frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=1)

View file

@ -22,10 +22,10 @@ class NodeService(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
self.top.rowconfigure(0, weight=1)
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(stick="nsew")
frame.rowconfigure(0, weight=1)
for i in range(3):
@ -47,7 +47,7 @@ class NodeService(Dialog):
for service in sorted(self.current_services):
self.current.listbox.insert(tk.END, service)
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(stick="ew")
for i in range(3):
frame.columnconfigure(i, weight=1)

View file

@ -18,15 +18,15 @@ class ObserverDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
self.top.rowconfigure(0, weight=1)
self.draw_listbox()
self.draw_form_fields()
self.draw_config_buttons()
self.draw_apply_buttons()
def draw_listbox(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(sticky="nsew")
frame.columnconfigure(0, weight=1)
frame.rowconfigure(0, weight=1)
@ -45,7 +45,7 @@ class ObserverDialog(Dialog):
scrollbar.config(command=self.observers.yview)
def draw_form_fields(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(sticky="ew")
frame.columnconfigure(1, weight=1)
@ -60,7 +60,7 @@ class ObserverDialog(Dialog):
entry.grid(row=1, column=1, sticky="ew")
def draw_config_buttons(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(pady=2, sticky="ew")
for i in range(3):
frame.columnconfigure(i, weight=1)
@ -79,7 +79,7 @@ class ObserverDialog(Dialog):
self.delete_button.grid(row=0, column=2, sticky="ew")
def draw_apply_buttons(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(sticky="ew")
for i in range(2):
frame.columnconfigure(i, weight=1)

View file

@ -15,12 +15,12 @@ class PreferencesDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
self.draw_programs()
self.draw_buttons()
def draw_programs(self):
frame = ttk.LabelFrame(self, text="Programs")
frame = ttk.LabelFrame(self.top, text="Programs")
frame.grid(sticky="ew", pady=2)
frame.columnconfigure(1, weight=1)
@ -47,7 +47,7 @@ class PreferencesDialog(Dialog):
entry.grid(row=2, column=1, sticky="ew")
def draw_buttons(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(sticky="ew")
for i in range(2):
frame.columnconfigure(i, weight=1)

View file

@ -23,15 +23,15 @@ class ServersDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
self.top.rowconfigure(0, weight=1)
self.draw_servers()
self.draw_server_configuration()
self.draw_servers_buttons()
self.draw_apply_buttons()
def draw_servers(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(pady=2, sticky="nsew")
frame.columnconfigure(0, weight=1)
frame.rowconfigure(0, weight=1)
@ -51,10 +51,10 @@ class ServersDialog(Dialog):
scrollbar.config(command=self.servers.yview)
def draw_server_configuration(self):
label = ttk.Label(self, text="Server Configuration")
label = ttk.Label(self.top, text="Server Configuration")
label.grid(pady=2, sticky="ew")
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(pady=2, sticky="ew")
frame.columnconfigure(1, weight=1)
frame.columnconfigure(3, weight=1)
@ -76,7 +76,7 @@ class ServersDialog(Dialog):
entry.grid(row=0, column=5, sticky="ew")
def draw_servers_buttons(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(pady=2, sticky="ew")
for i in range(3):
frame.columnconfigure(i, weight=1)
@ -95,7 +95,7 @@ class ServersDialog(Dialog):
self.delete_button.grid(row=0, column=2, sticky="ew")
def draw_apply_buttons(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(sticky="ew")
for i in range(2):
frame.columnconfigure(i, weight=1)

View file

@ -34,7 +34,7 @@ class ServiceConfiguration(Dialog):
def draw(self):
# self.columnconfigure(1, weight=1)
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame1 = ttk.Frame(frame)
label = ttk.Label(frame1, text=self.service_name)
label.grid(row=0, column=0, sticky="ew")
@ -49,7 +49,7 @@ class ServiceConfiguration(Dialog):
frame2.grid(row=1, column=0)
frame.grid(row=0, column=0)
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
self.tab_parent = ttk.Notebook(frame)
tab1 = ttk.Frame(self.tab_parent)
tab2 = ttk.Frame(self.tab_parent)
@ -190,11 +190,11 @@ class ServiceConfiguration(Dialog):
frame.grid(row=2 + i, column=0, sticky="nsew")
button = ttk.Button(
self, text="onle store values that have changed from their defaults"
self.top, text="onle store values that have changed from their defaults"
)
button.grid(row=2, column=0)
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
button = ttk.Button(frame, text="Apply", command=self.click_apply)
button.grid(row=0, column=0, sticky="nsew")
button = ttk.Button(

View file

@ -15,18 +15,18 @@ class SessionOptionsDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
self.top.rowconfigure(0, weight=1)
session_id = self.app.core.session_id
response = self.app.core.client.get_session_options(session_id)
logging.info("session options: %s", response)
self.config_frame = ConfigFrame(self, config=response.config)
self.config_frame = ConfigFrame(self.top, config=response.config)
self.config_frame.draw_config()
self.config_frame.grid(sticky="nsew")
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(sticky="ew")
for i in range(2):
frame.columnconfigure(i, weight=1)

View file

@ -16,7 +16,7 @@ class SessionsDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
self.draw_description()
self.draw_tree()
self.draw_buttons()
@ -27,7 +27,7 @@ class SessionsDialog(Dialog):
:return: nothing
"""
label = ttk.Label(
self,
self.top,
text="Below is a list of active CORE sessions. Double-click to \n"
"connect to an existing session. Usually, only sessions in \n"
"the RUNTIME state persist in the daemon, except for the \n"
@ -37,7 +37,7 @@ class SessionsDialog(Dialog):
def draw_tree(self):
self.tree = ttk.Treeview(
self, columns=("id", "state", "nodes"), show="headings"
self.top, columns=("id", "state", "nodes"), show="headings"
)
self.tree.grid(row=1, sticky="nsew")
self.tree.column("id", stretch=tk.YES)
@ -60,16 +60,18 @@ class SessionsDialog(Dialog):
self.tree.bind("<Double-1>", self.on_selected)
self.tree.bind("<<TreeviewSelect>>", self.click_select)
yscrollbar = ttk.Scrollbar(self, orient="vertical", command=self.tree.yview)
yscrollbar = ttk.Scrollbar(self.top, orient="vertical", command=self.tree.yview)
yscrollbar.grid(row=1, column=1, sticky="ns")
self.tree.configure(yscrollcommand=yscrollbar.set)
xscrollbar = ttk.Scrollbar(self, orient="horizontal", command=self.tree.xview)
xscrollbar = ttk.Scrollbar(
self.top, orient="horizontal", command=self.tree.xview
)
xscrollbar.grid(row=2, sticky="ew", pady=5)
self.tree.configure(xscrollcommand=xscrollbar.set)
def draw_buttons(self):
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
for i in range(4):
frame.columnconfigure(i, weight=1)
frame.grid(row=3, sticky="ew")

View file

@ -7,6 +7,7 @@ from tkinter import ttk
from coretk.dialogs.dialog import Dialog
from coretk.dialogs.icondialog import IconDialog
from coretk.dialogs.mobilityconfig import MobilityConfigDialog
class WlanConfigDialog(Dialog):
@ -30,7 +31,7 @@ class WlanConfigDialog(Dialog):
self.draw()
def draw(self):
self.columnconfigure(0, weight=1)
self.top.columnconfigure(0, weight=1)
self.draw_name_config()
self.draw_wlan_config()
self.draw_subnet()
@ -43,7 +44,7 @@ class WlanConfigDialog(Dialog):
:return: nothing
"""
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(pady=2, sticky="ew")
frame.columnconfigure(0, weight=1)
@ -59,10 +60,10 @@ class WlanConfigDialog(Dialog):
:return: nothing
"""
label = ttk.Label(self, text="Wireless")
label = ttk.Label(self.top, text="Wireless")
label.grid(sticky="w", pady=2)
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(pady=2, sticky="ew")
for i in range(2):
frame.columnconfigure(i, weight=1)
@ -108,7 +109,7 @@ class WlanConfigDialog(Dialog):
:return: nothing
"""
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(pady=3, sticky="ew")
frame.columnconfigure(1, weight=1)
frame.columnconfigure(3, weight=1)
@ -130,12 +131,14 @@ class WlanConfigDialog(Dialog):
:return:
"""
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(pady=2, sticky="ew")
for i in range(3):
frame.columnconfigure(i, weight=1)
button = ttk.Button(frame, text="ns-2 mobility script...")
button = ttk.Button(
frame, text="ns-2 mobility script...", command=self.click_mobility
)
button.grid(row=0, column=0, padx=2, sticky="ew")
button = ttk.Button(frame, text="Link to all routers")
@ -150,7 +153,7 @@ class WlanConfigDialog(Dialog):
:return: nothing
"""
frame = ttk.Frame(self)
frame = ttk.Frame(self.top)
frame.grid(sticky="ew")
for i in range(2):
frame.columnconfigure(i, weight=1)
@ -161,6 +164,10 @@ class WlanConfigDialog(Dialog):
button = ttk.Button(frame, text="Cancel", command=self.destroy)
button.grid(row=0, column=1, padx=2, sticky="ew")
def click_mobility(self):
dialog = MobilityConfigDialog(self, self.app, self.canvas_node)
dialog.show()
def click_icon(self):
dialog = IconDialog(
self, self.app, self.canvas_node.name, self.canvas_node.image

View file

@ -1,162 +0,0 @@
import tkinter as tk
from tkinter import ttk
class Colors:
disabledfg = "DarkGrey"
frame = "#424242"
dark = "#222222"
darker = "#121212"
darkest = "black"
lighter = "#626262"
lightest = "#ffffff"
selectbg = "#4a6984"
selectfg = "#ffffff"
white = "white"
black = "black"
style = ttk.Style()
style.theme_create(
"black",
"clam",
{
".": {
"configure": {
"background": Colors.frame,
"foreground": Colors.white,
"bordercolor": Colors.darkest,
"darkcolor": Colors.dark,
"lightcolor": Colors.lighter,
"troughcolor": Colors.darker,
"selectbackground": Colors.selectbg,
"selectforeground": Colors.selectfg,
"selectborderwidth": 0,
"font": "TkDefaultFont",
},
"map": {
"background": [("disabled", Colors.frame), ("active", Colors.lighter)],
"foreground": [("disabled", Colors.disabledfg)],
"selectbackground": [("!focus", Colors.darkest)],
"selectforeground": [("!focus", Colors.white)],
},
},
"TButton": {
"configure": {"width": 8, "padding": (5, 1), "relief": tk.RAISED},
"map": {
"relief": [("pressed", tk.SUNKEN)],
"shiftrelief": [("pressed", 1)],
},
},
"TMenubutton": {
"configure": {"width": 11, "padding": (5, 1), "relief": tk.RAISED}
},
"TCheckbutton": {
"configure": {
"indicatorbackground": Colors.white,
"indicatormargin": (1, 1, 4, 1),
}
},
"TRadiobutton": {
"configure": {
"indicatorbackground": Colors.white,
"indicatormargin": (1, 1, 4, 1),
}
},
"TEntry": {
"configure": {
"fieldbackground": Colors.white,
"foreground": Colors.black,
"padding": (2, 0),
}
},
"TCombobox": {
"configure": {
"fieldbackground": Colors.white,
"foreground": Colors.black,
"padding": (2, 0),
}
},
"TNotebook.Tab": {
"configure": {"padding": (6, 2, 6, 2)},
"map": {"background": [("selected", Colors.lighter)]},
},
"Treeview": {
"configure": {
"fieldbackground": Colors.white,
"background": Colors.white,
"foreground": Colors.black,
},
"map": {
"background": [("selected", Colors.selectbg)],
"foreground": [("selected", Colors.selectfg)],
},
},
},
)
style.theme_use("black")
def update_menu(event):
bg = style.lookup(".", "background")
fg = style.lookup(".", "foreground")
abg = style.lookup(".", "lightcolor")
event.widget.config(
background=bg, foreground=fg, activebackground=abg, activeforeground=fg
)
class Application(ttk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master.bind_class("Menu", "<<ThemeChanged>>", update_menu)
self.master.geometry("800x600")
menu = tk.Menu(self.master)
menu.add_command(label="Command1")
menu.add_command(label="Command2")
submenu = tk.Menu(menu, tearoff=False)
submenu.add_command(label="Command1")
submenu.add_command(label="Command2")
menu.add_cascade(label="Submenu", menu=submenu)
self.master.config(menu=menu)
self.master.columnconfigure(0, weight=1)
self.master.rowconfigure(0, weight=1)
notebook = ttk.Notebook(self.master)
notebook.grid(sticky="nsew")
frame = ttk.Frame(notebook)
frame.grid(sticky="nsew")
ttk.Label(frame, text="Label").grid()
ttk.Entry(frame).grid()
ttk.Button(frame, text="Button").grid()
ttk.Combobox(frame, values=("one", "two", "three")).grid()
menubutton = ttk.Menubutton(frame, text="MenuButton")
menubutton.grid()
mbmenu = tk.Menu(menubutton, tearoff=False)
menubutton.config(menu=mbmenu)
mbmenu.add_command(label="Menu1")
mbmenu.add_command(label="Menu2")
submenu = tk.Menu(mbmenu, tearoff=False)
submenu.add_command(label="Command1")
submenu.add_command(label="Command2")
mbmenu.add_cascade(label="Submenu", menu=submenu)
ttk.Radiobutton(frame, text="Radio Button").grid()
ttk.Checkbutton(frame, text="Check Button").grid()
tv = ttk.Treeview(frame, columns=("one", "two", "three"), show="headings")
tv.grid()
tv.column("one", stretch=tk.YES)
tv.heading("one", text="ID")
tv.column("two", stretch=tk.YES)
tv.heading("two", text="State")
tv.column("three", stretch=tk.YES)
tv.heading("three", text="Node Count")
tv.insert("", tk.END, text="1", values=("v1", "v2", "v3"))
tv.insert("", tk.END, text="2", values=("v1", "v2", "v3"))
notebook.add(frame, text="Tab1")
frame = ttk.Frame(notebook)
frame.grid(sticky="nsew")
notebook.add(frame, text="Tab2")
if __name__ == "__main__":
app = Application()
app.mainloop()

127
coretk/coretk/themes.py Normal file
View file

@ -0,0 +1,127 @@
import tkinter as tk
DARK = "black"
class Styles:
tooltip = "Tooltip.TLabel"
tooltip_frame = "Tooltip.TFrame"
class Colors:
disabledfg = "DarkGrey"
frame = "#424242"
dark = "#222222"
darker = "#121212"
darkest = "black"
lighter = "#626262"
lightest = "#ffffff"
selectbg = "#4a6984"
selectfg = "#ffffff"
white = "white"
black = "black"
def load(style):
style.theme_create(
DARK,
"clam",
{
".": {
"configure": {
"background": Colors.frame,
"foreground": Colors.white,
"bordercolor": Colors.darkest,
"darkcolor": Colors.dark,
"lightcolor": Colors.lighter,
"troughcolor": Colors.darker,
"selectbackground": Colors.selectbg,
"selectforeground": Colors.selectfg,
"selectborderwidth": 0,
"font": "TkDefaultFont",
},
"map": {
"background": [
("disabled", Colors.frame),
("active", Colors.lighter),
],
"foreground": [("disabled", Colors.disabledfg)],
"selectbackground": [("!focus", Colors.darkest)],
"selectforeground": [("!focus", Colors.white)],
},
},
"TButton": {
"configure": {"width": 8, "padding": (5, 1), "relief": tk.RAISED},
"map": {
"relief": [("pressed", tk.SUNKEN)],
"shiftrelief": [("pressed", 1)],
},
},
"TMenubutton": {
"configure": {"width": 11, "padding": (5, 1), "relief": tk.RAISED}
},
"TCheckbutton": {
"configure": {
"indicatorbackground": Colors.white,
"indicatormargin": (1, 1, 4, 1),
}
},
"TRadiobutton": {
"configure": {
"indicatorbackground": Colors.white,
"indicatormargin": (1, 1, 4, 1),
}
},
"TEntry": {
"configure": {
"fieldbackground": Colors.white,
"foreground": Colors.black,
"padding": (2, 0),
}
},
"TCombobox": {
"configure": {
"fieldbackground": Colors.white,
"foreground": Colors.black,
"padding": (2, 0),
}
},
"TNotebook.Tab": {
"configure": {"padding": (6, 2, 6, 2)},
"map": {"background": [("selected", Colors.lighter)]},
},
"Treeview": {
"configure": {
"fieldbackground": Colors.white,
"background": Colors.white,
"foreground": Colors.black,
},
"map": {
"background": [("selected", Colors.selectbg)],
"foreground": [("selected", Colors.selectfg)],
},
},
Styles.tooltip: {
"configure": {"justify": tk.LEFT, "relief": tk.SOLID, "borderwidth": 0}
},
Styles.tooltip_frame: {"configure": {}},
},
)
def update_toplevel(style, event):
if not isinstance(event.widget, tk.Toplevel):
return
bg = style.lookup(".", "background")
event.widget.config(background=bg)
def update_menu(style, event):
if not isinstance(event.widget, tk.Menu):
return
bg = style.lookup(".", "background")
fg = style.lookup(".", "foreground")
abg = style.lookup(".", "lightcolor")
event.widget.config(
background=bg, foreground=fg, activebackground=abg, activeforeground=fg
)

View file

@ -1,6 +1,8 @@
import tkinter as tk
from tkinter import ttk
from coretk.themes import Styles
class Tooltip(object):
"""
@ -41,15 +43,12 @@ class Tooltip(object):
self.tw = tk.Toplevel(self.widget)
self.tw.wm_overrideredirect(True)
self.tw.wm_geometry("+%d+%d" % (x, y))
label = ttk.Label(
self.tw,
text=self.text,
justify=tk.LEFT,
background="#FFFFEA",
relief=tk.SOLID,
borderwidth=0,
)
label.grid(padx=1)
self.tw.rowconfigure(0, weight=1)
self.tw.columnconfigure(0, weight=1)
frame = ttk.Frame(self.tw, style=Styles.tooltip_frame, padding=3)
frame.grid(sticky="nsew")
label = ttk.Label(frame, text=self.text, style=Styles.tooltip)
label.grid()
def close(self, event=None):
if self.tw:

View file

@ -17,9 +17,9 @@ INT_TYPES = {
}
class FrameScroll(tk.LabelFrame):
def __init__(self, master=None, cnf={}, _cls=tk.Frame, **kw):
super().__init__(master, cnf, **kw)
class FrameScroll(ttk.LabelFrame):
def __init__(self, master=None, _cls=tk.Frame, **kw):
super().__init__(master, **kw)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.canvas = tk.Canvas(self, highlightthickness=0)
@ -54,8 +54,8 @@ class FrameScroll(tk.LabelFrame):
class ConfigFrame(FrameScroll):
def __init__(self, master=None, cnf={}, config=None, **kw):
super().__init__(master, cnf, ttk.Notebook, **kw)
def __init__(self, master=None, config=None, **kw):
super().__init__(master, ttk.Notebook, **kw)
self.config = config
self.values = {}
@ -126,9 +126,9 @@ class ConfigFrame(FrameScroll):
return {x: self.config[x].value for x in self.config}
class ListboxScroll(tk.LabelFrame):
def __init__(self, master=None, cnf={}, **kw):
super().__init__(master, cnf, **kw)
class ListboxScroll(ttk.LabelFrame):
def __init__(self, master=None, **kw):
super().__init__(master, **kw)
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.scrollbar = ttk.Scrollbar(self, orient=tk.VERTICAL)
@ -141,8 +141,8 @@ class ListboxScroll(tk.LabelFrame):
class CheckboxList(FrameScroll):
def __init__(self, master=None, cnf={}, clicked=None, **kw):
super().__init__(master, cnf, **kw)
def __init__(self, master=None, clicked=None, **kw):
super().__init__(master, **kw)
self.clicked = clicked
self.frame.columnconfigure(0, weight=1)