Improved naming and imports
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
import ctypes
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
import tkinter
|
||||
from typing import Literal
|
||||
from ctypes import byref, c_int, sizeof, windll
|
||||
from distutils.version import StrictVersion as Version
|
||||
from os import system
|
||||
from tkinter import Tcl, Toplevel
|
||||
from typing import Literal, Union
|
||||
|
||||
def dark_title_bar(window, mode: Literal["dark", "light"]):
|
||||
from ttkthemes import ThemedTk
|
||||
|
||||
|
||||
def theme_title_bar(window: Union[ThemedTk, Toplevel], mode: Literal["dark", "light"]) -> None:
|
||||
"""
|
||||
MORE INFO:
|
||||
https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
|
||||
@@ -25,27 +28,27 @@ def dark_title_bar(window, mode: Literal["dark", "light"]):
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
|
||||
hwnd = ctypes.windll.user32.GetParent(window.winfo_id())
|
||||
hwnd = windll.user32.GetParent(window.winfo_id())
|
||||
DWMWA_USE_IMMERSIVE_DARK_MODE = 20
|
||||
DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19
|
||||
|
||||
# try with DWMWA_USE_IMMERSIVE_DARK_MODE
|
||||
if ctypes.windll.dwmapi.DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, ctypes.byref(ctypes.c_int(value)), ctypes.sizeof(ctypes.c_int(value))) != 0:
|
||||
if windll.dwmapi.DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, byref(c_int(value)), sizeof(c_int(value))) != 0:
|
||||
|
||||
# try with DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20h1
|
||||
ctypes.windll.dwmapi.DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, ctypes.byref(ctypes.c_int(value)), ctypes.sizeof(ctypes.c_int(value)))
|
||||
windll.dwmapi.DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, byref(c_int(value)), sizeof(c_int(value)))
|
||||
|
||||
elif sys.platform == "darwin":
|
||||
|
||||
if value == 1:
|
||||
if Version(platform.python_version()) < Version("3.10"):
|
||||
if Version(tkinter.Tcl().call("info", "patchlevel")) >= Version("8.6.9"): # Tcl/Tk >= 8.6.9
|
||||
os.system("defaults write -g NSRequiresAquaSystemAppearance -bool No")
|
||||
if Version(Tcl().call("info", "patchlevel")) >= Version("8.6.9"): # Tcl/Tk >= 8.6.9
|
||||
system("defaults write -g NSRequiresAquaSystemAppearance -bool No")
|
||||
# This command allows dark-mode for all programs
|
||||
else:
|
||||
if Version(platform.python_version()) < Version("3.10"):
|
||||
if Version(tkinter.Tcl().call("info", "patchlevel")) >= Version("8.6.9"): # Tcl/Tk >= 8.6.9
|
||||
os.system("defaults delete -g NSRequiresAquaSystemAppearance")
|
||||
if Version(Tcl().call("info", "patchlevel")) >= Version("8.6.9"): # Tcl/Tk >= 8.6.9
|
||||
system("defaults delete -g NSRequiresAquaSystemAppearance")
|
||||
# This command reverts the dark-mode setting for all programs.
|
||||
|
||||
except Exception as err:
|
@@ -1,7 +1,9 @@
|
||||
from json import JSONDecodeError, loads, dumps
|
||||
from json import JSONDecodeError, dumps, loads
|
||||
from typing import Any
|
||||
|
||||
import darkdetect
|
||||
|
||||
|
||||
def jsonLoad(filename):
|
||||
"""Loads arg1 as json and returns its contents"""
|
||||
with open(filename, "r", encoding='utf8') as file:
|
||||
|
Reference in New Issue
Block a user