2019-11-13 18:45:43 +00:00
|
|
|
import tkinter as tk
|
2019-12-16 21:11:23 +00:00
|
|
|
from tkinter import ttk
|
2019-11-13 18:45:43 +00:00
|
|
|
|
2019-12-11 22:36:27 +00:00
|
|
|
THEME_DARK = "black"
|
|
|
|
PADX = (0, 5)
|
|
|
|
PADY = (0, 5)
|
|
|
|
FRAME_PAD = 5
|
|
|
|
DIALOG_PAD = 5
|
2019-11-13 18:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Styles:
|
|
|
|
tooltip = "Tooltip.TLabel"
|
|
|
|
tooltip_frame = "Tooltip.TFrame"
|
2019-11-13 20:42:16 +00:00
|
|
|
service_checkbutton = "Service.TCheckbutton"
|
2019-12-11 19:42:05 +00:00
|
|
|
picker_button = "Picker.TButton"
|
2019-12-13 05:05:45 +00:00
|
|
|
green_alert = "GAlert.TButton"
|
|
|
|
red_alert = "RAlert.TButton"
|
|
|
|
yellow_alert = "YAlert.TButton"
|
2019-11-13 18:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Colors:
|
|
|
|
disabledfg = "DarkGrey"
|
|
|
|
frame = "#424242"
|
|
|
|
dark = "#222222"
|
|
|
|
darker = "#121212"
|
|
|
|
darkest = "black"
|
|
|
|
lighter = "#626262"
|
|
|
|
lightest = "#ffffff"
|
|
|
|
selectbg = "#4a6984"
|
|
|
|
selectfg = "#ffffff"
|
|
|
|
white = "white"
|
|
|
|
black = "black"
|
2019-11-13 20:42:16 +00:00
|
|
|
listboxbg = "#f2f1f0"
|
2019-11-13 18:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
def load(style):
|
|
|
|
style.theme_create(
|
2019-12-11 22:36:27 +00:00
|
|
|
THEME_DARK,
|
2019-11-13 18:45:43 +00:00
|
|
|
"clam",
|
|
|
|
{
|
|
|
|
".": {
|
|
|
|
"configure": {
|
|
|
|
"background": Colors.frame,
|
|
|
|
"foreground": Colors.white,
|
|
|
|
"bordercolor": Colors.darkest,
|
|
|
|
"darkcolor": Colors.dark,
|
|
|
|
"lightcolor": Colors.lighter,
|
|
|
|
"troughcolor": Colors.darker,
|
|
|
|
"selectbackground": Colors.selectbg,
|
|
|
|
"selectforeground": Colors.selectfg,
|
|
|
|
"selectborderwidth": 0,
|
|
|
|
"font": "TkDefaultFont",
|
|
|
|
},
|
|
|
|
"map": {
|
|
|
|
"background": [
|
|
|
|
("disabled", Colors.frame),
|
|
|
|
("active", Colors.lighter),
|
|
|
|
],
|
|
|
|
"foreground": [("disabled", Colors.disabledfg)],
|
|
|
|
"selectbackground": [("!focus", Colors.darkest)],
|
|
|
|
"selectforeground": [("!focus", Colors.white)],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"TButton": {
|
2019-11-16 07:31:41 +00:00
|
|
|
"configure": {
|
|
|
|
"width": 8,
|
|
|
|
"padding": (5, 1),
|
|
|
|
"relief": tk.RAISED,
|
|
|
|
"anchor": tk.CENTER,
|
|
|
|
},
|
2019-11-13 18:45:43 +00:00
|
|
|
"map": {
|
|
|
|
"relief": [("pressed", tk.SUNKEN)],
|
|
|
|
"shiftrelief": [("pressed", 1)],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"TMenubutton": {
|
|
|
|
"configure": {"width": 11, "padding": (5, 1), "relief": tk.RAISED}
|
|
|
|
},
|
|
|
|
"TCheckbutton": {
|
|
|
|
"configure": {
|
|
|
|
"indicatorbackground": Colors.white,
|
|
|
|
"indicatormargin": (1, 1, 4, 1),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"TRadiobutton": {
|
|
|
|
"configure": {
|
|
|
|
"indicatorbackground": Colors.white,
|
|
|
|
"indicatormargin": (1, 1, 4, 1),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"TEntry": {
|
|
|
|
"configure": {
|
|
|
|
"fieldbackground": Colors.white,
|
2019-12-09 21:05:07 +00:00
|
|
|
"foreground": Colors.black,
|
|
|
|
"padding": (2, 0),
|
|
|
|
},
|
|
|
|
"map": {"fieldbackground": [("disabled", Colors.frame)]},
|
|
|
|
},
|
|
|
|
"TSpinbox": {
|
|
|
|
"configure": {
|
|
|
|
"fieldbackground": Colors.white,
|
2019-11-13 18:45:43 +00:00
|
|
|
"foreground": Colors.black,
|
|
|
|
"padding": (2, 0),
|
2019-11-20 18:59:30 +00:00
|
|
|
},
|
|
|
|
"map": {"fieldbackground": [("disabled", Colors.frame)]},
|
2019-11-13 18:45:43 +00:00
|
|
|
},
|
|
|
|
"TCombobox": {
|
|
|
|
"configure": {
|
|
|
|
"fieldbackground": Colors.white,
|
|
|
|
"foreground": Colors.black,
|
|
|
|
"padding": (2, 0),
|
|
|
|
}
|
|
|
|
},
|
2019-11-13 20:11:37 +00:00
|
|
|
"TLabelframe": {"configure": {"relief": tk.GROOVE}},
|
2019-11-13 18:45:43 +00:00
|
|
|
"TNotebook.Tab": {
|
|
|
|
"configure": {"padding": (6, 2, 6, 2)},
|
|
|
|
"map": {"background": [("selected", Colors.lighter)]},
|
|
|
|
},
|
|
|
|
"Treeview": {
|
|
|
|
"configure": {
|
|
|
|
"fieldbackground": Colors.white,
|
|
|
|
"background": Colors.white,
|
|
|
|
"foreground": Colors.black,
|
|
|
|
},
|
|
|
|
"map": {
|
|
|
|
"background": [("selected", Colors.selectbg)],
|
|
|
|
"foreground": [("selected", Colors.selectfg)],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Styles.tooltip: {
|
|
|
|
"configure": {"justify": tk.LEFT, "relief": tk.SOLID, "borderwidth": 0}
|
|
|
|
},
|
|
|
|
Styles.tooltip_frame: {"configure": {}},
|
2019-11-13 20:42:16 +00:00
|
|
|
Styles.service_checkbutton: {
|
|
|
|
"configure": {
|
|
|
|
"background": Colors.listboxbg,
|
|
|
|
"foreground": Colors.black,
|
|
|
|
}
|
|
|
|
},
|
2019-11-13 18:45:43 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-12-16 22:30:38 +00:00
|
|
|
def theme_change_menu(event):
|
2019-11-13 18:45:43 +00:00
|
|
|
if not isinstance(event.widget, tk.Menu):
|
|
|
|
return
|
2019-12-16 22:30:38 +00:00
|
|
|
style_menu(event.widget)
|
2019-12-11 22:09:50 +00:00
|
|
|
|
|
|
|
|
2019-12-16 22:30:38 +00:00
|
|
|
def style_menu(widget):
|
|
|
|
style = ttk.Style()
|
2019-11-13 18:45:43 +00:00
|
|
|
bg = style.lookup(".", "background")
|
|
|
|
fg = style.lookup(".", "foreground")
|
|
|
|
abg = style.lookup(".", "lightcolor")
|
2019-11-22 06:39:39 +00:00
|
|
|
if not abg:
|
|
|
|
abg = bg
|
2019-12-11 22:09:50 +00:00
|
|
|
widget.config(
|
2019-12-16 21:11:23 +00:00
|
|
|
background=bg, foreground=fg, activebackground=abg, activeforeground=fg, bd=0
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-12-16 22:21:30 +00:00
|
|
|
def style_listbox(widget):
|
2019-12-16 21:11:23 +00:00
|
|
|
style = ttk.Style()
|
|
|
|
bg = style.lookup(".", "background")
|
|
|
|
fg = style.lookup(".", "foreground")
|
2019-12-16 22:30:38 +00:00
|
|
|
bc = style.lookup(".", "bordercolor")
|
|
|
|
if not bc:
|
|
|
|
bc = "black"
|
2019-12-16 21:11:23 +00:00
|
|
|
widget.config(
|
|
|
|
background=bg,
|
|
|
|
foreground=fg,
|
|
|
|
highlightthickness=1,
|
2019-12-16 22:30:38 +00:00
|
|
|
highlightcolor=bc,
|
|
|
|
highlightbackground=bc,
|
2019-12-16 21:11:23 +00:00
|
|
|
bd=0,
|
2019-11-13 18:45:43 +00:00
|
|
|
)
|
2019-12-11 19:42:05 +00:00
|
|
|
|
|
|
|
|
2019-12-16 22:30:38 +00:00
|
|
|
def theme_change(event):
|
|
|
|
style = ttk.Style()
|
2019-12-11 19:42:05 +00:00
|
|
|
style.configure(Styles.picker_button, font=("TkDefaultFont", 8, "normal"))
|
2019-12-13 05:05:45 +00:00
|
|
|
style.configure(
|
|
|
|
Styles.green_alert,
|
|
|
|
background="green",
|
|
|
|
padding=0,
|
|
|
|
relief=tk.NONE,
|
|
|
|
font=("TkDefaultFont", 8, "normal"),
|
|
|
|
)
|
|
|
|
style.configure(
|
|
|
|
Styles.yellow_alert,
|
|
|
|
background="yellow",
|
|
|
|
padding=0,
|
|
|
|
relief=tk.NONE,
|
|
|
|
font=("TkDefaultFont", 8, "normal"),
|
|
|
|
)
|
|
|
|
style.configure(
|
|
|
|
Styles.red_alert,
|
|
|
|
background="red",
|
|
|
|
padding=0,
|
|
|
|
relief=tk.NONE,
|
|
|
|
font=("TkDefaultFont", 8, "normal"),
|
|
|
|
)
|