Skip to content

Commit

Permalink
added dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Arne-Weber authored and Windows200000 committed May 21, 2024
1 parent 3ca39b3 commit fa75358
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 33 deletions.
126 changes: 93 additions & 33 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,11 @@ def __init__(
command: abc.Callable[[_T], Any] | None = None,
default: str | None = None,
relief: tk._Relief = "solid",
background: str = "white",
**kwargs: Any,
):
width = max((len(k) for k in options.keys()), default=20)
super().__init__(
master, *args, background=background, relief=relief, width=width, **kwargs
master, *args, relief=relief, width=width, **kwargs
)
self._menu_options: dict[str, _T] = options
self._command = command
Expand Down Expand Up @@ -1499,12 +1498,13 @@ def __init__(self, manager: GUIManager, master: ttk.Widget, root: tk.Tk):
language_frame = ttk.Frame(center_frame2)
language_frame.grid(column=0, row=0)
ttk.Label(language_frame, text="Language 🌐 (requires restart): ").grid(column=0, row=0)
SelectMenu(
self._select_menu = SelectMenu(
language_frame,
default=_.current,
options={k: k for k in _.languages},
command=lambda lang: setattr(self._settings, "language", lang),
).grid(column=1, row=0)
)
self._select_menu.grid(column=1, row=0)
# checkboxes frame
checkboxes_frame = ttk.Frame(center_frame2)
checkboxes_frame.grid(column=0, row=1)
Expand Down Expand Up @@ -2159,45 +2159,105 @@ def print(self, message: str):

def set_theme(root, manager, name):
style = ttk.Style(root)
# Style options
default_font = nametofont("TkDefaultFont")
large_font = default_font.copy()
large_font.config(size=12)
link_font = default_font.copy()
link_font.config(underline=True)

def configure_combobox_list(combobox, flag, value):
combobox.update_idletasks()
popdown_window = combobox.tk.call("ttk::combobox::PopdownWindow", combobox)
listbox = f"{popdown_window}.f.l"
combobox.tk.call(listbox, "configure", flag, value)

# Style options, !!!"background" and "bg" is not interchangable for some reason!!!
match name:
case "dark":
style.theme_use('alt')
style.configure('.', background="#181818", foreground="#ffffff")
style.configure("TButton", background="#181818")
bg_grey = "#181818"
active_grey = "#2b2b2b"
# General
style.theme_use('alt') # We have to switch the theme, because OS-defaults ("vista") don't support certain customisations, like Treeview-fieldbackground etc.
style.configure('.', background=bg_grey, foreground="white")
style.configure("Link.TLabel", font=link_font, foreground="#00aaff")
# Buttons
style.map("TButton",
background=[("active", "#2b2b2b")],
foreground=[("pressed", "black")])
style.configure("TNotebook.Tab", background="#181818")
background=[("active", active_grey)])
# Tabs
style.configure("TNotebook.Tab", background=bg_grey)
style.map("TNotebook.Tab",
background=[("selected", "#2b2b2b")])
style.configure("TCheckbutton", foreground="black")
background=[("selected", active_grey)])
# Checkboxes
style.configure("TCheckbutton", foreground="black") # The checkbox has to be white since it's an image, so the tick has to be black
style.map("TCheckbutton",
background=[('active', '#2b2b2b')])
style.configure("TLabelFrame", background="#181818")
manager.output._text.configure(bg="#181818")
manager.settings._exclude_list.configure(bg="#181818", fg="#ffffff")
manager.settings._priority_list.configure(bg="#181818", fg="#ffffff")



case "light" | "default" | _ : # TEMP RETURN VALUES
background=[('active', active_grey)])
# Output field
manager.output._text.configure(bg=bg_grey, fg="white", selectbackground=active_grey)
# Include/Exclude lists
manager.settings._exclude_list.configure(bg=bg_grey, fg="white")
manager.settings._priority_list.configure(bg=bg_grey, fg="white")
# Channel list
style.configure('Treeview', background=bg_grey, fieldbackground=bg_grey)
manager.channels._table
# Inventory
manager.inv._canvas.configure(bg=bg_grey)
# Scroll bars
style.configure("TScrollbar", foreground="white", troughcolor=bg_grey, bordercolor=bg_grey, arrowcolor="white")
style.map("TScrollbar",
background=[("active", bg_grey), ("!active", bg_grey)])
# Language selection box _select_menu
manager.settings._select_menu.configure(bg=bg_grey, fg="white", activebackground=active_grey, activeforeground="white") # Couldn't figure out how to change the border, so it stays black
for index in range(manager.settings._select_menu.menu.index("end")+1):
manager.settings._select_menu.menu.entryconfig(index, background=bg_grey, activebackground=active_grey, foreground="white")
# Proxy field
style.configure("TEntry", foreground="white", selectbackground=active_grey, fieldbackground=bg_grey)
# Include/Exclude box
style.configure("TCombobox", foreground="white", selectbackground=active_grey, fieldbackground=bg_grey, arrowcolor="white")
style.map("TCombobox", background=[("active", active_grey), ("disabled", bg_grey)])
# Include list
configure_combobox_list(manager.settings._priority_entry, "-background", bg_grey)
configure_combobox_list(manager.settings._priority_entry, "-foreground", "white")
configure_combobox_list(manager.settings._priority_entry, "-selectbackground", active_grey)
# Exclude list
configure_combobox_list(manager.settings._exclude_entry, "-background", bg_grey)
configure_combobox_list(manager.settings._exclude_entry, "-foreground", "white")
configure_combobox_list(manager.settings._exclude_entry, "-selectbackground", active_grey)

case "light" | "default" | _ : # When creating a new theme, additional values might need to be set, so the default theme remains consistent
# General
style.theme_use('vista')
style.configure('.', background="#ffffff", foreground="#000000")
style.configure("TButton", background="#ffffff")
style.configure('.', background="#f0f0f0", foreground="#000000")
# Buttons
style.map("TButton",
background=[("active", "#e0e0e0")],
foreground=[("pressed", "black")])
style.configure("TNotebook.Tab", background="#ffffff")
background=[("active", "#ffffff")])
# Tabs
style.configure("TNotebook.Tab", background="#f0f0f0")
style.map("TNotebook.Tab",
background=[("selected", "#e0e0e0")])
style.configure("TCheckbutton", foreground="black")
style.map("TCheckbutton",
background=[('active', '#e0e0e0')])
style.configure("TLabelFrame", background="#ffffff")
manager.output._text.configure(bg="#ffffff")
background=[("selected", "#ffffff")])
# Checkboxes don't need to be reverted
# Output field
manager.output._text.configure(bg="#ffffff", fg="#000000")
# Include/Exclude lists
manager.settings._exclude_list.configure(bg="#ffffff", fg="#000000")
manager.settings._priority_list.configure(bg="#ffffff", fg="#000000")
# Channel list doesn't need to be reverted
# Inventory
manager.inv._canvas.configure(bg="#f0f0f0")
# Scroll bars don't need to be reverted
# Language selection box _select_menu
manager.settings._select_menu.configure(bg="#ffffff", fg="black", activebackground="#f0f0f0", activeforeground="black") # Couldn't figure out how to change the border, so it stays black
for index in range(manager.settings._select_menu.menu.index("end")+1):
manager.settings._select_menu.menu.entryconfig(index, background="#f0f0f0", activebackground="#0078d7", foreground="black")
# Proxy field doesn't need to be reverted
# Include/Exclude dropdown - Only the lists have to be reverted
# Include list
configure_combobox_list(manager.settings._priority_entry, "-background", "white")
configure_combobox_list(manager.settings._priority_entry, "-foreground", "black")
configure_combobox_list(manager.settings._priority_entry, "-selectbackground", "#0078d7")
# Exclude list
configure_combobox_list(manager.settings._exclude_entry, "-background", "white")
configure_combobox_list(manager.settings._exclude_entry, "-foreground", "black")
configure_combobox_list(manager.settings._exclude_entry, "-selectbackground", "#0078d7")


###################
Expand Down
3 changes: 3 additions & 0 deletions patch_notes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## v15.3.0
### 22.5.2024
- Completed dark mode 🎉

### 20.5.2024
- Added incomplete dark mode

Expand Down

0 comments on commit fa75358

Please sign in to comment.