revamped codetext widget to use ttk scrollbars for better theme matching, slight adjustments to service config dialog layout

This commit is contained in:
Blake Harnden 2019-12-17 10:01:25 -08:00
parent 9c4b42f77e
commit 02695f1672
5 changed files with 49 additions and 42 deletions

View file

@ -38,7 +38,7 @@ class AboutDialog(Dialog):
self.top.columnconfigure(0, weight=1) self.top.columnconfigure(0, weight=1)
self.top.rowconfigure(0, weight=1) self.top.rowconfigure(0, weight=1)
text = CodeText(self.top) codetext = CodeText(self.top)
text.insert("1.0", LICENSE) codetext.text.insert("1.0", LICENSE)
text.config(state=tk.DISABLED) codetext.text.config(state=tk.DISABLED)
text.grid(sticky="nsew") codetext.grid(sticky="nsew")

View file

@ -17,7 +17,7 @@ class AlertsDialog(Dialog):
super().__init__(master, app, "Alerts", modal=True) super().__init__(master, app, "Alerts", modal=True)
self.app = app self.app = app
self.tree = None self.tree = None
self.text = None self.codetext = None
self.draw() self.draw()
def draw(self): def draw(self):
@ -76,9 +76,9 @@ class AlertsDialog(Dialog):
xscrollbar.grid(row=1, sticky="ew") xscrollbar.grid(row=1, sticky="ew")
self.tree.configure(xscrollcommand=xscrollbar.set) self.tree.configure(xscrollcommand=xscrollbar.set)
self.text = CodeText(self.top) self.codetext = CodeText(self.top)
self.text.config(state=tk.DISABLED) self.codetext.text.config(state=tk.DISABLED)
self.text.grid(sticky="nsew", pady=PADY) self.codetext.grid(sticky="nsew", pady=PADY)
frame = ttk.Frame(self.top) frame = ttk.Frame(self.top)
frame.grid(sticky="ew") frame.grid(sticky="ew")
@ -96,7 +96,7 @@ class AlertsDialog(Dialog):
button.grid(row=0, column=3, sticky="ew") button.grid(row=0, column=3, sticky="ew")
def reset_alerts(self): def reset_alerts(self):
self.text.delete("1.0", tk.END) self.codetext.text.delete("1.0", tk.END)
for item in self.tree.get_children(): for item in self.tree.get_children():
self.tree.delete(item) self.tree.delete(item)
self.app.statusbar.core_alarms.clear() self.app.statusbar.core_alarms.clear()
@ -137,8 +137,8 @@ class AlertsDialog(Dialog):
text = text + "node created" text = text + "node created"
except RpcError: except RpcError:
text = text + "node not created" text = text + "node not created"
self.text.delete("1.0", "end") self.codetext.text.delete("1.0", "end")
self.text.insert("1.0", text) self.codetext.text.insert("1.0", text)
class DaemonLog(Dialog): class DaemonLog(Dialog):
@ -155,8 +155,8 @@ class DaemonLog(Dialog):
frame.grid(row=0, column=0, sticky="ew", pady=PADY) frame.grid(row=0, column=0, sticky="ew", pady=PADY)
frame.columnconfigure(0, weight=1) frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=9) frame.columnconfigure(1, weight=9)
label = ttk.Label(frame, text="File: ") label = ttk.Label(frame, text="File", anchor="w")
label.grid(row=0, column=0) label.grid(row=0, column=0, sticky="ew")
entry = ttk.Entry(frame, textvariable=self.path, state="disabled") entry = ttk.Entry(frame, textvariable=self.path, state="disabled")
entry.grid(row=0, column=1, sticky="ew") entry.grid(row=0, column=1, sticky="ew")
try: try:
@ -164,8 +164,8 @@ class DaemonLog(Dialog):
log = file.readlines() log = file.readlines()
except FileNotFoundError: except FileNotFoundError:
log = "Log file not found" log = "Log file not found"
text = CodeText(self.top) codetext = CodeText(self.top)
text.insert("1.0", log) codetext.text.insert("1.0", log)
text.see("end") codetext.text.see("end")
text.config(state=tk.DISABLED) codetext.text.config(state=tk.DISABLED)
text.grid(row=1, column=0, sticky="nsew") codetext.grid(row=1, column=0, sticky="nsew")

View file

