updated config frame widget to draw tabs for each config group
This commit is contained in:
parent
0147bb9988
commit
5d6d22c6eb
2 changed files with 65 additions and 47 deletions
|
@ -18,7 +18,7 @@ INT_TYPES = {
|
||||||
|
|
||||||
|
|
||||||
class FrameScroll(tk.LabelFrame):
|
class FrameScroll(tk.LabelFrame):
|
||||||
def __init__(self, master=None, cnf={}, **kw):
|
def __init__(self, master=None, cnf={}, _cls=tk.Frame, **kw):
|
||||||
super().__init__(master, cnf, **kw)
|
super().__init__(master, cnf, **kw)
|
||||||
self.rowconfigure(0, weight=1)
|
self.rowconfigure(0, weight=1)
|
||||||
self.columnconfigure(0, weight=1)
|
self.columnconfigure(0, weight=1)
|
||||||
|
@ -30,7 +30,7 @@ class FrameScroll(tk.LabelFrame):
|
||||||
self, orient="vertical", command=self.canvas.yview
|
self, orient="vertical", command=self.canvas.yview
|
||||||
)
|
)
|
||||||
self.scrollbar.grid(row=0, column=1, sticky="ns")
|
self.scrollbar.grid(row=0, column=1, sticky="ns")
|
||||||
self.frame = tk.Frame(self.canvas, padx=2, pady=2)
|
self.frame = _cls(self.canvas)
|
||||||
self.frame_id = self.canvas.create_window(0, 0, anchor="nw", window=self.frame)
|
self.frame_id = self.canvas.create_window(0, 0, anchor="nw", window=self.frame)
|
||||||
self.canvas.update_idletasks()
|
self.canvas.update_idletasks()
|
||||||
self.canvas.configure(
|
self.canvas.configure(
|
||||||
|
@ -48,12 +48,6 @@ class FrameScroll(tk.LabelFrame):
|
||||||
def _configure_canvas(self, event):
|
def _configure_canvas(self, event):
|
||||||
self.canvas.itemconfig(self.frame_id, width=event.width)
|
self.canvas.itemconfig(self.frame_id, width=event.width)
|
||||||
|
|
||||||
def update_canvas(self):
|
|
||||||
self.canvas.update_idletasks()
|
|
||||||
self.canvas.configure(
|
|
||||||
scrollregion=self.canvas.bbox("all"), yscrollcommand=self.scrollbar.set
|
|
||||||
)
|
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
for widget in self.frame.winfo_children():
|
for widget in self.frame.winfo_children():
|
||||||
widget.destroy()
|
widget.destroy()
|
||||||
|
@ -61,53 +55,60 @@ class FrameScroll(tk.LabelFrame):
|
||||||
|
|
||||||
class ConfigFrame(FrameScroll):
|
class ConfigFrame(FrameScroll):
|
||||||
def __init__(self, master=None, cnf={}, config=None, **kw):
|
def __init__(self, master=None, cnf={}, config=None, **kw):
|
||||||
super().__init__(master, cnf, **kw)
|
super().__init__(master, cnf, ttk.Notebook, **kw)
|
||||||
self.frame.columnconfigure(1, weight=1)
|
|
||||||
if not config:
|
|
||||||
config = {}
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.values = {}
|
self.values = {}
|
||||||
|
|
||||||
def draw_config(self):
|
def draw_config(self):
|
||||||
padx = 2
|
padx = 2
|
||||||
pady = 2
|
pady = 2
|
||||||
for index, key in enumerate(sorted(self.config)):
|
group_mapping = {}
|
||||||
|
for key in self.config:
|
||||||
option = self.config[key]
|
option = self.config[key]
|
||||||
label = tk.Label(self.frame, text=option.label)
|
group = group_mapping.setdefault(option.group, [])
|
||||||
label.grid(row=index, pady=pady, padx=padx, sticky="w")
|
group.append(option)
|
||||||
value = tk.StringVar()
|
|
||||||
if option.type == core_pb2.ConfigOptionType.BOOL:
|
for group_name in sorted(group_mapping):
|
||||||
select = tuple(option.select)
|
group = group_mapping[group_name]
|
||||||
combobox = ttk.Combobox(
|
frame = tk.Frame(self.frame)
|
||||||
self.frame, textvariable=value, values=select, state="readonly"
|
frame.columnconfigure(1, weight=1)
|
||||||
)
|
self.frame.add(frame, text=group_name)
|
||||||
combobox.grid(row=index, column=1, sticky="ew", pady=pady)
|
for index, option in enumerate(sorted(group, key=lambda x: x.name)):
|
||||||
if option.value == "1":
|
label = tk.Label(frame, text=option.label)
|
||||||
value.set("On")
|
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)
|
||||||
|
if option.value == "1":
|
||||||
|
value.set("On")
|
||||||
|
else:
|
||||||
|
value.set("Off")
|
||||||
|
elif option.select:
|
||||||
|
value.set(option.value)
|
||||||
|
select = tuple(option.select)
|
||||||
|
combobox = ttk.Combobox(
|
||||||
|
frame, textvariable=value, values=select, state="readonly"
|
||||||
|
)
|
||||||
|
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.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.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.grid(row=index, column=1, sticky="ew", pady=pady)
|
||||||
else:
|
else:
|
||||||
value.set("Off")
|
logging.error("unhandled config option type: %s", option.type)
|
||||||
elif option.select:
|
self.values[option.name] = value
|
||||||
value.set(option.value)
|
|
||||||
select = tuple(option.select)
|
|
||||||
combobox = ttk.Combobox(
|
|
||||||
self.frame, textvariable=value, values=select, state="readonly"
|
|
||||||
)
|
|
||||||
combobox.grid(row=index, column=1, sticky="ew", pady=pady)
|
|
||||||
elif option.type == core_pb2.ConfigOptionType.STRING:
|
|
||||||
value.set(option.value)
|
|
||||||
entry = tk.Entry(self.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(self.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(self.frame, textvariable=value)
|
|
||||||
entry.grid(row=index, column=1, sticky="ew", pady=pady)
|
|
||||||
else:
|
|
||||||
logging.error("unhandled config option type: %s", option.type)
|
|
||||||
self.values[key] = value
|
|
||||||
|
|
||||||
def parse_config(self):
|
def parse_config(self):
|
||||||
for key in self.config:
|
for key in self.config:
|
||||||
|
|
|
@ -768,6 +768,23 @@ message NodeType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ConfigOptionType {
|
||||||
|
enum Enum {
|
||||||
|
NONE = 0;
|
||||||
|
UINT8 = 1;
|
||||||
|
UINT16 = 2;
|
||||||
|
UINT32 = 3;
|
||||||
|
UINT64 = 4;
|
||||||
|
INT8 = 5;
|
||||||
|
INT16 = 6;
|
||||||
|
INT32 = 7;
|
||||||
|
INT64 = 8;
|
||||||
|
FLOAT = 9;
|
||||||
|
STRING = 10;
|
||||||
|
BOOL = 11;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
message ServiceValidationMode {
|
message ServiceValidationMode {
|
||||||
enum Enum {
|
enum Enum {
|
||||||
BLOCKING = 0;
|
BLOCKING = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue