Skip to content

Commit 381064d

Browse files
committed
rm dark mode toggle
1 parent 008bbfb commit 381064d

File tree

1 file changed

+17
-40
lines changed

1 file changed

+17
-40
lines changed

gui/main.py

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ def __init__(self, root: tk.Tk):
280280
self.root.geometry("1400x920")
281281
self.root.minsize(1100, 750)
282282
self.history: list[HistoryItem] = []
283-
self.dark_mode = tk.BooleanVar(master=self.root, value=self._detect_dark_mode())
284283
self.preview_visible = tk.BooleanVar(master=self.root, value=True)
285284
self.recent_files: list[str] = []
286285
self.preferences = self._load_preferences()
@@ -292,35 +291,23 @@ def __init__(self, root: tk.Tk):
292291
except Exception:
293292
pass
294293

295-
self._apply_native_theme()
294+
# Build UI first, then apply theme
296295
self._build_ui()
297-
self._apply_theme(self.dark_mode.get())
296+
self._apply_native_theme()
298297
self._setup_keyboard_shortcuts()
299298

300299
# Save window geometry on close
301300
self.root.protocol("WM_DELETE_WINDOW", self._on_close)
302301

303302
def _apply_native_theme(self) -> None:
304-
style = ttk.Style()
305-
if sys.platform == "win32":
306-
for name in ("vista", "xpnative", "winnative"):
307-
if name in style.theme_names():
308-
style.theme_use(name)
309-
return
310-
elif sys.platform == "darwin":
311-
if "aqua" in style.theme_names():
312-
style.theme_use("aqua")
313-
return
314-
style.theme_use(style.theme_use())
315-
316-
def _apply_theme(self, dark: bool) -> None:
303+
"""Apply native OS theme with dark mode detection."""
317304
style = ttk.Style()
318305

319-
# Update appearance based on dark mode preference
320306
if sys.platform == "darwin":
321-
# On macOS, set the appearance mode
307+
# Detect macOS dark mode and apply appearance
308+
dark_mode = self._detect_dark_mode()
322309
try:
323-
appearance = "darkAqua" if dark else "aqua"
310+
appearance = "darkAqua" if dark_mode else "aqua"
324311
self.root.tk.call("::tk::unsupported::MacWindowStyle", "appearance", self.root._w, appearance)
325312
except Exception:
326313
pass
@@ -330,9 +317,11 @@ def _apply_theme(self, dark: bool) -> None:
330317
style.theme_use("aqua")
331318

332319
elif sys.platform == "win32":
333-
# Windows: Use alt theme for dark mode, default theme for light mode
334-
if dark:
335-
# Try to use alt theme which is darker on Windows
320+
# Detect Windows dark mode
321+
dark_mode = self._detect_dark_mode()
322+
323+
if dark_mode:
324+
# Use alt/clam theme for better dark mode support
336325
if "alt" in style.theme_names():
337326
style.theme_use("alt")
338327
elif "clam" in style.theme_names():
@@ -393,20 +382,8 @@ def _apply_theme(self, dark: bool) -> None:
393382
if name in style.theme_names():
394383
style.theme_use(name)
395384
break
396-
397-
# Try to set title bar to light mode
398-
try:
399-
import ctypes
400-
hwnd = ctypes.windll.user32.GetParent(self.root.winfo_id())
401-
DWMWA_USE_IMMERSIVE_DARK_MODE = 20
402-
ctypes.windll.dwmapi.DwmSetWindowAttribute(
403-
hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE,
404-
ctypes.byref(ctypes.c_int(0)), ctypes.sizeof(ctypes.c_int)
405-
)
406-
except Exception:
407-
pass
408385

409-
# Minimal styling - let native theme handle colors
386+
# Apply standard styling
410387
style.configure("Primary.TButton", padding=(PADDING_MEDIUM, PADDING_SMALL))
411388
style.configure("TLabelframe.Label", font=("TkDefaultFont", 10, "bold"))
412389
style.configure("Header.TLabel", font=("TkDefaultFont", 16, "bold"))
@@ -613,7 +590,7 @@ def _show_help(self) -> None:
613590
win.transient(self.root)
614591

615592
# Apply theme based on mode
616-
if self.dark_mode.get():
593+
if self._detect_dark_mode():
617594
win.configure(bg="#2b2d31")
618595
text = tk.Text(win, wrap=tk.WORD, padx=PADDING_MEDIUM, pady=PADDING_MEDIUM,
619596
bg="#2b2d31", fg="#dcddde", insertbackground="#dcddde", borderwidth=0)
@@ -697,7 +674,7 @@ def _show_settings(self) -> None:
697674
settings.grab_set()
698675

699676
# Apply theme colors to toplevel window
700-
if self.dark_mode.get():
677+
if self._detect_dark_mode():
701678
settings.configure(bg="#2b2d31")
702679
else:
703680
settings.configure(bg="SystemButtonFace")
@@ -733,8 +710,8 @@ def _show_settings(self) -> None:
733710
notebook.add(appearance, text="Appearance")
734711

735712
ttk.Label(appearance, text="Theme:").pack(anchor=tk.W, padx=PADDING_MEDIUM, pady=(PADDING_MEDIUM, 0))
736-
ttk.Checkbutton(appearance, text="Dark mode", variable=self.dark_mode,
737-
command=lambda: self._apply_theme(self.dark_mode.get())).pack(anchor=tk.W, padx=PADDING_MEDIUM)
713+
ttk.Label(appearance, text="Using system theme (Light/Dark mode)",
714+
foreground="gray").pack(anchor=tk.W, padx=PADDING_MEDIUM)
738715

739716
# Save button
740717
btn_frame = ttk.Frame(settings)
@@ -2701,7 +2678,7 @@ def _show_text_output(self, text: str) -> None:
27012678
win.geometry("700x400")
27022679

27032680
# Apply theme based on mode
2704-
if self.dark_mode.get():
2681+
if self._detect_dark_mode():
27052682
win.configure(bg="#2b2d31")
27062683
txt = tk.Text(win, wrap=tk.WORD, bg="#1e1f22", fg="#dcddde",
27072684
insertbackground="#dcddde", borderwidth=0, padx=8, pady=8)

0 commit comments

Comments
 (0)