From 899eb51c55bc2b71f575e183709a1537fafa237b Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Wed, 11 Dec 2019 14:36:27 -0800 Subject: [PATCH] added common padding for x, y, and frame paddings, to easily modify and provide consistent look and feel --- coretk/coretk/appconfig.py | 2 +- coretk/coretk/dialogs/canvassizeandscale.py | 60 +++++++++++---------- coretk/coretk/dialogs/canvaswallpaper.py | 17 +++--- coretk/coretk/dialogs/customnodes.py | 31 ++++++----- coretk/coretk/dialogs/dialog.py | 3 +- coretk/coretk/dialogs/emaneconfig.py | 23 ++++---- coretk/coretk/dialogs/hooks.py | 19 ++++--- coretk/coretk/dialogs/icondialog.py | 13 +++-- coretk/coretk/dialogs/mobilityconfig.py | 7 ++- coretk/coretk/dialogs/mobilityplayer.py | 16 +++--- coretk/coretk/dialogs/nodeconfig.py | 29 +++++----- coretk/coretk/dialogs/nodeservice.py | 19 ++++--- coretk/coretk/dialogs/observers.py | 19 ++++--- coretk/coretk/dialogs/preferences.py | 17 +++--- coretk/coretk/dialogs/servers.py | 22 ++++---- coretk/coretk/dialogs/sessionoptions.py | 10 ++-- coretk/coretk/dialogs/sessions.py | 17 +++--- coretk/coretk/dialogs/shapemod.py | 19 ++++--- coretk/coretk/dialogs/wlanconfig.py | 7 ++- coretk/coretk/themes.py | 8 ++- coretk/coretk/widgets.py | 24 ++++----- 21 files changed, 189 insertions(+), 193 deletions(-) diff --git a/coretk/coretk/appconfig.py b/coretk/coretk/appconfig.py index 0617562a..b2606994 100644 --- a/coretk/coretk/appconfig.py +++ b/coretk/coretk/appconfig.py @@ -75,7 +75,7 @@ def check_directory(): editor = EDITORS[1] config = { "preferences": { - "theme": themes.DARK, + "theme": themes.THEME_DARK, "editor": editor, "terminal": terminal, "gui3d": "/usr/local/bin/std3d.sh", diff --git a/coretk/coretk/dialogs/canvassizeandscale.py b/coretk/coretk/dialogs/canvassizeandscale.py index 1fcfff59..5a472104 100644 --- a/coretk/coretk/dialogs/canvassizeandscale.py +++ b/coretk/coretk/dialogs/canvassizeandscale.py @@ -5,8 +5,8 @@ import tkinter as tk from tkinter import font, ttk from coretk.dialogs.dialog import Dialog +from coretk.themes import FRAME_PAD, PADX, PADY -PAD = 5 PIXEL_SCALE = 100 @@ -50,17 +50,17 @@ class SizeAndScaleDialog(Dialog): self.draw_buttons() def draw_size(self): - label_frame = ttk.Labelframe(self.top, text="Size", padding=PAD) + label_frame = ttk.Labelframe(self.top, text="Size", padding=FRAME_PAD) label_frame.grid(sticky="ew") label_frame.columnconfigure(0, weight=1) # draw size row 1 frame = ttk.Frame(label_frame) - frame.grid(sticky="ew", pady=3) + frame.grid(sticky="ew", pady=PADY) frame.columnconfigure(1, weight=1) frame.columnconfigure(3, weight=1) label = ttk.Label(frame, text="Width") - label.grid(row=0, column=0, sticky="w", padx=PAD) + label.grid(row=0, column=0, sticky="w", padx=PADX) entry = ttk.Entry( frame, textvariable=self.pixel_width, @@ -68,9 +68,9 @@ class SizeAndScaleDialog(Dialog): validatecommand=(self.validation.positive_int, "%P"), ) entry.bind("", lambda event: self.validation.focus_out(event, "0")) - entry.grid(row=0, column=1, sticky="ew", padx=PAD) + entry.grid(row=0, column=1, sticky="ew", padx=PADX) label = ttk.Label(frame, text="x Height") - label.grid(row=0, column=2, sticky="w", padx=PAD) + label.grid(row=0, column=2, sticky="w", padx=PADX) entry = ttk.Entry( frame, textvariable=self.pixel_height, @@ -78,17 +78,17 @@ class SizeAndScaleDialog(Dialog): validatecommand=(self.validation.positive_int, "%P"), ) entry.bind("", lambda event: self.validation.focus_out(event, "0")) - entry.grid(row=0, column=3, sticky="ew", padx=PAD) + entry.grid(row=0, column=3, sticky="ew", padx=PADX) label = ttk.Label(frame, text="Pixels") label.grid(row=0, column=4, sticky="w") # draw size row 2 frame = ttk.Frame(label_frame) - frame.grid(sticky="ew", pady=3) + frame.grid(sticky="ew", pady=PADY) frame.columnconfigure(1, weight=1) frame.columnconfigure(3, weight=1) label = ttk.Label(frame, text="Width") - label.grid(row=0, column=0, sticky="w", padx=PAD) + label.grid(row=0, column=0, sticky="w", padx=PADX) entry = ttk.Entry( frame, textvariable=self.meters_width, @@ -96,9 +96,9 @@ class SizeAndScaleDialog(Dialog): validatecommand=(self.validation.positive_float, "%P"), ) entry.bind("", lambda event: self.validation.focus_out(event, "0")) - entry.grid(row=0, column=1, sticky="ew", padx=PAD) + entry.grid(row=0, column=1, sticky="ew", padx=PADX) label = ttk.Label(frame, text="x Height") - label.grid(row=0, column=2, sticky="w", padx=PAD) + label.grid(row=0, column=2, sticky="w", padx=PADX) entry = ttk.Entry( frame, textvariable=self.meters_height, @@ -106,12 +106,12 @@ class SizeAndScaleDialog(Dialog): validatecommand=(self.validation.positive_float, "%P"), ) entry.bind("", lambda event: self.validation.focus_out(event, "0")) - entry.grid(row=0, column=3, sticky="ew", padx=PAD) + entry.grid(row=0, column=3, sticky="ew", padx=PADX) label = ttk.Label(frame, text="Meters") label.grid(row=0, column=4, sticky="w") def draw_scale(self): - label_frame = ttk.Labelframe(self.top, text="Scale", padding=PAD) + label_frame = ttk.Labelframe(self.top, text="Scale", padding=FRAME_PAD) label_frame.grid(sticky="ew") label_frame.columnconfigure(0, weight=1) @@ -119,7 +119,7 @@ class SizeAndScaleDialog(Dialog): frame.grid(sticky="ew") frame.columnconfigure(1, weight=1) label = ttk.Label(frame, text=f"{PIXEL_SCALE} Pixels =") - label.grid(row=0, column=0, sticky="w", padx=PAD) + label.grid(row=0, column=0, sticky="w", padx=PADX) entry = ttk.Entry( frame, textvariable=self.scale, @@ -127,12 +127,14 @@ class SizeAndScaleDialog(Dialog): validatecommand=(self.validation.positive_float, "%P"), ) entry.bind("", lambda event: self.validation.focus_out(event, "0")) - entry.grid(row=0, column=1, sticky="ew", padx=PAD) + entry.grid(row=0, column=1, sticky="ew", padx=PADX) label = ttk.Label(frame, text="Meters") label.grid(row=0, column=2, sticky="w") def draw_reference_point(self): - label_frame = ttk.Labelframe(self.top, text="Reference Point", padding=PAD) + label_frame = ttk.Labelframe( + self.top, text="Reference Point", padding=FRAME_PAD + ) label_frame.grid(sticky="ew") label_frame.columnconfigure(0, weight=1) @@ -142,12 +144,12 @@ class SizeAndScaleDialog(Dialog): label.grid() frame = ttk.Frame(label_frame) - frame.grid(sticky="ew", pady=3) + frame.grid(sticky="ew", pady=PADY) frame.columnconfigure(1, weight=1) frame.columnconfigure(3, weight=1) label = ttk.Label(frame, text="X") - label.grid(row=0, column=0, sticky="w", padx=PAD) + label.grid(row=0, column=0, sticky="w", padx=PADX) entry = ttk.Entry( frame, textvariable=self.x, @@ -155,10 +157,10 @@ class SizeAndScaleDialog(Dialog): validatecommand=(self.validation.positive_float, "%P"), ) entry.bind("", lambda event: self.validation.focus_out(event, "0")) - entry.grid(row=0, column=1, sticky="ew", padx=PAD) + entry.grid(row=0, column=1, sticky="ew", padx=PADX) label = ttk.Label(frame, text="Y") - label.grid(row=0, column=2, sticky="w", padx=PAD) + label.grid(row=0, column=2, sticky="w", padx=PADX) entry = ttk.Entry( frame, textvariable=self.y, @@ -166,19 +168,19 @@ class SizeAndScaleDialog(Dialog): validatecommand=(self.validation.positive_float, "%P"), ) entry.bind("", lambda event: self.validation.focus_out(event, "0")) - entry.grid(row=0, column=3, sticky="ew", padx=PAD) + entry.grid(row=0, column=3, sticky="ew", padx=PADX) label = ttk.Label(label_frame, text="Translates To") label.grid() frame = ttk.Frame(label_frame) - frame.grid(sticky="ew", pady=3) + frame.grid(sticky="ew", pady=PADY) frame.columnconfigure(1, weight=1) frame.columnconfigure(3, weight=1) frame.columnconfigure(5, weight=1) label = ttk.Label(frame, text="Lat") - label.grid(row=0, column=0, sticky="w", padx=PAD) + label.grid(row=0, column=0, sticky="w", padx=PADX) entry = ttk.Entry( frame, textvariable=self.lat, @@ -186,10 +188,10 @@ class SizeAndScaleDialog(Dialog): validatecommand=(self.validation.positive_float, "%P"), ) entry.bind("", lambda event: self.validation.focus_out(event, "0")) - entry.grid(row=0, column=1, sticky="ew", padx=PAD) + entry.grid(row=0, column=1, sticky="ew", padx=PADX) label = ttk.Label(frame, text="Lon") - label.grid(row=0, column=2, sticky="w", padx=PAD) + label.grid(row=0, column=2, sticky="w", padx=PADX) entry = ttk.Entry( frame, textvariable=self.lon, @@ -197,10 +199,10 @@ class SizeAndScaleDialog(Dialog): validatecommand=(self.validation.positive_float, "%P"), ) entry.bind("", lambda event: self.validation.focus_out(event, "0")) - entry.grid(row=0, column=3, sticky="ew", padx=PAD) + entry.grid(row=0, column=3, sticky="ew", padx=PADX) label = ttk.Label(frame, text="Alt") - label.grid(row=0, column=4, sticky="w", padx=PAD) + label.grid(row=0, column=4, sticky="w", padx=PADX) entry = ttk.Entry( frame, textvariable=self.alt, @@ -214,7 +216,7 @@ class SizeAndScaleDialog(Dialog): button = ttk.Checkbutton( self.top, text="Save as default?", variable=self.save_default ) - button.grid(sticky="w", pady=3) + button.grid(sticky="w", pady=PADY) def draw_buttons(self): frame = ttk.Frame(self.top) @@ -223,7 +225,7 @@ class SizeAndScaleDialog(Dialog): frame.grid(sticky="ew") button = ttk.Button(frame, text="Apply", command=self.click_apply) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + 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") diff --git a/coretk/coretk/dialogs/canvaswallpaper.py b/coretk/coretk/dialogs/canvaswallpaper.py index bf6bf922..923e4d5f 100644 --- a/coretk/coretk/dialogs/canvaswallpaper.py +++ b/coretk/coretk/dialogs/canvaswallpaper.py @@ -8,8 +8,7 @@ from tkinter import filedialog, ttk from coretk.appconfig import BACKGROUNDS_PATH from coretk.dialogs.dialog import Dialog from coretk.images import Images - -PAD = 5 +from coretk.themes import PADX, PADY class CanvasBackgroundDialog(Dialog): @@ -43,7 +42,7 @@ class CanvasBackgroundDialog(Dialog): self.image_label = ttk.Label( self.top, text="(image preview)", width=32, anchor=tk.CENTER ) - self.image_label.grid(pady=PAD) + self.image_label.grid(pady=PADY) def draw_image_label(self): label = ttk.Label(self.top, text="Image filename: ") @@ -60,10 +59,10 @@ class CanvasBackgroundDialog(Dialog): entry = ttk.Entry(frame, textvariable=self.filename) entry.focus() - entry.grid(row=0, column=0, sticky="ew", padx=PAD) + entry.grid(row=0, column=0, sticky="ew", padx=PADX) button = ttk.Button(frame, text="...", command=self.click_open_image) - button.grid(row=0, column=1, sticky="ew", padx=PAD) + button.grid(row=0, column=1, sticky="ew", padx=PADX) button = ttk.Button(frame, text="Clear", command=self.click_clear) button.grid(row=0, column=2, sticky="ew") @@ -104,7 +103,7 @@ class CanvasBackgroundDialog(Dialog): checkbutton = ttk.Checkbutton( self.top, text="Show grid", variable=self.show_grid ) - checkbutton.grid(sticky="ew", padx=PAD) + checkbutton.grid(sticky="ew", padx=PADX) checkbutton = ttk.Checkbutton( self.top, @@ -112,16 +111,16 @@ class CanvasBackgroundDialog(Dialog): variable=self.adjust_to_dim, command=self.click_adjust_canvas, ) - checkbutton.grid(sticky="ew", padx=PAD) + checkbutton.grid(sticky="ew", padx=PADX) def draw_buttons(self): frame = ttk.Frame(self.top) - frame.grid(pady=PAD, sticky="ew") + frame.grid(pady=PADY, sticky="ew") frame.columnconfigure(0, weight=1) frame.columnconfigure(1, weight=1) button = ttk.Button(frame, text="Apply", command=self.click_apply) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + 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") diff --git a/coretk/coretk/dialogs/customnodes.py b/coretk/coretk/dialogs/customnodes.py index 75052e6b..d17d8d19 100644 --- a/coretk/coretk/dialogs/customnodes.py +++ b/coretk/coretk/dialogs/customnodes.py @@ -6,10 +6,9 @@ from tkinter import ttk from coretk.dialogs.dialog import Dialog from coretk.dialogs.icondialog import IconDialog from coretk.nodeutils import NodeDraw +from coretk.themes import FRAME_PAD, PADX, PADY from coretk.widgets import CheckboxList, ListboxScroll -PAD = 5 - class ServicesSelectDialog(Dialog): def __init__(self, master, app, current_services): @@ -25,11 +24,11 @@ class ServicesSelectDialog(Dialog): self.top.rowconfigure(0, weight=1) frame = ttk.Frame(self.top) - frame.grid(stick="nsew", pady=PAD) + frame.grid(stick="nsew", pady=PADY) frame.rowconfigure(0, weight=1) for i in range(3): frame.columnconfigure(i, weight=1) - self.groups = ListboxScroll(frame, text="Groups", padding=PAD) + self.groups = ListboxScroll(frame, text="Groups", padding=FRAME_PAD) self.groups.grid(row=0, column=0, sticky="nsew") for group in sorted(self.app.core.services): self.groups.listbox.insert(tk.END, group) @@ -37,11 +36,15 @@ class ServicesSelectDialog(Dialog): self.groups.listbox.selection_set(0) self.services = CheckboxList( - frame, self.app, text="Services", clicked=self.service_clicked, padding=PAD + frame, + self.app, + text="Services", + clicked=self.service_clicked, + padding=FRAME_PAD, ) self.services.grid(row=0, column=1, sticky="nsew") - self.current = ListboxScroll(frame, text="Selected", padding=PAD) + self.current = ListboxScroll(frame, text="Selected", padding=FRAME_PAD) self.current.grid(row=0, column=2, sticky="nsew") for service in sorted(self.current_services): self.current.listbox.insert(tk.END, service) @@ -51,7 +54,7 @@ class ServicesSelectDialog(Dialog): for i in range(2): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Save", command=self.destroy) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + button.grid(row=0, column=0, sticky="ew", padx=PADX) button = ttk.Button(frame, text="Cancel", command=self.click_cancel) button.grid(row=0, column=1, sticky="ew") @@ -106,12 +109,12 @@ class CustomNodesDialog(Dialog): def draw_node_config(self): frame = ttk.Frame(self.top) - frame.grid(sticky="nsew", pady=PAD) + frame.grid(sticky="nsew", pady=PADY) frame.columnconfigure(0, weight=1) frame.rowconfigure(0, weight=1) - self.nodes_list = ListboxScroll(frame, text="Nodes", padding=PAD) - self.nodes_list.grid(row=0, column=0, sticky="nsew", padx=PAD) + self.nodes_list = ListboxScroll(frame, text="Nodes", padding=FRAME_PAD) + self.nodes_list.grid(row=0, column=0, sticky="nsew", padx=PADX) self.nodes_list.listbox.bind("<>", self.handle_node_select) for name in sorted(self.app.core.custom_nodes): self.nodes_list.listbox.insert(tk.END, name) @@ -130,17 +133,17 @@ class CustomNodesDialog(Dialog): def draw_node_buttons(self): frame = ttk.Frame(self.top) - frame.grid(sticky="ew", pady=PAD) + frame.grid(sticky="ew", pady=PADY) for i in range(3): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Create", command=self.click_create) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + button.grid(row=0, column=0, sticky="ew", padx=PADX) 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", padx=PAD) + self.edit_button.grid(row=0, column=1, sticky="ew", padx=PADX) self.delete_button = ttk.Button( frame, text="Delete", state=tk.DISABLED, command=self.click_delete @@ -154,7 +157,7 @@ class CustomNodesDialog(Dialog): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Save", command=self.click_save) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + 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") diff --git a/coretk/coretk/dialogs/dialog.py b/coretk/coretk/dialogs/dialog.py index 49662cc4..92d9a7db 100644 --- a/coretk/coretk/dialogs/dialog.py +++ b/coretk/coretk/dialogs/dialog.py @@ -2,8 +2,7 @@ import tkinter as tk from tkinter import ttk from coretk.images import ImageEnum, Images - -DIALOG_PAD = 5 +from coretk.themes import DIALOG_PAD class Dialog(tk.Toplevel): diff --git a/coretk/coretk/dialogs/emaneconfig.py b/coretk/coretk/dialogs/emaneconfig.py index b16f7cd4..a1c30a6f 100644 --- a/coretk/coretk/dialogs/emaneconfig.py +++ b/coretk/coretk/dialogs/emaneconfig.py @@ -11,10 +11,9 @@ import grpc from coretk.dialogs.dialog import Dialog from coretk.errors import show_grpc_error from coretk.images import ImageEnum, Images +from coretk.themes import PADX, PADY from coretk.widgets import ConfigFrame -PAD = 5 - class GlobalEmaneDialog(Dialog): def __init__(self, master, app): @@ -27,7 +26,7 @@ class GlobalEmaneDialog(Dialog): self.top.rowconfigure(0, weight=1) self.config_frame = ConfigFrame(self.top, self.app, self.app.core.emane_config) self.config_frame.draw_config() - self.config_frame.grid(sticky="nsew", pady=PAD) + self.config_frame.grid(sticky="nsew", pady=PADY) self.draw_spacer() self.draw_buttons() @@ -37,7 +36,7 @@ class GlobalEmaneDialog(Dialog): for i in range(2): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Apply", command=self.click_apply) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + 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") @@ -68,7 +67,7 @@ class EmaneModelDialog(Dialog): self.top.rowconfigure(0, weight=1) self.config_frame = ConfigFrame(self.top, self.app, self.config) self.config_frame.draw_config() - self.config_frame.grid(sticky="nsew", pady=PAD) + self.config_frame.grid(sticky="nsew", pady=PADY) self.draw_spacer() self.draw_buttons() @@ -78,7 +77,7 @@ class EmaneModelDialog(Dialog): for i in range(2): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Apply", command=self.click_apply) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + 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") @@ -126,7 +125,7 @@ class EmaneConfigDialog(Dialog): "\nusing pluggable MAC and PHY modules. Refer to the wiki for configuration option details", justify=tk.CENTER, ) - label.grid(pady=PAD) + label.grid(pady=PADY) image = Images.get(ImageEnum.EDITNODE, 16) button = ttk.Button( @@ -139,7 +138,7 @@ class EmaneConfigDialog(Dialog): ), ) button.image = image - button.grid(sticky="ew", pady=PAD) + button.grid(sticky="ew", pady=PADY) def draw_emane_models(self): """ @@ -148,7 +147,7 @@ class EmaneConfigDialog(Dialog): :return: nothing """ frame = ttk.Frame(self.top) - frame.grid(sticky="ew", pady=PAD) + frame.grid(sticky="ew", pady=PADY) frame.columnconfigure(1, weight=1) label = ttk.Label(frame, text="Model") @@ -166,7 +165,7 @@ class EmaneConfigDialog(Dialog): def draw_emane_buttons(self): frame = ttk.Frame(self.top) - frame.grid(sticky="ew", pady=PAD) + frame.grid(sticky="ew", pady=PADY) for i in range(2): frame.columnconfigure(i, weight=1) @@ -179,7 +178,7 @@ class EmaneConfigDialog(Dialog): command=self.click_model_config, ) self.emane_model_button.image = image - self.emane_model_button.grid(row=0, column=0, padx=PAD, sticky="ew") + self.emane_model_button.grid(row=0, column=0, padx=PADX, sticky="ew") image = Images.get(ImageEnum.EDITNODE, 16) button = ttk.Button( @@ -199,7 +198,7 @@ class EmaneConfigDialog(Dialog): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Apply", command=self.click_apply) - button.grid(row=0, column=0, padx=PAD, sticky="ew") + button.grid(row=0, column=0, padx=PADX, sticky="ew") button = ttk.Button(frame, text="Cancel", command=self.destroy) button.grid(row=0, column=1, sticky="ew") diff --git a/coretk/coretk/dialogs/hooks.py b/coretk/coretk/dialogs/hooks.py index 2850d70e..40101823 100644 --- a/coretk/coretk/dialogs/hooks.py +++ b/coretk/coretk/dialogs/hooks.py @@ -3,10 +3,9 @@ from tkinter import ttk from core.api.grpc import core_pb2 from coretk.dialogs.dialog import Dialog +from coretk.themes import PADX, PADY from coretk.widgets import CodeText -PAD = 5 - class HookDialog(Dialog): def __init__(self, master, app): @@ -23,14 +22,14 @@ class HookDialog(Dialog): # name and states frame = ttk.Frame(self.top) - frame.grid(sticky="ew", pady=PAD) + frame.grid(sticky="ew", pady=PADY) frame.columnconfigure(0, weight=2) frame.columnconfigure(1, weight=7) frame.columnconfigure(2, weight=1) label = ttk.Label(frame, text="Name") - label.grid(row=0, column=0, sticky="ew", padx=PAD) + label.grid(row=0, column=0, sticky="ew", padx=PADX) entry = ttk.Entry(frame, textvariable=self.name) - entry.grid(row=0, column=1, sticky="ew", padx=PAD) + entry.grid(row=0, column=1, sticky="ew", padx=PADX) 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) self.state.set(initial_state) @@ -59,7 +58,7 @@ class HookDialog(Dialog): for i in range(2): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Save", command=lambda: self.save()) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + button.grid(row=0, column=0, sticky="ew", padx=PADX) button = ttk.Button(frame, text="Cancel", command=lambda: self.destroy()) button.grid(row=0, column=1, sticky="ew") @@ -98,7 +97,7 @@ class HooksDialog(Dialog): self.top.rowconfigure(0, weight=1) self.listbox = tk.Listbox(self.top) - self.listbox.grid(sticky="nsew", pady=PAD) + self.listbox.grid(sticky="nsew", pady=PADY) self.listbox.bind("<>", self.select) for hook_file in self.app.core.hooks: self.listbox.insert(tk.END, hook_file) @@ -108,15 +107,15 @@ class HooksDialog(Dialog): for i in range(4): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Create", command=self.click_create) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + button.grid(row=0, column=0, sticky="ew", padx=PADX) 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", padx=PAD) + self.edit_button.grid(row=0, column=1, sticky="ew", padx=PADX) 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", padx=PAD) + self.delete_button.grid(row=0, column=2, sticky="ew", padx=PADX) button = ttk.Button(frame, text="Cancel", command=lambda: self.destroy()) button.grid(row=0, column=3, sticky="ew") diff --git a/coretk/coretk/dialogs/icondialog.py b/coretk/coretk/dialogs/icondialog.py index 9273a177..ecbb5d54 100644 --- a/coretk/coretk/dialogs/icondialog.py +++ b/coretk/coretk/dialogs/icondialog.py @@ -5,8 +5,7 @@ from coretk import nodeutils from coretk.appconfig import ICONS_PATH from coretk.dialogs.dialog import Dialog from coretk.images import Images - -PAD = 5 +from coretk.themes import PADX, PADY class IconDialog(Dialog): @@ -22,19 +21,19 @@ class IconDialog(Dialog): # row one frame = ttk.Frame(self.top) - frame.grid(pady=PAD, sticky="ew") + frame.grid(pady=PADY, sticky="ew") frame.columnconfigure(0, weight=1) frame.columnconfigure(1, weight=3) label = ttk.Label(frame, text="Image") - label.grid(row=0, column=0, sticky="ew", padx=PAD) + label.grid(row=0, column=0, sticky="ew", padx=PADX) entry = ttk.Entry(frame, textvariable=self.file_path) - entry.grid(row=0, column=1, sticky="ew", padx=PAD) + entry.grid(row=0, column=1, sticky="ew", padx=PADX) button = ttk.Button(frame, text="...", command=self.click_file) button.grid(row=0, column=2) # row two self.image_label = ttk.Label(self.top, image=self.image, anchor=tk.CENTER) - self.image_label.grid(pady=PAD, sticky="ew") + self.image_label.grid(pady=PADY, sticky="ew") # spacer self.draw_spacer() @@ -45,7 +44,7 @@ class IconDialog(Dialog): frame.columnconfigure(0, weight=1) frame.columnconfigure(1, weight=1) button = ttk.Button(frame, text="Apply", command=self.destroy) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + button.grid(row=0, column=0, sticky="ew", padx=PADX) button = ttk.Button(frame, text="Cancel", command=self.click_cancel) button.grid(row=0, column=1, sticky="ew") diff --git a/coretk/coretk/dialogs/mobilityconfig.py b/coretk/coretk/dialogs/mobilityconfig.py index 007209dd..19dc46f4 100644 --- a/coretk/coretk/dialogs/mobilityconfig.py +++ b/coretk/coretk/dialogs/mobilityconfig.py @@ -7,10 +7,9 @@ import grpc from coretk.dialogs.dialog import Dialog from coretk.errors import show_grpc_error +from coretk.themes import PADX, PADY from coretk.widgets import ConfigFrame -PAD = 5 - class MobilityConfigDialog(Dialog): def __init__(self, master, app, canvas_node): @@ -35,7 +34,7 @@ class MobilityConfigDialog(Dialog): self.top.rowconfigure(0, weight=1) self.config_frame = ConfigFrame(self.top, self.app, self.config) self.config_frame.draw_config() - self.config_frame.grid(sticky="nsew", pady=PAD) + self.config_frame.grid(sticky="nsew", pady=PADY) self.draw_apply_buttons() def draw_apply_buttons(self): @@ -45,7 +44,7 @@ class MobilityConfigDialog(Dialog): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Apply", command=self.click_apply) - button.grid(row=0, column=0, padx=PAD, sticky="ew") + button.grid(row=0, column=0, padx=PADX, sticky="ew") button = ttk.Button(frame, text="Cancel", command=self.destroy) button.grid(row=0, column=1, sticky="ew") diff --git a/coretk/coretk/dialogs/mobilityplayer.py b/coretk/coretk/dialogs/mobilityplayer.py index 1e7b4dc1..f0b46499 100644 --- a/coretk/coretk/dialogs/mobilityplayer.py +++ b/coretk/coretk/dialogs/mobilityplayer.py @@ -7,8 +7,8 @@ from core.api.grpc.core_pb2 import MobilityAction from coretk.dialogs.dialog import Dialog from coretk.errors import show_grpc_error from coretk.images import ImageEnum, Images +from coretk.themes import PADX, PADY -PAD = 5 ICON_SIZE = 16 @@ -77,36 +77,36 @@ class MobilityPlayerDialog(Dialog): file_name = self.config["file"].value label = ttk.Label(self.top, text=file_name) - label.grid(sticky="ew", pady=PAD) + label.grid(sticky="ew", pady=PADY) self.progressbar = ttk.Progressbar(self.top, mode="indeterminate") - self.progressbar.grid(sticky="ew", pady=PAD) + self.progressbar.grid(sticky="ew", pady=PADY) frame = ttk.Frame(self.top) - frame.grid(sticky="ew", pady=PAD) + frame.grid(sticky="ew", pady=PADY) for i in range(3): frame.columnconfigure(i, weight=1) image = Images.get(ImageEnum.START, width=ICON_SIZE) self.play_button = ttk.Button(frame, image=image, command=self.click_play) self.play_button.image = image - self.play_button.grid(row=0, column=0, sticky="ew", padx=PAD) + self.play_button.grid(row=0, column=0, sticky="ew", padx=PADX) image = Images.get(ImageEnum.PAUSE, width=ICON_SIZE) self.pause_button = ttk.Button(frame, image=image, command=self.click_pause) self.pause_button.image = image - self.pause_button.grid(row=0, column=1, sticky="ew", padx=PAD) + self.pause_button.grid(row=0, column=1, sticky="ew", padx=PADX) image = Images.get(ImageEnum.STOP, width=ICON_SIZE) self.stop_button = ttk.Button(frame, image=image, command=self.click_stop) self.stop_button.image = image - self.stop_button.grid(row=0, column=2, sticky="ew", padx=PAD) + self.stop_button.grid(row=0, column=2, sticky="ew", padx=PADX) loop = tk.IntVar(value=int(self.config["loop"].value == "1")) checkbutton = ttk.Checkbutton( frame, text="Loop?", variable=loop, state=tk.DISABLED ) - checkbutton.grid(row=0, column=3, padx=PAD) + checkbutton.grid(row=0, column=3, padx=PADX) rate = self.config["refresh_ms"].value label = ttk.Label(frame, text=f"rate {rate} ms") diff --git a/coretk/coretk/dialogs/nodeconfig.py b/coretk/coretk/dialogs/nodeconfig.py index 619c5ee7..56c2a08d 100644 --- a/coretk/coretk/dialogs/nodeconfig.py +++ b/coretk/coretk/dialogs/nodeconfig.py @@ -7,10 +7,9 @@ from coretk.dialogs.dialog import Dialog from coretk.dialogs.icondialog import IconDialog from coretk.dialogs.nodeservice import NodeService from coretk.nodeutils import NodeUtils +from coretk.themes import FRAME_PAD, PADX, PADY from coretk.widgets import FrameScroll -PAD = 5 - def mac_auto(is_auto, entry): logging.info("mac auto clicked") @@ -68,7 +67,7 @@ class NodeConfigDialog(Dialog): # icon field label = ttk.Label(frame, text="Icon") - label.grid(row=row, column=0, sticky="ew", padx=PAD, pady=PAD) + label.grid(row=row, column=0, sticky="ew", padx=PADX, pady=PADY) self.image_button = ttk.Button( frame, text="Icon", @@ -81,7 +80,7 @@ class NodeConfigDialog(Dialog): # name field label = ttk.Label(frame, text="Name") - label.grid(row=row, column=0, sticky="ew", padx=PAD, pady=PAD) + label.grid(row=row, column=0, sticky="ew", padx=PADX, pady=PADY) entry = ttk.Entry( frame, textvariable=self.name, @@ -97,7 +96,7 @@ class NodeConfigDialog(Dialog): # node type field if NodeUtils.is_model_node(self.node.type): label = ttk.Label(frame, text="Type") - label.grid(row=row, column=0, sticky="ew", padx=PAD, pady=PAD) + label.grid(row=row, column=0, sticky="ew", padx=PADX, pady=PADY) combobox = ttk.Combobox( frame, textvariable=self.type, @@ -110,7 +109,7 @@ class NodeConfigDialog(Dialog): # container image field if NodeUtils.is_image_node(self.node.type): label = ttk.Label(frame, text="Image") - label.grid(row=row, column=0, sticky="ew", padx=PAD, pady=PAD) + label.grid(row=row, column=0, sticky="ew", padx=PADX, pady=PADY) entry = ttk.Entry(frame, textvariable=self.container_image) entry.grid(row=row, column=1, sticky="ew") row += 1 @@ -120,7 +119,7 @@ class NodeConfigDialog(Dialog): frame.grid(sticky="ew") frame.columnconfigure(1, weight=1) label = ttk.Label(frame, text="Server") - label.grid(row=row, column=0, sticky="ew", padx=PAD, pady=PAD) + label.grid(row=row, column=0, sticky="ew", padx=PADX, pady=PADY) servers = ["localhost"] servers.extend(list(sorted(self.app.core.servers.keys()))) combobox = ttk.Combobox( @@ -131,7 +130,7 @@ class NodeConfigDialog(Dialog): # services button = ttk.Button(self.top, text="Services", command=self.click_services) - button.grid(sticky="ew", pady=PAD) + button.grid(sticky="ew", pady=PADY) # interfaces if self.canvas_node.interfaces: @@ -147,17 +146,17 @@ class NodeConfigDialog(Dialog): scroll.frame.rowconfigure(0, weight=1) for interface in self.canvas_node.interfaces: logging.info("interface: %s", interface) - frame = ttk.LabelFrame(scroll.frame, text=interface.name, padding=PAD) - frame.grid(sticky="ew", pady=PAD) + frame = ttk.LabelFrame(scroll.frame, text=interface.name, padding=FRAME_PAD) + frame.grid(sticky="ew", pady=PADY) frame.columnconfigure(1, weight=1) frame.columnconfigure(2, weight=1) label = ttk.Label(frame, text="MAC") - label.grid(row=0, column=0, padx=PAD, pady=PAD) + label.grid(row=0, column=0, padx=PADX, pady=PADY) is_auto = tk.BooleanVar(value=True) checkbutton = ttk.Checkbutton(frame, text="Auto?", variable=is_auto) checkbutton.var = is_auto - checkbutton.grid(row=0, column=1, padx=PAD) + checkbutton.grid(row=0, column=1, padx=PADX) mac = tk.StringVar(value=interface.mac) entry = ttk.Entry(frame, textvariable=mac, state=tk.DISABLED) entry.grid(row=0, column=2, sticky="ew") @@ -165,14 +164,14 @@ class NodeConfigDialog(Dialog): checkbutton.config(command=func) label = ttk.Label(frame, text="IPv4") - label.grid(row=1, column=0, padx=PAD, pady=PAD) + label.grid(row=1, column=0, padx=PADX, pady=PADY) ip4 = tk.StringVar(value=f"{interface.ip4}/{interface.ip4mask}") entry = ttk.Entry(frame, textvariable=ip4) entry.bind("", self.app.validation.ip_focus_out) entry.grid(row=1, column=1, columnspan=2, sticky="ew") label = ttk.Label(frame, text="IPv6") - label.grid(row=2, column=0, padx=PAD, pady=PAD) + label.grid(row=2, column=0, padx=PADX, pady=PADY) ip6 = tk.StringVar(value=f"{interface.ip6}/{interface.ip6mask}") entry = ttk.Entry(frame, textvariable=ip6) entry.bind("", self.app.validation.ip_focus_out) @@ -187,7 +186,7 @@ class NodeConfigDialog(Dialog): frame.columnconfigure(1, weight=1) button = ttk.Button(frame, text="Apply", command=self.config_apply) - button.grid(row=0, column=0, padx=2, sticky="ew") + button.grid(row=0, column=0, padx=PADX, sticky="ew") button = ttk.Button(frame, text="Cancel", command=self.destroy) button.grid(row=0, column=1, sticky="ew") diff --git a/coretk/coretk/dialogs/nodeservice.py b/coretk/coretk/dialogs/nodeservice.py index dfcef922..c49aea50 100644 --- a/coretk/coretk/dialogs/nodeservice.py +++ b/coretk/coretk/dialogs/nodeservice.py @@ -6,10 +6,9 @@ from tkinter import messagebox, ttk from coretk.dialogs.dialog import Dialog from coretk.dialogs.serviceconfiguration import ServiceConfiguration +from coretk.themes import FRAME_PAD, PADX, PADY from coretk.widgets import CheckboxList, ListboxScroll -PAD = 5 - class NodeService(Dialog): def __init__(self, master, app, canvas_node, services=None): @@ -36,11 +35,11 @@ class NodeService(Dialog): self.top.rowconfigure(0, weight=1) frame = ttk.Frame(self.top) - frame.grid(stick="nsew") + frame.grid(stick="nsew", pady=PADY) frame.rowconfigure(0, weight=1) for i in range(3): frame.columnconfigure(i, weight=1) - self.groups = ListboxScroll(frame, text="Groups", padding=PAD) + self.groups = ListboxScroll(frame, text="Groups", padding=FRAME_PAD) self.groups.grid(row=0, column=0, sticky="nsew") for group in sorted(self.app.core.services): self.groups.listbox.insert(tk.END, group) @@ -48,11 +47,15 @@ class NodeService(Dialog): self.groups.listbox.selection_set(0) self.services = CheckboxList( - frame, self.app, text="Services", clicked=self.service_clicked, padding=PAD + frame, + self.app, + text="Services", + clicked=self.service_clicked, + padding=FRAME_PAD, ) self.services.grid(row=0, column=1, sticky="nsew") - self.current = ListboxScroll(frame, text="Selected", padding=PAD) + self.current = ListboxScroll(frame, text="Selected", padding=FRAME_PAD) self.current.grid(row=0, column=2, sticky="nsew") for service in sorted(self.current_services): self.current.listbox.insert(tk.END, service) @@ -62,9 +65,9 @@ class NodeService(Dialog): for i in range(3): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Configure", command=self.click_configure) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + button.grid(row=0, column=0, sticky="ew", padx=PADX) button = ttk.Button(frame, text="Save", command=self.click_save) - button.grid(row=0, column=1, sticky="ew", padx=PAD) + button.grid(row=0, column=1, sticky="ew", padx=PADX) button = ttk.Button(frame, text="Cancel", command=self.click_cancel) button.grid(row=0, column=2, sticky="ew") diff --git a/coretk/coretk/dialogs/observers.py b/coretk/coretk/dialogs/observers.py index 525939e0..f496f7ef 100644 --- a/coretk/coretk/dialogs/observers.py +++ b/coretk/coretk/dialogs/observers.py @@ -3,8 +3,7 @@ from tkinter import ttk from coretk.coreclient import Observer from coretk.dialogs.dialog import Dialog - -PAD = 5 +from coretk.themes import PADX, PADY class ObserverDialog(Dialog): @@ -29,7 +28,7 @@ class ObserverDialog(Dialog): def draw_listbox(self): frame = ttk.Frame(self.top) - frame.grid(sticky="nsew", pady=PAD) + frame.grid(sticky="nsew", pady=PADY) frame.columnconfigure(0, weight=1) frame.rowconfigure(0, weight=1) @@ -48,32 +47,32 @@ class ObserverDialog(Dialog): def draw_form_fields(self): frame = ttk.Frame(self.top) - frame.grid(sticky="ew", pady=PAD) + frame.grid(sticky="ew", pady=PADY) frame.columnconfigure(1, weight=1) label = ttk.Label(frame, text="Name") - label.grid(row=0, column=0, sticky="w", padx=PAD) + label.grid(row=0, column=0, sticky="w", padx=PADX) entry = ttk.Entry(frame, textvariable=self.name) entry.grid(row=0, column=1, sticky="ew") label = ttk.Label(frame, text="Command") - label.grid(row=1, column=0, sticky="w", padx=PAD) + label.grid(row=1, column=0, sticky="w", padx=PADX) entry = ttk.Entry(frame, textvariable=self.cmd) entry.grid(row=1, column=1, sticky="ew") def draw_config_buttons(self): frame = ttk.Frame(self.top) - frame.grid(sticky="ew", pady=PAD) + frame.grid(sticky="ew", pady=PADY) for i in range(3): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Create", command=self.click_create) - button.grid(row=0, column=0, sticky="ew") + button.grid(row=0, column=0, sticky="ew", padx=PADX) 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.save_button.grid(row=0, column=1, sticky="ew", padx=PADX) self.delete_button = ttk.Button( frame, text="Delete", state=tk.DISABLED, command=self.click_delete @@ -87,7 +86,7 @@ class ObserverDialog(Dialog): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Save", command=self.click_save_config) - button.grid(row=0, column=0, sticky="ew") + 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") diff --git a/coretk/coretk/dialogs/preferences.py b/coretk/coretk/dialogs/preferences.py index b094eec6..8c369027 100644 --- a/coretk/coretk/dialogs/preferences.py +++ b/coretk/coretk/dialogs/preferences.py @@ -4,8 +4,7 @@ from tkinter import ttk from coretk import appconfig from coretk.dialogs.dialog import Dialog - -PAD = 5 +from coretk.themes import FRAME_PAD, PADX, PADY class PreferencesDialog(Dialog): @@ -25,12 +24,12 @@ class PreferencesDialog(Dialog): self.draw_buttons() def draw_preferences(self): - frame = ttk.LabelFrame(self.top, text="Preferences", padding=PAD) - frame.grid(sticky="nsew", pady=2) + frame = ttk.LabelFrame(self.top, text="Preferences", padding=FRAME_PAD) + frame.grid(sticky="nsew", pady=PADY) frame.columnconfigure(1, weight=1) label = ttk.Label(frame, text="Theme") - label.grid(row=0, column=0, pady=PAD, padx=PAD, sticky="w") + label.grid(row=0, column=0, pady=PADY, padx=PADX, sticky="w") themes = self.app.style.theme_names() combobox = ttk.Combobox( frame, textvariable=self.theme, values=themes, state="readonly" @@ -40,14 +39,14 @@ class PreferencesDialog(Dialog): combobox.bind("<>", self.theme_change) label = ttk.Label(frame, text="Editor") - label.grid(row=1, column=0, pady=PAD, padx=PAD, sticky="w") + label.grid(row=1, column=0, pady=PADY, padx=PADX, sticky="w") combobox = ttk.Combobox( frame, textvariable=self.editor, values=appconfig.EDITORS, state="readonly" ) combobox.grid(row=1, column=1, sticky="ew") label = ttk.Label(frame, text="Terminal") - label.grid(row=2, column=0, pady=PAD, padx=PAD, sticky="w") + label.grid(row=2, column=0, pady=PADY, padx=PADX, sticky="w") combobox = ttk.Combobox( frame, textvariable=self.terminal, @@ -57,7 +56,7 @@ class PreferencesDialog(Dialog): combobox.grid(row=2, column=1, sticky="ew") label = ttk.Label(frame, text="3D GUI") - label.grid(row=3, column=0, pady=PAD, padx=PAD, sticky="w") + label.grid(row=3, column=0, pady=PADY, padx=PADX, sticky="w") entry = ttk.Entry(frame, textvariable=self.gui3d) entry.grid(row=3, column=1, sticky="ew") @@ -68,7 +67,7 @@ class PreferencesDialog(Dialog): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Save", command=self.click_save) - button.grid(row=0, column=0, sticky="ew") + 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") diff --git a/coretk/coretk/dialogs/servers.py b/coretk/coretk/dialogs/servers.py index 18c5d6d1..ef406ecb 100644 --- a/coretk/coretk/dialogs/servers.py +++ b/coretk/coretk/dialogs/servers.py @@ -3,8 +3,8 @@ from tkinter import ttk from coretk.coreclient import CoreServer from coretk.dialogs.dialog import Dialog +from coretk.themes import FRAME_PAD, PADX, PADY -PAD = 5 DEFAULT_NAME = "example" DEFAULT_ADDRESS = "127.0.0.1" DEFAULT_PORT = 50051 @@ -33,7 +33,7 @@ class ServersDialog(Dialog): def draw_servers(self): frame = ttk.Frame(self.top) - frame.grid(pady=PAD, sticky="nsew") + frame.grid(pady=PADY, sticky="nsew") frame.columnconfigure(0, weight=1) frame.rowconfigure(0, weight=1) @@ -52,24 +52,24 @@ class ServersDialog(Dialog): scrollbar.config(command=self.servers.yview) def draw_server_configuration(self): - frame = ttk.LabelFrame(self.top, text="Server Configuration", padding=PAD) - frame.grid(pady=PAD, sticky="ew") + frame = ttk.LabelFrame(self.top, text="Server Configuration", padding=FRAME_PAD) + frame.grid(pady=PADY, sticky="ew") frame.columnconfigure(1, weight=1) frame.columnconfigure(3, weight=1) frame.columnconfigure(5, weight=1) label = ttk.Label(frame, text="Name") - label.grid(row=0, column=0, sticky="w", padx=PAD, pady=PAD) + label.grid(row=0, column=0, sticky="w", padx=PADX, pady=PADY) entry = ttk.Entry(frame, textvariable=self.name) entry.grid(row=0, column=1, sticky="ew") label = ttk.Label(frame, text="Address") - label.grid(row=0, column=2, sticky="w", padx=PAD, pady=PAD) + label.grid(row=0, column=2, sticky="w", padx=PADX, pady=PADY) entry = ttk.Entry(frame, textvariable=self.address) entry.grid(row=0, column=3, sticky="ew") label = ttk.Label(frame, text="Port") - label.grid(row=0, column=4, sticky="w", padx=PAD, pady=PAD) + label.grid(row=0, column=4, sticky="w", padx=PADX, pady=PADY) entry = ttk.Entry( frame, textvariable=self.port, @@ -83,17 +83,17 @@ class ServersDialog(Dialog): def draw_servers_buttons(self): frame = ttk.Frame(self.top) - frame.grid(pady=PAD, sticky="ew") + frame.grid(pady=PADY, sticky="ew") for i in range(3): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Create", command=self.click_create) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + button.grid(row=0, column=0, sticky="ew", padx=PADX) 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", padx=PAD) + self.save_button.grid(row=0, column=1, sticky="ew", padx=PADX) self.delete_button = ttk.Button( frame, text="Delete", state=tk.DISABLED, command=self.click_delete @@ -109,7 +109,7 @@ class ServersDialog(Dialog): button = ttk.Button( frame, text="Save Configuration", command=self.click_save_configuration ) - button.grid(row=0, column=0, sticky="ew", padx=PAD) + 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") diff --git a/coretk/coretk/dialogs/sessionoptions.py b/coretk/coretk/dialogs/sessionoptions.py index 7c77f9df..24ff7381 100644 --- a/coretk/coretk/dialogs/sessionoptions.py +++ b/coretk/coretk/dialogs/sessionoptions.py @@ -5,11 +5,9 @@ import grpc from coretk.dialogs.dialog import Dialog from coretk.errors import show_grpc_error +from coretk.themes import PADX, PADY from coretk.widgets import ConfigFrame -PAD_X = 2 -PAD_Y = 2 - class SessionOptionsDialog(Dialog): def __init__(self, master, app): @@ -33,16 +31,16 @@ class SessionOptionsDialog(Dialog): self.config_frame = ConfigFrame(self.top, self.app, config=self.config) self.config_frame.draw_config() - self.config_frame.grid(sticky="nsew") + self.config_frame.grid(sticky="nsew", pady=PADY) 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.save) - button.grid(row=0, column=0, pady=PAD_Y, padx=PAD_X, sticky="ew") + button.grid(row=0, column=0, padx=PADX, sticky="ew") button = ttk.Button(frame, text="Cancel", command=self.destroy) - button.grid(row=0, column=1, pady=PAD_Y, padx=PAD_X, sticky="ew") + button.grid(row=0, column=1, padx=PADX, sticky="ew") def save(self): config = self.config_frame.parse_config() diff --git a/coretk/coretk/dialogs/sessions.py b/coretk/coretk/dialogs/sessions.py index f8d26667..b1fb970f 100644 --- a/coretk/coretk/dialogs/sessions.py +++ b/coretk/coretk/dialogs/sessions.py @@ -9,8 +9,7 @@ from core.api.grpc import core_pb2 from coretk.dialogs.dialog import Dialog from coretk.errors import show_grpc_error from coretk.images import ImageEnum, Images - -PAD = 5 +from coretk.themes import PADX, PADY class SessionsDialog(Dialog): @@ -51,13 +50,13 @@ class SessionsDialog(Dialog): "one you might be concurrently editting.", justify=tk.CENTER, ) - label.grid(pady=PAD) + label.grid(pady=PADY) def draw_tree(self): frame = ttk.Frame(self.top) frame.columnconfigure(0, weight=1) frame.rowconfigure(0, weight=1) - frame.grid(sticky="nsew") + frame.grid(sticky="nsew", pady=PADY) self.tree = ttk.Treeview( frame, columns=("id", "state", "nodes"), show="headings" ) @@ -85,7 +84,7 @@ class SessionsDialog(Dialog): self.tree.configure(yscrollcommand=yscrollbar.set) xscrollbar = ttk.Scrollbar(frame, orient="horizontal", command=self.tree.xview) - xscrollbar.grid(row=1, sticky="ew", pady=5) + xscrollbar.grid(row=1, sticky="ew") self.tree.configure(xscrollcommand=xscrollbar.set) def draw_buttons(self): @@ -99,7 +98,7 @@ class SessionsDialog(Dialog): frame, image=image, text="New", compound=tk.LEFT, command=self.click_new ) b.image = image - b.grid(row=0, padx=2, sticky="ew") + b.grid(row=0, padx=PADX, sticky="ew") image = Images.get(ImageEnum.FILEOPEN, 16) b = ttk.Button( @@ -110,7 +109,7 @@ class SessionsDialog(Dialog): command=self.click_connect, ) b.image = image - b.grid(row=0, column=1, padx=2, sticky="ew") + b.grid(row=0, column=1, padx=PADX, sticky="ew") image = Images.get(ImageEnum.EDITDELETE, 16) b = ttk.Button( @@ -121,10 +120,10 @@ class SessionsDialog(Dialog): command=self.click_shutdown, ) b.image = image - b.grid(row=0, column=2, padx=2, sticky="ew") + b.grid(row=0, column=2, padx=PADX, sticky="ew") b = ttk.Button(frame, text="Cancel", command=self.click_new) - b.grid(row=0, column=3, padx=2, sticky="ew") + b.grid(row=0, column=3, sticky="ew") def click_new(self): self.app.core.create_new_session() diff --git a/coretk/coretk/dialogs/shapemod.py b/coretk/coretk/dialogs/shapemod.py index 63037c9d..a6da0e3b 100644 --- a/coretk/coretk/dialogs/shapemod.py +++ b/coretk/coretk/dialogs/shapemod.py @@ -7,9 +7,8 @@ from tkinter import colorchooser, font, ttk from coretk.dialogs.dialog import Dialog from coretk.graph import tags from coretk.graph.shapeutils import is_draw_shape, is_shape_text +from coretk.themes import FRAME_PAD, PADX, PADY -PADX = (0, 5) -PAD = 5 FONT_SIZES = [8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72] BORDER_WIDTH = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] @@ -50,16 +49,16 @@ class ShapeDialog(Dialog): self.draw_buttons() def draw_label_options(self): - label_frame = ttk.LabelFrame(self.top, text="Label", padding=PAD) + label_frame = ttk.LabelFrame(self.top, text="Label", padding=FRAME_PAD) label_frame.grid(sticky="ew") label_frame.columnconfigure(0, weight=1) entry = ttk.Entry(label_frame, textvariable=self.shape_text) - entry.grid(sticky="ew", pady=PAD) + entry.grid(sticky="ew", pady=PADY) # font options frame = ttk.Frame(label_frame) - frame.grid(sticky="nsew", padx=3, pady=3) + frame.grid(sticky="nsew", pady=PADY) frame.columnconfigure(0, weight=1) frame.columnconfigure(1, weight=1) frame.columnconfigure(2, weight=1) @@ -73,7 +72,7 @@ class ShapeDialog(Dialog): combobox = ttk.Combobox( frame, textvariable=self.font_size, values=FONT_SIZES, state="readonly" ) - combobox.grid(row=0, column=1, padx=3, sticky="nsew") + combobox.grid(row=0, column=1, padx=PADX, sticky="nsew") button = ttk.Button(frame, text="Color", command=self.choose_text_color) button.grid(row=0, column=2, sticky="nsew") @@ -85,13 +84,13 @@ class ShapeDialog(Dialog): button = ttk.Checkbutton(frame, variable=self.bold, text="Bold") button.grid(row=0, column=0, sticky="ew") button = ttk.Checkbutton(frame, variable=self.italic, text="Italic") - button.grid(row=0, column=1, padx=3, sticky="ew") + button.grid(row=0, column=1, padx=PADX, sticky="ew") button = ttk.Checkbutton(frame, variable=self.underline, text="Underline") button.grid(row=0, column=2, sticky="ew") def draw_shape_options(self): - label_frame = ttk.LabelFrame(self.top, text="Shape", padding=PAD) - label_frame.grid(sticky="ew", pady=PAD) + label_frame = ttk.LabelFrame(self.top, text="Shape", padding=FRAME_PAD) + label_frame.grid(sticky="ew", pady=PADY) label_frame.columnconfigure(0, weight=1) frame = ttk.Frame(label_frame) @@ -115,7 +114,7 @@ class ShapeDialog(Dialog): button.grid(row=1, column=2, sticky="ew") frame = ttk.Frame(label_frame) - frame.grid(sticky="ew", pady=PAD) + frame.grid(sticky="ew", pady=PADY) frame.columnconfigure(1, weight=1) label = ttk.Label(frame, text="Border Width") label.grid(row=0, column=0, sticky="w", padx=PADX) diff --git a/coretk/coretk/dialogs/wlanconfig.py b/coretk/coretk/dialogs/wlanconfig.py index 711f94f0..aed411b8 100644 --- a/coretk/coretk/dialogs/wlanconfig.py +++ b/coretk/coretk/dialogs/wlanconfig.py @@ -8,10 +8,9 @@ import grpc from coretk.dialogs.dialog import Dialog from coretk.errors import show_grpc_error +from coretk.themes import PADX, PADY from coretk.widgets import ConfigFrame -PAD = 5 - class WlanConfigDialog(Dialog): def __init__(self, master, app, canvas_node): @@ -33,7 +32,7 @@ class WlanConfigDialog(Dialog): self.top.rowconfigure(0, weight=1) self.config_frame = ConfigFrame(self.top, self.app, self.config) self.config_frame.draw_config() - self.config_frame.grid(sticky="nsew", pady=PAD) + self.config_frame.grid(sticky="nsew", pady=PADY) self.draw_apply_buttons() def draw_apply_buttons(self): @@ -48,7 +47,7 @@ class WlanConfigDialog(Dialog): frame.columnconfigure(i, weight=1) button = ttk.Button(frame, text="Apply", command=self.click_apply) - button.grid(row=0, column=0, padx=PAD, sticky="ew") + button.grid(row=0, column=0, padx=PADX, sticky="ew") button = ttk.Button(frame, text="Cancel", command=self.destroy) button.grid(row=0, column=1, sticky="ew") diff --git a/coretk/coretk/themes.py b/coretk/coretk/themes.py index a870b278..cb8a8b06 100644 --- a/coretk/coretk/themes.py +++ b/coretk/coretk/themes.py @@ -1,7 +1,11 @@ import logging import tkinter as tk -DARK = "black" +THEME_DARK = "black" +PADX = (0, 5) +PADY = (0, 5) +FRAME_PAD = 5 +DIALOG_PAD = 5 class Styles: @@ -28,7 +32,7 @@ class Colors: def load(style): style.theme_create( - DARK, + THEME_DARK, "clam", { ".": { diff --git a/coretk/coretk/widgets.py b/coretk/coretk/widgets.py index e3fd5c35..cdbfea28 100644 --- a/coretk/coretk/widgets.py +++ b/coretk/coretk/widgets.py @@ -5,6 +5,7 @@ from tkinter import filedialog, font, ttk from tkinter.scrolledtext import ScrolledText from core.api.grpc import core_pb2 +from coretk.themes import FRAME_PAD, PADX, PADY INT_TYPES = { core_pb2.ConfigOptionType.UINT8, @@ -16,7 +17,6 @@ INT_TYPES = { core_pb2.ConfigOptionType.INT32, core_pb2.ConfigOptionType.INT64, } -PAD = 5 def file_button_click(value): @@ -71,8 +71,6 @@ class ConfigFrame(FrameScroll): self.values = {} def draw_config(self): - padx = 2 - pady = 2 group_mapping = {} for key in self.config: option = self.config[key] @@ -81,19 +79,19 @@ class ConfigFrame(FrameScroll): for group_name in sorted(group_mapping): group = group_mapping[group_name] - frame = ttk.Frame(self.frame, padding=PAD) + frame = ttk.Frame(self.frame, padding=FRAME_PAD) 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 = ttk.Label(frame, text=option.label) - label.grid(row=index, pady=pady, padx=padx, sticky="w") + label.grid(row=index, pady=PADY, padx=PADX, sticky="w") value = tk.StringVar() if option.type == core_pb2.ConfigOptionType.BOOL: select = tuple(option.select) combobox = ttk.Combobox( frame, textvariable=value, values=select, state="readonly" ) - combobox.grid(row=index, column=1, sticky="ew", pady=pady) + combobox.grid(row=index, column=1, sticky="ew") if option.value == "1": value.set("On") else: @@ -104,15 +102,15 @@ class ConfigFrame(FrameScroll): combobox = ttk.Combobox( frame, textvariable=value, values=select, state="readonly" ) - combobox.grid(row=index, column=1, sticky="ew", pady=pady) + combobox.grid(row=index, column=1, sticky="ew") elif option.type == core_pb2.ConfigOptionType.STRING: value.set(option.value) if "file" in option.label: file_frame = ttk.Frame(frame) - file_frame.grid(row=index, column=1, sticky="ew", pady=pady) + file_frame.grid(row=index, column=1, sticky="ew") file_frame.columnconfigure(0, weight=1) entry = ttk.Entry(file_frame, textvariable=value) - entry.grid(row=0, column=0, sticky="ew", padx=padx) + entry.grid(row=0, column=0, sticky="ew", padx=PADX) func = partial(file_button_click, value) button = ttk.Button(file_frame, text="...", command=func) button.grid(row=0, column=1) @@ -124,10 +122,10 @@ class ConfigFrame(FrameScroll): validate="key", validatecommand=(self.app.validation.ip4, "%P"), ) - entry.grid(row=index, column=1, sticky="ew", pady=pady) + entry.grid(row=index, column=1, sticky="ew") else: entry = ttk.Entry(frame, textvariable=value) - entry.grid(row=index, column=1, sticky="ew", pady=pady) + entry.grid(row=index, column=1, sticky="ew") elif option.type in INT_TYPES: value.set(option.value) @@ -141,7 +139,7 @@ class ConfigFrame(FrameScroll): "", lambda event: self.app.validation.focus_out(event, "0"), ) - entry.grid(row=index, column=1, sticky="ew", pady=pady) + entry.grid(row=index, column=1, sticky="ew") elif option.type == core_pb2.ConfigOptionType.FLOAT: value.set(option.value) entry = ttk.Entry( @@ -154,7 +152,7 @@ class ConfigFrame(FrameScroll): "", lambda event: self.app.validation.focus_out(event, "0"), ) - entry.grid(row=index, column=1, sticky="ew", pady=pady) + entry.grid(row=index, column=1, sticky="ew") else: logging.error("unhandled config option type: %s", option.type) self.values[option.name] = value