Skip to content

Commit

Permalink
Merge development branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Valer100 authored Aug 19, 2024
2 parents ad9fc2b + 26fa2fe commit 7690992
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,21 @@ print(winaccent.accent_light) # Prints the light mode accent color

### Update accent colors

The accent colors can be updated using the ```update_accent_colors()``` function. This function will retrieve the values again.
The accent colors can be updated manually using the ```update_accent_colors()``` function. This function will retrieve the values again.

### Accent color change listener
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:

```python
import winaccent, threading

# Replace `callback` with the function that you want to be called
thread = threading.Thread(target = lambda: winaccent.on_accent_changed_listener(callback), daemon = True)
thread.start()
```

> [!NOTE]
> 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.
## 🖥️ Output
Here is the output for the default (blue) accent color on Windows 11:
Expand All @@ -53,4 +67,4 @@ Here is the output for a custom accent color (green):
| accent_normal | #008B00 | <img src="https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_normal_green.png?raw=true"> |

## 📋 To do
- [ ] Add an accent color change listener
- [x] ~~Add an accent color change listener~~
7 changes: 4 additions & 3 deletions demo_gui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tkinter as tk, winaccent
import tkinter as tk, winaccent, threading
from tkinter import ttk

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

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

update_accent_colors()

thread = threading.Thread(target = lambda: winaccent.on_accent_changed_listener(update_accent_colors), daemon = True)
thread.start()

window.mainloop()
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name = "winaccent",
version = "0.2.0",
version = "0.3.0",
license = "MIT",
author = "Valer100",
description = "A simple module for getting Windows' accent color",
Expand Down
10 changes: 9 additions & 1 deletion winaccent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
A simple module for getting Windows' accent color. With this module you can get both light and dark mode accent colors.
'''

import winreg, sys
import winreg, sys, time

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

def on_accent_changed_listener(callback):
while True:
old_value = accent_normal
update_accent_colors()

if old_value != accent_normal: callback()
time.sleep(1)

update_accent_colors()

0 comments on commit 7690992

Please sign in to comment.