revamped codetext widget to use ttk scrollbars for better theme matching, slight adjustments to service config dialog layout
This commit is contained in:
parent
9c4b42f77e
commit
02695f1672
5 changed files with 49 additions and 42 deletions
|
@ -38,7 +38,7 @@ class AboutDialog(Dialog):
|
|||
self.top.columnconfigure(0, weight=1)
|
||||
self.top.rowconfigure(0, weight=1)
|
||||
|
||||
text = CodeText(self.top)
|
||||
text.insert("1.0", LICENSE)
|
||||
text.config(state=tk.DISABLED)
|
||||
text.grid(sticky="nsew")
|
||||
codetext = CodeText(self.top)
|
||||
codetext.text.insert("1.0", LICENSE)
|
||||
codetext.text.config(state=tk.DISABLED)
|
||||
codetext.grid(sticky="nsew")
|
||||
|
|
|
@ -17,7 +17,7 @@ class AlertsDialog(Dialog):
|
|||
super().__init__(master, app, "Alerts", modal=True)
|
||||
self.app = app
|
||||
self.tree = None
|
||||
self.text = None
|
||||
self.codetext = None
|
||||
self.draw()
|
||||
|
||||
def draw(self):
|
||||
|
@ -76,9 +76,9 @@ class AlertsDialog(Dialog):
|
|||
xscrollbar.grid(row=1, sticky="ew")
|
||||
self.tree.configure(xscrollcommand=xscrollbar.set)
|
||||
|
||||
self.text = CodeText(self.top)
|
||||
self.text.config(state=tk.DISABLED)
|
||||
self.text.grid(sticky="nsew", pady=PADY)
|
||||
self.codetext = CodeText(self.top)
|
||||
self.codetext.text.config(state=tk.DISABLED)
|
||||
self.codetext.grid(sticky="nsew", pady=PADY)
|
||||
|
||||
frame = ttk.Frame(self.top)
|
||||
frame.grid(sticky="ew")
|
||||
|
@ -96,7 +96,7 @@ class AlertsDialog(Dialog):
|
|||
button.grid(row=0, column=3, sticky="ew")
|
||||
|
||||
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():
|
||||
self.tree.delete(item)
|
||||
self.app.statusbar.core_alarms.clear()
|
||||
|
@ -137,8 +137,8 @@ class AlertsDialog(Dialog):
|
|||
text = text + "node created"
|
||||
except RpcError:
|
||||
text = text + "node not created"
|
||||
self.text.delete("1.0", "end")
|
||||
self.text.insert("1.0", text)
|
||||
self.codetext.text.delete("1.0", "end")
|
||||
self.codetext.text.insert("1.0", text)
|
||||
|
||||
|
||||
class DaemonLog(Dialog):
|
||||
|
@ -155,8 +155,8 @@ class DaemonLog(Dialog):
|
|||
frame.grid(row=0, column=0, sticky="ew", pady=PADY)
|
||||
frame.columnconfigure(0, weight=1)
|
||||
frame.columnconfigure(1, weight=9)
|
||||
label = ttk.Label(frame, text="File: ")
|
||||
label.grid(row=0, column=0)
|
||||
label = ttk.Label(frame, text="File", anchor="w")
|
||||
label.grid(row=0, column=0, sticky="ew")
|
||||
entry = ttk.Entry(frame, textvariable=self.path, state="disabled")
|
||||
entry.grid(row=0, column=1, sticky="ew")
|
||||
try:
|
||||
|
@ -164,8 +164,8 @@ class DaemonLog(Dialog):
|
|||
log = file.readlines()
|
||||
except FileNotFoundError:
|
||||
log = "Log file not found"
|
||||
text = CodeText(self.top)
|
||||
text.insert("1.0", log)
|
||||
text.see("end")
|
||||
text.config(state=tk.DISABLED)
|
||||
text.grid(row=1, column=0, sticky="nsew")
|
||||
codetext = CodeText(self.top)
|
||||
codetext.text.insert("1.0", log)
|
||||
codetext.text.see("end")
|
||||
codetext.text.config(state=tk.DISABLED)
|
||||
codetext.grid(row=1, column=0, sticky="nsew")
|
||||
|
|
|
@ -11,7 +11,7 @@ class HookDialog(Dialog):
|
|||
def __init__(self, master, app):
|
||||
super().__init__(master, app, "Hook", modal=True)
|
||||
self.name = tk.StringVar()
|
||||
self.data = None
|
||||
self.codetext = None
|
||||
self.hook = core_pb2.Hook()
|
||||
self.state = tk.StringVar()
|
||||
self.draw()
|
||||
|
@ -41,8 +41,8 @@ class HookDialog(Dialog):
|
|||
combobox.bind("<<ComboboxSelected>>", self.state_change)
|
||||
|
||||
# data
|
||||
self.data = CodeText(self.top)
|
||||
self.data.insert(
|
||||
self.codetext = CodeText(self.top)
|
||||
self.codetext.text.insert(
|
||||
1.0,
|
||||
(
|
||||
"#!/bin/sh\n"
|
||||
|
@ -50,7 +50,7 @@ class HookDialog(Dialog):
|
|||
"# specified state\n"
|
||||
),
|
||||
)
|
||||
self.data.grid(sticky="nsew")
|
||||
self.codetext.grid(sticky="nsew", pady=PADY)
|
||||
|
||||
# button row
|
||||
frame = ttk.Frame(self.top)
|
||||
|
@ -69,13 +69,13 @@ class HookDialog(Dialog):
|
|||
def set(self, hook):
|
||||
self.hook = hook
|
||||
self.name.set(hook.file)
|
||||
self.data.delete(1.0, tk.END)
|
||||
self.data.insert(tk.END, hook.data)
|
||||
self.codetext.text.delete(1.0, tk.END)
|
||||
self.codetext.text.insert(tk.END, hook.data)
|
||||
state_name = core_pb2.SessionState.Enum.Name(hook.state)
|
||||
self.state.set(state_name)
|
||||
|
||||
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())
|
||||
self.hook.file = self.name.get()
|
||||
self.hook.data = data
|
||||
|
|
|
@ -110,7 +110,7 @@ class ServiceConfiguration(Dialog):
|
|||
|
||||
# draw notebook
|
||||
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_directories()
|
||||
self.draw_tab_startstop()
|
||||
|
@ -192,11 +192,13 @@ class ServiceConfiguration(Dialog):
|
|||
tab.rowconfigure(self.service_file_data.grid_info()["row"], weight=1)
|
||||
if len(self.filenames) > 0:
|
||||
self.filename_combobox.current(0)
|
||||
self.service_file_data.delete(1.0, "end")
|
||||
self.service_file_data.insert(
|
||||
self.service_file_data.text.delete(1.0, "end")
|
||||
self.service_file_data.text.insert(
|
||||
"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):
|
||||
tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
|
||||
|
@ -275,14 +277,14 @@ class ServiceConfiguration(Dialog):
|
|||
frame.columnconfigure(1, weight=1)
|
||||
|
||||
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.insert("end", self.validation_time)
|
||||
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.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:
|
||||
mode = "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.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.grid(row=2, column=0, sticky="w")
|
||||
label.grid(row=2, column=0, sticky="w", padx=PADX)
|
||||
self.validation_period_entry = ttk.Entry(
|
||||
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.grid(sticky="nsew", pady=PADY)
|
||||
|
@ -429,8 +431,8 @@ class ServiceConfiguration(Dialog):
|
|||
def display_service_file_data(self, event):
|
||||
combobox = event.widget
|
||||
filename = combobox.get()
|
||||
self.service_file_data.delete(1.0, "end")
|
||||
self.service_file_data.insert("end", self.temp_service_files[filename])
|
||||
self.service_file_data.text.delete(1.0, "end")
|
||||
self.service_file_data.text.insert("end", self.temp_service_files[filename])
|
||||
|
||||
def update_temp_service_file_data(self, event):
|
||||
scrolledtext = event.widget
|
||||
|
|
|
@ -2,7 +2,6 @@ import logging
|
|||
import tkinter as tk
|
||||
from functools import partial
|
||||
from tkinter import filedialog, font, ttk
|
||||
from tkinter.scrolledtext import ScrolledText
|
||||
|
||||
from core.api.grpc import core_pb2
|
||||
from coretk import themes
|
||||
|
@ -208,10 +207,13 @@ class CodeFont(font.Font):
|
|||
super().__init__(font="TkFixedFont", color="green")
|
||||
|
||||
|
||||
class CodeText(ScrolledText):
|
||||
class CodeText(ttk.Frame):
|
||||
def __init__(self, master, **kwargs):
|
||||
super().__init__(
|
||||
master,
|
||||
super().__init__(master, **kwargs)
|
||||
self.rowconfigure(0, weight=1)
|
||||
self.columnconfigure(0, weight=1)
|
||||
self.text = tk.Text(
|
||||
self,
|
||||
bd=0,
|
||||
bg="black",
|
||||
cursor="xterm lime lime",
|
||||
|
@ -222,8 +224,11 @@ class CodeText(ScrolledText):
|
|||
selectbackground="lime",
|
||||
selectforeground="black",
|
||||
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):
|
||||
|
|
Loading…
Reference in a new issue