Merge branch 'coretk' into coretk-selectbox

This commit is contained in:
Huy Pham 2019-12-12 08:33:36 -08:00
commit a7e1035f5a
3 changed files with 143 additions and 125 deletions

View file

@ -12,7 +12,8 @@ from coretk.widgets import CheckboxList, ListboxScroll
class NodeService(Dialog): class NodeService(Dialog):
def __init__(self, master, app, canvas_node, services=None): def __init__(self, master, app, canvas_node, services=None):
super().__init__(master, app, "Node Services", modal=True) title = f"{canvas_node.core_node.name} Services"
super().__init__(master, app, title, modal=True)
self.app = app self.app = app
self.canvas_node = canvas_node self.canvas_node = canvas_node
self.node_id = canvas_node.core_node.id self.node_id = canvas_node.core_node.id

View file

@ -9,12 +9,14 @@ from core.api.grpc import core_pb2
from coretk.dialogs.dialog import Dialog from coretk.dialogs.dialog import Dialog
from coretk.errors import show_grpc_error from coretk.errors import show_grpc_error
from coretk.images import ImageEnum, Images from coretk.images import ImageEnum, Images
from coretk.themes import FRAME_PAD, PADX, PADY
from coretk.widgets import CodeText, ListboxScroll from coretk.widgets import CodeText, ListboxScroll
class ServiceConfiguration(Dialog): class ServiceConfiguration(Dialog):
def __init__(self, master, app, service_name, node_id): def __init__(self, master, app, service_name, node_id):
super().__init__(master, app, f"{service_name} service", modal=True) title = f"{service_name} Service"
super().__init__(master, app, title, modal=True)
self.app = app self.app = app
self.core = app.core self.core = app.core
self.node_id = node_id self.node_id = node_id
@ -34,7 +36,7 @@ class ServiceConfiguration(Dialog):
self.documentnew_img = Images.get(ImageEnum.DOCUMENTNEW, 16) self.documentnew_img = Images.get(ImageEnum.DOCUMENTNEW, 16)
self.editdelete_img = Images.get(ImageEnum.EDITDELETE, 16) self.editdelete_img = Images.get(ImageEnum.EDITDELETE, 16)
self.tab_parent = None self.notebook = None
self.metadata_entry = None self.metadata_entry = None
self.filename_combobox = None self.filename_combobox = None
self.startup_commands_listbox = None self.startup_commands_listbox = None
@ -94,88 +96,88 @@ class ServiceConfiguration(Dialog):
show_grpc_error(e) show_grpc_error(e)
def draw(self): def draw(self):
# self.columnconfigure(1, weight=1) self.top.columnconfigure(0, weight=1)
self.top.rowconfigure(1, weight=1)
# draw metadata
frame = ttk.Frame(self.top) frame = ttk.Frame(self.top)
frame1 = ttk.Frame(frame) frame.grid(sticky="ew", pady=PADY)
label = ttk.Label(frame1, text=self.service_name) frame.columnconfigure(1, weight=1)
label.grid(row=0, column=0, sticky="ew") label = ttk.Label(frame, text="Meta-data")
frame1.grid(row=0, column=0) label.grid(row=0, column=0, sticky="w", padx=PADX)
frame2 = ttk.Frame(frame) self.metadata_entry = ttk.Entry(frame, textvariable=self.metadata)
label = ttk.Label(frame2, text="Meta-data") self.metadata_entry.grid(row=0, column=1, sticky="ew")
label.grid(row=0, column=0)
self.metadata_entry = ttk.Entry(frame2, textvariable=self.metadata) # draw notebook
self.metadata_entry.grid(row=0, column=1) self.notebook = ttk.Notebook(self.top)
frame2.grid(row=1, column=0) self.notebook.grid(sticky="nsew")
frame.grid(row=0, column=0) self.draw_tab_files()
self.draw_tab_directories()
self.draw_tab_startstop()
self.draw_tab_configuration()
frame = ttk.Frame(self.top) button = ttk.Button(self.top, text="Only Save Changes")
self.tab_parent = ttk.Notebook(frame) button.grid(sticky="ew", pady=PADY)
tab1 = ttk.Frame(self.tab_parent) self.draw_buttons()
tab2 = ttk.Frame(self.tab_parent)
tab3 = ttk.Frame(self.tab_parent)
tab4 = ttk.Frame(self.tab_parent)
tab1.columnconfigure(0, weight=1)
tab2.columnconfigure(0, weight=1)
tab3.columnconfigure(0, weight=1)
tab4.columnconfigure(0, weight=1)
self.tab_parent.add(tab1, text="Files", sticky="nsew") def draw_tab_files(self):
self.tab_parent.add(tab2, text="Directories", sticky="nsew") tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
self.tab_parent.add(tab3, text="Startup/shutdown", sticky="nsew") tab.grid(sticky="nsew")
self.tab_parent.add(tab4, text="Configuration", sticky="nsew") tab.columnconfigure(0, weight=1)
self.tab_parent.grid(row=0, column=0, sticky="nsew") self.notebook.add(tab, text="Files")
frame.grid(row=1, column=0, sticky="nsew")
# tab 1
label = ttk.Label( label = ttk.Label(
tab1, text="Config files and scripts that are generated for this service." tab, text="Config files and scripts that are generated for this service."
) )
label.grid(row=0, column=0, sticky="nsew") label.grid()
frame = ttk.Frame(tab1) frame = ttk.Frame(tab)
label = ttk.Label(frame, text="File name: ") frame.grid(sticky="ew", pady=PADY)
label.grid(row=0, column=0) frame.columnconfigure(1, weight=1)
label = ttk.Label(frame, text="File Name")
label.grid(row=0, column=0, padx=PADX, sticky="w")
self.filename_combobox = ttk.Combobox( self.filename_combobox = ttk.Combobox(
frame, values=self.filenames, state="readonly" frame, values=self.filenames, state="readonly"
) )
self.filename_combobox.grid(row=0, column=1)
self.filename_combobox.bind( self.filename_combobox.bind(
"<<ComboboxSelected>>", self.display_service_file_data "<<ComboboxSelected>>", self.display_service_file_data
) )
self.filename_combobox.grid(row=0, column=1, sticky="ew", padx=PADX)
button = ttk.Button(frame, image=self.documentnew_img, state="disabled") button = ttk.Button(frame, image=self.documentnew_img, state="disabled")
button.bind("<Button-1>", self.add_filename) button.bind("<Button-1>", self.add_filename)
button.grid(row=0, column=2) button.grid(row=0, column=2, padx=PADX)
button = ttk.Button(frame, image=self.editdelete_img, state="disabled") button = ttk.Button(frame, image=self.editdelete_img, state="disabled")
button.bind("<Button-1>", self.delete_filename) button.bind("<Button-1>", self.delete_filename)
button.grid(row=0, column=3) button.grid(row=0, column=3)
frame.grid(row=1, column=0, sticky="nsew")
frame = ttk.Frame(tab1) frame = ttk.Frame(tab)
frame.grid(sticky="ew", pady=PADY)
frame.columnconfigure(1, weight=1)
button = ttk.Radiobutton( button = ttk.Radiobutton(
frame, frame,
variable=self.radiovar, variable=self.radiovar,
text="Copy this source file:", text="Copy Source File",
value=1, value=1,
state="disabled", state=tk.DISABLED,
) )
button.grid(row=0, column=0) button.grid(row=0, column=0, sticky="w", padx=PADX)
entry = ttk.Entry(frame, state=tk.DISABLED) entry = ttk.Entry(frame, state=tk.DISABLED)
entry.grid(row=0, column=1) entry.grid(row=0, column=1, sticky="ew", padx=PADX)
image = Images.get(ImageEnum.FILEOPEN, 16) image = Images.get(ImageEnum.FILEOPEN, 16)
button = ttk.Button(frame, image=image) button = ttk.Button(frame, image=image)
button.image = image button.image = image
button.grid(row=0, column=2) button.grid(row=0, column=2)
frame.grid(row=2, column=0, sticky="nsew")
frame = ttk.Frame(tab1) frame = ttk.Frame(tab)
frame.grid(sticky="ew", pady=PADY)
frame.columnconfigure(0, weight=1)
button = ttk.Radiobutton( button = ttk.Radiobutton(
frame, frame,
variable=self.radiovar, variable=self.radiovar,
text="Use text below for file contents:", text="Use text below for file contents",
value=2, value=2,
) )
button.grid(row=0, column=0) button.grid(row=0, column=0, sticky="ew")
image = Images.get(ImageEnum.FILEOPEN, 16) image = Images.get(ImageEnum.FILEOPEN, 16)
button = ttk.Button(frame, image=image) button = ttk.Button(frame, image=image)
button.image = image button.image = image
@ -184,10 +186,10 @@ class ServiceConfiguration(Dialog):
button = ttk.Button(frame, image=image) button = ttk.Button(frame, image=image)
button.image = image button.image = image
button.grid(row=0, column=2) button.grid(row=0, column=2)
frame.grid(row=3, column=0, sticky="nsew")
self.service_file_data = CodeText(tab1) self.service_file_data = CodeText(tab)
self.service_file_data.grid(row=4, column=0, sticky="nsew") self.service_file_data.grid(sticky="nsew")
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.delete(1.0, "end")
@ -196,38 +198,60 @@ class ServiceConfiguration(Dialog):
) )
self.service_file_data.bind("<FocusOut>", self.update_temp_service_file_data) self.service_file_data.bind("<FocusOut>", self.update_temp_service_file_data)
# tab 2 def draw_tab_directories(self):
tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
tab.grid(sticky="nsew")
tab.columnconfigure(0, weight=1)
self.notebook.add(tab, text="Directories")
label = ttk.Label( label = ttk.Label(
tab2, tab,
text="Directories required by this service that are unique for each node.", text="Directories required by this service that are unique for each node.",
) )
label.grid(row=0, column=0, sticky="nsew") label.grid()
def draw_tab_startstop(self):
tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
tab.grid(sticky="nsew")
tab.columnconfigure(0, weight=1)
for i in range(3):
tab.rowconfigure(i, weight=1)
self.notebook.add(tab, text="Startup/shutdown")
# tab 3 # tab 3
for i in range(3): for i in range(3):
label_frame = None label_frame = None
if i == 0: if i == 0:
label_frame = ttk.LabelFrame(tab3, text="Startup commands") label_frame = ttk.LabelFrame(
tab, text="Startup commands", padding=FRAME_PAD
)
commands = self.startup_commands commands = self.startup_commands
elif i == 1: elif i == 1:
label_frame = ttk.LabelFrame(tab3, text="Shutdown commands") label_frame = ttk.LabelFrame(
tab, text="Shutdown commands", padding=FRAME_PAD
)
commands = self.shutdown_commands commands = self.shutdown_commands
elif i == 2: elif i == 2:
label_frame = ttk.LabelFrame(tab3, text="Validation commands") label_frame = ttk.LabelFrame(
tab, text="Validation commands", padding=FRAME_PAD
)
commands = self.validation_commands commands = self.validation_commands
label_frame.columnconfigure(0, weight=1) label_frame.columnconfigure(0, weight=1)
label_frame.rowconfigure(1, weight=1)
label_frame.grid(row=i, column=0, sticky="nsew")
frame = ttk.Frame(label_frame) frame = ttk.Frame(label_frame)
frame.grid(row=0, column=0, sticky="nsew")
frame.columnconfigure(0, weight=1) frame.columnconfigure(0, weight=1)
entry = ttk.Entry(frame, textvariable=tk.StringVar()) entry = ttk.Entry(frame, textvariable=tk.StringVar())
entry.grid(row=0, column=0, stick="nsew") entry.grid(row=0, column=0, stick="ew", padx=PADX)
button = ttk.Button(frame, image=self.documentnew_img) button = ttk.Button(frame, image=self.documentnew_img)
button.bind("<Button-1>", self.add_command) button.bind("<Button-1>", self.add_command)
button.grid(row=0, column=1, sticky="nsew") button.grid(row=0, column=1, sticky="ew", padx=PADX)
button = ttk.Button(frame, image=self.editdelete_img) button = ttk.Button(frame, image=self.editdelete_img)
button.grid(row=0, column=2, sticky="nsew") button.grid(row=0, column=2, sticky="ew")
button.bind("<Button-1>", self.delete_command) button.bind("<Button-1>", self.delete_command)
frame.grid(row=0, column=0, sticky="nsew") listbox_scroll = ListboxScroll(label_frame, borderwidth=0)
listbox_scroll = ListboxScroll(label_frame)
listbox_scroll.listbox.bind("<<ListboxSelect>>", self.update_entry) listbox_scroll.listbox.bind("<<ListboxSelect>>", self.update_entry)
for command in commands: for command in commands:
listbox_scroll.listbox.insert("end", command) listbox_scroll.listbox.insert("end", command)
@ -239,81 +263,75 @@ class ServiceConfiguration(Dialog):
self.shutdown_commands_listbox = listbox_scroll.listbox self.shutdown_commands_listbox = listbox_scroll.listbox
elif i == 2: elif i == 2:
self.validate_commands_listbox = listbox_scroll.listbox self.validate_commands_listbox = listbox_scroll.listbox
label_frame.grid(row=i, column=0, sticky="nsew")
# tab 4 def draw_tab_configuration(self):
for i in range(2): tab = ttk.Frame(self.notebook, padding=FRAME_PAD)
label_frame = None tab.grid(sticky="nsew")
if i == 0: tab.columnconfigure(0, weight=1)
label_frame = ttk.LabelFrame(tab4, text="Executables") self.notebook.add(tab, text="Configuration", sticky="nsew")
elif i == 1:
label_frame = ttk.LabelFrame(tab4, text="Dependencies")
label_frame.columnconfigure(0, weight=1)
listbox_scroll = ListboxScroll(label_frame)
listbox_scroll.listbox.config(height=4)
listbox_scroll.grid(row=0, column=0, sticky="nsew")
label_frame.grid(row=i, column=0, sticky="nsew")
if i == 0:
for executable in self.executables:
print(executable)
listbox_scroll.listbox.insert("end", executable)
if i == 1:
for dependency in self.dependencies:
listbox_scroll.listbox.insert("end", dependency)
for i in range(3): frame = ttk.Frame(tab)
frame = ttk.Frame(tab4) frame.grid(sticky="ew", pady=PADY)
frame.columnconfigure(0, weight=1) frame.columnconfigure(1, weight=1)
if i == 0:
label = ttk.Label(frame, text="Validation time:")
self.validation_time_entry = ttk.Entry(frame)
self.validation_time_entry.insert("end", self.validation_time)
self.validation_time_entry.config(state="disabled")
self.validation_time_entry.grid(row=i, column=1)
elif i == 1:
label = ttk.Label(frame, text="Validation mode:")
if self.validation_mode == core_pb2.ServiceValidationMode.BLOCKING:
mode = "BLOCKING"
elif (
self.validation_mode == core_pb2.ServiceValidationMode.NON_BLOCKING
):
mode = "NON_BLOCKING"
elif self.validation_mode == core_pb2.ServiceValidationMode.TIMER:
mode = "TIMER"
self.validation_mode_entry = ttk.Entry(
frame, textvariable=tk.StringVar(value=mode)
)
self.validation_mode_entry.insert("end", mode)
self.validation_mode_entry.config(state="disabled")
self.validation_mode_entry.grid(row=i, column=1)
elif i == 2:
label = ttk.Label(frame, text="Validation period:")
self.validation_period_entry = ttk.Entry(
frame, state="disabled", textvariable=tk.StringVar()
)
self.validation_period_entry.grid(row=i, column=1)
label.grid(row=i, column=0)
frame.grid(row=2 + i, column=0, sticky="nsew")
button = ttk.Button( label = ttk.Label(frame, text="Validation Time")
self.top, text="onle store values that have changed from their defaults" label.grid(row=0, column=0, sticky="w")
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")
label = ttk.Label(frame, text="Validation Mode")
label.grid(row=1, column=0, sticky="w")
if self.validation_mode == core_pb2.ServiceValidationMode.BLOCKING:
mode = "BLOCKING"
elif self.validation_mode == core_pb2.ServiceValidationMode.NON_BLOCKING:
mode = "NON_BLOCKING"
else:
mode = "TIMER"
self.validation_mode_entry = ttk.Entry(
frame, textvariable=tk.StringVar(value=mode)
) )
button.grid(row=2, column=0) 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")
label = ttk.Label(frame, text="Validation Period")
label.grid(row=2, column=0, sticky="w")
self.validation_period_entry = ttk.Entry(
frame, state=tk.DISABLED, textvariable=tk.StringVar()
)
self.validation_period_entry.grid(row=2, column=1, sticky="ew")
listbox_scroll = ListboxScroll(tab, text="Executables", padding=FRAME_PAD)
listbox_scroll.grid(sticky="nsew", pady=PADY)
tab.rowconfigure(listbox_scroll.grid_info()["row"], weight=1)
for executable in self.executables:
listbox_scroll.listbox.insert("end", executable)
listbox_scroll = ListboxScroll(tab, text="Dependencies", padding=FRAME_PAD)
listbox_scroll.grid(sticky="nsew")
tab.rowconfigure(listbox_scroll.grid_info()["row"], weight=1)
for dependency in self.dependencies:
listbox_scroll.listbox.insert("end", dependency)
def draw_buttons(self):
frame = ttk.Frame(self.top) frame = ttk.Frame(self.top)
frame.grid(sticky="ew")
for i in range(4):
frame.columnconfigure(i, weight=1)
button = ttk.Button(frame, text="Apply", command=self.click_apply) button = ttk.Button(frame, text="Apply", command=self.click_apply)
button.grid(row=0, column=0, sticky="nsew") button.grid(row=0, column=0, sticky="ew", padx=PADX)
button = ttk.Button( button = ttk.Button(
frame, text="Dafults", command=self.click_defaults, state="disabled" frame, text="Dafults", command=self.click_defaults, state="disabled"
) )
button.grid(row=0, column=1, sticky="nsew") button.grid(row=0, column=1, sticky="ew", padx=PADX)
button = ttk.Button( button = ttk.Button(
frame, text="Copy...", command=self.click_copy, state="disabled" frame, text="Copy...", command=self.click_copy, state="disabled"
) )
button.grid(row=0, column=2, sticky="nsew") button.grid(row=0, column=2, sticky="ew", padx=PADX)
button = ttk.Button(frame, text="Cancel", command=self.destroy) button = ttk.Button(frame, text="Cancel", command=self.destroy)
button.grid(row=0, column=3, sticky="nsew") button.grid(row=0, column=3, sticky="ew")
frame.grid(row=3, column=0)
def add_filename(self, event): def add_filename(self, event):
# not worry about it for now # not worry about it for now

View file

@ -183,7 +183,6 @@ class ListboxScroll(ttk.LabelFrame):
self.listbox = tk.Listbox( self.listbox = tk.Listbox(
self, selectmode=tk.SINGLE, yscrollcommand=self.scrollbar.set self, selectmode=tk.SINGLE, yscrollcommand=self.scrollbar.set
) )
logging.info("listbox background: %s", self.listbox.cget("background"))
self.listbox.grid(row=0, column=0, sticky="nsew") self.listbox.grid(row=0, column=0, sticky="nsew")
self.scrollbar.config(command=self.listbox.yview) self.scrollbar.config(command=self.listbox.yview)