Skip to content

Commit 7690992

Browse files
authored
Merge development branch
2 parents ad9fc2b + 26fa2fe commit 7690992

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,21 @@ print(winaccent.accent_light) # Prints the light mode accent color
3232

3333
### Update accent colors
3434

35-
The accent colors can be updated using the ```update_accent_colors()``` function. This function will retrieve the values again.
35+
The accent colors can be updated manually using the ```update_accent_colors()``` function. This function will retrieve the values again.
36+
37+
### Accent color change listener
38+
This module allows you to add a listener that will call a specific function when the accent color changes. Here's how you can add it:
39+
40+
```python
41+
import winaccent, threading
42+
43+
# Replace `callback` with the function that you want to be called
44+
thread = threading.Thread(target = lambda: winaccent.on_accent_changed_listener(callback), daemon = True)
45+
thread.start()
46+
```
47+
48+
> [!NOTE]
49+
> If you added the listener, there's no need to call `update_accent_colors` because it will be called automatically every time the accent color changes.
3650
3751
## 🖥️ Output
3852
Here is the output for the default (blue) accent color on Windows 11:
@@ -53,4 +67,4 @@ Here is the output for a custom accent color (green):
5367
| accent_normal | #008B00 | <img src="https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_normal_green.png?raw=true"> |
5468

5569
## 📋 To do
56-
- [ ] Add an accent color change listener
70+
- [x] ~~Add an accent color change listener~~

demo_gui.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import tkinter as tk, winaccent
1+
import tkinter as tk, winaccent, threading
22
from tkinter import ttk
33

44
window = tk.Tk()
@@ -24,8 +24,9 @@ def update_accent_colors():
2424
add_item(winaccent.accent_dark, "Dark mode accent color")
2525
add_item(winaccent.accent_normal, "Normal accent color")
2626

27-
ttk.Button(window, text = "Refresh", command = update_accent_colors, default = "active").pack(fill = "x", pady = 8, padx = 5)
28-
2927
update_accent_colors()
3028

29+
thread = threading.Thread(target = lambda: winaccent.on_accent_changed_listener(update_accent_colors), daemon = True)
30+
thread.start()
31+
3132
window.mainloop()

requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name = "winaccent",
7-
version = "0.2.0",
7+
version = "0.3.0",
88
license = "MIT",
99
author = "Valer100",
1010
description = "A simple module for getting Windows' accent color",

winaccent/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
A simple module for getting Windows' accent color. With this module you can get both light and dark mode accent colors.
33
'''
44

5-
import winreg, sys
5+
import winreg, sys, time
66

77
if not sys.platform == "win32" or not sys.getwindowsversion().major == 10:
88
raise Exception("This module only works on Windows 10 and later!")
@@ -27,4 +27,12 @@ def update_accent_colors():
2727
dwm = "Software\\Microsoft\\Windows\\DWM"
2828
accent_normal = f"#{get_registry_value(winreg.HKEY_CURRENT_USER, f'{dwm}', 'ColorizationAfterglow'): X}".replace("# C4", "#")
2929

30+
def on_accent_changed_listener(callback):
31+
while True:
32+
old_value = accent_normal
33+
update_accent_colors()
34+
35+
if old_value != accent_normal: callback()
36+
time.sleep(1)
37+
3038
update_accent_colors()

0 commit comments

Comments
 (0)