From 58a4db6050ed8d852c043261bf693f6fc41eb056 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Mon, 11 Nov 2019 16:33:51 -0800 Subject: [PATCH] updates to convert more dialogs to use ttk widgets when possible --- coretk/coretk/dialogs/customnodes.py | 33 +++++----- coretk/coretk/dialogs/emaneconfig.py | 82 ++++++++++--------------- coretk/coretk/dialogs/hooks.py | 26 ++++---- coretk/coretk/dialogs/icondialog.py | 18 +++--- coretk/coretk/dialogs/observers.py | 29 ++++----- coretk/coretk/dialogs/servers.py | 35 ++++++----- coretk/coretk/dialogs/sessionoptions.py | 8 +-- coretk/coretk/dialogs/sessions.py | 28 ++++----- coretk/coretk/widgets.py | 16 ++--- 9 files changed, 127 insertions(+), 148 deletions(-) diff --git a/coretk/coretk/dialogs/customnodes.py b/coretk/coretk/dialogs/customnodes.py index 5caa19ff..f5c1ab78 100644 --- a/coretk/coretk/dialogs/customnodes.py +++ b/coretk/coretk/dialogs/customnodes.py @@ -1,6 +1,7 @@ import logging import tkinter as tk from pathlib import Path +from tkinter import ttk from coretk.coreclient import CustomNode from coretk.dialogs.dialog import Dialog @@ -21,7 +22,7 @@ class ServicesSelectDialog(Dialog): self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(stick="nsew") frame.rowconfigure(0, weight=1) for i in range(3): @@ -43,13 +44,13 @@ class ServicesSelectDialog(Dialog): for service in sorted(self.current_services): self.current.listbox.insert(tk.END, service) - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(stick="ew") for i in range(2): frame.columnconfigure(i, weight=1) - button = tk.Button(frame, text="Save", command=self.destroy) + button = ttk.Button(frame, text="Save", command=self.destroy) button.grid(row=0, column=0, sticky="ew") - button = tk.Button(frame, text="Cancel", command=self.click_cancel) + button = ttk.Button(frame, text="Cancel", command=self.click_cancel) button.grid(row=0, column=1, sticky="ew") # trigger group change @@ -102,7 +103,7 @@ class CustomNodesDialog(Dialog): self.draw_buttons() def draw_node_config(self): - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(sticky="nsew") frame.columnconfigure(0, weight=1) frame.rowconfigure(0, weight=1) @@ -113,45 +114,45 @@ class CustomNodesDialog(Dialog): for name in sorted(self.app.core.custom_nodes): self.nodes_list.listbox.insert(tk.END, name) - frame = tk.Frame(frame) + frame = ttk.Frame(frame) frame.grid(row=0, column=2, sticky="nsew") frame.columnconfigure(0, weight=1) - entry = tk.Entry(frame, textvariable=self.name) + entry = ttk.Entry(frame, textvariable=self.name) entry.grid(sticky="ew") - self.image_button = tk.Button(frame, text="Icon", command=self.click_icon) + self.image_button = ttk.Button(frame, text="Icon", command=self.click_icon) self.image_button.grid(sticky="ew") - button = tk.Button(frame, text="Services", command=self.click_services) + button = ttk.Button(frame, text="Services", command=self.click_services) button.grid(sticky="ew") def draw_node_buttons(self): - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(pady=2, sticky="ew") for i in range(3): frame.columnconfigure(i, weight=1) - button = tk.Button(frame, text="Create", command=self.click_create) + button = ttk.Button(frame, text="Create", command=self.click_create) button.grid(row=0, column=0, sticky="ew") - self.edit_button = tk.Button( + self.edit_button = ttk.Button( frame, text="Edit", state=tk.DISABLED, command=self.click_edit ) self.edit_button.grid(row=0, column=1, sticky="ew") - self.delete_button = tk.Button( + self.delete_button = ttk.Button( frame, text="Delete", state=tk.DISABLED, command=self.click_delete ) self.delete_button.grid(row=0, column=2, sticky="ew") def draw_buttons(self): - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(sticky="ew") for i in range(2): frame.columnconfigure(i, weight=1) - button = tk.Button(frame, text="Save", command=self.click_save) + button = ttk.Button(frame, text="Save", command=self.click_save) button.grid(row=0, column=0, sticky="ew") - button = tk.Button(frame, text="Cancel", command=self.destroy) + button = ttk.Button(frame, text="Cancel", command=self.destroy) button.grid(row=0, column=1, sticky="ew") def reset_values(self): diff --git a/coretk/coretk/dialogs/emaneconfig.py b/coretk/coretk/dialogs/emaneconfig.py index 6950dc10..7fd577e2 100644 --- a/coretk/coretk/dialogs/emaneconfig.py +++ b/coretk/coretk/dialogs/emaneconfig.py @@ -58,18 +58,18 @@ class EmaneConfiguration(Dialog): print("not implemented") def node_name_and_image(self): - f = tk.Frame(self, bg="#d9d9d9") + f = ttk.Frame(self) - lbl = tk.Label(f, text="Node name:", bg="#d9d9d9") + lbl = ttk.Label(f, text="Node name:") lbl.grid(row=0, column=0, padx=2, pady=2) - e = tk.Entry(f, textvariable=self.create_text_variable(""), bg="white") + e = ttk.Entry(f, textvariable=self.create_text_variable("")) e.grid(row=0, column=1, padx=2, pady=2) cbb = ttk.Combobox(f, values=["(none)", "core1", "core2"], state="readonly") cbb.current(0) cbb.grid(row=0, column=2, padx=2, pady=2) - b = tk.Button(f, image=self.canvas_node.image) + b = ttk.Button(f, image=self.canvas_node.image) b.grid(row=0, column=3, padx=2, pady=2) f.grid(row=0, column=0, sticky="nsew") @@ -96,13 +96,13 @@ class EmaneConfiguration(Dialog): self.emane_config_frame.draw_config() self.emane_config_frame.grid(sticky="nsew") - frame = tk.Frame(self.emane_dialog) + frame = ttk.Frame(self.emane_dialog) frame.grid(sticky="ew") for i in range(2): frame.columnconfigure(i, weight=1) - b1 = tk.Button(frame, text="Appy", command=self.save_emane_option) + b1 = ttk.Button(frame, text="Appy", command=self.save_emane_option) b1.grid(row=0, column=0, sticky="ew") - b2 = tk.Button(frame, text="Cancel", command=self.emane_dialog.destroy) + b2 = ttk.Button(frame, text="Cancel", command=self.emane_dialog.destroy) b2.grid(row=0, column=1, sticky="ew") self.emane_dialog.show() @@ -170,35 +170,33 @@ class EmaneConfiguration(Dialog): self.model_config_frame.grid(sticky="nsew") self.model_config_frame.draw_config() - frame = tk.Frame(self.emane_model_dialog) + frame = ttk.Frame(self.emane_model_dialog) frame.grid(sticky="ew") for i in range(2): frame.columnconfigure(i, weight=1) - b1 = tk.Button(frame, text="Apply", command=self.save_emane_model_options) + b1 = ttk.Button(frame, text="Apply", command=self.save_emane_model_options) b1.grid(row=0, column=0, sticky="ew") - b2 = tk.Button(frame, text="Cancel", command=self.emane_model_dialog.destroy) + b2 = ttk.Button(frame, text="Cancel", command=self.emane_model_dialog.destroy) b2.grid(row=0, column=1, sticky="ew") self.emane_model_dialog.show() def draw_option_buttons(self, parent): - f = tk.Frame(parent, bg="#d9d9d9") + f = ttk.Frame(parent) f.columnconfigure(0, weight=1) f.columnconfigure(1, weight=1) - b = tk.Button( + b = ttk.Button( f, text=self.emane_models[0] + " options", image=Images.get(ImageEnum.EDITNODE), compound=tk.RIGHT, - bg="#d9d9d9", command=self.draw_model_options, ) b.grid(row=0, column=0, padx=10, pady=2, sticky="nsew") - b = tk.Button( + b = ttk.Button( f, text="EMANE options", image=Images.get(ImageEnum.EDITNODE), compound=tk.RIGHT, - bg="#d9d9d9", command=self.draw_emane_options, ) b.grid(row=0, column=1, padx=10, pady=2, sticky="nsew") @@ -233,21 +231,14 @@ class EmaneConfiguration(Dialog): self.emane_models = [x.split("_")[1] for x in response.models] # create combo box and its binding - f = tk.Frame( - parent, - bg="#d9d9d9", - highlightbackground="#b3b3b3", - highlightcolor="#b3b3b3", - highlightthickness=0.5, - bd=0, - ) + f = ttk.Frame(parent) self.emane_model_combobox = ttk.Combobox( f, values=self.emane_models, state="readonly" ) self.emane_model_combobox.grid() self.emane_model_combobox.current(0) self.emane_model_combobox.bind("<>", self.combobox_select) - f.grid(row=3, column=0, sticky=tk.W + tk.E) + f.grid(row=3, column=0, sticky="ew") def draw_text_label_and_entry(self, parent, label_text, entry_text): """ @@ -257,10 +248,10 @@ class EmaneConfiguration(Dialog): """ var = tk.StringVar() var.set(entry_text) - f = tk.Frame(parent) - lbl = tk.Label(f, text=label_text) + f = ttk.Frame(parent) + lbl = ttk.Label(f, text=label_text) lbl.grid(row=0, column=0) - e = tk.Entry(f, textvariable=var, bg="white") + e = ttk.Entry(f, textvariable=var) e.grid(row=0, column=1) f.grid(stick=tk.W, padx=2, pady=2) @@ -271,44 +262,33 @@ class EmaneConfiguration(Dialog): :return: nothing """ # draw label - lbl = tk.Label(self, text="Emane") + lbl = ttk.Label(self, text="Emane") lbl.grid(row=1, column=0) # main frame that has emane wiki, a short description, emane models and the configure buttons - f = tk.Frame( - self, - bg="#d9d9d9", - highlightbackground="#b3b3b3", - highlightcolor="#b3b3b3", - highlightthickness=0.5, - bd=0, - relief=tk.RAISED, - ) + f = ttk.Frame(self) f.columnconfigure(0, weight=1) - b = tk.Button( + b = ttk.Button( f, image=Images.get(ImageEnum.EDITNODE), text="EMANE Wiki", compound=tk.RIGHT, - relief=tk.RAISED, - bg="#d9d9d9", command=lambda: webbrowser.open_new( "https://github.com/adjacentlink/emane/wiki" ), ) - b.grid(row=0, column=0, sticky=tk.W) + b.grid(row=0, column=0, sticky="w") - lbl = tk.Label( + lbl = ttk.Label( f, text="The EMANE emulation system provides more complex wireless radio emulation " "\nusing pluggable MAC and PHY modules. Refer to the wiki for configuration option details", - bg="#d9d9d9", ) lbl.grid(row=1, column=0, sticky="nsew") - lbl = tk.Label(f, text="EMANE Models", bg="#d9d9d9") - lbl.grid(row=2, column=0, sticky=tk.W) + lbl = ttk.Label(f, text="EMANE Models") + lbl.grid(row=2, column=0, sticky="w") self.draw_emane_models(f) self.draw_option_buttons(f) @@ -325,12 +305,12 @@ class EmaneConfiguration(Dialog): :return: """ - f = tk.Frame(self, bg="#d9d9d9") + f = ttk.Frame(self) f.columnconfigure(0, weight=1) f.columnconfigure(1, weight=1) - b = tk.Button(f, text="Link to all routers", bg="#d9d9d9") + b = ttk.Button(f, text="Link to all routers") b.grid(row=0, column=0, padx=10, pady=2, sticky="nsew") - b = tk.Button(f, text="Choose WLAN members", bg="#d9d9d9") + b = ttk.Button(f, text="Choose WLAN members") b.grid(row=0, column=1, padx=10, pady=2, sticky="nsew") f.grid(row=5, column=0, sticky="nsew") @@ -340,12 +320,12 @@ class EmaneConfiguration(Dialog): self.destroy() def draw_apply_and_cancel(self): - f = tk.Frame(self, bg="#d9d9d9") + f = ttk.Frame(self) f.columnconfigure(0, weight=1) f.columnconfigure(1, weight=1) - b = tk.Button(f, text="Apply", bg="#d9d9d9", command=self.apply) + b = ttk.Button(f, text="Apply", command=self.apply) b.grid(row=0, column=0, padx=10, pady=2, sticky="nsew") - b = tk.Button(f, text="Cancel", bg="#d9d9d9", command=self.destroy) + b = ttk.Button(f, text="Cancel", command=self.destroy) b.grid(row=0, column=1, padx=10, pady=2, sticky="nsew") f.grid(sticky="nsew") diff --git a/coretk/coretk/dialogs/hooks.py b/coretk/coretk/dialogs/hooks.py index 99647635..5ae9da8a 100644 --- a/coretk/coretk/dialogs/hooks.py +++ b/coretk/coretk/dialogs/hooks.py @@ -19,14 +19,14 @@ class HookDialog(Dialog): self.rowconfigure(1, weight=1) # name and states - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(row=0, sticky="ew", pady=2) frame.columnconfigure(0, weight=2) frame.columnconfigure(1, weight=7) frame.columnconfigure(2, weight=1) - label = tk.Label(frame, text="Name") + label = ttk.Label(frame, text="Name") label.grid(row=0, column=0, sticky="ew") - entry = tk.Entry(frame, textvariable=self.name) + entry = ttk.Entry(frame, textvariable=self.name) entry.grid(row=0, column=1, sticky="ew") values = tuple(x for x in core_pb2.SessionState.Enum.keys() if x != "NONE") initial_state = core_pb2.SessionState.Enum.Name(core_pb2.SessionState.RUNTIME) @@ -39,7 +39,7 @@ class HookDialog(Dialog): combobox.bind("<>", self.state_change) # data - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.columnconfigure(0, weight=1) frame.rowconfigure(0, weight=1) frame.grid(row=1, sticky="nsew", pady=2) @@ -53,19 +53,19 @@ class HookDialog(Dialog): ), ) self.data.grid(row=0, column=0, sticky="nsew") - scrollbar = tk.Scrollbar(frame) + scrollbar = ttk.Scrollbar(frame) scrollbar.grid(row=0, column=1, sticky="ns") self.data.config(yscrollcommand=scrollbar.set) scrollbar.config(command=self.data.yview) # button row - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(row=2, sticky="ew", pady=2) for i in range(2): frame.columnconfigure(i, weight=1) - button = tk.Button(frame, text="Save", command=lambda: self.save()) + button = ttk.Button(frame, text="Save", command=lambda: self.save()) button.grid(row=0, column=0, sticky="ew") - button = tk.Button(frame, text="Cancel", command=lambda: self.destroy()) + button = ttk.Button(frame, text="Cancel", command=lambda: self.destroy()) button.grid(row=0, column=1, sticky="ew") def state_change(self, event): @@ -106,21 +106,21 @@ class HooksDialog(Dialog): self.listbox.bind("<>", self.select) for hook_file in self.app.core.hooks: self.listbox.insert(tk.END, hook_file) - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(row=1, sticky="ew") for i in range(4): frame.columnconfigure(i, weight=1) - button = tk.Button(frame, text="Create", command=self.click_create) + button = ttk.Button(frame, text="Create", command=self.click_create) button.grid(row=0, column=0, sticky="ew") - self.edit_button = tk.Button( + self.edit_button = ttk.Button( frame, text="Edit", state=tk.DISABLED, command=self.click_edit ) self.edit_button.grid(row=0, column=1, sticky="ew") - self.delete_button = tk.Button( + self.delete_button = ttk.Button( frame, text="Delete", state=tk.DISABLED, command=self.click_delete ) self.delete_button.grid(row=0, column=2, sticky="ew") - button = tk.Button(frame, text="Cancel", command=lambda: self.destroy()) + button = ttk.Button(frame, text="Cancel", command=lambda: self.destroy()) button.grid(row=0, column=3, sticky="ew") def click_create(self): diff --git a/coretk/coretk/dialogs/icondialog.py b/coretk/coretk/dialogs/icondialog.py index bf7b08cf..fb6fb6bb 100644 --- a/coretk/coretk/dialogs/icondialog.py +++ b/coretk/coretk/dialogs/icondialog.py @@ -1,5 +1,5 @@ import tkinter as tk -from tkinter import filedialog +from tkinter import filedialog, ttk from coretk.appconfig import ICONS_PATH from coretk.dialogs.dialog import Dialog @@ -18,30 +18,30 @@ class IconDialog(Dialog): self.columnconfigure(0, weight=1) # row one - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(row=0, column=0, pady=2, sticky="ew") frame.columnconfigure(0, weight=1) frame.columnconfigure(1, weight=3) - label = tk.Label(frame, text="Image") + label = ttk.Label(frame, text="Image") label.grid(row=0, column=0, sticky="ew") - entry = tk.Entry(frame, textvariable=self.file_path) + entry = ttk.Entry(frame, textvariable=self.file_path) entry.grid(row=0, column=1, sticky="ew") - button = tk.Button(frame, text="...", command=self.click_file) + button = ttk.Button(frame, text="...", command=self.click_file) button.grid(row=0, column=2) # row two - self.image_label = tk.Label(self, image=self.image) + self.image_label = ttk.Label(self, image=self.image, anchor=tk.CENTER) self.image_label.grid(row=1, column=0, pady=2, sticky="ew") # row three - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(row=2, column=0, sticky="ew") frame.columnconfigure(0, weight=1) frame.columnconfigure(1, weight=1) - button = tk.Button(frame, text="Apply", command=self.destroy) + button = ttk.Button(frame, text="Apply", command=self.destroy) button.grid(row=0, column=0, sticky="ew") - button = tk.Button(frame, text="Cancel", command=self.click_cancel) + button = ttk.Button(frame, text="Cancel", command=self.click_cancel) button.grid(row=0, column=1, sticky="ew") def click_file(self): diff --git a/coretk/coretk/dialogs/observers.py b/coretk/coretk/dialogs/observers.py index 6546493d..6c57f08e 100644 --- a/coretk/coretk/dialogs/observers.py +++ b/coretk/coretk/dialogs/observers.py @@ -1,4 +1,5 @@ import tkinter as tk +from tkinter import ttk from coretk.coreclient import Observer from coretk.dialogs.dialog import Dialog @@ -25,12 +26,12 @@ class ObserverDialog(Dialog): self.draw_apply_buttons() def draw_listbox(self): - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(sticky="nsew") frame.columnconfigure(0, weight=1) frame.rowconfigure(0, weight=1) - scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL) + scrollbar = ttk.Scrollbar(frame, orient=tk.VERTICAL) scrollbar.grid(row=0, column=1, sticky="ns") self.observers = tk.Listbox( @@ -44,49 +45,49 @@ class ObserverDialog(Dialog): scrollbar.config(command=self.observers.yview) def draw_form_fields(self): - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(sticky="ew") frame.columnconfigure(1, weight=1) - label = tk.Label(frame, text="Name") + label = ttk.Label(frame, text="Name") label.grid(row=0, column=0, sticky="w") - entry = tk.Entry(frame, textvariable=self.name) + entry = ttk.Entry(frame, textvariable=self.name) entry.grid(row=0, column=1, sticky="ew") - label = tk.Label(frame, text="Command") + label = ttk.Label(frame, text="Command") label.grid(row=1, column=0, sticky="w") - entry = tk.Entry(frame, textvariable=self.cmd) + entry = ttk.Entry(frame, textvariable=self.cmd) entry.grid(row=1, column=1, sticky="ew") def draw_config_buttons(self): - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(pady=2, sticky="ew") for i in range(3): frame.columnconfigure(i, weight=1) - button = tk.Button(frame, text="Create", command=self.click_create) + button = ttk.Button(frame, text="Create", command=self.click_create) button.grid(row=0, column=0, sticky="ew") - self.save_button = tk.Button( + self.save_button = ttk.Button( frame, text="Save", state=tk.DISABLED, command=self.click_save ) self.save_button.grid(row=0, column=1, sticky="ew") - self.delete_button = tk.Button( + self.delete_button = ttk.Button( frame, text="Delete", state=tk.DISABLED, command=self.click_delete ) self.delete_button.grid(row=0, column=2, sticky="ew") def draw_apply_buttons(self): - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(sticky="ew") for i in range(2): frame.columnconfigure(i, weight=1) - button = tk.Button(frame, text="Save", command=self.click_save_config) + button = ttk.Button(frame, text="Save", command=self.click_save_config) button.grid(row=0, column=0, sticky="ew") - button = tk.Button(frame, text="Cancel", command=self.destroy) + button = ttk.Button(frame, text="Cancel", command=self.destroy) button.grid(row=0, column=1, sticky="ew") def click_save_config(self): diff --git a/coretk/coretk/dialogs/servers.py b/coretk/coretk/dialogs/servers.py index c917ddf2..25f3e826 100644 --- a/coretk/coretk/dialogs/servers.py +++ b/coretk/coretk/dialogs/servers.py @@ -1,4 +1,5 @@ import tkinter as tk +from tkinter import ttk from coretk.coreclient import CoreServer from coretk.dialogs.dialog import Dialog @@ -30,12 +31,12 @@ class ServersDialog(Dialog): self.draw_apply_buttons() def draw_servers(self): - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(pady=2, sticky="nsew") frame.columnconfigure(0, weight=1) frame.rowconfigure(0, weight=1) - scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL) + scrollbar = ttk.Scrollbar(frame, orient=tk.VERTICAL) scrollbar.grid(row=0, column=1, sticky="ns") self.servers = tk.Listbox( @@ -50,61 +51,61 @@ class ServersDialog(Dialog): scrollbar.config(command=self.servers.yview) def draw_server_configuration(self): - label = tk.Label(self, text="Server Configuration") + label = ttk.Label(self, text="Server Configuration") label.grid(pady=2, sticky="ew") - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(pady=2, sticky="ew") frame.columnconfigure(1, weight=1) frame.columnconfigure(3, weight=1) frame.columnconfigure(5, weight=1) - label = tk.Label(frame, text="Name") + label = ttk.Label(frame, text="Name") label.grid(row=0, column=0, sticky="w") - entry = tk.Entry(frame, textvariable=self.name) + entry = ttk.Entry(frame, textvariable=self.name) entry.grid(row=0, column=1, sticky="ew") - label = tk.Label(frame, text="Address") + label = ttk.Label(frame, text="Address") label.grid(row=0, column=2, sticky="w") - entry = tk.Entry(frame, textvariable=self.address) + entry = ttk.Entry(frame, textvariable=self.address) entry.grid(row=0, column=3, sticky="ew") - label = tk.Label(frame, text="Port") + label = ttk.Label(frame, text="Port") label.grid(row=0, column=4, sticky="w") - entry = tk.Entry(frame, textvariable=self.port) + entry = ttk.Entry(frame, textvariable=self.port) entry.grid(row=0, column=5, sticky="ew") def draw_servers_buttons(self): - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(pady=2, sticky="ew") for i in range(3): frame.columnconfigure(i, weight=1) - button = tk.Button(frame, text="Create", command=self.click_create) + button = ttk.Button(frame, text="Create", command=self.click_create) button.grid(row=0, column=0, sticky="ew") - self.save_button = tk.Button( + self.save_button = ttk.Button( frame, text="Save", state=tk.DISABLED, command=self.click_save ) self.save_button.grid(row=0, column=1, sticky="ew") - self.delete_button = tk.Button( + self.delete_button = ttk.Button( frame, text="Delete", state=tk.DISABLED, command=self.click_delete ) self.delete_button.grid(row=0, column=2, sticky="ew") def draw_apply_buttons(self): - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(sticky="ew") for i in range(2): frame.columnconfigure(i, weight=1) - button = tk.Button( + button = ttk.Button( frame, text="Save Configuration", command=self.click_save_configuration ) button.grid(row=0, column=0, sticky="ew") - button = tk.Button(frame, text="Cancel", command=self.destroy) + button = ttk.Button(frame, text="Cancel", command=self.destroy) button.grid(row=0, column=1, sticky="ew") def click_save_configuration(self): diff --git a/coretk/coretk/dialogs/sessionoptions.py b/coretk/coretk/dialogs/sessionoptions.py index 8702d581..45f26a58 100644 --- a/coretk/coretk/dialogs/sessionoptions.py +++ b/coretk/coretk/dialogs/sessionoptions.py @@ -1,5 +1,5 @@ import logging -import tkinter as tk +from tkinter import ttk from coretk.dialogs.dialog import Dialog from coretk.widgets import ConfigFrame @@ -26,13 +26,13 @@ class SessionOptionsDialog(Dialog): self.config_frame.draw_config() self.config_frame.grid(sticky="nsew") - frame = tk.Frame(self) + frame = ttk.Frame(self) frame.grid(sticky="ew") for i in range(2): frame.columnconfigure(i, weight=1) - button = tk.Button(frame, text="Save", command=self.save) + button = ttk.Button(frame, text="Save", command=self.save) button.grid(row=0, column=0, pady=PAD_Y, padx=PAD_X, sticky="ew") - button = tk.Button(frame, text="Cancel", command=self.destroy) + button = ttk.Button(frame, text="Cancel", command=self.destroy) button.grid(row=0, column=1, pady=PAD_Y, padx=PAD_X, sticky="ew") def save(self): diff --git a/coretk/coretk/dialogs/sessions.py b/coretk/coretk/dialogs/sessions.py index b7c4d128..40d09c44 100644 --- a/coretk/coretk/dialogs/sessions.py +++ b/coretk/coretk/dialogs/sessions.py @@ -1,6 +1,6 @@ import logging import tkinter as tk -from tkinter.ttk import Scrollbar, Treeview +from tkinter import ttk from core.api.grpc import core_pb2 from coretk.dialogs.dialog import Dialog @@ -9,12 +9,6 @@ from coretk.images import ImageEnum, Images class SessionsDialog(Dialog): def __init__(self, master, app): - """ - create session table instance - - :param coretk.coreclient.CoreClient grpc: coregrpc - :param root.master master: - """ super().__init__(master, app, "Sessions", modal=True) self.selected = False self.selected_id = None @@ -32,7 +26,7 @@ class SessionsDialog(Dialog): write a short description :return: nothing """ - label = tk.Label( + label = ttk.Label( self, text="Below is a list of active CORE sessions. Double-click to \n" "connect to an existing session. Usually, only sessions in \n" @@ -42,7 +36,9 @@ class SessionsDialog(Dialog): label.grid(row=0, sticky="ew", pady=5) def draw_tree(self): - self.tree = Treeview(self, columns=("id", "state", "nodes"), show="headings") + self.tree = ttk.Treeview( + self, columns=("id", "state", "nodes"), show="headings" + ) self.tree.grid(row=1, sticky="nsew") self.tree.column("id", stretch=tk.YES) self.tree.heading("id", text="ID") @@ -64,20 +60,20 @@ class SessionsDialog(Dialog): self.tree.bind("", self.on_selected) self.tree.bind("<>", self.click_select) - yscrollbar = Scrollbar(self, orient="vertical", command=self.tree.yview) + yscrollbar = ttk.Scrollbar(self, orient="vertical", command=self.tree.yview) yscrollbar.grid(row=1, column=1, sticky="ns") self.tree.configure(yscrollcommand=yscrollbar.set) - xscrollbar = Scrollbar(self, orient="horizontal", command=self.tree.xview) + xscrollbar = ttk.Scrollbar(self, 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 = tk.Frame(self) + frame = ttk.Frame(self) for i in range(4): frame.columnconfigure(i, weight=1) frame.grid(row=3, sticky="ew") - b = tk.Button( + b = ttk.Button( frame, image=Images.get(ImageEnum.DOCUMENTNEW), text="New", @@ -85,7 +81,7 @@ class SessionsDialog(Dialog): command=self.click_new, ) b.grid(row=0, padx=2, sticky="ew") - b = tk.Button( + b = ttk.Button( frame, image=Images.get(ImageEnum.FILEOPEN), text="Connect", @@ -93,7 +89,7 @@ class SessionsDialog(Dialog): command=self.click_connect, ) b.grid(row=0, column=1, padx=2, sticky="ew") - b = tk.Button( + b = ttk.Button( frame, image=Images.get(ImageEnum.EDITDELETE), text="Shutdown", @@ -101,7 +97,7 @@ class SessionsDialog(Dialog): command=self.click_shutdown, ) b.grid(row=0, column=2, padx=2, sticky="ew") - b = tk.Button(frame, text="Cancel", command=self.click_new) + b = ttk.Button(frame, text="Cancel", command=self.click_new) b.grid(row=0, column=3, padx=2, sticky="ew") def click_new(self): diff --git a/coretk/coretk/widgets.py b/coretk/coretk/widgets.py index 236dbc24..9ae9e851 100644 --- a/coretk/coretk/widgets.py +++ b/coretk/coretk/widgets.py @@ -26,7 +26,7 @@ class FrameScroll(tk.LabelFrame): self.canvas.grid(row=0, sticky="nsew", padx=2, pady=2) self.canvas.columnconfigure(0, weight=1) self.canvas.rowconfigure(0, weight=1) - self.scrollbar = tk.Scrollbar( + self.scrollbar = ttk.Scrollbar( self, orient="vertical", command=self.canvas.yview ) self.scrollbar.grid(row=0, column=1, sticky="ns") @@ -70,11 +70,11 @@ class ConfigFrame(FrameScroll): for group_name in sorted(group_mapping): group = group_mapping[group_name] - frame = tk.Frame(self.frame) + frame = ttk.Frame(self.frame) frame.columnconfigure(1, weight=1) self.frame.add(frame, text=group_name) for index, option in enumerate(sorted(group, key=lambda x: x.name)): - label = tk.Label(frame, text=option.label) + label = ttk.Label(frame, text=option.label) label.grid(row=index, pady=pady, padx=padx, sticky="w") value = tk.StringVar() if option.type == core_pb2.ConfigOptionType.BOOL: @@ -96,15 +96,15 @@ class ConfigFrame(FrameScroll): combobox.grid(row=index, column=1, sticky="ew", pady=pady) elif option.type == core_pb2.ConfigOptionType.STRING: value.set(option.value) - entry = tk.Entry(frame, textvariable=value) + entry = ttk.Entry(frame, textvariable=value) entry.grid(row=index, column=1, sticky="ew", pady=pady) elif option.type in INT_TYPES: value.set(option.value) - entry = tk.Entry(frame, textvariable=value) + entry = ttk.Entry(frame, textvariable=value) entry.grid(row=index, column=1, sticky="ew", pady=pady) elif option.type == core_pb2.ConfigOptionType.FLOAT: value.set(option.value) - entry = tk.Entry(frame, textvariable=value) + entry = ttk.Entry(frame, textvariable=value) entry.grid(row=index, column=1, sticky="ew", pady=pady) else: logging.error("unhandled config option type: %s", option.type) @@ -131,7 +131,7 @@ class ListboxScroll(tk.LabelFrame): super().__init__(master, cnf, **kw) self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) - self.scrollbar = tk.Scrollbar(self, orient=tk.VERTICAL) + self.scrollbar = ttk.Scrollbar(self, orient=tk.VERTICAL) self.scrollbar.grid(row=0, column=1, sticky="ns") self.listbox = tk.Listbox( self, selectmode=tk.SINGLE, yscrollcommand=self.scrollbar.set @@ -149,5 +149,5 @@ class CheckboxList(FrameScroll): def add(self, name, checked): var = tk.BooleanVar(value=checked) func = partial(self.clicked, name, var) - checkbox = tk.Checkbutton(self.frame, text=name, variable=var, command=func) + checkbox = ttk.Checkbutton(self.frame, text=name, variable=var, command=func) checkbox.grid(sticky="w")