From 67f87e083090537c0c149c34df250a32faea84e3 Mon Sep 17 00:00:00 2001 From: Profitroll <47523801+profitrollgame@users.noreply.github.com> Date: Sun, 22 Jan 2023 00:35:32 +0100 Subject: [PATCH] Improved naming and imports --- classes/app.py | 15 ++++++----- classes/frames.py | 3 ++- classes/window_config.py | 14 +++++----- .../{dark_titlebar.py => theme_titlebar.py} | 27 ++++++++++--------- modules/utils.py | 4 ++- 5 files changed, 37 insertions(+), 26 deletions(-) rename modules/{dark_titlebar.py => theme_titlebar.py} (51%) diff --git a/classes/app.py b/classes/app.py index e3bb6fd..9f41f7b 100644 --- a/classes/app.py +++ b/classes/app.py @@ -1,12 +1,15 @@ +from os import path +from tkinter import NW, E, N, S, W, messagebox, ttk + import requests import sv_ttk -from os import path -from tkinter import ttk, messagebox, N, S, W, E, NW from ttkthemes import ThemedTk -from modules.dark_titlebar import dark_title_bar -from modules.utils import configGet, use_dark_mode -from classes.window_config import WindowConfig + from classes.frames import FrameDevices, FrameSaves, FrameSettings +from classes.window_config import WindowConfig +from modules.theme_titlebar import theme_title_bar +from modules.utils import configGet, use_dark_mode + class App(ThemedTk): @@ -32,7 +35,7 @@ class App(ThemedTk): if use_dark_mode(): self.configure(background="#1c1c1c") - dark_title_bar(self, mode="dark") + theme_title_bar(self, mode="dark") sv_ttk.set_theme("dark") else: sv_ttk.set_theme("light") diff --git a/classes/frames.py b/classes/frames.py index 3741c33..e5e92c0 100644 --- a/classes/frames.py +++ b/classes/frames.py @@ -1,4 +1,5 @@ -from tkinter import ttk, NS, EW +from tkinter import EW, NS, ttk + from ttkthemes import ThemedTk diff --git a/classes/window_config.py b/classes/window_config.py index cf54f71..6612e13 100644 --- a/classes/window_config.py +++ b/classes/window_config.py @@ -1,10 +1,12 @@ -import time -import requests from os import path -from tkinter import ttk, messagebox, IntVar, Toplevel, N, S, W, E, END -from modules.dark_titlebar import dark_title_bar -from modules.utils import configGet, configSet, use_dark_mode +from tkinter import END, E, IntVar, N, S, Toplevel, W, messagebox, ttk + +import requests + +from modules.theme_titlebar import theme_title_bar from modules.logger import logger +from modules.utils import configGet, configSet, use_dark_mode + class WindowConfig(Toplevel): @@ -28,7 +30,7 @@ class WindowConfig(Toplevel): self.focus_set() if use_dark_mode() is True: - dark_title_bar(self, "dark") + theme_title_bar(self, "dark") self.columnconfigure(0, weight=1) self.columnconfigure(1, weight=3) diff --git a/modules/dark_titlebar.py b/modules/theme_titlebar.py similarity index 51% rename from modules/dark_titlebar.py rename to modules/theme_titlebar.py index 45d4fdd..391c78d 100644 --- a/modules/dark_titlebar.py +++ b/modules/theme_titlebar.py @@ -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: diff --git a/modules/utils.py b/modules/utils.py index d543d14..811813c 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -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: