added theme configuration to preferences dialog

This commit is contained in:
bharnden 2019-11-13 22:49:32 -08:00
parent d63da73581
commit 145abca863
3 changed files with 32 additions and 11 deletions

View file

@ -15,6 +15,7 @@ from coretk.toolbar import Toolbar
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.config = appconfig.read()
self.style = ttk.Style()
self.setup_theme()
self.menubar = None
@ -29,7 +30,6 @@ class Application(tk.Frame):
self.radiovar = tk.IntVar(value=1)
self.show_grid_var = tk.IntVar(value=1)
self.adjust_to_dim_var = tk.IntVar(value=0)
self.config = appconfig.read()
self.core = CoreClient(self)
self.setup_app()
self.draw()
@ -37,7 +37,7 @@ class Application(tk.Frame):
def setup_theme(self):
themes.load(self.style)
self.style.theme_use(themes.DARK)
self.style.theme_use(self.config["preferences"]["theme"])
func = partial(themes.update_menu, self.style)
self.master.bind_class("Menu", "<<ThemeChanged>>", func)

View file

@ -6,6 +6,8 @@ from pathlib import Path
import yaml
# gui home paths
from coretk import themes
HOME_PATH = Path.home().joinpath(".coretk")
BACKGROUNDS_PATH = HOME_PATH.joinpath("backgrounds")
CUSTOM_EMANE_PATH = HOME_PATH.joinpath("custom_emane")
@ -68,6 +70,7 @@ def check_directory():
editor = EDITORS[1]
config = {
"preferences": {
"theme": themes.DARK,
"editor": editor,
"terminal": terminal,
"gui3d": "/usr/local/bin/std3d.sh",

View file

@ -1,3 +1,4 @@
import logging
import tkinter as tk
from tkinter import ttk
@ -10,41 +11,52 @@ class PreferencesDialog(Dialog):
super().__init__(master, app, "Preferences", modal=True)
preferences = self.app.config["preferences"]
self.editor = tk.StringVar(value=preferences["editor"])
self.theme = tk.StringVar(value=preferences["theme"])
self.terminal = tk.StringVar(value=preferences["terminal"])
self.gui3d = tk.StringVar(value=preferences["gui3d"])
self.draw()
def draw(self):
self.top.columnconfigure(0, weight=1)
self.draw_programs()
self.draw_preferences()
self.draw_buttons()
def draw_programs(self):
frame = ttk.LabelFrame(self.top, text="Programs")
def draw_preferences(self):
frame = ttk.LabelFrame(self.top, text="Preferences")
frame.grid(sticky="ew", pady=2)
frame.columnconfigure(1, weight=1)
label = ttk.Label(frame, text="Editor")
label = ttk.Label(frame, text="Theme")
label.grid(row=0, column=0, pady=2, padx=2, sticky="w")
themes = self.app.style.theme_names()
combobox = ttk.Combobox(
frame, textvariable=self.theme, values=themes, state="readonly"
)
combobox.set(self.theme.get())
combobox.grid(row=0, column=1, sticky="ew")
combobox.bind("<<ComboboxSelected>>", self.theme_change)
label = ttk.Label(frame, text="Editor")
label.grid(row=1, column=0, pady=2, padx=2, sticky="w")
combobox = ttk.Combobox(
frame, textvariable=self.editor, values=appconfig.EDITORS, state="readonly"
)
combobox.grid(row=0, column=1, sticky="ew")
combobox.grid(row=1, column=1, sticky="ew")
label = ttk.Label(frame, text="Terminal")
label.grid(row=1, column=0, pady=2, padx=2, sticky="w")
label.grid(row=2, column=0, pady=2, padx=2, sticky="w")
combobox = ttk.Combobox(
frame,
textvariable=self.terminal,
values=appconfig.TERMINALS,
state="readonly",
)
combobox.grid(row=1, column=1, sticky="ew")
combobox.grid(row=2, column=1, sticky="ew")
label = ttk.Label(frame, text="3D GUI")
label.grid(row=2, column=0, pady=2, padx=2, sticky="w")
label.grid(row=3, column=0, pady=2, padx=2, sticky="w")
entry = ttk.Entry(frame, textvariable=self.gui3d)
entry.grid(row=2, column=1, sticky="ew")
entry.grid(row=3, column=1, sticky="ew")
def draw_buttons(self):
frame = ttk.Frame(self.top)
@ -58,10 +70,16 @@ class PreferencesDialog(Dialog):
button = ttk.Button(frame, text="Cancel", command=self.destroy)
button.grid(row=0, column=1, sticky="ew")
def theme_change(self, event):
theme = self.theme.get()
logging.info("changing theme: %s", theme)
self.app.style.theme_use(theme)
def click_save(self):
preferences = self.app.config["preferences"]
preferences["terminal"] = self.terminal.get()
preferences["editor"] = self.editor.get()
preferences["gui3d"] = self.gui3d.get()
preferences["theme"] = self.theme.get()
self.app.save_config()
self.destroy()