updated framescroll to dynamically set bg based on current style

This commit is contained in:
Blake Harnden 2019-11-13 13:19:18 -08:00
parent 08927b180a
commit d63da73581
7 changed files with 17 additions and 24 deletions

View file

@ -40,8 +40,6 @@ class Application(tk.Frame):
self.style.theme_use(themes.DARK) self.style.theme_use(themes.DARK)
func = partial(themes.update_menu, self.style) func = partial(themes.update_menu, self.style)
self.master.bind_class("Menu", "<<ThemeChanged>>", func) self.master.bind_class("Menu", "<<ThemeChanged>>", func)
func = partial(themes.update_toplevel, self.style)
self.master.bind_class("Toplevel", "<<ThemeChanged>>", func)
def setup_app(self): def setup_app(self):
self.master.title("CORE") self.master.title("CORE")

View file

@ -35,7 +35,7 @@ class ServicesSelectDialog(Dialog):
self.groups.listbox.selection_set(0) self.groups.listbox.selection_set(0)
self.services = CheckboxList( self.services = CheckboxList(
frame, text="Services", clicked=self.service_clicked frame, self.app, text="Services", clicked=self.service_clicked
) )
self.services.grid(row=0, column=1, sticky="nsew") self.services.grid(row=0, column=1, sticky="nsew")

View file

@ -93,7 +93,7 @@ class EmaneConfiguration(Dialog):
self.emane_dialog.top.columnconfigure(0, weight=1) self.emane_dialog.top.columnconfigure(0, weight=1)
self.emane_dialog.top.rowconfigure(0, weight=1) self.emane_dialog.top.rowconfigure(0, weight=1)
self.emane_config_frame = ConfigFrame( self.emane_config_frame = ConfigFrame(
self.emane_dialog.top, config=self.options self.emane_dialog.top, self.app, config=self.options
) )
self.emane_config_frame.draw_config() self.emane_config_frame.draw_config()
self.emane_config_frame.grid(sticky="nsew") self.emane_config_frame.grid(sticky="nsew")
@ -167,7 +167,7 @@ class EmaneConfiguration(Dialog):
self.model_options = response.config self.model_options = response.config
self.model_config_frame = ConfigFrame( self.model_config_frame = ConfigFrame(
self.emane_model_dialog.top, config=self.model_options self.emane_model_dialog.top, self.app, config=self.model_options
) )
self.model_config_frame.grid(sticky="nsew") self.model_config_frame.grid(sticky="nsew")
self.model_config_frame.draw_config() self.model_config_frame.draw_config()

View file

@ -38,7 +38,7 @@ class NodeService(Dialog):
self.groups.listbox.selection_set(0) self.groups.listbox.selection_set(0)
self.services = CheckboxList( self.services = CheckboxList(
frame, text="Services", clicked=self.service_clicked frame, self.app, text="Services", clicked=self.service_clicked
) )
self.services.grid(row=0, column=1, sticky="nsew") self.services.grid(row=0, column=1, sticky="nsew")

View file

@ -22,7 +22,7 @@ class SessionOptionsDialog(Dialog):
response = self.app.core.client.get_session_options(session_id) response = self.app.core.client.get_session_options(session_id)
logging.info("session options: %s", response) logging.info("session options: %s", response)
self.config_frame = ConfigFrame(self.top, config=response.config) self.config_frame = ConfigFrame(self.top, self.app, config=response.config)
self.config_frame.draw_config() self.config_frame.draw_config()
self.config_frame.grid(sticky="nsew") self.config_frame.grid(sticky="nsew")

View file

@ -1,3 +1,4 @@
import logging
import tkinter as tk import tkinter as tk
DARK = "black" DARK = "black"
@ -118,9 +119,8 @@ def load(style):
) )
def update_toplevel(style, event): def update_bg(style, event):
if not isinstance(event.widget, tk.Toplevel): logging.info("updating background: %s", event.widget)
return
bg = style.lookup(".", "background") bg = style.lookup(".", "background")
event.widget.config(background=bg) event.widget.config(background=bg)

View file

@ -4,7 +4,6 @@ from functools import partial
from tkinter import ttk from tkinter import ttk
from core.api.grpc import core_pb2 from core.api.grpc import core_pb2
from coretk.themes import Styles
INT_TYPES = { INT_TYPES = {
core_pb2.ConfigOptionType.UINT8, core_pb2.ConfigOptionType.UINT8,
@ -19,11 +18,13 @@ INT_TYPES = {
class FrameScroll(ttk.LabelFrame): class FrameScroll(ttk.LabelFrame):
def __init__(self, master=None, _cls=tk.Frame, **kw): def __init__(self, master, app, _cls=ttk.Frame, **kw):
super().__init__(master, **kw) super().__init__(master, **kw)
self.app = app
self.rowconfigure(0, weight=1) self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1) self.columnconfigure(0, weight=1)
self.canvas = tk.Canvas(self, highlightthickness=0) bg = self.app.style.lookup(".", "background")
self.canvas = tk.Canvas(self, highlightthickness=0, background=bg)
self.canvas.grid(row=0, sticky="nsew", padx=2, pady=2) self.canvas.grid(row=0, sticky="nsew", padx=2, pady=2)
self.canvas.columnconfigure(0, weight=1) self.canvas.columnconfigure(0, weight=1)
self.canvas.rowconfigure(0, weight=1) self.canvas.rowconfigure(0, weight=1)
@ -55,8 +56,8 @@ class FrameScroll(ttk.LabelFrame):
class ConfigFrame(FrameScroll): class ConfigFrame(FrameScroll):
def __init__(self, master=None, config=None, **kw): def __init__(self, master, app, config, **kw):
super().__init__(master, ttk.Notebook, **kw) super().__init__(master, app, ttk.Notebook, **kw)
self.config = config self.config = config
self.values = {} self.values = {}
@ -143,19 +144,13 @@ class ListboxScroll(ttk.LabelFrame):
class CheckboxList(FrameScroll): class CheckboxList(FrameScroll):
def __init__(self, master=None, clicked=None, **kw): def __init__(self, master, app, clicked=None, **kw):
super().__init__(master, **kw) super().__init__(master, app, **kw)
self.clicked = clicked self.clicked = clicked
self.frame.columnconfigure(0, weight=1) self.frame.columnconfigure(0, weight=1)
def add(self, name, checked): def add(self, name, checked):
var = tk.BooleanVar(value=checked) var = tk.BooleanVar(value=checked)
func = partial(self.clicked, name, var) func = partial(self.clicked, name, var)
checkbox = ttk.Checkbutton( checkbox = ttk.Checkbutton(self.frame, text=name, variable=var, command=func)
self.frame,
text=name,
variable=var,
command=func,
style=Styles.service_checkbutton,
)
checkbox.grid(sticky="w") checkbox.grid(sticky="w")