@ -11,7 +11,7 @@ class HookDialog(Dialog):
def __init__(self, master, app): def __init__(self, master, app):
super().__init__(master, app, "Hook", modal=True) super().__init__(master, app, "Hook", modal=True)
self.name = tk.StringVar() self.name = tk.StringVar()
self.data = None self.codetext = None
self.hook = core_pb2.Hook() self.hook = core_pb2.Hook()
self.state = tk.StringVar() self.state = tk.StringVar()
self.draw() self.draw()
@ -41,8 +41,8 @@ class HookDialog(Dialog):
combobox.bind("<<ComboboxSelected>>", self.state_change) combobox.bind("<<ComboboxSelected>>", self.state_change)
# data # data
self.data = CodeText(self.top) self.codetext = CodeText(self.top)
self.data.insert( self.codetext.text.insert(
1.0, 1.0,
( (
"#!/bin/sh\n" "#!/bin/sh\n"
@ -50,7 +50,7 @@ class HookDialog(Dialog):
"# specified state\n" "# specified state\n"
), ),
) )
self.data.grid(sticky="nsew") self.codetext.grid(sticky="nsew", pady=PADY)
# button row # button row
frame = ttk.Frame(self.top) frame = ttk.Frame(self.top)
@ -69,13 +69,13 @@ class HookDialog(Dialog):
def set(self, hook): def set(self, hook):
self.hook = hook self.hook = hook
self.name.set(hook.file) self.name.set(hook.file)
self.data.delete(1.0, tk.END) self.codetext.text.delete(1.0, tk.END)
self.data.insert(tk.END, hook.data) self.codetext.text.insert(tk.END, hook.data)
state_name = core_pb2.SessionState.Enum.Name(hook.state) state_name = core_pb2.SessionState.Enum.Name(hook.state)
self.state.set(state_name) self.state.set(state_name)
def save(self): def save(self):
data = self.data.get("1.0", tk.END).strip() data = self.codetext.text.get("1.0", tk.END).strip()
state_value = core_pb2.SessionState.Enum.Value(self.state.get()) state_value = core_pb2.SessionState.Enum.Value(self.state.get())
self.hook.file = self.name.get() self.hook.file = self.name.get()
self.hook.data = data self.hook.data = data

View file

@ -110,7 +110,7 @@ class ServiceConfiguration(Dialog):
# draw notebook # draw notebook
self.notebook = ttk.Notebook(self.top) self.notebook = ttk.Notebook(self.top)
self.notebook.grid(sticky="nsew") self.notebook.grid(sticky="nsew", pady=PADY)
self.draw_tab_files() self.draw_tab_files()
self.draw_tab_directories() self.draw_tab_directories()
self.draw_tab_startstop() self.draw_tab_startstop()
@ -192,11 +192,13 @@ class ServiceConfiguration(Dialog):
tab.rowconfigure(self.service_file_data.grid_info()["row"], weight=1) tab.rowconfigure(self.service_file_data.grid_info()["row"], weight=1)
if len(self.filenames) > 0: if len(self.filenames) > 0:
self.filename_combobox.current(0) self.filename_combobox.current(0)
self.service_file_data.delete(1.0, "end") self.service_file_data.text.delete(1.0, "end")
self.service_file_data.insert( self.service_file_data.text.insert(
"end", self.temp_service_files[self.filenames[0]] "end", self.temp_service_files[self.filenames[0]]
) )
self.service_file_data.bind("<FocusOut>", self.update_temp_service_file_data) self.service_file_data.text.bind(
"<FocusOut>", self.update_temp_service_file_data
)
def draw_tab_directories(self): def draw_tab_directories(self):
tab = ttk.Frame(self.notebook, padding=FRAME_PAD) tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
@ -275,14 +277,14 @@ class ServiceConfiguration(Dialog):
frame.columnconfigure(1, weight=1) frame.columnconfigure(1, weight=1)
label = ttk.Label(frame, text="Validation Time") label = ttk.Label(frame, text="Validation Time")
label.grid(row=0, column=0, sticky="w") label.grid(row=0, column=0, sticky="w", padx=PADX)
self.validation_time_entry = ttk.Entry(frame) self.validation_time_entry = ttk.Entry(frame)
self.validation_time_entry.insert("end", self.validation_time) self.validation_time_entry.insert("end", self.validation_time)
self.validation_time_entry.config(state=tk.DISABLED) self.validation_time_entry.config(state=tk.DISABLED)
self.validation_time_entry.grid(row=0, column=1, sticky="ew") self.validation_time_entry.grid(row=0, column=1, sticky="ew", pady=PADY)
label = ttk.Label(frame, text="Validation Mode") label = ttk.Label(frame, text="Validation Mode")
label.grid(row=1, column=0, sticky="w") label.grid(row=1, column=0, sticky="w", padx=PADX)
if self.validation_mode == core_pb2.ServiceValidationMode.BLOCKING: if self.validation_mode == core_pb2.ServiceValidationMode.BLOCKING:
mode = "BLOCKING" mode = "BLOCKING"
elif self.validation_mode == core_pb2.ServiceValidationMode.NON_BLOCKING: elif self.validation_mode == core_pb2.ServiceValidationMode.NON_BLOCKING:
@ -294,14 +296,14 @@ class ServiceConfiguration(Dialog):
) )
self.validation_mode_entry.insert("end", mode) self.validation_mode_entry.insert("end", mode)
self.validation_mode_entry.config(state=tk.DISABLED) self.validation_mode_entry.config(state=tk.DISABLED)
self.validation_mode_entry.grid(row=1, column=1, sticky="ew") self.validation_mode_entry.grid(row=1, column=1, sticky="ew", pady=PADY)
label = ttk.Label(frame, text="Validation Period") label = ttk.Label(frame, text="Validation Period")
label.grid(row=2, column=0, sticky="w") label.grid(row=2, column=0, sticky="w", padx=PADX)
self.validation_period_entry = ttk.Entry( self.validation_period_entry = ttk.Entry(
frame, state=tk.DISABLED, textvariable=tk.StringVar() frame, state=tk.DISABLED, textvariable=tk.StringVar()
) )
self.validation_period_entry.grid(row=2, column=1, sticky="ew") self.validation_period_entry.grid(row=2, column=1, sticky="ew", pady=PADY)
label_frame = ttk.LabelFrame(tab, text="Executables", padding=FRAME_PAD) label_frame = ttk.LabelFrame(tab, text="Executables", padding=FRAME_PAD)
label_frame.grid(sticky="nsew", pady=PADY) label_frame.grid(sticky="nsew", pady=PADY)
@ -429,8 +431,8 @@ class ServiceConfiguration(Dialog):
def display_service_file_data(self, event): def display_service_file_data(self, event):
combobox = event.widget combobox = event.widget
filename = combobox.get() filename = combobox.get()
self.service_file_data.delete(1.0, "end") self.service_file_data.text.delete(1.0, "end")
self.service_file_data.insert("end", self.temp_service_files[filename]) self.service_file_data.text.insert("end", self.temp_service_files[filename])
def update_temp_service_file_data(self, event): def update_temp_service_file_data(self, event):
scrolledtext = event.widget scrolledtext = event.widget

View file

@ -2,7 +2,6 @@ import logging
import tkinter as tk import tkinter as tk
from functools import partial from functools import partial
from tkinter import filedialog, font, ttk from tkinter import filedialog, font, ttk
from tkinter.scrolledtext import ScrolledText
from core.api.grpc import core_pb2 from core.api.grpc import core_pb2
from coretk import themes from coretk import themes
@ -208,10 +207,13 @@ class CodeFont(font.Font):
super().__init__(font="TkFixedFont", color="green") super().__init__(font="TkFixedFont", color="green")
class CodeText(ScrolledText): class CodeText(ttk.Frame):
def __init__(self, master, **kwargs): def __init__(self, master, **kwargs):
super().__init__( super().__init__(master, **kwargs)
master, self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.text = tk.Text(
self,
bd=0, bd=0,
bg="black", bg="black",
cursor="xterm lime lime", cursor="xterm lime lime",
@ -222,8 +224,11 @@ class CodeText(ScrolledText):
selectbackground="lime", selectbackground="lime",
selectforeground="black", selectforeground="black",
relief=tk.FLAT, relief=tk.FLAT,
**kwargs
) )
self.text.grid(row=0, column=0, sticky="nsew")
yscrollbar = ttk.Scrollbar(self, orient=tk.VERTICAL, command=self.text.yview)
yscrollbar.grid(row=0, column=1, sticky="ns")
self.text.configure(yscrollcommand=yscrollbar.set)
class Spinbox(ttk.Entry): class Spinbox(ttk.Entry):